APIs, concepts, guides, and more
_helpers.cs
1using RSI.RapidCode; // RSI.RapidCode.dotNET;
2
4public static class Helpers
5{
15 public static void CheckErrors(RapidCodeObject rsiObject)
16 {
17 var hasErrors = false;
18 var errorStrBuilder = new System.Text.StringBuilder();
19
20 while (rsiObject.ErrorLogCountGet() > 0)
21 {
22 // get error
23 RsiError rsiError = rsiObject.ErrorLogGet();
24
25 // get message
26 var errorMsg = rsiError.isWarning ? $"WARNING: {rsiError.Message}" : $"ERROR: {rsiError.Message}";
27 errorStrBuilder.AppendLine(errorMsg);
28
29 // set flag
30 hasErrors = !rsiError.isWarning;
31 }
32
33 if (hasErrors)
34 throw new Exception(errorStrBuilder.ToString());
35 }
37
47 public static void StartTheNetwork(MotionController controller)
48 {
49 // check if network is started already
50 if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
51 {
52 Console.WriteLine("Starting Network..");
53
54 // if not started, initialize the network
55 controller.NetworkStart();
56 }
57
58 // check if network is started again
59 if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
60 {
61 // read network log messages
62 int messagesToRead = controller.NetworkLogMessageCountGet();
63
64 // print all the messages to help figure out the problem
65 for (int i = 0; i < messagesToRead; i++)
66 Console.WriteLine(controller.NetworkLogMessageGet(i));
67
68 throw new SystemException("Expected OPERATIONAL state but the network did not get there.");
69 }
70 else
71 {
72 Console.WriteLine("Network Started");
73 }
74 }
76
86 public static void ShutdownTheNetwork(MotionController controller)
87 {
88 // check if the network is already shutdown
89 if (controller.NetworkStateGet() == RSINetworkState.RSINetworkStateUNINITIALIZED ||
90 controller.NetworkStateGet() == RSINetworkState.RSINetworkStateSHUTDOWN)
91 return;
92
93 // shutdown the network
94 Console.WriteLine("Shutting down the network..");
95 controller.NetworkShutdown();
96
97 // check if the network is shutdown
98 var networkState = controller.NetworkStateGet();
99 if (networkState != RSINetworkState.RSINetworkStateUNINITIALIZED &&
100 networkState != RSINetworkState.RSINetworkStateSHUTDOWN)
101 {
102 // some kind of error shutting down the network, read the network log messages
103 int messagesToRead = controller.NetworkLogMessageCountGet();
104
105 // print all the messages to help figure out the problem
106 for (int i = 0; i < messagesToRead; i++)
107 Console.WriteLine(controller.NetworkLogMessageGet(i));
108
109 throw new SystemException("Expected SHUTDOWN state but the network did not get there.");
110 }
111 else
112 {
113 Console.WriteLine("Network Shutdown");
114 }
115 }
117
126 public static void SetupControllerForHardware(MotionController controller)
127 {
128 ShutdownTheNetwork(controller);
129
130 // reset the controller to ensure it is in a known state
131 controller.Reset();
132
133 StartTheNetwork(controller);
134 }
136
144 public static void ConfigurePhantomAxis(Axis phantomAxis)
145 {
146 if (phantomAxis.MotorTypeGet() != RSIMotorType.RSIMotorTypePHANTOM)
147 {
148 throw new Exception($"Axis {phantomAxis.NumberGet()} is not configured as a phantom axis. Please ensure the axis is set to phantom before calling ConfigurePhantomAxis.");
149 }
150
151 // disable all limits (not used for phantom axes)
152 phantomAxis.ErrorLimitActionSet(RSIAction.RSIActionNONE);
153 phantomAxis.HardwareNegLimitActionSet(RSIAction.RSIActionNONE);
154 phantomAxis.HardwarePosLimitActionSet(RSIAction.RSIActionNONE);
155 phantomAxis.HomeActionSet(RSIAction.RSIActionNONE);
156 phantomAxis.SoftwareNegLimitActionSet(RSIAction.RSIActionNONE);
157 phantomAxis.SoftwarePosLimitActionSet(RSIAction.RSIActionNONE);
158
159 // set position tolerances to max value for immediate MotionDone
160 double POSITION_TOLERANCE_MAX = Double.MaxValue / 10.0;
161 phantomAxis.PositionToleranceCoarseSet(POSITION_TOLERANCE_MAX);
162 phantomAxis.PositionToleranceFineSet(POSITION_TOLERANCE_MAX);
163
164 // clear any faults
165 phantomAxis.Abort();
166 phantomAxis.ClearFaults();
167
168 // check for idle state
169 if (phantomAxis.StateGet() != RSIState.RSIStateIDLE)
170 {
171 RSISource source = phantomAxis.SourceGet(); // get state source enum
172 string errorMsg = @$"Axis {phantomAxis.NumberGet()} failed to enter IDLE state after configuring phantom axis.
173 The source of the axis error is: {phantomAxis.SourceNameGet(source)}";
174 throw new Exception(errorMsg);
175 }
176 }
178}
static void ConfigurePhantomAxis(Axis phantomAxis)
Configures a phantom axis on the controller.
Definition _helpers.cs:144
static void SetupControllerForHardware(MotionController controller)
Sets up the controller for hardware use by resetting it and starting the network.
Definition _helpers.cs:126
static void StartTheNetwork(MotionController controller)
Starts the network communication for the given MotionController.
Definition _helpers.cs:47
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
static void ShutdownTheNetwork(MotionController controller)
Shuts down the network communication for the given MotionController.
Definition _helpers.cs:86
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
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 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 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,...
Definition rsi.h:5870
RSINetworkState NetworkStateGet()
void Reset()
Reset the controller which stops and restarts the RMP firmware.
void NetworkShutdown()
Shutdown the EtherCAT network.
void NetworkStart()
Start the network, doing both a discovery followed by starting to OPERATIONAL state.
const char *const NetworkLogMessageGet(int32_t messageIndex)
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
RSIState StateGet()
Get the Axis or MultiAxis state.
RSISource SourceGet()
Get the source of an error state for an Axis or 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.
Definition rsi.h:184
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:111
bool isWarning
Whether the error is or is not a warning.
Definition rsi.h:120
RSINetworkState
State of network.
Definition rsienums.h:568
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
RSIMotorType
Motor Type.
Definition rsienums.h:1311
RSISource
Possible sources that have caused an Error state.
Definition rsienums.h:1014