The RMP Motion Controller APIs
MultiaxisMotion.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
#include <conio.h>
using namespace RSI::RapidCode;
const int AXIS_X = 0;
const int AXIS_Y = 1;
const int AXIS_COUNT = (2);
long axisNumber[AXIS_COUNT] = { 0, 1, };
double start_position[2] = { 0 , 0 };
double end_position[2] = { 2000 , 6000 };
double velocity[2] = { 1000, 1000 };
double accel[2] = { 10000, 10000 };
double decel[2] = { 10000, 10000 };
double jerkPct[2] = { 0, 0 };
long index;
/*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());
}
void multiaxisMotionMain()
{
// Create and initialize RsiController class
try
{
// enable one MotionSupervisor for the MultiAxis
controller->MotionCountSet(controller->AxisCountGet() + 1);
// Get Axis X and Y respectively.
Axis *axisX = controller->AxisGet(AXIS_X);
Axis *axisY = controller->AxisGet(AXIS_Y);
// 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->ClearFaults();
multiAxisXY->AmpEnableSet(true);
while (controller->OS->KeyGet((int32_t)RSIWait::RSIWaitPOLL) < 0)
{
// 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, accel, decel, jerkPct);
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, accel, decel, jerkPct);
// while loop to keep motor spinning while motion not completed.
multiAxisXY->MotionDoneWait();
PrintResult(axisX, axisY);
}
printf("\nTrapezoidal Motion Done\n");
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text);
}
controller->Delete();
}
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:10986
RSI::RapidCode::MotionController::OS
RapidCodeOS * OS
Provides access to operating system (Windows) features.
Definition: rsi.h:3569
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:90
RSI::RapidCode::MotionController::Delete
void Delete(void)
Delete the MotionController and all its objects.
RSI::RapidCode::RapidCodeOS::KeyGet
int32_t KeyGet(int32_t milliseconds)
Wait for a key to be pressed and return its value.
RSI::RapidCode::MotionController::CreateFromSoftware
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
RSI::RapidCode::MultiAxis::MoveSCurve
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.
RSI::RapidCode
RSI::RapidCode::MotionController::AxisGet
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSI::RapidCode::Axis::ActualPositionGet
double ActualPositionGet()
Get the current actual position.
RSI::RapidCode::Axis::CommandPositionGet
double CommandPositionGet()
Get the current command position.
RSI::RapidCode::MotionController
The MotionController object represents the RMP INtime soft motion controller.
Definition: rsi.h:743
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:5852
RSI::RapidCode::RapidCodeMotion::AmpEnableSet
void AmpEnableSet(bool enable)
Enable all amplifiers.
HelperFunctions.CheckErrors
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCode Object has any errors.
Definition: HelperFunctions.cs:64
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::RapidCodeMotion::MotionAttributeMaskOnSet
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
RSI::RapidCode::MotionController::AxisCountGet
int32_t AxisCountGet()
Get the number of axes processing.