The RMP Motion Controller API
MotionStreaming.cs

Example code of streaming motion.

Precondition
This is a sample assumes you already have a RapidCode MotionController and Axis Object. See the Template.cs or HelperFunctions.cs sample app to see how to set up those objects.
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.

PTmotion
Visit our Topic Page for more information.
This code demonstrates how to use PT motion. PT motion is the simplest streaming motion to use because it only requires an array of Positions and Time deltas. The controller is responsible for figuring out the velocity, and acceleration for each motion segment.

int points = 3; // Specify the total number of streamed points.
int emptyCount = -1; // E-stop generated if there are this number or fewer frames loaded. Use the value “0” to trigger an E-stop when the buffer is empty, or “-1” to not trigger an E-stop. (Typically for PT motion there are two frames per PT point)
double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
double[] times = { 0.2, 0.3, 0.1 }; // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
//---COMMAND MOTION---
axis.MovePT(RSIMotionType.RSIMotionTypePT,// Specify the type of PT Motion that you want to perform. (RSIMotionType.RSIMotionTypePT, RSIMotionType.RSIMotionTypeBSPLINE, RSIMotionType.RSIMotionTypeBSPLINE2)
positions, // Specify the positions that you want to reach. (it can be n number)
times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
points, // Specify the total number of streamed points.
emptyCount, // E-stop generated if there are this number or fewer frames loaded. Use the value “0” to trigger an E-stop when the buffer is empty, or “-1” to not trigger an E-stop. (Typically for PT motion there are two frames per PT point)
false, // Specify whether points are kept, or are not kept.
true); // Specify if this is the last MovePT. (If True, this is the final point. If False, more points expected.)
axis.MotionDoneWait(); // Wait for motion to be completed.
//---ASSERT---
Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");

PVTmotion
Visit our Topic Page for more information.
This code demonstrates how to use PVT motion. PVT motion is another Streaming motion. PVT motion is a bit more complicated to use because it requires an array of Positions, Velocities, and Time deltas. The controller is only responsible for figuring out the acceleration for each motion segment.

// Constants
int points = 3; // Specify the total number of streamed points. (Very Important!)
int emptyCount = -1; // E-stop generated if there are this number or fewer frames loaded. Use the value “0” to trigger an E-stop when the buffer is empty, or “-1” to not trigger an E-stop. (Typically for PT motion there are two frames per PT point)
double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
double[] velocities = { 12.0, 10.0, 6.0 }; // Specify the velocities that you want to use to reach your position.
double[] times = { 0.1, 0.2, 0.1 }; // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
axis.MovePVT(positions, // Specify the type of PT Motion that you want to perform. (RSIMotionType.RSIMotionTypePT, RSIMotionType.RSIMotionTypeBSPLINE, RSIMotionType.RSIMotionTypeBSPLINE2)
velocities, // Specify the positions that you want to reach. (it can be n number)
times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
points, // Specify the total number of streamed points.
emptyCount, // E-stop generated if there are this number or fewer frames loaded. Use the value “0” to trigger an E-stop when the buffer is empty, or “-1” to not trigger an E-stop. (Typically for PT motion there are two frames per PT point)
false, // Specify whether points are kept, or are not kept.
true); // Specify if this is the last MovePT. (If True, this is the final point. If False, more points expected.)
axis.MotionDoneWait();
//---ASSERT---
Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");

PVAJTmotion
Visit our Topic Page for more information.
This code demonstrates how to use PVAJT motion.

// Constants
int points = 3; // Specify the total number of streamed points. (Very Important!)
int emptyCount = -1; // E-stop generated if there aren't at least this many points loaded. ("-1" if you don't wish to trigger an E-Stop)
double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
double[] velocities = { 10.0, 20.0, 40.0 }; // Specify the velocities that you want to use to reach your position.
double[] accelerations = { 4, 4, 4 }; // Specify the accelerations that you want to use to reach your position.
double[] jerks = { 50, 50, 50 }; // Specify the jerk that you want to use in each move.
double[] times = { 0.4, 0.2, 0.1 }; // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
axis.MovePVAJT(positions, // Specify the type of PT Motion that you want to perform. (RSIMotionType.RSIMotionTypePT, RSIMotionType.RSIMotionTypeBSPLINE, RSIMotionType.RSIMotionTypeBSPLINE2)
velocities, // Specify the positions that you want to reach. (it can be n number)
accelerations, // Specify the accelerations that you want to use during every move.
jerks, // Specify the jerk that you want to use during every move.
times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
points, // Specify the total number of streamed points.
emptyCount, // E-stop generated if there are this number or fewer frames loaded. Use the value “0” to trigger an E-stop when the buffer is empty, or “-1” to not trigger an E-stop. (Typically for PT motion there are two frames per PT point)
false, // Specify whether points are kept, or are not kept.
true); // Specify if this is the last MovePT. (If True, this is the final point. If False, more points expected.)
axis.MotionDoneWait(); // Wait for motion to be completed.
//---ASSERT---
Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");

