APIs, concepts, guides, and more
axis-motion-point-to-point.cs
/* 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");
// 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;
const double FINAL_VELOCITY = 5;
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// get axis
Axis axis = controller.AxisGet(Constants.AXIS_0_INDEX);
// configure phantom axis
/*
┌──────────┐
│ ABSOLUTE │
└──────────┘
*/
Console.WriteLine("\n1. Absolute Motion");
axis.AmpEnableSet(true);
axis.MoveTrapezoidal(POSITION, VELOCITY, ACCELERATION, DECELERATION);
axis.MotionDoneWait(); // wait for motion to complete
Console.WriteLine($" CommandPosition after absolute motion: {axis.CommandPositionGet()} (expected: {POSITION})");
Helpers.PhantomAxisReset(axis); // reset
/*
┌─────────┐
│ S-CURVE │
└─────────┘
*/
Console.WriteLine("\n2. S-Curve Motion");
axis.AmpEnableSet(true);
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})");
Helpers.PhantomAxisReset(axis); // reset
/*
┌──────────┐
│ RELATIVE │
└──────────┘
*/
Console.WriteLine("\n3. Relative Motion");
axis.AmpEnableSet(true);
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)");
Helpers.PhantomAxisReset(axis); // reset
/*
┌────────────────┐
│ FINAL VELOCITY │
└────────────────┘
*/
Console.WriteLine("\n4. Final Velocity Motion");
axis.AmpEnableSet(true);
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})");
Helpers.PhantomAxisReset(axis); // reset
/*
┌──────────┐
│ VELOCITY │
└──────────┘
*/
Console.WriteLine("\n5. Velocity Motion");
axis.AmpEnableSet(true);
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}) ");
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 MoveVelocity(double velocity)
void MoveTrapezoidal(double position, double vel, double accel, double decel)
Point-to-point trapezoidal move.
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: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.
bool StatusBitGet(RSIEventType bitMask)
Return the state of a status bit.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:966