APIs, concepts, guides, and more
Quick Start

Learn how to create a MotionController, set an AxisCount and get Axis status.

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.
Precondition
A helper function to check each response for errors.
// Check each response header for errors. Stop execution if errors were received.
private static void CheckErrors(ResponseHeader header)
{
if (header.Errors.Count > 0)
{
string message = "RPC had errors!\n";
foreach (var error in header.Errors)
{
message += " " + error.Message + "\n";
}
Assert.Fail(message);
}
}


📜 Create the client
Create an instance of RMPServiceClient. Channel is a class from the C# gRPC API that establishes a connection to the server listening at the specified IP and port.

channel = new Channel(ipAddress, PORT, ChannelCredentials.Insecure);
rmpClient = new RMPService.RMPServiceClient(channel);


📜 Create the motion controller
Create the motion controller on the server.

// First, before doing any other RapidCodeRemote RPCs, create the motion controller on the server
MotionControllerResponse motionControllerResponse = rmpClient.MotionController(new MotionControllerRequest
{
Action = new MotionControllerAction { Create = new MotionControllerAction.Types.Create() },
});
CheckErrors(motionControllerResponse.Header);


📜 Start the network
Start the EtherCAT network and master-slave communication.

private void StartTheNetwork(bool discoverBeforeStart = false)
{
var action = new NetworkAction();
if (discoverBeforeStart)
action.DiscoverAndStart = new NetworkAction.Types.DiscoverAndStart();
else
action.Start = new NetworkAction.Types.Start();
NetworkResponse networkResponse = rmpClient.Network(new NetworkRequest
{
Action = action
});
CheckErrors(networkResponse.Header);
}


📜 Set the axis count
Set the axis count within the motion controller.

// Next, set the axis count so we have axes to work with.
motionControllerResponse = rmpClient.MotionController(new MotionControllerRequest
{
Config = new MotionControllerConfig { AxisCount = Constants.AXIS_COUNT },
});
CheckErrors(motionControllerResponse.Header);


📜 Check an axis status
Check the current state within the status message of an Axis.

// Check the state of the axis at index 0
AxisResponse axisResponse = rmpClient.Axis(new AxisRequest { Index = 0 });
CheckErrors(axisResponse.Header);


📜 Spin an axis
Command basic motion.

// Command a point-to-point move on axis 0 from position 0 to position 20
var action = new AxisAction();
var move = new AxisMovePointToPoint() {
Acceleration = 100,
Deceleration = 100,
Velocity = 10,
Position = 20,
JerkPercent = 50
};
action.Move = new AxisAction.Types.Move();
action.Move.PointToPoint = move;
axisResponse = rmpClient.Axis(new AxisRequest { Index = 0 , Action = action });
CheckErrors(axisResponse.Header);