17 var hasErrors =
false;
18 var errorStrBuilder =
new System.Text.StringBuilder();
26 var errorMsg = rsiError.isWarning ? $
"WARNING: {rsiError.Message}" : $
"ERROR: {rsiError.Message}";
27 errorStrBuilder.AppendLine(errorMsg);
34 throw new Exception(errorStrBuilder.ToString());
50 if (controller.NetworkStateGet() !=
RSINetworkState.RSINetworkStateOPERATIONAL)
52 Console.WriteLine(
"Starting Network..");
55 controller.NetworkStart();
59 if (controller.NetworkStateGet() !=
RSINetworkState.RSINetworkStateOPERATIONAL)
62 int messagesToRead = controller.NetworkLogMessageCountGet();
65 for (
int i = 0; i < messagesToRead; i++)
66 Console.WriteLine(controller.NetworkLogMessageGet(i));
68 throw new SystemException(
"Expected OPERATIONAL state but the network did not get there.");
72 Console.WriteLine(
"Network Started");
89 if (controller.NetworkStateGet() ==
RSINetworkState.RSINetworkStateUNINITIALIZED ||
90 controller.NetworkStateGet() ==
RSINetworkState.RSINetworkStateSHUTDOWN)
94 Console.WriteLine(
"Shutting down the network..");
95 controller.NetworkShutdown();
98 var networkState = controller.NetworkStateGet();
103 int messagesToRead = controller.NetworkLogMessageCountGet();
106 for (
int i = 0; i < messagesToRead; i++)
107 Console.WriteLine(controller.NetworkLogMessageGet(i));
109 throw new SystemException(
"Expected SHUTDOWN state but the network did not get there.");
113 Console.WriteLine(
"Network Shutdown");
148 throw new Exception(@$
"Axis {phantomAxis.NumberGet()} is not configured as a phantom axis.
149 Please ensure the axis is set to phantom before calling PhantomAxisConfigure.");
164 double POSITION_TOLERANCE_MAX = Double.MaxValue / 10.0;
197 string errorMsg = @$
"Axis or MultiAxis {motionObject.NumberGet()} failed to enter IDLE state after aborting.
198 The source of the axis error is: {motionObject.SourceNameGet(source)}";
199 throw new Exception(errorMsg);
216 bool networkIsOperational = controller.NetworkStateGet() ==
RSINetworkState.RSINetworkStateOPERATIONAL;
218 if (USE_HARDWARE && !networkIsOperational)
220 throw new Exception(
"USE_HARDWARE is set to true, but the network is not operational. " +
221 "Please properly configure your hardware or run _setup.cs.");
223 else if (!USE_HARDWARE && networkIsOperational)
225 throw new Exception(
"USE_HARDWARE is set to false, but the network is operational. " +
226 "Please ensure you are not connected to real hardware, or set USE_HARDWARE in _constants.cs to true.");
228 else if (!USE_HARDWARE && !networkIsOperational)
230 Console.WriteLine(
"Running with phantom axes as expected.");
235 Console.WriteLine(
"Caution: You are currently running with hardware. " +
236 "Do not continue unless you have configured your axes through _setup.cs or another tool!");
237 Console.Write(
"Press 'y' to continue: ");
238 var input = Console.ReadKey();
241 if (input.KeyChar !=
'y' && input.KeyChar !=
'Y')
243 throw new Exception(
"User chose not to continue with hardware operation.");
259 public static void VerifyAxisCount(MotionController controller,
int minRequiredSampleAxisCount = 1,
int minRequiredSampleMultiAxisCount = 0)
262 int AXIS_COUNT = Constants.AXIS_COUNT;
265 if (controllerAxisCount != AXIS_COUNT)
268 throw new Exception($
"Controller axis count ({controllerAxisCount}) does not match intended AXIS_COUNT ({AXIS_COUNT}). " +
269 "Please ensure AXIS_COUNT in _constants.cs matches your number of hardware axes, then run _setup.cs or another tool " +
270 "to configure your hardware.");
275 if (AXIS_COUNT < minRequiredSampleAxisCount)
277 throw new Exception($
"This sample requires at least {minRequiredSampleAxisCount} " +
278 $
"{(minRequiredSampleAxisCount == 1 ? "axis
" : "axes
")}, but AXIS_COUNT is only {AXIS_COUNT}. " +
279 $
"Update your AXIS_COUNT in _constants.cs to meet the minimum requirement.");
283 if (controller.
MotionCountGet() - controllerAxisCount < minRequiredSampleMultiAxisCount)
285 throw new Exception($
"This sample requires at least {minRequiredSampleMultiAxisCount} " +
286 $
"MultiAxis object{(minRequiredSampleMultiAxisCount == 1 ? "" : "s
")}. " +
287 "Please add more motion supervisors.");
Constants used in the C# sample apps.
const bool USE_HARDWARE
Default: false.
static void AbortMotionObject(RapidCodeMotion motionObject)
Aborts motion on the given RapidCodeMotion object (Axis or MultiAxis), waits for motion to stop,...
static void NetworkShutdown(MotionController controller)
Shuts down the network communication for the given MotionController.
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PhantomAxisReset(Axis phantomAxis)
Configures a phantom axis on the controller.
static void NetworkStart(MotionController controller)
Starts the network communication for the given MotionController.
static void ControllerSetup(MotionController controller)
Sets up the controller for hardware use by resetting it and starting the network.
void HardwareNegLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Negative Limit Event triggers.
void HardwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Hardware Positive Limit Event triggers.
RSIMotorType MotorTypeGet()
Get the motor type.
void PositionToleranceCoarseSet(double tolerance)
Set the Coarse Position Tolerance for Axis settling.
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 HomeActionSet(RSIAction action)
Set the action that will occur when the Home Event triggers.
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.
void PositionSet(double position)
Set the Command and Actual positions.
void SoftwarePosLimitActionSet(RSIAction action)
Set the action that will occur when the Software Positive Limit Event triggers.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
void DefaultVelocitySet(double velocity)
Set the default velocity in UserUnits.
void DefaultAccelerationSet(double acceleration)
Set the default acceleration in UserUnits.
void DefaultDecelerationSet(double deceleration)
Set the default deceleration in UserUnits.
void DefaultJerkPercentSet(double jerkPercent)
Set the default jerk percent.
int32_t AxisCountGet()
Get the number of axes processing.
int32_t MotionCountGet()
Get the number of Motion Supervisors available in the firmware.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
int32_t MotionDoneWait(int32_t waitTimeoutMilliseconds=WaitForever)
Waits for a move to complete.
RSIState StateGet()
Get the Axis or MultiAxis state.
RSISource SourceGet()
Get the source of an error state for an Axis or MultiAxis.
void EStopAbort()
E-Stop, then abort an axis.
The RapidCodeMotion interface is implemented by Axis and MultiAxis .
const RsiError *const ErrorLogGet()
Get the next RsiError in the log.
int32_t ErrorLogCountGet()
Get the number of software errors in the error log.
The RapidCode base class. All non-error objects are derived from this class.
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
bool isWarning
Whether the error is or is not a warning.
RSINetworkState
State of network.
RSIAction
Action to perform on an Axis.
RSISource
Possible sources that have caused an Error state.
void NetworkStart(MotionController *controller)
[CheckErrors]
void NetworkShutdown(MotionController *controller)
[NetworkStart]
Helpers namespace provides utility functions for common tasks in RMP applications.