MotionController Axis MultiAxis IO IOPoint NetworkNode RsiError
Sample Apps Changelog

RapidCode API

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
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
// enable one MotionSupervisor for the MultiAxis
controller->MotionCountSet(controller->AxisCountGet() + 1);
// Get Axis X and Y respectively.
Axis *axisX = controller->AxisGet(AXIS_X);
SampleAppsCPP::HelperFunctions::CheckErrors(axisX);
Axis *axisY = controller->AxisGet(AXIS_Y);
SampleAppsCPP::HelperFunctions::CheckErrors(axisY);
// Initialize a MultiAxis, using the last MotionSupervisor.
MultiAxis *multiAxisXY = controller->MultiAxisGet(controller->MotionCountGet() - 1);
SampleAppsCPP::HelperFunctions::CheckErrors(multiAxisXY);
multiAxisXY->AxisAdd(axisX);
multiAxisXY->AxisAdd(axisY);
// make sure all axes are enabled and ready
multiAxisXY->ClearFaults();
multiAxisXY->AmpEnableSet(true);
while (controller->OS->KeyGet(RSIWaitPOLL) < 0)
{
// Set SYNC_START motion attribute mask.
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
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();
}