The RMP Motion Controller API
PathMotion.cpp
#include <iostream>
#include <fstream>
#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;
const double UserUnits = 600000;
double running_x = 0;
double running_y = 0;
double line_A[2] = { running_x, running_y };
running_x += -5.746;
double line_B[2] = { running_x, running_y };
running_y += -2.537;
double line_C[2] = { running_x, running_y };
running_x += 1.025;
double line_D[2] = { running_x, running_y };
//curve down
running_y += (-0.525);
double arc_center_A[2] = { running_x,running_y };
running_x += (0.525);
running_y += -1.875;
double line_E[2] = { running_x, running_y };
//curve left
running_x += -0.525;
double arc_center_B[2] = { running_x,running_y };
running_y += -0.525;
running_x += -2.07;
double line_F[2] = { running_x, running_y };
//curve up
running_y += 0.525;
double arc_center_C[2] = { running_x,running_y };
running_x += -0.525;
running_y += 1.875;
double line_G[2] = { running_x, running_y };
//curve right
running_x += 0.525;
double arc_center_D[2] = { running_x,running_y };
running_y += 0.525;
running_x += 1.02;
double line_H[2] = { running_x, running_y };
running_y += 2.538;
double line_I[2] = { running_x, running_y };
running_x += -1.581;
double line_J[2] = { running_x, running_y };
running_x += -0.47;
running_y += -0.471;
double line_K[2] = { running_x, running_y };
// Create and initialize RsiController class
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
controller->MotionCountSet(0);
controller->AxisCountSet(0);
controller->MotionCountSet(3);
controller->AxisCountSet(2);
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);
axisY = controller->AxisGet(AXIS_Y);
// Initialize a MultiAxis, using the last MotionSupervisor.
multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
axisX->Abort();
axisY->Abort();
multiAxisXY->AxisAdd(axisX);
multiAxisXY->AxisAdd(axisY);
SampleAppsCPP::HelperFunctions::CheckErrors(multiAxisXY);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->UserUnitsSet(UserUnits);
//axisX->ErrorLimitTriggerValueSet(1);
axisX->Abort();
axisX->ClearFaults();
axisX->AmpEnableSet(true);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->Home();
axisY->UserUnitsSet(UserUnits);
//axisY->ErrorLimitTriggerValueSet(1);
axisY->Abort();
axisY->ClearFaults();
axisY->AmpEnableSet(true);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisY->Home();
//axisX->UserUnitsSet(1000);
axisX->UserUnitsSet(UserUnits);
//axisY->UserUnitsSet(1000);
axisY->UserUnitsSet(UserUnits);
SampleAppsCPP::HelperFunctions::CheckErrors(axisX);
SampleAppsCPP::HelperFunctions::CheckErrors(axisY);
// set the trajectory info
multiAxisXY->VectorVelocitySet(5.0 * UserUnits);
multiAxisXY->VectorAccelerationSet(10.0 * UserUnits);
multiAxisXY->VectorDecelerationSet(10.0 * UserUnits);
// start path list
double start_positions[2] = { axisX->CommandPositionGet(),axisY->CommandPositionGet() };
multiAxisXY->PathListStart(start_positions);
multiAxisXY->ClearFaults();
// turn on blending (smooth corners)
multiAxisXY->PathBlendSet(true);
// Lines and arcs
multiAxisXY->PathLineAdd(line_A);
multiAxisXY->PathLineAdd(line_B);
multiAxisXY->PathLineAdd(line_C);
multiAxisXY->PathLineAdd(line_D);
multiAxisXY->PathArcAdd(arc_center_A, -90.0);
multiAxisXY->PathLineAdd(line_E);
multiAxisXY->PathArcAdd(arc_center_B, -90.0);
multiAxisXY->PathLineAdd(line_F);
multiAxisXY->PathArcAdd(arc_center_C, -90.0);
multiAxisXY->PathLineAdd(line_G);
multiAxisXY->PathArcAdd(arc_center_D, -90.0);
multiAxisXY->PathLineAdd(line_H);
multiAxisXY->PathLineAdd(line_I);
multiAxisXY->PathLineAdd(line_J);
multiAxisXY->PathLineAdd(line_K);
// end path list
multiAxisXY->PathListEnd();
// make sure all axes are enabled and ready
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
// execute the motion
multiAxisXY->PathMotionStart();
// log positions
std::ofstream myfile;
myfile.open("path.csv");
myfile << "samples,x,y,\n";
while (!multiAxisXY->MotionDoneGet()) {
myfile << controller->SampleCounterGet() << "," << axisX->CommandPositionGet() << "," << axisY->CommandPositionGet() << ",\n";
controller->SampleWait(10);
}
// wait for motion to complete
multiAxisXY->MotionDoneWait();
myfile.close();
printf("path.csv");
}
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.
}