APIs, concepts, guides, and more
AxisConfiguration.cpp
Attention
See the following Concept pages for a detailed explanation of this sample: Counts Per Unit (User Units), Hardware Limits, Settling, Stopping Rates.
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.
#include <cmath>
#include "SampleAppsHelper.h" // Import our helper functions.
#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";
/* 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
MotionController *controller = MotionController::Create(&params);
// 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 SampleAppsHelper.h depending on the configuration
SampleAppsHelper::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 SampleAppsHelper::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
// 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
SampleAppsHelper::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:5549
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.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
void AmpEnableSet(bool enable)
Enable all amplifiers.
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.
double StopTimeGet()
Get Stop Event deceleration time.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1072
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static void Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
CreationParameters for MotionController::Create.
Definition rsi.h:857