APIs, concepts, guides, and more
UserLimitCommandPositionDirect.cs
Attention
See the following Concept pages for a detailed explanation of this sample: User Limits.
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.
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using NUnit.Framework;
using System;
[TestFixture]
[Category("Software")]
public class UserLimitCommandPositionDirect : StaticMemoryTestBase
{
// Constants
const int AXIS_COUNT = 1;
const int USER_LIMIT_FIRST = 0; // Specify which user limit to use.
const int USER_LIMIT_SECOND = 1;
const int USER_LIMIT_COUNT = 2;
const RSIUserLimitLogic LOGIC = RSIUserLimitLogic.RSIUserLimitLogicEQ; // Logic for input value comparison.
const RSIUserLimitTriggerType TRIGGER_TYPE = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION; // Choose the how the condition (s) should be evaluated.
const RSIAction ACTION = RSIAction.RSIActionTRIGGERED_MODIFY; // Choose the action you want to cause when the User Limit triggers.
const int DURATION = 0; // Enter the time delay before the action is executed after the User Limit has triggered.
const bool ONE_SHOT = true; // if true, User Limit will only trigger ONCE
// User Limit Interrupt constants
const int COMMAND_POSITION_INDEX = 0;
const int ACTUAL_POSITION_INDEX = 1;
const int TC_COMMAND_POSITION_INDEX = 2;
const int TC_ACTUAL_POSITION_INDEX = 3;
public void UserLimitCommandPositionDirectSet()
{
// Some Necessary Pre User Limit Configuration
controller.AxisCountSet(AXIS_COUNT);
controller.UserLimitCountSet(USER_LIMIT_COUNT); // Set the amount of UserLimits that you want to use.
axis = CreateAndReadyAxis(Constants.AXIS_NUMBER); // Initialize your axis object.
// set the triggered modify values to stop very quickly
axis.TriggeredModifyDecelerationSet(Constants.DECELERATION);
axis.TriggeredModifyJerkPercentSet(Constants.JERK_PERCENT);
// USER LIMIT CONDITION 0 (trigger on digital input)
controller.UserLimitConditionSet(USER_LIMIT_FIRST, 0, LOGIC, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeDIGITAL_INPUTS), 0x400000, 0x400000); // Set your User Limit Condition (1st step to setting up your user limit)
// controller.UserLimitOutputSet(USER_LIMIT_FIRST, RSIDataType.RSIDataTypeDOUBLE, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeTC_ACTUAL_POSITION), controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER), true);
controller.UserLimitConfigSet(USER_LIMIT_FIRST, TRIGGER_TYPE, ACTION, axis.NumberGet(), DURATION, ONE_SHOT); // Set your User Limit Configuration. (2nd step to setting up your user limit)
// CONDITION 0 (wait for first user limit to trigger)
controller.UserLimitConditionSet(USER_LIMIT_SECOND, 0, RSIUserLimitLogic.RSIUserLimitLogicEQ, controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSERLIMIT_STATUS, USER_LIMIT_FIRST), 1, 1);
// CONDITION 1 (AND wait for Axis command velcity = 0.0)
controller.UserLimitConditionSet(USER_LIMIT_SECOND, 1, RSIUserLimitLogic.RSIUserLimitLogicEQ, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_VELOCITY), 0.0);
// OUTPUT (copy value from UserBuffer to TC.CommandPosition when trigered)
//controller.UserLimitOutputSet(USER_LIMIT_SECOND, RSIDataType.RSIDataTypeDOUBLE, controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER), axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeTC_COMMAND_POSITION), true);
controller.UserLimitConfigSet(USER_LIMIT_SECOND, RSIUserLimitTriggerType.RSIUserLimitTriggerTypeCONDITION_AND, RSIAction.RSIActionNONE, 0, 0, ONE_SHOT);
// get the Axis moving
axis.ClearFaults();
axis.AmpEnableSet(true);
axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
// configure and enable interrupts
ConfigureUserLimitInterrupts(USER_LIMIT_FIRST);
ConfigureUserLimitInterrupts(USER_LIMIT_SECOND);
controller.InterruptEnableSet(true);
// wait for (and print) interrupts
WaitForInterrupts();
}
public void ConfigureUserLimitInterrupts(int userLimitIndex)
{
controller.UserLimitInterruptUserDataAddressSet(userLimitIndex, COMMAND_POSITION_INDEX, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_POSITION));
controller.UserLimitInterruptUserDataAddressSet(userLimitIndex, ACTUAL_POSITION_INDEX, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION));
}
public void WaitForInterrupts()
{
bool done = false;
int timeout_millseconds = 10;
while (!done)
{
RSIEventType eventType = controller.InterruptWait(timeout_millseconds);
Console.WriteLine("IRQ: " + eventType.ToString() + " at sample " + controller.InterruptSampleTimeGet());
switch (eventType)
{
case RSIEventType.RSIEventTypeUSER_LIMIT:
Console.WriteLine("UserLimit " + controller.InterruptSourceNumberGet());
Console.WriteLine("CmdPos: " + controller.InterruptUserDataDoubleGet(COMMAND_POSITION_INDEX));
Console.WriteLine("ActPos: " + controller.InterruptUserDataDoubleGet(ACTUAL_POSITION_INDEX));
Console.WriteLine("TC.CmdPos: " + controller.InterruptUserDataDoubleGet(TC_COMMAND_POSITION_INDEX));
Console.WriteLine("TC.ActPos: " + controller.InterruptUserDataDoubleGet(TC_ACTUAL_POSITION_INDEX));
break;
case RSIEventType.RSIEventTypeTIMEOUT:
done = true;
break;
default:
break;
}
}
}
}
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.
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.
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 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.
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.
int32_t InterruptSampleTimeGet()
Get the sample timer value when the last interrupt was generated.
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 AmpEnableSet(bool enable)
Enable all amplifiers.
int32_t NumberGet()
Get the axis number.