APIs, concepts, guides, and more
gcode-units.cs
Note
See Motion: G-Code 📜 for a detailed explanation of this sample code.
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.
/* This sample demonstrates how changing linear units affects G-Code velocity and acceleration setters.
Shows how to work with different unit systems in G-Code and understand the impact on motion parameters.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 Motion: G-Code Units");
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// set robot axis labels
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string zLabel = "Z-Axis";
const string aLabel = "A-Axis";
const string bLabel = "B-Axis";
const string cLabel = "C-Axis";
// get the 6 axis needed for XYZABC robot
Axis xAxis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(xAxis);
Axis yAxis = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(yAxis);
Axis zAxis = controller.AxisGet(Constants.AXIS_2_INDEX);
Helpers.CheckErrors(zAxis);
Axis aAxis = controller.AxisGet(Constants.AXIS_3_INDEX);
Helpers.CheckErrors(aAxis);
Axis bAxis = controller.AxisGet(Constants.AXIS_4_INDEX);
Helpers.CheckErrors(bAxis);
Axis cAxis = controller.AxisGet(Constants.AXIS_5_INDEX);
Helpers.CheckErrors(cAxis);
// configure phantom axes
Helpers.PhantomAxisReset(xAxis);
Helpers.PhantomAxisReset(yAxis);
Helpers.PhantomAxisReset(zAxis);
Helpers.PhantomAxisReset(aAxis);
Helpers.PhantomAxisReset(bAxis);
Helpers.PhantomAxisReset(cAxis);
// set axis labels
xAxis.UserLabelSet(xLabel);
yAxis.UserLabelSet(yLabel);
zAxis.UserLabelSet(zLabel);
aAxis.UserLabelSet(aLabel);
bAxis.UserLabelSet(bLabel);
cAxis.UserLabelSet(cLabel);
// create multi-axis object for joints
MultiAxis jointsMultiAxis = controller.MultiAxisGet(0);
Axis[] axes = [xAxis, yAxis, zAxis, aAxis, bAxis, cAxis];
jointsMultiAxis.AxesAdd(axes, axes.Length);
jointsMultiAxis.ClearFaults();
// create kinematic model with centimeters
const LinearUnits units = LinearUnits.Centimeters;
const string modelName = "RSI_XYZABC_Centimeters";
const double scaling = 1.0;
const double offset = 0.0;
// build model
LinearModelBuilder builder = new(modelName);
builder.UnitsSet(units);
builder.JointAdd(new LinearJointMapping(0, CartesianAxis.X) { ExpectedLabel = xLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(1, CartesianAxis.Y) { ExpectedLabel = yLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(2, CartesianAxis.Z) { ExpectedLabel = zLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(3, CartesianAxis.Roll) { ExpectedLabel = aLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(4, CartesianAxis.Pitch) { ExpectedLabel = bLabel, Scaling = scaling, Offset = offset });
builder.JointAdd(new LinearJointMapping(5, CartesianAxis.Yaw) { ExpectedLabel = cLabel, Scaling = scaling, Offset = offset });
// create Robot object
Robot robot = Robot.RobotCreate(controller, jointsMultiAxis, builder, MotionController.AxisFrameBufferSizeDefault);
Helpers.CheckErrors(robot);
// note: to use the above kinematic model you must have a gantry (linear 1:1 kinematics)
// and each linear axis must have its user units scaled to millimeters
// this will return none - a gcode unit hasn't been established so it will use path units
// if path units are not set it will use user units
Console.WriteLine($"Initial G-Code units: {robot.Gcode.UnitsGet()}");
robot.Gcode.AccelerationRateSet(10); // sets G-Code acceleration to 10 Centimeters per MINUTE squared
robot.Gcode.FeedRateSet(10); // sets G-Code velocity to 10 Centimeters per MINUTE
Console.WriteLine($"Acceleration rate (cm/min²): {robot.Gcode.AccelerationRateGet()}");
Console.WriteLine($"Feed rate (cm/min): {robot.Gcode.FeedRateGet()}");
robot.Gcode.UnitsSet(LinearUnits.Inches); // this is the same as executing G-Code line G20
Console.WriteLine($"G-Code units after setting to inches: {robot.Gcode.UnitsGet()}");
robot.Gcode.AccelerationRateSet(10); // sets G-Code acceleration to 10 Inches per MINUTE squared
robot.Gcode.FeedRateSet(10); // sets G-Code velocity to 10 Inches per MINUTE
Console.WriteLine($"Acceleration rate (in/min²): {robot.Gcode.AccelerationRateGet()}");
Console.WriteLine($"Feed rate (in/min): {robot.Gcode.FeedRateGet()}");
// cleanup
Robot.RobotDelete(controller, robot);
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
Constants used in the C# sample apps.
Definition _constants.cs:3
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:11
const int AXIS_5_INDEX
Default: 5.
Definition _constants.cs:16
const int AXIS_3_INDEX
Default: 3.
Definition _constants.cs:14
const int AXIS_4_INDEX
Default: 4.
Definition _constants.cs:15
const int AXIS_1_INDEX
Default: 1.
Definition _constants.cs:12
const int AXIS_2_INDEX
Default: 2.
Definition _constants.cs:13
void UserLabelSet(const char *const userLabel)
Set the axis User defined Label.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
static constexpr int32_t AxisFrameBufferSizeDefault
The default value of the AxisFrameBufferSize, also the minimum allowable value.
Definition rsi.h:854
static MotionController * Get()
Get an already running RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
void AxesAdd(Axis **axes, int32_t axisCount)
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...
Definition rsi.h:10795
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21