APIs, concepts, guides, and more
⚙️ Helpers

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();
while (rsiObject.ErrorLogCountGet() > 0)
{
// get error
RsiError rsiError = rsiObject.ErrorLogGet();
// get message
var errorMsg = rsiError.isWarning ? $"WARNING: {rsiError.Message}" : $"ERROR: {rsiError.Message}";
errorStrBuilder.AppendLine(errorMsg);
// set flag
hasErrors = !rsiError.isWarning;
}
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)
{
// check if network is started already
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
Console.WriteLine("Starting Network..");
// if not started, initialize the network
controller.NetworkStart();
}
// check if network is started again
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL)
{
// read network log messages
int messagesToRead = controller.NetworkLogMessageCountGet();
// print all the messages to help figure out the problem
for (int i = 0; i < messagesToRead; i++)
Console.WriteLine(controller.NetworkLogMessageGet(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.

public static void NetworkShutdown(MotionController controller)
{
// check if the network is already shutdown
if (controller.NetworkStateGet() == RSINetworkState.RSINetworkStateUNINITIALIZED ||
controller.NetworkStateGet() == RSINetworkState.RSINetworkStateSHUTDOWN)
return;
// shutdown the network
Console.WriteLine("Shutting down the network..");
controller.NetworkShutdown();
// check if the network is shutdown
var networkState = controller.NetworkStateGet();
if (networkState != RSINetworkState.RSINetworkStateUNINITIALIZED &&
networkState != RSINetworkState.RSINetworkStateSHUTDOWN)
{
// some kind of error shutting down the network, read the network log messages
int messagesToRead = controller.NetworkLogMessageCountGet();
// print all the messages to help figure out the problem
for (int i = 0; i < messagesToRead; i++)
Console.WriteLine(controller.NetworkLogMessageGet(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.

public static void ControllerSetup(MotionController controller)
{
NetworkShutdown(controller);
// reset the controller to ensure it is in a known state
controller.Reset();
NetworkStart(controller);
}


⚙️ 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.

public static void PhantomAxisReset(Axis phantomAxis)
{
if (phantomAxis.MotorTypeGet() != RSIMotorType.RSIMotorTypePHANTOM)
{
throw new Exception(@$"Axis {phantomAxis.NumberGet()} is not configured as a phantom axis.
Please ensure the axis is set to phantom before calling PhantomAxisConfigure.");
}
// abort any motion
AbortMotionObject(phantomAxis);
// disable all limits (not used for phantom axes)
phantomAxis.ErrorLimitActionSet(RSIAction.RSIActionNONE);
phantomAxis.HardwareNegLimitActionSet(RSIAction.RSIActionNONE);
phantomAxis.HardwarePosLimitActionSet(RSIAction.RSIActionNONE);
phantomAxis.HomeActionSet(RSIAction.RSIActionNONE);
phantomAxis.SoftwareNegLimitActionSet(RSIAction.RSIActionNONE);
phantomAxis.SoftwarePosLimitActionSet(RSIAction.RSIActionNONE);
// set position tolerances to max value for immediate MotionDone
double POSITION_TOLERANCE_MAX = Double.MaxValue / 10.0;
phantomAxis.PositionToleranceCoarseSet(POSITION_TOLERANCE_MAX);
phantomAxis.PositionToleranceFineSet(POSITION_TOLERANCE_MAX);
// set sample apps default motion parameters
phantomAxis.UserUnitsSet(1);
phantomAxis.DefaultVelocitySet(100);
phantomAxis.DefaultAccelerationSet(1000);
phantomAxis.DefaultDecelerationSet(1000);
phantomAxis.DefaultJerkPercentSet(0);
phantomAxis.PositionSet(0);
}