APIs, concepts, guides, and more

◆ InterruptSourceNumberGet()

int32_t InterruptSourceNumberGet ( )
inherited
Description:
InterruptSourceNumberGet returns the number of the object (Axis, Motor, etc) that generated the interrupt.
Returns
(int32_t) Index or number of the object that generated the interrupt.
Sample Code:
User Limits
// 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;
}
}
}
See also
InterruptSampleTimeGet
Note
For UserLimit objects, RapidCode internally uses one UserLimit per Axis. To determine which UserLimit triggered, you must subtract the AxisCount.
int32_t triggeredUserLimit = controller.InterruptSourceNumberGet()-AXIS_COUNT;
int32_t InterruptSourceNumberGet()
Get the number (or index) of the object (Axis, Motor, etc) that generated the interrupt.
Examples
ControllerInterrupts.cpp, UserLimit.cs, and UserLimitCommandPositionDirect.cs.