APIs, concepts, guides, and more
MotionHold.cs
1
39using RSI.RapidCode.dotNET; // Import our RapidCode Library.
40using NUnit.Framework;
41using System;
42
43#if DOXYGEN // RSI internal documentation use only
44using RSI.RapidCode;
45#endif
46
48[TestFixture]
49[Category("Software")]
50public class MotionHold : SampleAppTestBase
51{
52 public void MotionHoldByDigitalInput()
53 {
55 // Constants
56 const int DIGITAL_INPUTS_PDO_INDEX = 3; // Specify the pdo inputs index that represent digital inputs.
57
58 // SET MOTION HOLD
59 ulong inputAddress = controller.NetworkInputAddressGet(DIGITAL_INPUTS_PDO_INDEX); // Get host address using the PDO Input Index of Digital Inputs.
60
61 axis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeCUSTOM); // Use TypeCUSTOM to hold execution based on a particular bit turning ON or OFF.
62 axis.MotionHoldUserAddressSet(inputAddress); // Specify the digital inputs host address. This address' value will be used to evaluate the motion hold condition.
63 axis.MotionHoldUserMaskSet(0x20000); // Specify the bit you want to mask/watch from the MotionHoldUserAddressSet' address value (this evaluates using a logic AND)
64 axis.MotionHoldUserPatternSet(0x20000); // Specify the bit value that will release the motion hold. (When this value is met, motion hold will be released)
65
66 axis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
67
68 axis.MoveRelative(10); // Command simple relative motion. (This motion will be HOLD by the condition above)
69 axis.MotionDoneWait(); // Wait for Motion to be completed.
70
71 axis.MoveRelative(10); // If motion attribute mask off has not been set, this motion will have same HOLD condition as previous move.
72 axis.MotionDoneWait(); // Wait for Motion to be completed.
73
74 axis.MotionAttributeMaskOffSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD);// Set the HOLD motion attribute mask OFF. (This will clear any motion HOLDS that were set on this Axis)
75
76 axis.MoveRelative(10); // This motion will have no HOLD since the previous line has set the motion attribute mask OFF.
77 axis.MotionDoneWait(); // Wait for Motion to be completed.
78
79 // Abort and Clear Faults
80 axis.Abort();
81 axis.ClearFaults();
83 }
84
85 [Test]
86 public void MotionHoldByPosition()
87 {
89 // Constants
90 const double TRIGGER_POS = 1; // Specify the position that will be evaluted on triggering/releasing motion
91 const int MOVING_AXIS_TARGET = 10;
92 const int HOLDINGAXIS_TARGET = 2;
93
94 // Initialize RapidCode Objects
95 // Initiazlize Axes: holdingAxis and movingAxis
96 Axis holdingAxis = controller.AxisGet(Constants.HOLDING_AXIS_INDEX); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
97 HelperFunctions.CheckErrors(holdingAxis); // [Helper Function] Check that the axis has been initialize correctly.
98
99 Axis movingAxis = controller.AxisGet(Constants.MOVING_AXIS_INDEX); // Initialize HoldAxis Class. (Use RapidSetup Tool to see what is your axis number)
100 HelperFunctions.CheckErrors(movingAxis); // [Helper Function] Check that the axis has been initialize correctly.
101
102 // SET UP MOTION HOLD // Condition/Configuration to the Axis(movingAxis) that will hold Motion and its Position that will trigger/release motion
103 holdingAxis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeAXIS_COMMAND_POSITION); // Use RSIMotionHoldTypeAXIS_ACTUAL_POSITION if it is not Phantom Axis.
104 holdingAxis.MotionHoldAxisNumberSet(movingAxis.NumberGet()); // Specify motion hold to the Axis(movingAxis) whose position will hold the motion of holdingAxis.
105 holdingAxis.MotionHoldAxisPositionSet(TRIGGER_POS); // Specify motion hold position which is the movingAxis's position(need to multiply with USER_UNITS to get correct position value) to trigger/release the motion of holdingAxis.
106 holdingAxis.MotionHoldAxisLogicSet(RSIUserLimitLogic.RSIUserLimitLogicGE); // Specify the logic condition that will be evaluated to trigger/release motion based on the SET POSITION(USER_UNITS * TRIGGER_POS).In this case, GT(Greater than or Equal to) motion hold position limit to release
107
108 // SET MOTION HOLD ON
109 holdingAxis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
110 holdingAxis.MoveRelative(HOLDINGAXIS_TARGET); // Command simple relative motion(This motion will be hold by condition above until movingAxis's Position passes motion hold position limit)
111
112 // Release MOTION HOLD
113 movingAxis.MoveRelative(MOVING_AXIS_TARGET); // Move movingAxis.MovingAxis's position reaches its MotionHold Position limit(in this case, limit is 5). It will trigger/release motion on holdingAxis (holidingAxis will move relatively 10).
114 movingAxis.MotionDoneWait();
115 holdingAxis.MotionDoneWait();
117
119 Assert.That(holdingAxis.CommandPositionGet(), Is.EqualTo(HOLDINGAXIS_TARGET));
120 }
121
122 [Test]
123 public void MotionHoldBySoftwareAddress()
124 {
126 // Constants
127 UInt64 SOFTWARE_ADDRESS = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 1);
128 int WAIT_TIME = 10;
129 int MOVE_DIST = 2;
130
131 // SET MOTION HOLD ON AVAILABLE SOFTWARE ADDRESS
132 axis.MotionHoldTypeSet(RSIMotionHoldType.RSIMotionHoldTypeCUSTOM); // Use TypeCUSTOM to hold execution based on a particular bit turning ON or OFF.
133 axis.MotionHoldUserAddressSet(SOFTWARE_ADDRESS); // Specify the available hostAddress . This address' value will be used to evaluate the motion hold condition.
134 axis.MotionHoldUserMaskSet(0x1); // Specify the bit you want to mask/watch from the MotionHoldUserAddressSet' address value (this evaluates using a logic AND)
135 axis.MotionHoldUserPatternSet(0x1); // Specify the bit value that will release the motion hold. (When this value is met, motion hold will be released)
136
137 // Check the condition to be false at first
138 if (controller.MemoryGet(SOFTWARE_ADDRESS) != 0x0) // Check Available host address value is mask to be false (in this case 0x0)
139 {
140 controller.MemorySet(SOFTWARE_ADDRESS, 0x0); // if not, mask it to false value/condition (in this case 0x0)
141 }
142
143 // SET MOTION HOLD
144 axis.MotionAttributeMaskOnSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask ON. (This initializes the HOLD on a particular motion)
145
146 axis.MoveRelative(MOVE_DIST); // Command simple relative motion. (This motion will be HOLD by the condition above)
147 System.Threading.Thread.Sleep(WAIT_TIME); // Sleep for (x) miliseconds before releasing motion hold.
148
149 var expectedCmdPos1 = axis.CommandPositionGet(); // Sould be 0
150
151 // RELEASE MOTION HOLD
152 controller.MemorySet(SOFTWARE_ADDRESS, 0x1); // Release Motion Hold by specifying the host address value to SET Condition (in this case 0x10000)
153 axis.MotionDoneWait(); // Wait for motion to be done
154 controller.MemorySet(SOFTWARE_ADDRESS, 0x0); // Specify host address value back to false value/condition (in this case 0x0)
155
156 var expectedCmdPos2 = axis.CommandPositionGet(); // Should be MOVE_DIST
157
158 // COMMAND MOTION AGAIN
159 axis.MoveRelative(MOVE_DIST); // Command simple relative motion again. (This motion will be HOLD by the condition above)
160 System.Threading.Thread.Sleep(WAIT_TIME); // Sleep for (x) miliseconds before releasing motion hold.
161
162 // RELEASE MOTION HOLD
163 controller.MemorySet(SOFTWARE_ADDRESS, 0x1); // Release Motion Hold by specifying the host address value to SET Condition (in this case 0x1)
164 axis.MotionDoneWait(); // Wait for motion to be done
165 controller.MemorySet(SOFTWARE_ADDRESS, 0x0); // Specify host address value back to false value/condition (in this case 0x0)
166
167 // CLEAR MOTION HOLD
168 axis.MotionAttributeMaskOffSet(RSIMotionAttrMask.RSIMotionAttrMaskHOLD); // Set the HOLD motion attribute mask OFF. (This will clear any motion HOLDS that were set on this Axis)
169
170 axis.MoveRelative(MOVE_DIST); // This motion will have no HOLD since the previous line has set the motion attribute mask OFF.
171 axis.MotionDoneWait(); // Wait for Motion to be completed.
173
175 Assert.That(expectedCmdPos1, Is.EqualTo(0));
176 Assert.That(expectedCmdPos2, Is.EqualTo(MOVE_DIST));
177 }
178}
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
double CommandPositionGet()
Get the current command position.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5513
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
int32_t MemoryGet(uint64_t address)
Read controller memory.
uint64_t NetworkInputAddressGet(int32_t index)
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void MotionHoldAxisPositionSet(double position)
Sets the Axis position.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
void MotionHoldUserMaskSet(int32_t holdMask)
Sets the Motion Hold User bit mask.
void MotionHoldUserPatternSet(int32_t pattern)
Sets the Motion Hold User pattern bit mask.
void MotionAttributeMaskOffSet(RSIMotionAttrMask maskOff)
Turn off a particular motion attribute mask.
void MotionHoldTypeSet(RSIMotionHoldType type)
Set the motion hold type.
void MotionHoldAxisNumberSet(int32_t number)
Sets the Axis number for Motion Hold.
void MotionHoldUserAddressSet(uint64_t address)
Sets the Motion Hold User Address.
int32_t NumberGet()
Get the axis number.
void MotionAttributeMaskOnSet(RSIMotionAttrMask maskOn)
Turn on a particular motion attribute mask.
void MotionHoldAxisLogicSet(RSIUserLimitLogic logic)
Set the logic when holding for Axis ActualPosition.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:404
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:639
RSIMotionAttrMask
Attribute masks for motion. You cannot mix RSIMotionAttrMaskDELAY and RSIMotionAttrMaskAPPEND.
Definition rsienums.h:1005
RSIMotionHoldType
Types for MotionHold attribute.
Definition rsienums.h:1041