APIs, concepts, guides, and more
axis-configuration.cpp
Note
See Axis: Configuration 📜 for a detailed explanation of this sample code.
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.
/* This sample app demonstrates how to configure different axis settings
including counts per unit, hardware limits, settling, and stopping rates.
*/
#include <cmath>
#include "helpers.h" // import our helper functions.
#include "config.h" // import our configuration.
#include "rsi.h" // import our RapidCode Library.
using namespace RSI::RapidCode; // import the RapidCode namespace
int main()
{
// print a start message to indicate that the sample app has started
const std::string SAMPLE_APP_NAME = "📜 Axis: Configuration";
Helpers::PrintHeader(SAMPLE_APP_NAME);
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
const int NUM_AXES = 1; // the number of axes to configure, default is 0 for this template
const int AXIS_INDEX = 0; // the index of the axis to configure
/* RAPIDCODE INITIALIZATION */
// create the controller
// set the exit code to an error value.
int exitCode = -1;
try // ensure that the controller is deleted if an error occurs
{
// prepare the controller as defined in config.h depending on the configuration
Helpers::CheckErrors(controller);
Config::SetupController(controller, NUM_AXES);
/* SAMPLE APP BODY */
/* SET CONTROLLER OBJECT COUNTS HERE*/
// normally you would set the number of axes here, but for samples that is handled in the Config::SetupController function
// controller->AxisCountSet(NUM_AXES);
// get the axes
Axis *axis = controller->AxisGet(AXIS_INDEX);
/* Amp Fault Configuration */
std::cout << "Configuring Amp Fault parameters\n" << std::endl;
// parameters
const double AMP_FAULT_DURATION_TIME = 1; // How long the axis must be in the trigger state to be considered an amp fault.
const RSIAction AMP_FAULT_ACTION = RSIAction::RSIActionABORT; // The action to take when an amp fault occurs.
const int AMP_FAULT_TRIGGER_STATE = 1; // the state that triggers the amp fault, active high = 1, active low = 0.
// set
axis->AmpEnableSet(false); // disable the axis
axis->AmpFaultDurationSet(AMP_FAULT_DURATION_TIME);
axis->AmpFaultActionSet(AMP_FAULT_ACTION);
axis->AmpFaultTriggerStateSet(AMP_FAULT_TRIGGER_STATE);
// get
double durationTime = axis->AmpFaultDurationGet();
RSIAction action = axis->AmpFaultActionGet();
int triggerState = axis->AmpFaultTriggerStateGet();
std::cout << "Axis Amp Fault parameters have been set" << std::endl;
/* Hardware Limits Configuration */
std::cout << "Configuring Hardware Limits parameters\n" << std::endl;
// parameters
const int TRIGGER_STATE = 1; // The state that triggers the positive software limit, active high = 1, active low = 0.
const double DURATION = 0.01; // How long the hardware limit must be in the trigger state to be considered triggered.
const RSIAction ACTION = RSIAction::RSIActionABORT; // the action to take when the positive hardware limit is triggered.
// set
axis->HardwarePosLimitTriggerStateSet(TRIGGER_STATE);
axis->HardwarePosLimitDurationSet(DURATION);
axis->HardwareNegLimitTriggerStateSet(TRIGGER_STATE);
axis->HardwareNegLimitDurationSet(DURATION);
// get
int posTriggerState = axis->HardwarePosLimitTriggerStateGet();
double posDuration = axis->HardwarePosLimitDurationGet();
RSIAction posAction = axis->HardwarePosLimitActionGet();
int negTriggerState = axis->HardwareNegLimitTriggerStateGet();
double negDuration = axis->HardwareNegLimitDurationGet();
RSIAction negAction = axis->HardwareNegLimitActionGet();
std::cout << "Axis Hardware Limits have been set" << std::endl;
/* Settling Configuration */
std::cout << "Configuring Settling parameters\n" << std::endl;
// parameters
const double POSITION_TOLERANCE_FINE = 200; // Tolerance for when a move is considered complete.
const double POSITION_TOLERANCE_COARSE = 300; // Tolerance for when a move is considered "near" complete.
const double VELOCITY_TOLERANCE = 12000; // Tolerance for when a velocity move is considered complete.
const double SETTLING_TIME = 5; // how long the axis must be within tolerance to be considered settled.
// set
axis->PositionToleranceFineSet(POSITION_TOLERANCE_FINE);
axis->PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE);
axis->VelocityToleranceSet(VELOCITY_TOLERANCE);
axis->SettlingTimeSet(SETTLING_TIME);
// get
double posTolFine = axis->PositionToleranceFineGet();
double posTolCoarse = axis->PositionToleranceCoarseGet();
double velTol = axis->VelocityToleranceGet();
double setTime = axis->SettlingTimeGet();
std::cout << "Axis Settling parameters have been set" << std::endl;
/* Stop Rate Configuration */
std::cout << "Configuring Stop Rate parameters\n" << std::endl;
// parameters
const double STOP_RATE_DEFAULT = 1.0; // Specify the default STOP rate in seconds.
const double ESTOP_RATE_DEFAULT = 0.05; // Specify the default ESTOP rate in seconds.
const double ESTOP_DECELERATION_RATE = 1000; // specify the default ESTOP deceleration rate in seconds.
// set
axis->StopTimeSet(STOP_RATE_DEFAULT);
axis->EStopTimeSet(ESTOP_RATE_DEFAULT);
axis->EStopDecelerationSet(ESTOP_DECELERATION_RATE);
// get
double stopRate = axis->StopTimeGet();
double eStopRate = axis->EStopTimeGet();
double eStopDeceleration = axis->EStopDecelerationGet();
std::cout << "Axis Stop Rate parameters have been set" << std::endl;
/* User Units Configuration */
std::cout << "Configuring User Units parameters\n" << std::endl;
// parameters
const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
const double USER_UNITS = std::pow(2, ENCODER_RESOLUTION_BITS); // The number of user units per revolution
// (2^20 = 1,048,576 user units per revolution)
// set
axis->UserUnitsSet(USER_UNITS);
// get
double userUnits = axis->UserUnitsGet();
std::cout << "Axis User Units have been set" << std::endl;
exitCode = 0; // set the exit code to success.
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
// clean up the controller and any other objects as needed
Config::Cleanup(controller);
// delete the controller as the program exits to ensure memory is deallocated in the correct order
controller->Delete();
// print a message to indicate the sample app has finished and if it was successful or not
Helpers::PrintFooter(SAMPLE_APP_NAME, exitCode);
return exitCode;
}
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
RSIAction AmpFaultActionGet()
Get the Amp Fault action.
double SettlingTimeGet()
Get the Settling time.
void HardwareNegLimitDurationSet(double seconds)
Set the duration required before the Hardware Negative Limit event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
double UserUnitsGet()
Get the number of counts per User Unit.
double PositionToleranceFineGet()
Get the Fine Position Tolerance for axis settling.
RSIAction HardwarePosLimitActionGet()
Get the action that will occur when the Hardware Positive Limit Event triggers.
void HardwarePosLimitTriggerStateSet(bool state)
sets the trigger state.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void AmpFaultActionSet(RSIAction action)
Set the Amp Fault action.
void AmpFaultTriggerStateSet(bool state)
Set the trigger state of the Amp Fault input.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
double AmpFaultDurationGet()
Get the duration required before the Amp Fault event triggers.
double HardwareNegLimitDurationGet()
Get the duration required before the Hardware Negative Limit event triggers.
bool HardwarePosLimitTriggerStateGet()
trigger state return.
void HardwarePosLimitDurationSet(double seconds)
Set the duration required before the Hardware Positive Limit event triggers.
void VelocityToleranceSet(double tolerance)
Set the Velocity Tolerance used for settling.
double PositionToleranceCoarseGet()
Get the Coarse Position Tolerance for axis settling.
double EStopDecelerationGet()
Get the deceleration rate for an E-Stop, Modify Event.
bool AmpFaultTriggerStateGet()
Get the Amp Fault trigger state.
double VelocityToleranceGet()
Get the velocity tolerance used for settling.
void EStopDecelerationSet(double decel)
Set the deceleration rate for an E-Stop, Modify Event.
bool HardwareNegLimitTriggerStateGet()
Trigger state return.
double HardwarePosLimitDurationGet()
Get the duration required before the Hardware Positive Limit event triggers.
void AmpFaultDurationSet(double seconds)
Set the duration required before the Amp Fault event triggers.
RSIAction HardwareNegLimitActionGet()
Get the action that will occur when the Hardware Negative Limit Event triggers.
void HardwareNegLimitTriggerStateSet(bool state)
Sets the trigger state.
void SettlingTimeSet(double time)
Set the settling time.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void StopTimeSet(double seconds)
Set the deceleration time for a Stop Event.
double EStopTimeGet()
Get E-Stop Event deceleration time.
void EStopTimeSet(double seconds)
Set the deceleration time for an E-Stop Event.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
double StopTimeGet()
Get Stop Event deceleration time.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
@ RSIActionABORT
Abort - disable the amplifier, zero filter output, leave in error state.
Definition rsienums.h:1123
void SetupController(MotionController *controller, int numAxes=0)
Setup the controller and check if the network is in the correct state for the configuration.
Definition config.h:134
MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
Definition config.h:68
void Cleanup(MotionController *controller)
[SetupController]
Definition config.h:193
void CheckErrors(RapidCodeObject *rsiObject, const std::source_location &location=std::source_location::current())
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition helpers.h:32
void PrintHeader(std::string sampleAppName)
[NetworkShutdown]
Definition helpers.h:146
void PrintFooter(std::string sampleAppName, int exitCode)
[PrintHeader]
Definition helpers.h:162
CreationParameters for MotionController::Create.
Definition rsi.h:866