APIs, concepts, guides, and more
axis-motion-modify.cs
/* 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);
// configure phantom 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
}
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
static void PhantomAxisReset(Axis phantomAxis)
Configures a phantom axis on the controller.
Definition _helpers.cs:144
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
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:5862
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
void Delete(void)
Delete the MotionController and all its objects.
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.