APIs, concepts, guides, and more
userlimit-command-position-direct.cs
/* This sample demonstrates using two user limits in sequence.
First user limit: triggers on digital input, executes triggered modify to decelerate, stores position.
Second user limit: triggers when first completes and axis is idle, directly sets command position.
This is an advanced example of coordinating multiple user limits.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("šŸ“œ User Limit: Command Position Direct Set");
// set sample config params
const int AXIS_COUNT = 1;
const int USER_LIMIT_FIRST = 0;
const int USER_LIMIT_SECOND = 1;
const int USER_LIMIT_COUNT = 2;
const int DURATION = 0;
const bool ONE_SHOT = true; // user limit triggers only once
// user limit interrupt constants
const int COMMAND_POSITION_INDEX = 0;
const int ACTUAL_POSITION_INDEX = 1;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// configure user limits
controller.AxisCountSet(AXIS_COUNT);
controller.UserLimitCountSet(USER_LIMIT_COUNT);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
// set the triggered modify values to stop very quickly
/*
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ FIRST USER LIMIT │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
*/
// condition 0: trigger on digital input
number: USER_LIMIT_FIRST,
conditionNumber: 0,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfUInt32: axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeDIGITAL_INPUTS),
userLimitMask: 0x400000,
limitValueUInt32: 0x400000);
// configuration: cause a triggered_modify action on the axis
controller.UserLimitConfigSet(
number: USER_LIMIT_FIRST,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION,
action: RSIAction.RSIActionTRIGGERED_MODIFY,
actionAxis: axis.NumberGet(),
duration: DURATION,
singleShot: ONE_SHOT);
/*
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ SECOND USER LIMIT │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
*/
// condition 0: wait for first user limit to trigger
number: USER_LIMIT_SECOND,
conditionNumber: 0,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfUInt32: controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSERLIMIT_STATUS, USER_LIMIT_FIRST),
userLimitMask: 1,
limitValueUInt32: 1);
// condition 1: AND wait for axis command velocity = 0.0
number: USER_LIMIT_SECOND,
conditionNumber: 1,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfDouble: axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_VELOCITY),
limitValueDouble: 0.0);
// configuration: no action, just monitoring
controller.UserLimitConfigSet(
number: USER_LIMIT_SECOND,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeCONDITION_AND,
action: RSIAction.RSIActionNONE,
actionAxis: 0,
duration: 0,
singleShot: ONE_SHOT);
// start motion
axis.ClearFaults();
axis.AmpEnableSet(true);
axis.MoveVelocity(velocity: 10, accel: 100);
Console.WriteLine("Axis moving... waiting for user limit triggers");
// configure and enable interrupts
ConfigureUserLimitInterrupts(controller, axis, USER_LIMIT_FIRST);
ConfigureUserLimitInterrupts(controller, axis, USER_LIMIT_SECOND);
controller.InterruptEnableSet(true);
// wait for and display interrupts
WaitForInterrupts(controller);
// cleanup
axis.Abort();
controller.UserLimitDisable(USER_LIMIT_FIRST);
controller.UserLimitDisable(USER_LIMIT_SECOND);
Console.WriteLine("\nUser limit command position direct set complete.");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
// configure interrupt user data addresses for a user limit
void ConfigureUserLimitInterrupts(MotionController controller, Axis axis, int userLimitIndex)
{
number: userLimitIndex,
userDataIndex: COMMAND_POSITION_INDEX,
number: userLimitIndex,
userDataIndex: ACTUAL_POSITION_INDEX,
}
// wait for and display user limit interrupts
void WaitForInterrupts(MotionController controller)
{
bool done = false;
int timeout_milliseconds = 100;
int interruptCount = 0;
while (!done)
{
RSIEventType eventType = controller.InterruptWait(timeout_milliseconds);
if (eventType != RSIEventType.RSIEventTypeTIMEOUT)
{
interruptCount++;
Console.WriteLine($"\nInterrupt {interruptCount}: {eventType} at sample {controller.InterruptSampleTimeGet()}");
}
switch (eventType)
{
case RSIEventType.RSIEventTypeUSER_LIMIT:
int userLimitNum = controller.InterruptSourceNumberGet();
double cmdPos = controller.InterruptUserDataDoubleGet(COMMAND_POSITION_INDEX);
double actPos = controller.InterruptUserDataDoubleGet(ACTUAL_POSITION_INDEX);
Console.WriteLine($" UserLimit: {userLimitNum}");
Console.WriteLine($" Command Position: {cmdPos}");
Console.WriteLine($" Actual Position: {actPos}");
break;
case RSIEventType.RSIEventTypeTIMEOUT:
done = true;
Console.WriteLine($"\nāœ“ Completed - received {interruptCount} interrupts");
break;
default:
break;
}
}
}
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
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
void TriggeredModifyDecelerationSet(double decel)
Set the deceleration rate for an Triggered Modify Event.
void MoveVelocity(double velocity)
void TriggeredModifyJerkPercentSet(double jerkPct)
Set the jerk percent for an Triggered Modify Event.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5862
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 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.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
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 ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
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
@ RSIAxisAddressTypeCOMMAND_POSITION
Command Position.
@ RSIAxisAddressTypeACTUAL_POSITION
Actual Position.
RSIUserLimitTriggerType
Trigger types for UserLimits.
Definition rsienums.h:633