APIs, concepts, guides, and more
userlimit-position-abort.cs
/* 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);
// configure user limit condition (trigger when position > TRIGGER_POSITION)
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
}
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
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:5862
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.
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.
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 UserLimitOutputSet(int32_t number, uint32_t andMask, uint32_t orMask, uint64_t outputPtr, bool enabled)
Configure a User Limit Output block.
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
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.
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