PTmotionWhileStopping
Visit our Topic Page for more information.
This code demonstrates that different actions that you can take after stopping a PT Streaming motion.

// Constants
const int POINTS = 1; // Specify how many points per streaming motion method call.
double[] first = { 0.1 }; // specify the array with position(s) that will go in the first MovePT call.
double[] second = { 0.3 }; // specify the array with position(s) that will go in the second MovePT call
double[] third = { 0.7 }; // specify the array with position(s) that will go in the third MovePT call
double[] time1 = { 0.5 }; // specify the array with time(s) that will go in the first MovePT call.
double[] time2 = { 0.3 }; // specify the array with time(s) that will go in the second MovePT call.
double[] time3 = { 0.25 }; // specify the array with time(s) that will go in the third MovePT call.
axis.MovePT(RSIMotionType.RSIMotionTypePT, first, time1, POINTS, -1, false, false); // Start motion and stream a point.
axis.MovePT(RSIMotionType.RSIMotionTypePT, second, time2, POINTS, -1, false, false); // Append a point.
// After you stop a streaming motion, you can do 2 things.
// 1. You can either RESUME motion and continue to append.
// 2. Or you can DISCARD the points before the stop and start new motion.
axis.Stop(); // Calling Stop() after streaming motion will put you in an STOPPED state.
//axis.EStop(); // Calling EStop() after streaming motion will put you in an ERROR state.
// Therefore, you must ClearFaults() before taking any action.
//axis.Abort(); // Calling Abort() after streaming motion will put you in an ERROR state and trigger an AmpEnable(false).
// Therefore, you must call AmpEnable(true) before taking action.
axis.MotionDoneWait(); // Wait for axis to come to a stop.
axis.Resume(); // Resume() is the key here.
// If you include Resume() you will append all next streaming points to the old ones.
// If you do not include Resume() you will discard all previous points and start with new motion with the new points.
axis.MovePT(RSIMotionType.RSIMotionTypePT, third, time3, POINTS, -1, false, true); // Depending on whether you include Resume() or not this point will be appended or will be starting motion.

SingleAxisSyncOutputs Visit our Topic Page for more information.
This sample application will show you a basic demonstartion on how to set up Sync Outputs, so that you can easily change any IO’s state based on a specified point index (or ElmentID) on your steaming motion.

// Constants
const int TOTAL_POINTS = 4; // total number of points
const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
const int OUTPUT_INDEX = 0; // This is the index of the digital output that will go active when the user limit triggers.
const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with
double[] positions = { 1.0, 2.0, 3.0, 4.0 }; // These will be the streaming motion 5 positions.
double[] times = { 0.5, 0.1, 0.2, 0.4 }; // These will be the streaming motion 5 positions' time.
int outputEnableID = 2; // The motion element ID at which to set the output
int outputDisableID = 3; // The motion element ID at which to set the output
// Set up the inputs
//IOPoint output0 = IOPoint.CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
IOPoint output0 = IOPoint.CreateDigitalOutput(controller.IOGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
output0.Set(false); // Set the output low
// Set up Sync Outputs
axis.StreamingOutputsEnableSet(true); // Enable streaming output.
// ENABLE the Sync Output(s)
axis.StreamingOutputAdd(output0, true, outputEnableID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
axis.StreamingOutputAdd(output0, false, outputDisableID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
// DISABLE the Sync Output(s)
//axis.StreamingOutputAdd(output0, false, outPutEnableID);
axis.MovePT(RSIMotionType.RSIMotionTypePT, positions, times, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
while (!axis.MotionDoneGet())
{
if (axis.MotionIdExecutingGet()>outputEnableID && axis.CommandPositionGet()<outputEnableID)
{
Assert.AreEqual(output0.Get(), true, "The output should be triggered");
}
else
{
Assert.AreEqual(output0.Get(), false, "The output should NOT be triggered");
}
}
axis.StreamingOutputsEnableSet(false); // Disable Sync Outputs.
axis.AmpEnableSet(false); // Disable the motor.