The RMP Motion Controller APIs
PathMotion.cpp
#include <iostream>
#include <fstream>
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctionsCpp.h" // Import our SampleApp helper functions.
#include "SampleApps.h"
using namespace RSI::RapidCode;
int PathMotion::Run()
{
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
// Axis configuration parameters
const int AXIS_COUNT = (2);
const int AXIS_X = 0;
const int AXIS_Y = 1;
const double USER_UNITS = 1048576;
// Default file path for recording the path followed by the axes
const char* const PATH_MOTION_FILEPATH = "PathMotion.csv";
// To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
USE_HARDWARE = false;
/* SAMPLE APP BODY */
Axis* axisX;
Axis* axisY;
MultiAxis* multiAxisXY;
double running_x = 0;
double running_y = 0;
double line_A[2] = { running_x, running_y };
running_x += -0.5;
double line_B[2] = { running_x, running_y };
running_y += -0.5;
double line_C[2] = { running_x, running_y };
//curve down
running_y += (-0.25);
double arc_center_A[2] = { running_x,running_y };
running_x += (0.25);
//curve left
running_x += -0.25;
double arc_center_B[2] = { running_x,running_y };
running_y += -0.25;
//curve up
running_y += 0.25;
double arc_center_C[2] = { running_x,running_y };
running_x += -0.25;
//curve right
running_x += 0.25;
double arc_center_D[2] = { running_x,running_y };
running_y += 0.25;
running_x += -0.5;
running_y += 0.5;
double line_D[2] = { running_x, running_y };
// Create and initialize RsiController class
MotionController* controller = MotionController::CreateFromSoftware();
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
HelperFunctionsCpp::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_X, AXIS_Y });
}
try
{
// enable one MotionSupervisor for the MultiAxis
controller->MotionCountSet(controller->AxisCountGet() + 1);
// Get Axis X and Y respectively.
Axis* axisX = controller->AxisGet(AXIS_X);
axisX->PositionSet(0);
axisX->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
axisX->ErrorLimitActionSet(RSIAction::RSIActionNONE);
axisX->UserUnitsSet(USER_UNITS);
axisX->Abort();
Axis* axisY = controller->AxisGet(AXIS_Y);
axisY->PositionSet(0);
axisY->HomeMethodSet(RSIHomeMethod::RSIHomeMethodCURRENT_POSITION);
axisY->ErrorLimitActionSet(RSIAction::RSIActionNONE);
axisY->UserUnitsSet(USER_UNITS);
axisY->Abort();
// Initialize a MultiAxis, using the last MotionSupervisor.
MultiAxis* multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
multiAxisXY->AxisAdd(axisX);
multiAxisXY->AxisAdd(axisY);
// make sure all axes are enabled and ready
multiAxisXY->Abort();
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
axisX->Home();
axisY->Home();
multiAxisXY->AmpEnableSet(false);
// set the trajectory info
multiAxisXY->VectorVelocitySet(1.0 * USER_UNITS);
multiAxisXY->VectorAccelerationSet(10.0 * USER_UNITS);
multiAxisXY->VectorDecelerationSet(10.0 * USER_UNITS);
// 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->PathArcAdd(arc_center_A, -90.0);
multiAxisXY->PathArcAdd(arc_center_B, -90.0);
multiAxisXY->PathArcAdd(arc_center_C, -90.0);
multiAxisXY->PathArcAdd(arc_center_D, -90.0);
multiAxisXY->PathLineAdd(line_D);
// 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_MOTION_FILEPATH);
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();
multiAxisXY->AmpEnableSet(false);
myfile.close();
printf("\n%s\n", PATH_MOTION_FILEPATH);
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text);
return -1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.
double CommandPositionGet()
Get the current command position.
void AmpDisableActionSet(RSIMotorDisableAction action)
Set the Amp Disable action.
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void Home()
Execute the homing routine.
void HomeMethodSet(RSIHomeMethod method)
Set the method to be used for homing.
void PositionSet(double position)
Set the Command and Actual positions.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5664
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MotionCountSet(int32_t motionCount)
Set the number of processed Motion Supervisors in the controller.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void Delete(void)
Delete the MotionController and all its objects.
int32_t SampleCounterGet()
Get the current value of the controller's processor's sample counter.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:762
void PathListStart(const double *const startPosition)
Start a line and arc point list for path motion.
void PathMotionStart()
Start the path motion.
void PathArcAdd(const double *const center, double angle)
Add an arc segment to the path.
void VectorDecelerationSet(double deceleration)
Set the vector deceleration.
void PathLineAdd(const double *const position)
Add a line segment to the path.
void PathBlendSet(bool blend)
Set the blending attribute.
void VectorAccelerationSet(double acceleration)
Set the vector acceleration.
void PathListEnd()
End a line and arc point list for path motion.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
void VectorVelocitySet(double velocity)
Set the vector velocity.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10564
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
bool MotionDoneGet()
Check to see if motion is done and settled.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:105
@ RSIMotorDisableActionNONE
No action taken when disabled.
@ RSIActionNONE
None - do not perform any action.