APIs, concepts, guides, and more
Motion: Sync Outputs

Single Axis Sync Outputs sample application.

This sample application will show you a basic demonstartion on how to set up Sync Outputs, so that you can easily change any IO�s state based on a specified point index (or ElmentID) on your steaming motion.

Precondition
This sample code presumes that the user has set the tuning paramters(PID, PIV, etc.) prior to running this program so that the motor can rotate in a stable manner.
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.
#include "rsi.h" // Import our RapidCode Library.
#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
#include "SampleApps.h"
using namespace RSI::RapidCode; // Import the RapidCode namespace
int SingleAxisSyncOutputs::Run()
{
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
// Axis configuration parameters
const int AXIS_COUNT = 1; // Specify how many axes you have.
const int AXIS_NUMBER = 0; // Specify which axis/motor to control.
const double USER_UNITS = 1048576; // Specify your counts per unit / user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
// IO configuration parameters
const int NODE_INDEX = 0; // Specify which EtherCat Node will be used
const int OUTPUT_INDEX = 0;
const int OUTPUT_ENABLE_ID = 2; // The motion element ID at which to set the output
const int OUTPUT_DISABLE_ID = 3; // The motion element ID at which to set the output
// Motion parameters
const int TOTAL_POINTS = 4; // total number of points
const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
const double POSITIONS[] = { 0.25, 0.50, 0.75, 1.0 }; // These will be the streaming motion 5 positions.
const double TIMES[] = { 0.5, 1.0, 1.5, 2.0 }; // These will be the streaming motion 5 positions' time.
// 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;
// The rmpPath only needs to be set if the project directory is different than the rapid setup directory.
// *NOTICE* When setting the rmpPath, be sure to uncomment the rmpPath arguement in MotionController::CreateFromSoftware() in the Run() function.
char rmpPath[] = "C:\\RSI\\X.X.X\\"; // Insert the path location of the RMP.rta (usually the RapidSetup folder)
// Initialize MotionController class.
MotionController* controller = MotionController::CreateFromSoftware(/*rmpPath*/); // NOTICE: Uncomment "rmpPath" if project directory is different than rapid setup directory.
SampleAppsHelper::CheckErrors(controller); // [Helper Function] Check that the axis has been initialize correctly.
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
}
try
{
Axis* axis = controller->AxisGet(AXIS_NUMBER); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
SampleAppsHelper::CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
axis->PositionSet(0); // Make sure motor starts at position 0 everytime.
axis->UserUnitsSet(USER_UNITS); // Change your user units.
axis->ErrorLimitActionSet(RSIAction::RSIActionNONE); // Set Error Limit Action.
axis->Abort(); // If there is any motion happening, abort it.
axis->ClearFaults(); // Clear faults.>
axis->AmpEnableSet(true); // Enable the motor.
// Set up the inputs
// Ensure the digital out is set low.
//IOPoint *output0 = IOPoint::CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
IOPoint* output0 = IOPoint::CreateDigitalOutput(controller->IOGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
output0->Set(false);
// Set up Sync Outputs
axis->StreamingOutputsEnableSet(true); // Enable streaming output.
// ENABLE the Sync Output(s)
axis->StreamingOutputAdd(output0, true, OUTPUT_ENABLE_ID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
axis->StreamingOutputAdd(output0, false, OUTPUT_DISABLE_ID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
// DISABLE the Sync Output(s)
//axis->StreamingOutputAdd(output0, false, outPutEnableID);
axis->MovePT(RSIMotionType::RSIMotionTypePT, POSITIONS, TIMES, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
printf("Motion started. Waiting to complete.\n");
axis->MotionDoneWait(); // What for Streaming Motion to be done.
printf("Motion Complete. The outputs should have been set\n");
axis->StreamingOutputsEnableSet(false); // Disable Sync Outputs.
axis->AmpEnableSet(false); // Disable the motor.
}
catch (RsiError const& err)
{
printf("%s\n", err.text); // If there are any exceptions/issues this will be printed out.
return -1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
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.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5643
void Set(bool state)
Set the state of a Digital Output.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11058
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void Delete(void)
Delete the MotionController and all its objects.
IO * IOGet(int32_t nodeNumber)
IOGet returns a pointer to an IO object using its node number and initializes its internals.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
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 StreamingOutputAdd(int32_t onMask, int32_t offMask, uint64_t address)
void StreamingOutputsEnableSet(bool enable)
Sets whether Streaming Output is enabled (true) or disabled (false).
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.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:107
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.