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");
// 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 int OUTPUT_INDEX = 1;
const int WAIT_FOR_TRIGGER_MILLISECONDS = 1000;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// configure user limits
controller.UserLimitCountSet(1);
controller.InterruptEnableSet(true);
// 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);
Helpers.PhantomAxisReset(axis);
// 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);
// configure user limit settings (abort action)
controller.UserLimitConfigSet(
number: USER_LIMIT_NUMBER,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION,
action: RSIAction.RSIActionABORT,
actionAxis: axis.NumberGet(),
duration: 0);
// 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.AmpEnableSet(true);
axis.MoveSCurve(MOVE_POSITION);
// 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();
int expectedSource = USER_LIMIT_NUMBER + 1; // account for extra user limit per axis
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
output0.Set(false);
controller.UserLimitDisable(USER_LIMIT_NUMBER);
controller.UserLimitCountSet(0);
Console.WriteLine("\nUser limit position abort complete.");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
Constants used in the C# sample apps.
Definition _constants.cs:3
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:11
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
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:5863
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:11550
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
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:966
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:646
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:434
RSIUserLimitTriggerType
Trigger types for UserLimits.
Definition rsienums.h:633
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21