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