PathMotion.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
using namespace RSI::RapidCode;
void pathMotionMain()
{
Axis *axisX;
Axis *axisY;
MultiAxis *multiAxisXY;
const int AXIS_X = 0;
const int AXIS_Y = 1;
double line_A[2] = { 0, 1000 };
double line_B[2] = { 1000,1000 };
double line_C[2] = { 1000, 0 };
double line_D[2] = { 0, 0 };
double arc_center[2] = { 1000,1000 };
// Create and initialize RsiController class
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
SampleAppsCPP::HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
// enable one MotionSupervisor for the MultiAxis
controller->MotionCountSet(controller->AxisCountGet() + 1);
// Get Axis X and Y respectively.
axisX = controller->AxisGet(AXIS_X);
SampleAppsCPP::HelperFunctions::CheckErrors(axisX);
axisY = controller->AxisGet(AXIS_Y);
SampleAppsCPP::HelperFunctions::CheckErrors(axisY);
// Initialize a MultiAxis, using the last MotionSupervisor.
multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
SampleAppsCPP::HelperFunctions::CheckErrors(multiAxisXY);
multiAxisXY->AxisAdd(axisX);
multiAxisXY->AxisAdd(axisY);
// make sure all axes are enabled and ready
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
// set the trajectory info
multiAxisXY->VectorVelocitySet(1000.0);
multiAxisXY->VectorAccelerationSet(10000.0);
multiAxisXY->VectorDecelerationSet(10000.0);
// start path list
double start_positions[2] = { axisX->CommandPositionGet(),axisY->CommandPositionGet() };
multiAxisXY->PathListStart(start_positions);
// turn on blending (smooth corners)
multiAxisXY->PathBlendSet(true);
// an X-Y circle
multiAxisXY->PathArcAdd(arc_center, 360.0);
// a rectangle
multiAxisXY->PathLineAdd(line_A);
multiAxisXY->PathLineAdd(line_B);
multiAxisXY->PathLineAdd(line_C);
multiAxisXY->PathLineAdd(line_D);
// end path list
multiAxisXY->PathListEnd();
// execute the motion
multiAxisXY->PathMotionStart();
// wait for motion to complete
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.
}