APIs, concepts, guides, and more
userlimit-estop-store-position.cs
/* 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);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
// start velocity motion
axis.AmpEnableSet(true);
axis.MoveVelocity(velocity: 10.0, accel: 20.0);
// configure user limit condition
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
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
}
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
static void PhantomAxisReset(Axis phantomAxis)
Configures a phantom axis on the controller.
Definition _helpers.cs:144
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
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:5862
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.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11549
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
void UserLimitConditionSet(int32_t number, int32_t conditionNumber, RSIUserLimitLogic logic, uint64_t addressOfUInt32, uint32_t userLimitMask, uint32_t limitValueUInt32)
Set the conditions for a User Limit with a 32-bit integer trigger value.
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
void UserLimitInterruptUserDataAddressSet(int32_t number, uint32_t userDataIndex, uint64_t address)
Set the User Data address based on a User Limit trigger.
void UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
void Delete(void)
Delete the MotionController and all its objects.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
void InterruptEnableSet(bool enable)
Control interrupts for this class.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
double InterruptUserDataDoubleGet(uint32_t userDataIndex)
Get the user data associated with the interrupt, as a 64-bit double.
int32_t InterruptSourceNumberGet()
Get the number (or index) of the object (Axis, Motor, etc) that generated the interrupt.
RSIEventType InterruptWait(int32_t milliseconds)
Suspend the current thread until an interrupt arrives from the controller.
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