APIs, concepts, guides, and more
axis-motion-modify.cs
Note
See Motion: Modify 📜 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 to modify motion in-flight using feed rate and velocity changes.
Shows how to use FeedRate to adjust speed, reverse motion, and change velocity mid-motion.
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
using System.Threading;
Console.WriteLine("📜 Axis Motion: Modify");
// set sample config params
const double POSITION = 10;
const double VELOCITY = 10;
const double ACCELERATION = 100;
const double DECELERATION = 100;
const double JERK_PERCENT = 50;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
Helpers.CheckErrors(axis);
// configure phantom axis
Helpers.PhantomAxisReset(axis);
/*
┌───────────┐
│ FEED RATE │
└───────────┘
*/
Console.WriteLine("\n1. Feed Rate");
axis.AmpEnableSet(true);
// start motion
axis.MoveSCurve(POSITION);
Console.WriteLine($"\tPosition commanded: {POSITION}");
// set feedrate to 150%
axis.FeedRateSet(1.5);
// wait here until we reach position 10
while (axis.CommandPositionGet() < 5)
Thread.Sleep(10);
// stop motion
axis.Stop();
axis.MotionDoneWait();
Console.WriteLine($"\tPosition after FeedRate (1.5): {axis.CommandPositionGet()}");
// set feedrate to reverse motion (-100%)
axis.FeedRateSet(-1);
// resume motion for a bit
axis.Resume();
Thread.Sleep(500);
Console.WriteLine($"\tPosition after FeedRate (-1): {axis.CommandPositionGet()}");
// restore feedrate (100%)
axis.FeedRateSet(1);
// wait for motion done
axis.MotionDoneWait();
Console.WriteLine($"\tPosition after FeedRate (1): {axis.CommandPositionGet()} (expected: {POSITION})");
Helpers.PhantomAxisReset(axis); // reset
/*
┌──────────────────────┐
│ CHANGE MOTION SPEED │
└──────────────────────┘
*/
Console.WriteLine("\n2. Change Motion Speed");
axis.AmpEnableSet(true);
// start motion
axis.MoveSCurve(POSITION, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENT);
// wait until position > 5
while (axis.CommandPositionGet() < 5)
Thread.Sleep(10);
// modify motion to go 10x faster
axis.MoveSCurve(POSITION, VELOCITY * 10, ACCELERATION, DECELERATION, JERK_PERCENT);
// wait for motion done
Console.WriteLine($"\tFinal position: {axis.CommandPositionGet()} (expected: {POSITION})");
Helpers.PhantomAxisReset(axis); // reset
}
// 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
double CommandPositionGet()
Get the current command position.
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: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
int32_t MotionDoneWait()
Waits for a move to complete.
void Resume()
Resume an axis.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
void FeedRateSet(double rate)
Set the feed rate for an Axis.
Helpers namespace provides utility functions for common tasks in RMP applications.
Definition helpers.h:21