The RMP Motion Controller APIs
AxisConfig.cs
1
65using RSI.RapidCode.dotNET; // Import our RapidCode Library
66using System;
67using NUnit.Framework;
68
70[TestFixture]
71[Category("Software")]
72public class AxisConfig : SampleAppTestBase
73{
74 [Test, Timeout(Constants.MAX_TEST_TIME)]
75 public void AxisSettling()
76 {
77 double POSITION_TOLERANCE_FINE_DEFAULT = axis.PositionToleranceFineGet();
78 double POSITION_TOLERANCE_COARSE_DEFAULT = axis.PositionToleranceCoarseGet();
79 double VELOCITY_TOLERANCE_DEFAULT = axis.VelocityToleranceGet();
80 double SETTLING_TIME_DEFAULT = axis.SettlingTimeGet();
81
84 const double POSITION_TOLERANCE_FINE = 200; // Specify the fine position tolerance.
85 const double POSITION_TOLERANCE_COARSE = 300; // Specify the coarse position tolerance.
86 const double VELOCITY_TOLERANCE = 12000; // Specify the velocity tolerance.
87 const double SETTLING_TIME = 5; // Specify the settling time.
88
90 // SET
91 axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE); // Set fine position tolerance.
92 axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE); // Set coarse position tolerance.
93 axis.VelocityToleranceSet(VELOCITY_TOLERANCE); // Set velocity tolerance.
94 axis.SettlingTimeSet(SETTLING_TIME); // Set settling time.
95
96 // GET
97 var posTolFine = axis.PositionToleranceFineGet();
98 var posTolCoarse = axis.PositionToleranceCoarseGet();
99 var velTol = axis.VelocityToleranceGet();
100 var setTime = axis.SettlingTimeGet();
102
104 Assert.That(posTolFine, Is.EqualTo(POSITION_TOLERANCE_FINE), "The getter function should return a value equal to POSITION_TOLERANCE_FINE");
105 Assert.That(posTolCoarse, Is.EqualTo(POSITION_TOLERANCE_COARSE), "The getter function should return a value equal to POSITION_TOLERANCE_COARSE");
106 Assert.That(velTol, Is.EqualTo(VELOCITY_TOLERANCE), "The getter function should return a value equal to VELOCITY_TOLERANCE");
107 Assert.That(setTime, Is.EqualTo(SETTLING_TIME), "The getter function should return a value equal to SETTLING_TIME");
108
109 axis.PositionToleranceFineSet(POSITION_TOLERANCE_FINE_DEFAULT); // Set fine position tolerance.
110 axis.PositionToleranceCoarseSet(POSITION_TOLERANCE_COARSE_DEFAULT); // Set coarse position tolerance.
111 axis.VelocityToleranceSet(VELOCITY_TOLERANCE_DEFAULT); // Set velocity tolerance.
112 axis.SettlingTimeSet(SETTLING_TIME_DEFAULT);
113 }
114
115 [Test, Timeout(Constants.MAX_TEST_TIME)]
116 public void ConfigAmpFault()
117 {
118 RSIAction RSIAction_DEFAULT = axis.AmpFaultActionGet(); // Set the action that will occur when there is an amp fault.
119 bool Trigger_DEFAULT = axis.AmpFaultTriggerStateGet(); //Set the state of the amp fault.
120 double AMP_FAULT_DURATION_TIME_DEFAULT = axis.AmpFaultDurationGet(); //Set the duration required before the Amp Fault event triggers.
121
124 const double AMP_FAULT_DURATION_TIME = 1; //value in seconds
125
127 // SET
128 axis.AmpEnableSet(false); // Disable the amp
129 axis.AmpFaultActionSet(RSIAction.RSIActionABORT); // Set the action that will occur when there is an amp fault.
130 axis.AmpFaultTriggerStateSet(false); //Set the state of the amp fault.
131 axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME); //Set the duration required before the Amp Fault event triggers.
132
133 // GET
134 var isEnabled = axis.AmpEnableGet();
135 var faultAction = axis.AmpFaultActionGet();
136 var faultTriggerState = axis.AmpFaultTriggerStateGet();
137 var faultDuration = axis.AmpFaultDurationGet();
139
141 Assert.That(isEnabled, Is.EqualTo(false), "The getter function should return a value equal to false");
142 Assert.That(faultAction, Is.EqualTo(RSIAction.RSIActionABORT), "The getter function should return a value equal to RSIActionABORT");
143 Assert.That(faultTriggerState, Is.EqualTo(false), "The getter function should return a value equal to false");
144 Assert.That(faultDuration, Is.EqualTo(AMP_FAULT_DURATION_TIME), "The getter function should return a value equal to AMP_FAULT_DURATION_TIME");
145
146 //---RESET---
147 axis.AmpFaultActionSet(RSIAction_DEFAULT); // Set the action that will occur when there is an amp fault.
148 axis.AmpFaultTriggerStateSet(Trigger_DEFAULT); //Set the state of the amp fault.
149 axis.AmpFaultDurationSet(AMP_FAULT_DURATION_TIME_DEFAULT); //Set the duration required before the Amp Fault event triggers.
150 }
151
152 [Test, Timeout(Constants.MAX_TEST_TIME)]
153 public void SetUserUnits()
154 {
155 // Other Variables
156 double currentUserUnits = axis.UserUnitsGet();
157
159 const int ENCODER_RESOLUTION_BITS = 20; // The number of bits defining the encoder resolution
160
161 // Specify your counts per unit/user units. (the motor used in this sample app has 1048576 encoder pulses per revolution)
162 // 1048576 Setting the user units to this value will result in a commanded position of 1 spinning the motor 1 full revolution
163 double USER_UNITS = Math.Pow(2, ENCODER_RESOLUTION_BITS);
164
165 // SET
166 axis.UserUnitsSet(USER_UNITS);
167 axis.ErrorLimitTriggerValueSet(1); // Specify the position error limit trigger. (Learn more about this on our support page)
168
169 // GET
170 var userUnits = axis.UserUnitsGet();
172
174 Assert.That(userUnits, Is.EqualTo(USER_UNITS)); // Verify that your user units were changed!
175 Assert.That(userUnits, Is.EqualTo(1048576)); // Verify that your user units were changed!
176
177 axis.UserUnitsSet(Constants.USER_UNITS); // Restore Default
178 }
179
180 [Test, Timeout(Constants.MAX_TEST_TIME)]
181 public void StopRate()
182 {
184 const double STOP_RATE = 1.2; // Specify the default STOP rate in seconds.
185 const double ESTOP_RATE = 1.3; // Specify the default ESTOP rate in seconds.
186 const double ESTOP_DECELERATION_RATE_T = 1.5; // Specify the default ESTOP deceleration rate in seconds.
187
188 axis.StopTimeSet(STOP_RATE); // Set the default STOP time to STOP_RATE_DEFAULT secs.
189 axis.EStopTimeSet(ESTOP_RATE); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
190 axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE_T); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
191 Assert.That(axis.StopTimeGet(), Is.EqualTo(STOP_RATE)); // Verify that your user units were changed!
192 Assert.That(axis.EStopTimeGet(), Is.EqualTo(ESTOP_RATE)); // Verify that your user units were changed!
193 Assert.That(axis.EStopDecelerationGet(), Is.EqualTo(ESTOP_DECELERATION_RATE_T)); // Verify that your user units were changed!
194
196 // Constants
197 const double STOP_RATE_DEFAULT = 1.0; // Specify the default STOP rate in seconds.
198 const double ESTOP_RATE_DEFAULT = 0.05; // Specify the default ESTOP rate in seconds.
199 const double ESTOP_DECELERATION_RATE = 1000; // Specify the default ESTOP deceleration rate in seconds.
200
201 // SET
202 axis.StopTimeSet(STOP_RATE_DEFAULT); // Set the default STOP time to STOP_RATE_DEFAULT secs.
203 axis.EStopTimeSet(ESTOP_RATE_DEFAULT); // Set the default ESTOP time to ESTOP_RATE_DEFAULT secs.
204 axis.EStopDecelerationSet(ESTOP_DECELERATION_RATE); // Set the default ESTOP time to ESTOP_DECELERATION_RATE secs.
206 }
207
208 [Test, Timeout(Constants.MAX_TEST_TIME)]
209 public void HardwareLimits()
210 {
211 var defaultTriggerState = axis.HardwarePosLimitTriggerStateGet();
212
215 const bool ACTIVE_HIGH = true; // Constant for active high.
216 const bool ACTIVE_LOW = false; // Constant for active low.
217 const double HW_POS_DURATION_TIME = 0.01; // Positive limit duration. (in seconds)
218 const double HW_NEG_DURATION_TIME = 0.01; // Negative limit duration. (in seconds)
219
221 // SET (Hardware POSITIVE (+) Limit characteristics)
222 axis.HardwarePosLimitActionSet(RSIAction.RSIActionE_STOP); // Set the positive limit action to E_STOP.
223 axis.HardwarePosLimitTriggerStateSet(ACTIVE_HIGH); // Set the positive limit trigger state to ACTIVE_HIGH.
224 axis.HardwarePosLimitDurationSet(HW_POS_DURATION_TIME); // Set the positive limit duration to 0.01 seconds.
225
226 // GET
227 var hPosLimAct = axis.HardwarePosLimitActionGet();
228 var hPosLimTrigState = axis.HardwarePosLimitTriggerStateGet();
229 var hPosLimDur = axis.HardwarePosLimitDurationGet();
230
231 // SET (Hardware NEGATIVE (-) Limit charateristics)
232 axis.HardwareNegLimitActionSet(RSIAction.RSIActionE_STOP); // Set the negative limit action to E_STOP.
233 axis.HardwareNegLimitTriggerStateSet(ACTIVE_LOW); // Set the negative limit trigger state to ACTIVE_LOW.
234 axis.HardwareNegLimitDurationSet(HW_NEG_DURATION_TIME); // Set the negative limit duration to 0.01 seconds.
235
236 // GET
237 var hNegLimAct = axis.HardwareNegLimitActionGet();
238 var hNegLimTrigState = axis.HardwareNegLimitTriggerStateGet();
239 var hNegLimDur = axis.HardwareNegLimitDurationGet();
241
243 Assert.That(hPosLimAct, Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
244 Assert.That(hPosLimTrigState, Is.EqualTo(ACTIVE_HIGH), "Hardware Positive Limit TriggerState should be set to ACTIVE_HIGH");
245 Assert.That(hPosLimDur, Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
246
247 Assert.That(hNegLimAct, Is.EqualTo(RSIAction.RSIActionE_STOP), "Hardware Positive Limit Action should be set to RSIAction.RSIActionE_STOP");
248 Assert.That(hNegLimTrigState, Is.EqualTo(ACTIVE_LOW), "Hardware Positive Limit TriggerState should be set to ACTIVE_LOW");
249 Assert.That(hNegLimDur, Is.EqualTo(HW_POS_DURATION_TIME), "Hardware Positive Limit Duration set to HW_POS_DURATION_TIME");
250
251 //---RESET---
252 axis.HardwarePosLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
253 axis.HardwareNegLimitTriggerStateSet(defaultTriggerState); // Set the positive limit trigger state to ACTIVE_HIGH.
254 }
255
256 public void PhantomAxis()
257 {
259 controller.AxisCountSet(controller.AxisCountGet() + 1); // Configure one additional axis to be used for the phantom axis
260
261 int axisNumber = controller.AxisCountGet() - 1; // Set the axis number to the last axis on the network (subtract one because the axes are zero indexed)
262
263 axis = controller.AxisGet(axisNumber); // Initialize Axis class
264 HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialized correctly
265
266 // These limits are not meaningful for a Phantom Axis (e.g., a phantom axis has no actual position so a position error trigger is not necessary)
267 // Therefore, you must set all of their actions to "NONE".
268 axis.ErrorLimitActionSet(RSIAction.RSIActionNONE); // Set Error Limit Action.
269 axis.HardwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Negative Limit Action.
270 axis.HardwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Hardware Positive Limit Action.
271 axis.HomeActionSet(RSIAction.RSIActionNONE); // Set Home Action.
272 axis.SoftwareNegLimitActionSet(RSIAction.RSIActionNONE); // Set Software Negative Limit Action.
273 axis.SoftwarePosLimitActionSet(RSIAction.RSIActionNONE); // Set Software Positive Limit Action.
274
275 const double positionToleranceMax = Double.MaxValue / 10.0; // Reduce from max slightly, so XML to string serialization and deserialization works without throwing System.OverflowException
276 axis.PositionToleranceCoarseSet(positionToleranceMax); // Set Settling Coarse Position Tolerance to max value
277 axis.PositionToleranceFineSet(positionToleranceMax); // Set Settling Fine Position Tolerance to max value (so Phantom axis will get immediate MotionDone when target is reached)
278
279 axis.MotorTypeSet(RSIMotorType.RSIMotorTypePHANTOM); // Set the MotorType to phantom
281 }
282}
static void CheckErrors(RapidCodeObject rsiObject)
Check if the RapidCodeObject has any errors.
Helper Functions for checking logged creation errors, starting the network, etc.
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
RSIAction AmpFaultActionGet()
Get the Amp Fault action.
double SettlingTimeGet()
Get the Settling time.
void HardwareNegLimitDurationSet(double seconds)
Set the duration required before the Hardware Negative Limit event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
double UserUnitsGet()
Get the number of counts per User Unit.
bool AmpEnableGet()
Get the state of the Amp Enable Output.
double PositionToleranceFineGet()
Get the Fine Position Tolerance for axis settling.
RSIAction HardwarePosLimitActionGet()
Get the action that will occur when the Hardware Positive Limit Event triggers.
void HardwarePosLimitTriggerStateSet(bool state)
sets the trigger state.
void SoftwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Software Negative Limit Event triggers.
void UserUnitsSet(double countsPerUserUnit)
Sets the number of counts per User Unit.
void AmpFaultActionSet(RSIAction action)
Set the Amp Fault action.
void AmpFaultTriggerStateSet(bool state)
Set the trigger state of the Amp Fault input.
void HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
void ErrorLimitTriggerValueSet(double triggerValue)
Set the Position Error Limit trigger value.
void PositionToleranceFineSet(double tolerance)
Set the Fine Position Tolerance for Axis settling.
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
double AmpFaultDurationGet()
Get the duration required before the Amp Fault event triggers.
double HardwareNegLimitDurationGet()
Get the duration required before the Hardware Negative Limit event triggers.
bool HardwarePosLimitTriggerStateGet()
trigger state return.
void HardwarePosLimitDurationSet(double seconds)
Set the duration required before the Hardware Positive Limit event triggers.
void VelocityToleranceSet(double tolerance)
Set the Velocity Tolerance used for settling.
double PositionToleranceCoarseGet()
Get the Coarse Position Tolerance for axis settling.
double EStopDecelerationGet()
Get the deceleration rate for an E-Stop, Modify Event.
bool AmpFaultTriggerStateGet()
Get the Amp Fault trigger state.
double VelocityToleranceGet()
Get the velocity tolerance used for settling.
void EStopDecelerationSet(double decel)
Set the deceleration rate for an E-Stop, Modify Event.
void MotorTypeSet(RSIMotorType type)
Set the motor type.
bool HardwareNegLimitTriggerStateGet()
Trigger state return.
double HardwarePosLimitDurationGet()
Get the duration required before the Hardware Positive Limit event triggers.
void AmpFaultDurationSet(double seconds)
Set the duration required before the Amp Fault event triggers.
RSIAction HardwareNegLimitActionGet()
Get the action that will occur when the Hardware Negative Limit Event triggers.
void HardwareNegLimitTriggerStateSet(bool state)
Sets the trigger state.
void SettlingTimeSet(double time)
Set the settling time.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
int32_t AxisCountGet()
Get the number of axes processing.
void AxisCountSet(int32_t axisCount)
Set the number of allocated and processed axes in the controller.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void StopTimeSet(double seconds)
Set the deceleration time for a Stop Event.
double EStopTimeGet()
Get E-Stop Event deceleration time.
void EStopTimeSet(double seconds)
Set the deceleration time for an E-Stop Event.
double StopTimeGet()
Get Stop Event deceleration time.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1051
RSIMotorType
Motor Type.
Definition rsienums.h:1247