The RMP Motion Controller APIs
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
try
{
controller->MotionCountSet(0);
controller->AxisCountSet(0);
controller->MotionCountSet(3);
controller->AxisCountSet(2);
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);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->UserUnitsSet(UserUnits);
//axisX->ErrorLimitTriggerValueSet(1);
axisX->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
axisX->Abort();
axisX->ClearFaults();
axisX->AmpEnableSet(true);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->Home();
axisY->UserUnitsSet(UserUnits);
//axisY->ErrorLimitTriggerValueSet(1);
axisY->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
axisY->Abort();
axisY->ClearFaults();
axisY->AmpEnableSet(true);
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisY->Home();
axisX->ErrorLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
//axisX->UserUnitsSet(1000);
axisX->AmpDisableActionSet(RSI::RapidCode::RSIMotorDisableAction::RSIMotorDisableActionNONE);
axisX->SoftwareNegLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
axisX->SoftwarePosLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
axisX->UserUnitsSet(UserUnits);
axisY->ErrorLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
//axisY->UserUnitsSet(1000);
axisY->AmpDisableActionSet(RSI::RapidCode::RSIMotorDisableAction::RSIMotorDisableActionNONE);
axisY->SoftwareNegLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
axisY->SoftwarePosLimitActionSet(RSI::RapidCode::RSIAction::RSIActionNONE);
axisY->UserUnitsSet(UserUnits);
// 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.
}
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:11232
RSI::RapidCode::MultiAxis::VectorVelocitySet
void VectorVelocitySet(double velocity)
Set the vector velocity.
RSI::RapidCode::MotionController::SampleWait
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
RSI::RapidCode::MultiAxis::PathListStart
void PathListStart(const double *const startPosition)
Start a line and arc point list for path motion.
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:100
RSI::RapidCode::Axis::HomeMethodSet
void HomeMethodSet(RSIHomeMethod method)
Set the method to be used for homing.
RSI::RapidCode::Axis::SoftwarePosLimitActionSet
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
RSI::RapidCode::MotionController::Delete
void Delete(void)
Delete the MotionController and all its objects.
RSI::RapidCode::RapidCodeMotion::MotionDoneGet
bool MotionDoneGet()
Check to see if motion is done and settled.
RSI::RapidCode::MotionController::CreateFromSoftware
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
RSI::RapidCode::MultiAxis::PathMotionStart
void PathMotionStart()
Start the path motion.
RSI::RapidCode
RSI::RapidCode::MultiAxis::PathBlendSet
void PathBlendSet(bool blend)
Set the blending attribute.
RSI::RapidCode::MotionController::AxisGet
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSI::RapidCode::Axis::SoftwareNegLimitActionSet
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
RSI::RapidCode::RapidCodeMotion::Abort
void Abort()
Abort an axis.
RSI::RapidCode::MultiAxis::VectorAccelerationSet
void VectorAccelerationSet(double acceleration)
Set the vector acceleration.
RSI::RapidCode::Axis::UserUnitsSet
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
RSI::RapidCode::Axis::CommandPositionGet
double CommandPositionGet()
Get the current command position.
RSI::RapidCode::Axis::Home
void Home()
Execute the homing routine.
RSI::RapidCode::MultiAxis::PathListEnd
void PathListEnd()
End a line and arc point list for path motion.
RSI::RapidCode::MotionController
The MotionController object represents the RMP INtime soft motion controller.
Definition: rsi.h:765
RSI::RapidCode::Axis::ErrorLimitActionSet
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
RSI::RapidCode::MultiAxis::VectorDecelerationSet
void VectorDecelerationSet(double deceleration)
Set the vector deceleration.
RSI::RapidCode::MotionController::SampleCounterGet
int32_t SampleCounterGet()
Get the current value of the controller's processor's sample counter.
RSI::RapidCode::MotionController::MotionCountSet
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
RSI::RapidCode::Axis
The Axis object manages a single physical axis on a motion controller.
Definition: rsi.h:6079
RSI::RapidCode::MultiAxis::PathArcAdd
void PathArcAdd(const double *const center, double angle)
Add an arc segment to the path.
RSI::RapidCode::RapidCodeMotion::AmpEnableSet
void AmpEnableSet(bool enable)
Enable all amplifiers.
RSI::RapidCode::Axis::AmpDisableActionSet
void AmpDisableActionSet(RSIMotorDisableAction action)
Set the Amp Disable action.
HelperFunctions.CheckErrors
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCode Object has any errors.
Definition: HelperFunctions.cs:64
RSI::RapidCode::MultiAxis::PathLineAdd
void PathLineAdd(const double *const position)
Add a line segment to the path.
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.
RSI::RapidCode::MotionController::AxisCountGet
int32_t AxisCountGet()
Get the number of axes processing.