APIs, concepts, guides, and more
Motion: Multi-Axis

Learn how to use multi-axis 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:


📜 Multi-Axis Velocity Motion

Learn how to update Multi-Axis Velocity 📖 synchronously and on the fly. This sample demonstrates updating multi-axis velocities at a rate of ~2ms. Before running this sample app: 1) Configure your Multi-Axis on RapidSetup, 2) Adjust your Limits and Action for all axes.

/* This sample demonstrates updating a multi-axis velocity synchronously and on the fly.
It can update velocities at a rate of ~2ms.
Before running this sample app:
1. Make sure to configure your Multi-Axis on RapidSetup.
2. Make sure to adjust your Limits and Action for all axes.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
using System.Threading;
Console.WriteLine("📜 MultiAxis Motion: Velocity");
// set sample config params
const int CYCLES = 3; // how many times to update the velocity
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// set the motion count to AxisCount + 1, every multiaxis needs a motion supervisor
var axisCount = controller.AxisCountGet();
controller.MotionCountSet(axisCount + 1);
// get axes
Axis axis0 = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis0);
Axis axis1 = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(axis1);
Axis axis2 = controller.AxisGet(Constants.AXIS_2_INDEX);
Helpers.CheckErrors(axis2);
// get multiaxis (motion supervisor number is equal to number of axes because indexing starts at 0)
MultiAxis multi = controller.MultiAxisGet(axisCount);
Helpers.CheckErrors(multi);
// remove any existing axes
multi.AxisRemoveAll();
// add axes to multiaxis
multi.AxisAdd(axis0);
multi.AxisAdd(axis1);
multi.AxisAdd(axis2);
// prepare for motion
multi.Abort();
multi.ClearFaults();
multi.AmpEnableSet(true);
// define motion parameters
double[] accelerations = [1000, 1000, 1000];
double[] velocities = [0, 0, 0];
Random rnd = new Random(); // for generating random velocities
// update velocities on the fly
for (int i = 0; i < CYCLES; i++)
{
// generate random velocities for all axes
velocities[0] = rnd.Next(1, 100);
velocities[1] = rnd.Next(1, 100);
velocities[2] = rnd.Next(1, 100);
Console.WriteLine($"Cycle {i + 1}: Velocities = [{velocities[0]}, {velocities[1]}, {velocities[2]}]");
// move multiaxis (this will also update the move on the fly)
multi.MoveVelocity(velocities, accelerations);
// short delay before next iteration
Thread.Sleep(100);
}
// clean up
Helpers.AbortMotionObject(multi); // stop motion on all axes
controller.MotionCountSet(axisCount); // remove multiaxis
}
// 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_1_INDEX
Default: 1.
Definition _constants.cs:12
const int AXIS_2_INDEX
Default: 2.
Definition _constants.cs:13
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5863
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 AxisRemoveAll()
Remove all axes from a MultiAxis group.s.
void MoveVelocity(const double *const velocity, const double *const accel)
Velocity move.
void AxisAdd(Axis *axis)
Add an Axis to a MultiAxis group.
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.
void Abort()
Abort an axis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21


📜 Multi-Axis Point-to-Point Motion

Learn how to perform S-Curve Motion 📖 for multiple axes simultaneously. Demonstrates both trapezoidal and S-curve motion profiles using the MultiAxis object.

/* This sample demonstrates both trapezoidal and S-curve point-to-point motion profiles for multi-axis motion.
The MultiAxis object coordinates the motion of multiple axes simultaneously.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 MultiAxis Motion: Point to Point");
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// set the motion count to AxisCount + 1, every multiaxis needs a motion supervisor
var axisCount = controller.AxisCountGet();
controller.MotionCountSet(axisCount + 1);
// get axes
Axis axis0 = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis0);
Axis axis1 = controller.AxisGet(Constants.AXIS_1_INDEX);
Helpers.CheckErrors(axis1);
// get multiaxis (motion supervisor number is equal to number of axes because indexing starts at 0)
MultiAxis multi = controller.MultiAxisGet(axisCount);
Helpers.CheckErrors(multi);
// remove any existing axes
multi.AxisRemoveAll();
// add axes to multiaxis
multi.AxisAdd(axis0);
multi.AxisAdd(axis1);
// prepare for motion
multi.Abort(); // stop any existing motion
multi.ClearFaults();
multi.AmpEnableSet(true);
// disable position error for phantom axes
axis0.ErrorLimitActionSet(RSIAction.RSIActionNONE);
axis1.ErrorLimitActionSet(RSIAction.RSIActionNONE);
// define motion parameters
double[] positions1 = [ 5, 10 ]; // first set of positions
double[] positions2 = [ 15, 15 ]; // second set of positions
double[] velocities1 = [ 1000, 1000 ]; // velocities for first move
double[] velocities2 = [ 1000, 1000 ]; // velocities for second move
double[] accelerations = [ 500, 500 ]; // accelerations for both axes
double[] decelerations = [ 500, 500 ]; // decelerations for both axes
double[] jerkPercent = [ 50, 50 ]; // jerk percent for s-curve motion
// move using s-curve motion profile
Console.WriteLine($"\nMove 1 (S-Curve): Positions = [{positions1[0]}, {positions1[1]}]");
multi.MoveSCurve(positions1, velocities1, accelerations, decelerations, jerkPercent);
multi.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($"Axis 0 CommandPosition: {axis0.CommandPositionGet()} (expected: {positions1[0]})");
Console.WriteLine($"Axis 1 CommandPosition: {axis1.CommandPositionGet()} (expected: {positions1[1]})");
// move using trapezoidal motion profile
Console.WriteLine($"\nMove 2 (Trapezoidal): Positions = [{positions2[0]}, {positions2[1]}]");
multi.MoveTrapezoidal(positions2, velocities2, accelerations, decelerations);
multi.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($"Axis 0 CommandPosition: {axis0.CommandPositionGet()} (expected: {positions2[0]})");
Console.WriteLine($"Axis 1 CommandPosition: {axis1.CommandPositionGet()} (expected: {positions2[1]})");
// cleanup
Helpers.AbortMotionObject(multi);
controller.MotionCountSet(axisCount); // remove multiaxis
Console.WriteLine("\nMulti-axis point-to-point motion complete.");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
void ErrorLimitActionSet(RSIAction action)
Set the action that will occur when the Error Limit Event triggers.
void MoveTrapezoidal(const double *const position, const double *const vel, const double *const accel, const double *const decel)
Point-to-point trapezoidal move.
void MoveSCurve(const double *const position, const double *const vel, const double *const accel, const double *const decel, const double *const jerkPct)
Point-to-point S-Curve Move.
int32_t MotionDoneWait()
Waits for a move to complete.
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115