APIs, concepts, guides, and more
AxisConfig.cs
Attention
See the following Concept pages for a detailed explanation of this sample: Counts Per Unit (User Units), Hardware Limits, Phantom Axes, 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.
using RSI.RapidCode.dotNET; // Import our RapidCode Library
using System;
using NUnit.Framework;
[TestFixture]
[Category("Software")]
public class AxisConfig : SampleAppTestBase
{
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void AxisSettling()
{
double POSITION_TOLERANCE_FINE_DEFAULT = axis.PositionToleranceFineGet();
double POSITION_TOLERANCE_COARSE_DEFAULT = axis.PositionToleranceCoarseGet();
double VELOCITY_TOLERANCE_DEFAULT = axis.VelocityToleranceGet();
double SETTLING_TIME_DEFAULT = axis.SettlingTimeGet();
const double POSITION_TOLERANCE_FINE = 200; // Specify the fine position tolerance.
const double POSITION_TOLERANCE_COARSE = 300; // Specify the coarse position tolerance.
const double VELOCITY_TOLERANCE = 12000; // Specify the velocity tolerance.
const double SETTLING_TIME = 5; // Specify the settling time.
// SET
axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE); // Set fine position tolerance.
axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE); // Set coarse position tolerance.
axis.VelocityToleranceSet(VELOCITY_TOLERANCE); // Set velocity tolerance.
axis.SettlingTimeSet(SETTLING_TIME); // Set settling time.
// GET
var posTolFine = axis.PositionToleranceFineGet();
var posTolCoarse = axis.PositionToleranceCoarseGet();
var velTol = axis.VelocityToleranceGet();
var setTime = axis.SettlingTimeGet();
Assert.That(posTolFine, Is.EqualTo(POSITION_TOLERANCE_FINE), "The getter function should return a value equal to POSITION_TOLERANCE_FINE");
Assert.That(posTolCoarse, Is.EqualTo(POSITION_TOLERANCE_COARSE), "The getter function should return a value equal to POSITION_TOLERANCE_COARSE");
Assert.That(velTol, Is.EqualTo(VELOCITY_TOLERANCE), "The getter function should return a value equal to VELOCITY_TOLERANCE");
Assert.That(setTime, Is.EqualTo(SETTLING_TIME), "The getter function should return a value equal to SETTLING_TIME");
axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE_DEFAULT); // Set fine position tolerance.
axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE_DEFAULT); // Set coarse position tolerance.
axis.VelocityToleranceSet(VELOCITY_TOLERANCE_DEFAULT); // Set velocity tolerance.
axis.SettlingTimeSet(SETTLING_TIME_DEFAULT);
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void ConfigAmpFault()
{
RSIAction RSIAction_DEFAULT = axis.AmpFaultActionGet(); // Set the action that will occur when there is an amp fault.
bool Trigger_DEFAULT = axis.AmpFaultTriggerStateGet(); //Set the state of the amp fault.
double AMP_FAULT_DURATION_TIME_DEFAULT = axis.AmpFaultDurationGet(); //Set the duration required before the Amp Fault event triggers.
const double AMP_FAULT_DURATION_TIME = 1; //value in seconds
// SET
axis.AmpEnableSet(false); // Disable the amp
axis.AmpFaultActionSet(RSIAction.RSIActionABORT); // Set the action that will occur when there is an amp fault.
axis.AmpFaultTriggerStateSet(false); //Set the state of the amp fault.
axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME); //Set the duration required before the Amp Fault event triggers.
// GET
var isEnabled = axis.AmpEnableGet();
var faultAction = axis.AmpFaultActionGet();
var faultTriggerState = axis.AmpFaultTriggerStateGet();
var faultDuration = axis.AmpFaultDurationGet();
Assert.That(isEnabled, Is.EqualTo(false), "The getter function should return a value equal to false");
Assert.That(faultAction, Is.EqualTo(RSIAction.RSIActionABORT), "The getter function should return a value equal to RSIActionABORT");
Assert.That(faultTriggerState, Is.EqualTo(false), "The getter function should return a value equal to false");
Assert.That(faultDuration, Is.EqualTo(AMP_FAULT_DURATION_TIME), "The getter function should return a value equal to AMP_FAULT_DURATION_TIME");
//---RESET---
axis.AmpFaultActionSet(RSIAction_DEFAULT); // Set the action that will occur when there is an amp fault.
axis.AmpFaultTriggerStateSet(Trigger_DEFAULT); //Set the state of the amp fault.
axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME_DEFAULT); //Set the duration required before the Amp Fault event triggers.
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void SetUserUnits()
{
// Other Variables
double currentUserUnits = axis.UserUnitsGet();
const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
// Specify your counts per unit/user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
// 1048576 Setting the user units to this value will result in a commanded position of 1 spinning the motor 1 full revolution
double USER_UNITS = Math.Pow(2, ENCODER_RESOLUTION_BITS);
// SET
axis.UserUnitsSet(USER_UNITS);
axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
// GET
var userUnits = axis.UserUnitsGet();
Assert.That(userUnits, Is.EqualTo(USER_UNITS)); // Verify that your user units were changed!
Assert.That(userUnits, Is.EqualTo(1048576)); // Verify that your user units were changed!
axis.UserUnitsSet(Constants.USER_UNITS); // Restore Default
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void StopRate()
{
const double STOP_RATE = 1.2; // Specify the default STOP rate in seconds.
const double ESTOP_RATE = 1.3; // Specify the default ESTOP rate in seconds.
const double ESTOP_DECELERATION_RATE_T = 1.5; // Specify the default ESTOP deceleration rate in seconds.
axis.StopTimeSet(STOP_RATE); // Set the default STOP time to STOP_RATE_DEFAULT secs.
axis.EStopTimeSet(ESTOP_RATE); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE_T); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
Assert.That(axis.StopTimeGet(), Is.EqualTo(STOP_RATE)); // Verify that your user units were changed!
Assert.That(axis.EStopTimeGet(), Is.EqualTo(ESTOP_RATE)); // Verify that your user units were changed!
Assert.That(axis.EStopDecelerationGet(), Is.EqualTo(ESTOP_DECELERATION_RATE_T)); // Verify that your user units were changed!
// Constants
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); // Set the default STOP time to STOP_RATE_DEFAULT secs.
axis.EStopTimeSet(ESTOP_RATE_DEFAULT); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void HardwareLimits()
{
var defaultTriggerState = axis.HardwarePosLimitTriggerStateGet();
const bool ACTIVE_HIGH = true; // Constant for active high.
const bool ACTIVE_LOW = false; // Constant for active low.
const double HW_POS_DURATION_TIME = 0.01; // Positive limit duration. (in seconds)
const double HW_NEG_DURATION_TIME = 0.01; // Negative limit duration. (in seconds)
// SET (Hardware POSITIVE (+) Limit characteristics)
axis.HardwarePosLimitActionSet(RSIAction.RSIActionE_STOP); // Set the positive limit action to E_STOP.
axis.HardwarePosLimitTriggerStateSet(ACTIVE_HIGH); // Set the positive limit trigger state to ACTIVE_HIGH.
axis.HardwarePosLimitDurationSet(HW_POS_DURATION_TIME); // Set the positive limit duration to 0.01 seconds.
// GET
var hPosLimAct = axis.HardwarePosLimitActionGet();
var hPosLimTrigState = axis.HardwarePosLimitTriggerStateGet();
var hPosLimDur = axis.HardwarePosLimitDurationGet();
// SET (Hardware NEGATIVE (-) Limit charateristics)
axis.HardwareNegLimitActionSet(RSIAction.RSIActionE_STOP); // Set the negative limit action to E_STOP.
axis.HardwareNegLimitTriggerStateSet(ACTIVE_LOW); // Set the negative limit trigger state to ACTIVE_LOW.
axis.HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME); // Set the negative limit duration to 0.01 seconds.
// GET
var hNegLimAct = axis.HardwareNegLimitActionGet();
var hNegLimTrigState = axis.HardwareNegLimitTriggerStateGet();
var hNegLimDur = axis.HardwareNegLimitDurationGet();
Assert.That(hPosLimAct, Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
Assert.That(hPosLimTrigState, Is.EqualTo(ACTIVE_HIGH), "Hardware Positive Limit TriggerState should be set to ACTIVE_HIGH");
Assert.That(hPosLimDur, Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
Assert.That(hNegLimAct, Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
Assert.That(hNegLimTrigState, Is.EqualTo(ACTIVE_LOW), "Hardware Positive Limit TriggerState should be set to ACTIVE_LOW");
Assert.That(hNegLimDur, Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
//---RESET---
axis.HardwarePosLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
axis.HardwareNegLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
}
public void PhantomAxis()
{
controller.AxisCountSet(controller.AxisCountGet() + 1); // Configure one additional axis to be used for the phantom axis
int axisNumber = controller.AxisCountGet() - 1; // Set the axis number to the last axis on the network (subtract one because the axes are zero indexed)
axis = controller.AxisGet(axisNumber); // Initialize Axis class
HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly
// These limits are not meaningful for a Phantom Axis (e.g., a phantom axis has no actual position so a position error trigger is not necessary)
// Therefore, you must set all of their actions to "NONE".
axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); // Set Error Limit Action.
axis.HardwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Negative Limit Action.
axis.HardwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Positive Limit Action.
axis.HomeActionSet(RSIAction.RSIActionNONE); // Set Home Action.
axis.SoftwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Software Negative Limit Action.
axis.SoftwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Software Positive Limit Action.
const double positionToleranceMax = Double.MaxValue / 10.0; // Reduce from max slightly, so XML to string serialization and deserialization works without throwing System.OverflowException
axis.PositionToleranceCoarseSet(positionToleranceMax); // Set Settling Coarse Position Tolerance to max value
axis.PositionToleranceFineSet(positionToleranceMax); // Set Settling Fine Position Tolerance to max value (so Phantom axis will get immediate MotionDone when target is reached)
axis.MotorTypeSet(RSIMotorType.RSIMotorTypePHANTOM); // Set the MotorType to phantom
}
}
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
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.
bool AmpEnableGet()
Get the state of the Amp Enable Output.
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 SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
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 HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
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.
void MotorTypeSet(RSIMotorType type)
Set the motor type.
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.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
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.