The RMP Motion Controller APIs
PVTmotionMultiAxis.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
void PVTmotionMultiAxisMain()
{
using namespace RSI::RapidCode;
const int AXIS_X = (0);
const int AXIS_Y = (1);
const int POINTS = (3000); //total points used
const int AXIS_COUNT = (2); //two axis computation (X & Y)
const double TIME_SLICE = (0.01); //each point processed within 10ms
const int USER_UNITS = 1; // Specify USER UNITS
char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
// Initialize MotionController class.
MotionController *controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
HelperFunctions::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
try
{
HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
controller->AxisCountSet(2); // Set the number of axis being used. A phantom axis will be created if for any axis not on the network. You may need to refresh rapid setup to see the phantom axis.
MultiAxis *multiAxisXY;
Axis *axisX = controller->AxisGet(AXIS_X); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
Axis *axisY = controller->AxisGet(AXIS_Y); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
HelperFunctions::CheckErrors(axisX); // [Helper Function] Check that the axis has been initialize correctly.
HelperFunctions::CheckErrors(axisY); // [Helper Function] Check that the axis has been initialize correctly.
axisX->UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
axisY->UserUnitsSet(USER_UNITS); // Specify the counts per Unit.
// enable one MotionSupervisor for the MultiAxis
//controller->MotionCountSet(controller->AxisCountGet() + 1);
// Get Axis X and Y respectively.
axisX = controller->AxisGet(AXIS_X);
axisY = controller->AxisGet(AXIS_Y);
// Initialize a MultiAxis, using the last MotionSupervisor.
multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
multiAxisXY->AxisAdd(axisX);
multiAxisXY->AxisAdd(axisY);
long radius = 1000; //radius of circle
double PI = 3.14159265358979323; //variable used in equation to convert degrees to radians
double degrees = 90.00 / (POINTS); //angle between each point. Used in the equation below.
double position[POINTS * AXIS_COUNT]; //defining size of position array
double vel[POINTS * AXIS_COUNT]; //defining size of velocity array
double time[POINTS]; //defining size of time array
for (int i = 0, x = 0, y = 1; i < POINTS; i++)
{
position[x] = (radius*cos((i + 1)*degrees*PI / 180.0));
position[y] = (radius*sin((i + 1)*degrees*PI / 180.0));
x = x + 2;
y = y + 2;
time[i] = TIME_SLICE;
}
for (int i = 0, x = 0, y = 1; i < (POINTS - 1); i++)
{
vel[x] = (position[x + 2] - position[x]) / TIME_SLICE;
vel[y] = (position[y + 2] - position[y]) / TIME_SLICE;
x = x + 2;
y = y + 2;
}
//Final two points (X Axis Final Vel, Y Axis Final Vel) need to be set to 0.
vel[(POINTS * 2) - 2] = 0; //X Axis
vel[(POINTS * 2) - 1] = 0; //Y Axis
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->PositionSet(radius);
axisY->PositionSet(0);
multiAxisXY->MovePVT(position, vel, time, POINTS, -1, false, true);
multiAxisXY->MotionDoneWait();
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text);
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
system("pause"); // Allow time to read Console.
}
RSI::RapidCode::MultiAxis::AxisAdd
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
RSI::RapidCode::MultiAxis
The MultiAxis object allows you to map two or more axes together and command synchronized motion.
Definition: rsi.h:11031
RSI::RapidCode::MotionController::AxisCountSet
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
RSI::RapidCode::RapidCodeMotion::ClearFaults
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
RSI::RapidCode::RsiError
The RsiError object contains information about any RapidCode API object's error/exception.
Definition: rsi.h:93
RSI::RapidCode::MotionController::Delete
void Delete(void)
Delete the MotionController and all its objects.
RSI::RapidCode::MotionController::CreateFromSoftware
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
RSI::RapidCode
RSI::RapidCode::MotionController::AxisGet
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSI::RapidCode::Axis::PositionSet
void PositionSet(double position)
Set the Command and Actual positions.
RSI::RapidCode::RapidCodeMotion::Abort
void Abort()
Abort an axis.
RSI::RapidCode::Axis::UserUnitsSet
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
RSI::RapidCode::MotionController
The MotionController object represents the RMP INtime soft motion controller.
Definition: rsi.h:747
RSI::RapidCode::RapidCodeMotion::MovePVT
void MovePVT(const double *const position, const double *const velocity, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
Move commanded by list of positions, velocities, and times.
RSI::RapidCode::Axis
The Axis object manages a single physical axis on a motion controller.
Definition: rsi.h:5887
RSI::RapidCode::RapidCodeMotion::AmpEnableSet
void AmpEnableSet(bool enable)
Enable all amplifiers.
HelperFunctions.CheckErrors
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCode Object has any errors.
Definition: HelperFunctions.cs:64
HelperFunctions.StartTheNetwork
static void StartTheNetwork(MotionController controller)
Start the controller communication/network.
Definition: HelperFunctions.cs:109
RSI::RapidCode::RapidCodeMotion::MotionDoneWait
int32_t MotionDoneWait()
Waits for a move to complete.
RSI::RapidCode::MotionController::MultiAxisGet
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
RSI::RapidCode::MotionController::MotionCountGet
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.