APIs, concepts, guides, and more
userlimit-position-abort.cs
Note
See IO: User Limits 📜 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 demonstrates how to configure a user limit to abort motion when a specified position is reached.
The user limit triggers when the command position exceeds the trigger value and executes an abort action.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 User Limit: Position Abort");
int exitCode = 0;
// set sample config params
const int USER_LIMIT_NUMBER = 0;
const double TRIGGER_POSITION = 5.0;
const double MOVE_POSITION = 10.0; // must be past the trigger position
const double VELOCITY = 3.0;
const double ACCELERATION = 2.0;
const double DECELERATION = 2.0;
const double JERK = 50.0;
const int OUTPUT_INDEX = 1;
const int WAIT_FOR_TRIGGER_MILLISECONDS = 5000;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// configure user limits
controller.UserLimitCountSet(1);
controller.InterruptEnableSet(true);
int initialAxisCount = controller.AxisCountGet();
// create simulated output
ulong userBufferAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0);
IOPoint output0 = IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX);
output0.Set(false); // start with output off
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis);
axis.PositionSet(0);
double encoderMultiplier = Constants.USE_HARDWARE ? Constants.AXIS_0_USER_UNITS : 1.0;
// configure user limit condition (trigger when position > TRIGGER_POSITION)
controller.UserLimitConditionSet(
number: USER_LIMIT_NUMBER,
conditionNumber: 0,
logic: RSIUserLimitLogic.RSIUserLimitLogicGT,
addressOfDouble: axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_POSITION), // for real axis use actual position
limitValueDouble: TRIGGER_POSITION * encoderMultiplier);
// configure user limit settings (abort action)
controller.UserLimitConfigSet(
number: USER_LIMIT_NUMBER,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION,
action: RSIAction.RSIActionABORT,
actionAxis: axis.NumberGet(),
duration: 0,
singleShot: true);
// configure user limit output
controller.UserLimitOutputSet(
number: USER_LIMIT_NUMBER,
andMask: (uint)output0.MaskGet(),
orMask: (uint)output0.MaskGet(),
outputPtr: output0.AddressGet(),
enabled: true);
Console.WriteLine($"Moving to position {MOVE_POSITION}...");
Console.WriteLine($"User limit will trigger abort at position {TRIGGER_POSITION}");
if (output0.Get())
Console.WriteLine("ERROR: Output should not be triggered yet");
// start motion
axis.MoveSCurve(MOVE_POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK);
// wait for user limit interrupt
RSIEventType interruptType = controller.InterruptWait(WAIT_FOR_TRIGGER_MILLISECONDS);
if (interruptType == RSIEventType.RSIEventTypeUSER_LIMIT)
{
// note: object number for user_limit interrupts is unscaled, add axis count since there's one user limit per axis
int interruptSource = controller.InterruptSourceNumberGet();
// Interrupt source number uses object count, not just user limit count, so account for axis objects
// E.g., 3 axes + 1 user limit = interrupt source 3 (0-based index)
int expectedSource = USER_LIMIT_NUMBER + initialAxisCount;
if (interruptSource == expectedSource)
{
Console.WriteLine($"✓ User limit triggered - abort executed");
Console.WriteLine($" Interrupt source: {interruptSource}");
if (output0.Get())
Console.WriteLine(" Output activated successfully");
else
Console.WriteLine(" WARNING: Output was not activated");
}
else
{
Console.WriteLine($"✗ Got USER_LIMIT interrupt but wrong source (expected: {expectedSource}, actual: {interruptSource})");
}
}
else
{
Console.WriteLine($"✗ Expected USER_LIMIT interrupt but got {interruptType}");
}
// cleanup
axis.AmpEnableSet(false);
axis.ClearFaults();
output0.Set(false);
controller.UserLimitDisable(USER_LIMIT_NUMBER);
controller.UserLimitCountSet(0);
Console.WriteLine("\nUser limit position abort complete.");
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
Constants used in the C# sample apps.
Definition _constants.cs:3
const double AXIS_0_USER_UNITS
Default: 1.
Definition _constants.cs:26
const bool USE_HARDWARE
Default: false.
Definition _constants.cs:10
const int EXIT_FAILURE
Exit code for failed execution.
Definition _constants.cs:69
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:20
const int AMP_ENABLE_MS
Default: 750.
Definition _constants.cs:35
const int EXIT_SUCCESS
Exit code for successful execution.
Definition _constants.cs:68
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
void PositionSet(double position)
Set the Command and Actual positions.
void MoveSCurve(double position, double vel, double accel, double decel, double jerkPct)
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5921
uint64_t AddressGet()
Get the Host Address for the I/O point.
void Set(bool state)
Set the state of a Digital Output.
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
bool Get()
Get the state of Digital Input or Output.
int32_t MaskGet()
Get the bit mask for the I/O point.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11597
static MotionController * Get()
Get an already running RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
int32_t MotionDoneWait(int32_t waitTimeoutMilliseconds=WaitForever)
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
int32_t NumberGet()
Get the axis number.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:405
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:973
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:651
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1122
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:439
RSIUserLimitTriggerType
Trigger types for UserLimits.
Definition rsienums.h:638
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21