Use helper functions to learn about RapidCode good practices.
- Warning
- This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.
The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.
In this page:
⚙️ Check Errors
Checks for errors in a RapidCodeObject and throws an exception if non-warning errors are found. This helper reads and prints all errors from the error log, ignoring warnings. Use after any RapidCode API call that might generate errors.
public static void CheckErrors(RapidCodeObject rsiObject)
{
var hasErrors = false;
var errorStrBuilder = new System.Text.StringBuilder();
{
var errorMsg = rsiError.isWarning ? $"WARNING: {rsiError.Message}" : $"ERROR: {rsiError.Message}";
errorStrBuilder.AppendLine(errorMsg);
}
if (hasErrors)
throw new Exception(errorStrBuilder.ToString());
}
⚙️ Network Start
Starts the network communication for a MotionController and verifies it reaches OPERATIONAL state. Prints network log messages if the network fails to start. Throws an exception if OPERATIONAL state is not reached.
public static void NetworkStart(MotionController controller)
{
{
Console.WriteLine("Starting Network..");
}
{
for (int i = 0; i < messagesToRead; i++)
throw new SystemException("Expected OPERATIONAL state but the network did not get there.");
}
else
{
Console.WriteLine("Network Started");
}
}
⚙️ Network Shutdown
Shuts down the network communication for a MotionController. Verifies the network reaches SHUTDOWN or UNINITIALIZED state. Prints network log messages if shutdown fails.
{
return;
Console.WriteLine("Shutting down the network..");
{
for (int i = 0; i < messagesToRead; i++)
throw new SystemException("Expected SHUTDOWN state but the network did not get there.");
}
else
{
Console.WriteLine("Network Shutdown");
}
}
⚙️ Controller Setup
Sets up the controller for hardware use by resetting it and starting the network. Shuts down any existing network connection, resets the controller to a known state, then starts the network. Use this at the beginning of hardware-based samples.
⚙️ Phantom Axis Reset
Resets a phantom axis to a known state with default configuration. Disables all limits, sets position tolerances for immediate MotionDone, configures default motion parameters, and clears faults. Validates the axis is configured as RSIMotorTypePHANTOM before proceeding.
{
{
throw new Exception(@$"Axis {phantomAxis.NumberGet()} is not configured as a phantom axis.
Please ensure the axis is set to phantom before calling PhantomAxisConfigure.");
}
double POSITION_TOLERANCE_MAX = Double.MaxValue / 10.0;
}