The RMP Motion Controller APIs
SyncOutputWithMotion.cpp
#include <cassert>
#include "rsi.h" // Import our RapidCode Library.
#include <cmath>
using namespace RSI::RapidCode;
void PrintStreamingOutputErrors(RapidCodeObject *rsiClass)
{
bool hasError = rsiClass->ErrorLogCountGet() > 0;
while (rsiClass->ErrorLogCountGet() > 0)
{
const RsiError *err = rsiClass->ErrorLogGet();
printf("%s\n", err->text);
}
if (hasError)
{
exit(1);
}
}
void PrintStreamingOutputNetworkErrors(MotionController *rsiClass)
{
;
bool hasError = rsiClass->NetworkLogMessageCountGet() > 0;
while (rsiClass->NetworkLogMessageCountGet() > 0)
{
const char* const err = rsiClass->NetworkLogMessageGet(0);
printf("%s\n", err);
}
if (hasError)
{
exit(1);
}
}
int syncOutputWithMotionMain(int argc, char *argv[])
{
const double TIME_SLICE = 0.01; // 0.01s = 10ms
const int AXIS_COUNT = 1; // number of axes
const int REVS = 4; // number of revolutions
const int RPS = 1; // revs / sec
const int CPS = (int)std::powl(2, 20); // encoder counts per rev (set as appropiate)
const int TOTAL_POINTS = (int)(REVS / TIME_SLICE / RPS); // total number of points
const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
// Initizalize the controller from software w/ multiple axes
try {
PrintStreamingOutputErrors(controller);
controller->NetworkStart();
PrintStreamingOutputNetworkErrors(controller);
// add an additional axis for the multiaxis supervisor
controller->MotionCountSet(AXIS_COUNT + 1);
// create the multiaxis using the ID of the first free axis (0 indexed)
multiAxis = controller->MultiAxisGet(AXIS_COUNT);
PrintStreamingOutputErrors(multiAxis);
// populate the multiaxis
for (int i = 0; i < AXIS_COUNT; i++)
{
Axis *tempAxis;
tempAxis = controller->AxisGet(i);
PrintStreamingOutputErrors(tempAxis);
tempAxis->EStopAbort();
tempAxis->ClearFaults();
tempAxis->PositionSet(0);
tempAxis->UserUnitsSet(CPS);
multiAxis->AxisAdd(tempAxis);
}
// populate the positions and times
std::vector<double> positions, times;
for (int i = 0; i < TOTAL_POINTS; i += AXIS_COUNT)
{
positions.push_back(i * TIME_SLICE * RPS);
times.push_back(TIME_SLICE);
}
// prepare the controller (and drive)
multiAxis->Abort();
multiAxis->ClearFaults();
assert(multiAxis->StateGet() == RSIState::RSIStateIDLE);
multiAxis->AmpEnableSet(true);
// set up the inputs
IOPoint *output0 = IOPoint::CreateDigitalOutput(multiAxis->AxisGet(0), RSIMotorGeneralIo::RSIMotorGeneralIo0);
// ensure the digital out is set low
output0->Set(0);
// The motion element ID at which to set the output
int outPutEnableID = TOTAL_POINTS / 2;
// enable streaming output
multiAxis->StreamingOutputsEnableSet(true);
// Enable the streaming output (The following are functionally equivalent)
//multiAxis->StreamingOutputAdd(output0->MaskGet(), 0, output0->AddressGet(), outPutEnableID);
multiAxis->StreamingOutputAdd(output0, true, outPutEnableID);
// Disable the output (The following are functionally equivalent)
//multiAxis->StreamingOutputAdd(0, output0->MaskGet(), output0->AddressGet(), outPutEnableID);
//multiAxis->StreamingOutputAdd(output0, false, outPutEnableID);
multiAxis->MovePT(RSIMotionType::RSIMotionTypePT, &positions[0], &times[0], TOTAL_POINTS, EMPTY_CT, false, true);
printf("Motion started. Waiting to complete.\n");
multiAxis->MotionDoneWait();
printf("Motion Complete. The outputs should have been set\n");
multiAxis->StreamingOutputsClear(); // cleanup for next run
multiAxis->EStopAbort();
controller->Delete();
}
catch (RsiError const& err) {
printf("\n%s\n", err.text);
argc = argc;
return 1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
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::RapidCodeMotion::StreamingOutputAdd
void StreamingOutputAdd(int32_t onMask, int32_t offMask, uint64_t address)
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::RapidCodeMotion::EStopAbort
void EStopAbort()
E-Stop, then abort an axis.
RSI::RapidCode::MotionController::NetworkStart
void NetworkStart()
Start the network with RSINetworkStartupMethodNORMAL.
RSI::RapidCode::MotionController::Delete
void Delete(void)
Delete the MotionController and all its objects.
RSI::RapidCode::MotionController::CreateFromSoftware
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
RSI::RapidCode::RapidCodeMotion::StateGet
RSIState StateGet()
Get the Axis or MultiAxis state.
RSI::RapidCode
RSI::RapidCode::MotionController::NetworkLogMessageGet
const char *const NetworkLogMessageGet(int32_t messageIndex)
RSI::RapidCode::RapidCodeObject
The RapidCode base class. All non-error objects are derived from this class.
Definition: rsi.h:145
RSI::RapidCode::MotionController::AxisGet
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
RSI::RapidCode::RapidCodeObject::ErrorLogGet
const RsiError *const ErrorLogGet()
Get the next RsiError in the log.
RSI::RapidCode::Axis::PositionSet
void PositionSet(double position)
Set the Command and Actual positions.
RSI::RapidCode::RapidCodeMotion::Abort
void Abort()
Abort an axis.
RSI::RapidCode::Axis::UserUnitsSet
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
RSI::RapidCode::RapidCodeMotion::StreamingOutputsEnableSet
void StreamingOutputsEnableSet(bool enable)
Sets whether Streaming Output is enabled (true) or disabled (false).
RSI::RapidCode::RapidCodeMotion::StreamingOutputsClear
void StreamingOutputsClear()
Clear the contents of the Streaming Output List.
RSI::RapidCode::IOPoint::Set
void Set(bool state)
Set the state of a Digital Output.
RSI::RapidCode::MotionController
The MotionController object represents the RMP INtime soft motion controller.
Definition: rsi.h:743
RSI::RapidCode::IOPoint
The IOPoint object represents one specific point class such as: Digital Output, Digital Input,...
Definition: rsi.h:11802
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.
RSI::RapidCode::RapidCodeObject::ErrorLogCountGet
int32_t ErrorLogCountGet()
Get the number of software errors in the error log.
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::NetworkLogMessageCountGet
int32_t NetworkLogMessageCountGet()
RSI::RapidCode::RapidCodeMotion::MovePT
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
RSI::RapidCode::IOPoint::CreateDigitalOutput
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
RSI::RapidCode::MultiAxis::AxisGet
Axis * AxisGet(int32_t index)
Get the Axis class used in this MultiAxis class.