APIs, concepts, guides, and more
MultiaxisMotion.cpp
Attention
See the following Concept pages for a detailed explanation of this sample: SCurve Motion.
Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
#include "rsi.h" // Import our RapidCode Library.
#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
#include <conio.h>
#include "SampleApps.h"
using namespace RSI::RapidCode; // Import the RapidCode namespace
/*This function will print all the results to the screen*/
void PrintResult(Axis* axisX, Axis* axisY)
{
printf("Motion Done \n AxisX position-> Commanded: %f \tActual: %f\n",
axisX->ActualPositionGet());
printf(" AxisY position-> Commanded: %f \tActual: %f\n",
axisY->ActualPositionGet());
}
int MultiaxisMotion::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 int MOTION_COUNT = 1;
const double USER_UNITS = 1048576;
// Motion parameters
const double START_POSITION[AXIS_COUNT] = { 0, 0 };
const double END_POSITION[AXIS_COUNT] = { 1, 2 };
const double VELOCITY[AXIS_COUNT] = { 1, 2 };
const double ACCELERATION[AXIS_COUNT] = { 10, 20 };
const double DECELERATION[AXIS_COUNT] = { 10, 20 };
const double JERK_PERCENTAGE[AXIS_COUNT] = { 0, 0 };
// 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 */
// Create and initialize RsiController class
MotionController* controller = MotionController::CreateFromSoftware();
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
SampleAppsHelper::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->UserUnitsSet(USER_UNITS);
axisX->PositionSet(0);
axisX->ErrorLimitActionSet(RSIAction::RSIActionNONE);
Axis* axisY = controller->AxisGet(AXIS_Y);
axisY->UserUnitsSet(USER_UNITS);
axisY->PositionSet(0);
axisY->ErrorLimitActionSet(RSIAction::RSIActionNONE);
// 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);
// Set SYNC_START motion attribute mask.
multiAxisXY->MotionAttributeMaskOnSet(RSIMotionAttrMask::RSIMotionAttrMaskSYNC_START);
printf("\nMotionStart...");
// Commanding motion using Syncpptart to start motion for both the axis at the same time.
multiAxisXY->MoveSCurve(END_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE);
multiAxisXY->MotionDoneWait();
// Calling function created on top.
PrintResult(axisX, axisY);
// Set SYNC_END motion attribute mask
multiAxisXY->MotionAttributeMaskOnSet(RSIMotionAttrMask::RSIMotionAttrMaskSYNC_END);
printf("\nMotionStart...");
// Commanding motion using SyncEnd to end motion for both the axis at the same time.
multiAxisXY->MoveSCurve(START_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE);
multiAxisXY->MotionDoneWait();
// Calling function created on top
PrintResult(axisX, axisY);
printf("\nTrapezoidal Motion Done\n");
// Disable the all the axes
multiAxisXY->AmpEnableSet(false);
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text);
return -1;
}
controller->Delete();
return 0;
}
double CommandPositionGet()
Get the current command position.
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 PositionSet(double position)
Set the Command and Actual positions.
double ActualPositionGet()
Get the current actual position.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5513
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 Delete(void)
Delete the MotionController and all its objects.
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:794
void MoveSCurve(const double *const position, const double *const vel, const double *const accel, const double *const decel, const double *const jerkPct)
Point-to-point S-Curve Move.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10208
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.
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:105
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.