APIs, concepts, guides, and more
axis-motion-point-to-point.cs
Note
See Motion: Point-to-Point 📜 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 various point-to-point motion commands for single axis motion.
Shows trapezoidal, S-curve, relative, final velocity, and velocity motion profiles.
Each motion command is followed by MotionDoneWait() to ensure completion before proceeding.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
using System.Threading;
Console.WriteLine("📜 Axis Motion: Point to Point");
int exitCode = 0;
// set sample config params
const double POSITION = 10;
const double VELOCITY = 10;
const double ACCELERATION = 20;
const double DECELERATION = 20;
const double JERK_PERCENT = 50;
const double FINAL_VELOCITY = 5;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
Helpers.VerifyHardwareUsage(controller);
Helpers.VerifyAxisCount(controller);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
// configure phantom axis
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis);
axis.PositionSet(0);
/*
┌──────────┐
│ ABSOLUTE │
└──────────┘
*/
Console.WriteLine("\n1. Absolute Motion");
axis.MoveTrapezoidal(POSITION, VELOCITY, ACCELERATION, DECELERATION);
axis.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($" CommandPosition after absolute motion: {axis.CommandPositionGet()} (expected: {POSITION})");
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis); // reset
axis.PositionSet(0);
/*
┌─────────┐
│ S-CURVE │
└─────────┘
*/
Console.WriteLine("\n2. S-Curve Motion");
axis.MoveSCurve(POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
axis.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($" CommandPosition after s-curve motion: {axis.CommandPositionGet()} (expected: {POSITION})");
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis); // reset
axis.PositionSet(0);
/*
┌──────────┐
│ RELATIVE │
└──────────┘
*/
Console.WriteLine("\n3. Relative Motion");
axis.MoveRelative(POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
axis.MotionDoneWait(); // wait for motion to complete
// move back to start using negative relative motion
axis.MoveRelative(-POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
axis.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($" CommandPosition after relative motion: {axis.CommandPositionGet()} (expected: 0)");
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis); // reset
axis.PositionSet(0);
/*
┌────────────────┐
│ FINAL VELOCITY │
└────────────────┘
*/
Console.WriteLine("\n4. Final Velocity Motion");
axis.MoveSCurve(POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT, FINAL_VELOCITY); // axis continues at final velocity after reaching position
// wait until axis transitions to final velocity
while (axis.StatusBitGet(RSIEventType.RSIEventTypeMOTION_AT_VELOCITY) == false)
Thread.Sleep(100);
Console.WriteLine($" CommandVelocity after final velocity motion: {axis.CommandVelocityGet()} (expected: {FINAL_VELOCITY})");
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis); // reset
axis.Stop();
axis.Abort();
axis.ClearFaults();
axis.PositionSet(0);
/*
┌──────────┐
│ VELOCITY │
└──────────┘
*/
Console.WriteLine("\n5. Velocity Motion");
axis.MoveVelocity(VELOCITY, ACCELERATION); // move at constant velocity
// wait until axis reaches target position, then stop
while (axis.CommandPositionGet() < POSITION)
Thread.Sleep(100);
Console.WriteLine($" CommandVelocity after velocity motion: {axis.CommandVelocityGet()} (expected: {VELOCITY}) ");
if (!Constants.USE_HARDWARE) Helpers.PhantomAxisReset(axis); // reset
axis.Stop();
Helpers.AbortMotionObject(axis);
exitCode = Constants.EXIT_SUCCESS;
}
// handle errors as needed
catch (Exception e)
{
Console.WriteLine($"❌ Error: {e.Message}");
exitCode = Constants.EXIT_FAILURE;
}
finally
{
controller.Delete(); // dispose
}
return exitCode;
Constants used in the C# sample apps.
Definition _constants.cs:3
const bool USE_HARDWARE
Default: false.
Definition _constants.cs:10
const int EXIT_FAILURE
Exit code for failed execution.
Definition _constants.cs:69
const int AXIS_0_INDEX
Default: 0.
Definition _constants.cs:20
const int AMP_ENABLE_MS
Default: 750.
Definition _constants.cs:35
const int EXIT_SUCCESS
Exit code for successful execution.
Definition _constants.cs:68
double CommandPositionGet()
Get the current command position.
void MoveVelocity(double velocity)
void MoveTrapezoidal(double position, double vel, double accel, double decel)
Point-to-point trapezoidal move.
void PositionSet(double position)
Set the Command and Actual positions.
void MoveRelative(double relativePosition, double vel, double accel, double decel, double jerkPct)
Command a relative point-to-point S-Curve motion.
void MoveSCurve(double position, double vel, double accel, double decel, double jerkPct)
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5921
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 ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
bool StatusBitGet(RSIEventType bitMask)
Return the state of a status bit.
int32_t MotionDoneWait(int32_t waitTimeoutMilliseconds=WaitForever)
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:973
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21