APIs, concepts, guides, and more
UserLimitCommandPositionDirect.cs
1
10using RSI.RapidCode.dotNET; // Import our RapidCode Library.
11using NUnit.Framework;
12using System;
13
15[TestFixture]
16[Category("Software")]
17public class UserLimitCommandPositionDirect : StaticMemoryTestBase
18 {
20 // Constants
21 const int AXIS_COUNT = 1;
22 const int USER_LIMIT_FIRST = 0; // Specify which user limit to use.
23 const int USER_LIMIT_SECOND = 1;
24 const int USER_LIMIT_COUNT = 2;
25 const RSIUserLimitLogic LOGIC = RSIUserLimitLogic.RSIUserLimitLogicEQ; // Logic for input value comparison.
26 const RSIUserLimitTriggerType TRIGGER_TYPE = RSIUserLimitTriggerType.RSIUserLimitTriggerTypeSINGLE_CONDITION; // Choose the how the condition (s) should be evaluated.
27 const RSIAction ACTION = RSIAction.RSIActionTRIGGERED_MODIFY; // Choose the action you want to cause when the User Limit triggers.
28
29 const int DURATION = 0; // Enter the time delay before the action is executed after the User Limit has triggered.
30 const bool ONE_SHOT = true; // if true, User Limit will only trigger ONCE
31
32 // User Limit Interrupt constants
33 const int COMMAND_POSITION_INDEX = 0;
34 const int ACTUAL_POSITION_INDEX = 1;
35 const int TC_COMMAND_POSITION_INDEX = 2;
36 const int TC_ACTUAL_POSITION_INDEX = 3;
37
38 public void UserLimitCommandPositionDirectSet()
39 {
40 // Some Necessary Pre User Limit Configuration
41 controller.AxisCountSet(AXIS_COUNT);
42 controller.UserLimitCountSet(USER_LIMIT_COUNT); // Set the amount of UserLimits that you want to use.
43 axis = CreateAndReadyAxis(Constants.AXIS_NUMBER); // Initialize your axis object.
44
45 // set the triggered modify values to stop very quickly
46 axis.TriggeredModifyDecelerationSet(Constants.DECELERATION);
47 axis.TriggeredModifyJerkPercentSet(Constants.JERK_PERCENT);
48
50 // USER LIMIT CONDITION 0 (trigger on digital input)
51 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)
52
54 // controller.UserLimitOutputSet(USER_LIMIT_FIRST, RSIDataType.RSIDataTypeDOUBLE, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeTC_ACTUAL_POSITION), controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER), true);
55
57 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)
58
60 // CONDITION 0 (wait for first user limit to trigger)
61 controller.UserLimitConditionSet(USER_LIMIT_SECOND, 0, RSIUserLimitLogic.RSIUserLimitLogicEQ, controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSERLIMIT_STATUS, USER_LIMIT_FIRST), 1, 1);
62
63 // CONDITION 1 (AND wait for Axis command velcity = 0.0)
64 controller.UserLimitConditionSet(USER_LIMIT_SECOND, 1, RSIUserLimitLogic.RSIUserLimitLogicEQ, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_VELOCITY), 0.0);
65
66 // OUTPUT (copy value from UserBuffer to TC.CommandPosition when trigered)
67 //controller.UserLimitOutputSet(USER_LIMIT_SECOND, RSIDataType.RSIDataTypeDOUBLE, controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER), axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeTC_COMMAND_POSITION), true);
68 controller.UserLimitConfigSet(USER_LIMIT_SECOND, RSIUserLimitTriggerType.RSIUserLimitTriggerTypeCONDITION_AND, RSIAction.RSIActionNONE, 0, 0, ONE_SHOT);
69
70 // get the Axis moving
71 axis.ClearFaults();
72 axis.AmpEnableSet(true);
73 axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
74
75 // configure and enable interrupts
76 ConfigureUserLimitInterrupts(USER_LIMIT_FIRST);
77 ConfigureUserLimitInterrupts(USER_LIMIT_SECOND);
78 controller.InterruptEnableSet(true);
79
80 // wait for (and print) interrupts
81 WaitForInterrupts();
82 }
83
84 public void ConfigureUserLimitInterrupts(int userLimitIndex)
85 {
86 controller.UserLimitInterruptUserDataAddressSet(userLimitIndex, COMMAND_POSITION_INDEX, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeCOMMAND_POSITION));
87 controller.UserLimitInterruptUserDataAddressSet(userLimitIndex, ACTUAL_POSITION_INDEX, axis.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION));
88 }
89
90 public void WaitForInterrupts()
91 {
92 bool done = false;
93 int timeout_millseconds = 10;
94
95 while (!done)
96 {
97 RSIEventType eventType = controller.InterruptWait(timeout_millseconds);
98
99 Console.WriteLine("IRQ: " + eventType.ToString() + " at sample " + controller.InterruptSampleTimeGet());
100
101 switch (eventType)
102 {
103 case RSIEventType.RSIEventTypeUSER_LIMIT:
104 Console.WriteLine("UserLimit " + controller.InterruptSourceNumberGet());
105 Console.WriteLine("CmdPos: " + controller.InterruptUserDataDoubleGet(COMMAND_POSITION_INDEX));
106 Console.WriteLine("ActPos: " + controller.InterruptUserDataDoubleGet(ACTUAL_POSITION_INDEX));
107 Console.WriteLine("TC.CmdPos: " + controller.InterruptUserDataDoubleGet(TC_COMMAND_POSITION_INDEX));
108 Console.WriteLine("TC.ActPos: " + controller.InterruptUserDataDoubleGet(TC_ACTUAL_POSITION_INDEX));
109 break;
110 case RSIEventType.RSIEventTypeTIMEOUT:
111 done = true;
112 break;
113 default:
114 break;
115 }
116 }
117 }
119 }
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.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:404
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:926
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:641
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1073
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:433
RSIUserLimitTriggerType
Trigger types for UserLimits.
Definition rsienums.h:628