APIs, concepts, guides, and more
userlimit-estop-store-position.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 that triggers an E-Stop when a digital input goes high.
The axis command position is stored when the user limit triggers.
Example uses Beckhoff IO Terminals (EL1088 for inputs).
Check your digital IO signal indexes in RapidSetup -> Tools -> NetworkIO.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 User Limit: EStop and Store Position");
// set sample config params
const int AXIS_INDEX = 0;
const int INPUT_INDEX = 0;
const int CONDITION = 0;
const int USER_DATA_INDEX = 0;
const double DURATION = 0.125; // time delay before action executes (seconds)
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// configure user limits
controller.UserLimitCountSet(1);
controller.InterruptEnableSet(true);
// create simulated io using user buffer memory
ulong userBufferAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0);
IOPoint input0 = IOPoint.CreateDigitalInput(controller, userBufferAddress, INPUT_INDEX);
Helpers.CheckErrors(input0);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
Helpers.PhantomAxisReset(axis);
// start velocity motion
axis.AmpEnableSet(true);
axis.MoveVelocity(velocity: 10.0, accel: 20.0);
// configure user limit condition
controller.UserLimitConditionSet(
number: 0,
conditionNumber: CONDITION,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfUInt32: input0.AddressGet(),
userLimitMask: (uint)input0.MaskGet(),
limitValueUInt32: 1);
// configure user limit settings (e-stop action)
controller.UserLimitConfigSet(
number: 0,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION,
action: RSIAction.RSIActionE_STOP_ABORT,
actionAxis: AXIS_INDEX,
duration: DURATION);
// configure user data to store axis command position
controller.UserLimitInterruptUserDataAddressSet(
number: 0,
userDataIndex: USER_DATA_INDEX,
address: axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_POSITION));
Console.WriteLine("Axis moving... waiting for input trigger to E-Stop");
// wait for user limit to trigger
while (controller.InterruptWait(250) != RSIEventType.RSIEventTypeUSER_LIMIT)
{
// simulate input trigger
controller.MemorySet(input0.AddressGet(), 1);
}
// wait for motion to stop
// get the stored position data
int triggeredUserLimit = controller.InterruptSourceNumberGet() - 1; // account for extra user limit per axis
double interruptPosition = controller.InterruptUserDataDoubleGet(USER_DATA_INDEX);
double positionInUserUnits = interruptPosition / axis.UserUnitsGet();
Console.WriteLine($"✓ User limit triggered - E-Stop executed");
Console.WriteLine($" Triggered User Limit: {triggeredUserLimit}");
Console.WriteLine($" Position at trigger: {positionInUserUnits} (user units)");
// cleanup
axis.Abort();
controller.UserLimitDisable(0);
controller.UserLimitCountSet(0);
Console.WriteLine("\nUser limit E-Stop store position 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.
double UserUnitsGet()
Get the number of counts per User Unit.
void MoveVelocity(double velocity)
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.
static IOPoint * CreateDigitalInput(Axis *axis, RSIMotorDedicatedIn motorDedicatedInNumber)
Create a Digital Input from an Axis' Dedicated Input bits.
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
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
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