Learn how to work with Path motion in C#.
- 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:
📜 Motion: Path
Learn how to set up and run Path Motion 📖 with a Robot object. Shows how to create kinematic models, program path movements using lines and arcs, and execute coordinated multi-axis motion.
using System.Threading;
Console.WriteLine("📜 Motion: Path");
try
{
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";
Axis xAxis = controller.
AxisGet(Constants.AXIS_0_INDEX);
Axis yAxis = controller.
AxisGet(Constants.AXIS_1_INDEX);
Axis zAxis = controller.
AxisGet(Constants.AXIS_2_INDEX);
Axis aAxis = controller.
AxisGet(Constants.AXIS_3_INDEX);
Axis bAxis = controller.
AxisGet(Constants.AXIS_4_INDEX);
Axis cAxis = controller.
AxisGet(Constants.AXIS_5_INDEX);
Axis[] axes = [ xAxis, yAxis, zAxis, aAxis, bAxis, cAxis ];
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const LinearUnits units = LinearUnits.Meters;
const string modelName = "RSI_XYZABC_Meters";
const double scaling = 1.0;
const double offset = 0.0;
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 });
Console.WriteLine($"Robot model: {robot.ModelGet().NameGet()}");
Console.WriteLine($"Robot units: {robot.ModelGet().UnitsGet()}");
robot.PathAccelerationSet(1000);
robot.PathVelocitySet(50);
robot.PathProgrammingModeSet(
PathMode.Absolute);
robot.PathLine(target: new Pose(1, 1, 1));
robot.PathArc(
target: new Pose(0, 2, 1),
center: new Vector3d(0, 1, 1),
robot.Run();
while (robot.IsRunning())
{
Thread.Sleep(100);
Console.WriteLine("Path motion executing...");
}
Robot.RobotDelete(controller, robot);
}
finally
{
}
static void ConfigurePhantomAxis(Axis phantomAxis)
Configures a phantom axis on the controller.
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Helpers class provides static methods for common tasks in RMP applications.
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,...
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static constexpr int32_t AxisFrameBufferSizeDefault
The default value of the AxisFrameBufferSize, also the minimum allowable value.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
MultiAxis * MultiAxisGet(int32_t motionSupervisorNumber)
MultiAxisGet returns a pointer to a MultiAxis object and initializes its internals.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
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...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
PathMode
Motion types. For G-code use and Cartesian path motion.
CartesianAxis
This enum specifies which Cartesian axis a LinearJointMapping maps a robot joint to.
RotationDirection
Rotational directions about an axis.
📜 Motion: Path Gantry
Learn how to set up a kinematic model with a gantry prime axis for Path Motion 📖 . Shows how to configure a 1:1 geared axis system where two physical axes work together.
Console.WriteLine("📜 Motion: Path Gantry");
try
{
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string yPrimeLabel = "Y-Prime";
Axis xAxis = controller.
AxisGet(Constants.AXIS_0_INDEX);
Axis yAxis = controller.
AxisGet(Constants.AXIS_1_INDEX);
Axis primeAxis = controller.
AxisGet(Constants.AXIS_2_INDEX);
Axis[] axes = [xAxis, yAxis, primeAxis];
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const LinearUnits units = LinearUnits.Millimeters;
const string modelName = "RSI_XY_Yp";
const double scaling = 1.0, offset = 0.0;
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.Y) { ExpectedLabel = yPrimeLabel, Scaling = scaling, Offset = offset });
const int motionFrameBufferSize = 50;
Robot robot = Robot.RobotCreate(controller, jointsMultiAxis, builder, motionFrameBufferSize);
Console.WriteLine($"Model name: {robot.ModelGet().NameGet()}");
Console.WriteLine($"Model units: {robot.ModelGet().UnitsGet()}");
Console.WriteLine("Gantry configuration: Y-axis and Y-Prime axis are geared 1:1");
Robot.RobotDelete(controller, robot);
}
finally
{
}
📜 Motion: Path 3D Rendering
Learn how to get 3D path points for rendering visualization from Path Motion 📖 . Shows how to retrieve planned positions for use with 3D graphics libraries.
Console.WriteLine("📜 Motion: Path 3D Rendering");
try
{
const string xLabel = "X-Axis";
const string yLabel = "Y-Axis";
const string zLabel = "Z-Axis";
Axis xAxis = controller.
AxisGet(Constants.AXIS_0_INDEX);
Axis yAxis = controller.
AxisGet(Constants.AXIS_1_INDEX);
Axis zAxis = controller.
AxisGet(Constants.AXIS_2_INDEX);
Axis[] axes = [xAxis, yAxis, zAxis];
jointsMultiAxis.
AxesAdd(axes, axes.Length);
const string modelName = "RSI_XYZ";
const double scaling = 1.0;
const double offset = 0.0;
LinearModelBuilder builder = new(modelName);
builder.UnitsSet(LinearUnits.Millimeters);
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 });
robot.PathAccelerationSet(100);
robot.PathVelocitySet(50);
robot.PathProgrammingModeSet(
PathMode.Absolute);
robot.PathLine(target: new Pose(1, 1, 1));
robot.PathArc(
target: new Pose(0, 2, 1),
center: new Vector3d(0, 1, 1),
robot.PathProcessLoadedMoves();
Console.WriteLine("Retrieving 3D path points for rendering:");
const ulong frameCount = 500;
ulong startFrame = 0;
int totalPointCount = 0;
ulong retrievedFrames;
do
{
RapidVectorRobotPosition positions = robot.PathPlannedPositionsGet(startFrame, frameCount);
retrievedFrames = positions.Size();
foreach (RobotPosition position in positions.ToArray())
{
Vector3d spatial = position.Pose.Position;
if (totalPointCount < 4)
{
Console.WriteLine($"Point {totalPointCount}: X={spatial.X:F2}, Y={spatial.Y:F2}, Z={spatial.Z:F2}");
}
totalPointCount++;
}
startFrame += retrievedFrames;
}
while (retrievedFrames == frameCount);
Console.WriteLine($"Total 3D points retrieved: {totalPointCount}");
Robot.RobotDelete(controller, robot);
}
finally
{
}