The RMP Motion Controller APIs
Helper Methods

This class includes the source code of all our SampleAppsCSOld helper functions.

Helper functions were created to reduce code. Please note that if you would like to use this classes on your personal project you will have to replicate this class.

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.


📜 Check Errors
Check the RSIError log for any logged errors. Read and print all the errors. Ignore warnings.

public static void CheckErrors(RapidCodeObject rsiObject)
{
bool hasErrors = false;
System.Text.StringBuilder errorStringBuilder = new System.Text.StringBuilder();
while (rsiObject.ErrorLogCountGet() > 0)
{
RsiError error = rsiObject.ErrorLogGet();
if (error.isWarning)
{
errorStringBuilder.AppendLine("WARNING: " + error.Message);
}
else
{
hasErrors = true;
errorStringBuilder.AppendLine("ERROR: " + error.Message);
}
}
if (errorStringBuilder.Length > 0)
{
Console.WriteLine(errorStringBuilder.ToString());
}
if (hasErrors)
{
throw new Exception(errorStringBuilder.ToString());
}
}


📜 Start the Network
Start the network and print any errors encountered.

public static void StartTheNetwork(MotionController controller)
{
// Initialize the Network
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL) // Check if network is started already.
{
Console.WriteLine("Starting Network..");
controller.NetworkStart(); // If not. Initialize The Network. (This can also be done from RapidSetup Tool)
}
if (controller.NetworkStateGet() != RSINetworkState.RSINetworkStateOPERATIONAL) // Check if network is started again.
{
int messagesToRead = controller.NetworkLogMessageCountGet(); // Some kind of error starting the network, read the network log messages
for (int i = 0; i < messagesToRead; i++)
{
Console.WriteLine(controller.NetworkLogMessageGet(i)); // Print all the messages to help figure out the problem
}
Console.WriteLine("Expected OPERATIONAL state but the network did not get there.");
//throw new RsiError(); // Uncomment if you want your application to exit when the network isn't operational. (Comment when using phantom axis)
}
else // Else, of network is operational.
{
Console.WriteLine("Network Started");
}
}


📜 Create and Ready Axis

public Axis CreateAndReadyAxis(int AxisNumber)
{
Axis axis = controller.AxisGet(AxisNumber); // Initialize Axis Class. (Use RapidSetup Tool to see what is your axis number)
HelperFunctions.CheckErrors(axis); // [Helper Function] Check that the axis has been initialize correctly.
ResetAxis(axis);
return axis;
}


📜 Reset Axis

public void ResetAxis(Axis myAxis)
{
myAxis.UserUnitsSet(Constants.USER_UNITS); // Specify the counts per Unit.
myAxis.PositionSet(0); // Sets the current position as 0 effectively 'homing' it.
myAxis.Abort(); // If there is any motion happening, abort it (creates a fault).
myAxis.DefaultAccelerationSet(Constants.ACCELERATION);
myAxis.DefaultDecelerationSet(Constants.ACCELERATION);
myAxis.DefaultVelocitySet(Constants.VELOCITY);
EnableAmp(myAxis);
}


📜 Enable Axis Amp

public void EnableAmp(Axis myAxis)
{
myAxis.ClearFaults(); // To enable after an abort faults must be cleared.
myAxis.AmpEnableSet(true); // Enable the motor.
}