APIs, concepts, guides, and more
Motion.cs
Attention
See the following Concept pages for a detailed explanation of this sample: Final Velocity Motion, Absolute Motion, Relative Motion, S-Curve Motion, Velocity Motion.
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.
using RSI.RapidCode.dotNET; // Import our RapidCode Library.
using NUnit.Framework;
[TestFixture]
[Category("Software")]
public class Motion : SampleAppTestBase
{
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void AbsoluteMotion()
{
axis.MoveTrapezoidal(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION);// Command simple trapezoidal motion.
axis.MotionDoneWait();// Wait for motion to be done
Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void SCurveMotion()
{
axis.MoveSCurve(Constants.POSITION); // Command SCurve Motion. This overload willuse default velocity, acceleration, deceleration, jerk values for the axis. See axis config to learn how to set those values.
axis.MotionDoneWait(); // Wait for motion to finish
Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void FinalVelocity()
{
int finalVelocity = 5;
axis.MoveSCurve(Constants.POSITION, // Command an SCurve move with a final velocity of FINAL_VELOCITY.
Constants.VELOCITY,
Constants.ACCELERATION,
Constants.DECELERATION,
Constants.JERK_PERCENT,
finalVelocity); // Once the commanded position has been reached, the motor will begin spinning with a speed of FINAL_VELOCITY, and continue to spin at that velocity until stopped.
if (axis.CommandPositionGet() >= Constants.POSITION)
{
Assert.That(axis.CommandVelocityGet(), Is.EqualTo(finalVelocity), "The command velocity should be equal to FINAL_VELOCITY");
TearDown();
}
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void RelativeMotion()
{
axis.MoveRelative(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT); // Command a relative to the current position
axis.MotionDoneWait(); // Wait for motion to finish. (the motion should take 2.5 seconds)
var cmdPositionAfterMove = axis.CommandPositionGet(); // The command position should be equal to Constants.POSITION
// Move back to the start position by moving negative relative to current position
axis.MoveRelative(-1 * Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT);
Assert.That(cmdPositionAfterMove, Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
}
[Test]
public void MoveVelocity()
{
// Command a velocity move
axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
if (axis.CommandPositionGet() >= Constants.POSITION)
{
Assert.That(axis.CommandVelocityGet(), Is.EqualTo(Constants.VELOCITY), "The command velocity should be equal to FINAL_VELOCITY");
TearDown();
}
}
}
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.
double CommandVelocityGet()
Get the current commanded velocity.
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)
Command a point-to-point S-Curve motion.
int32_t MotionDoneWait()
Waits for a move to complete.