APIs, concepts, guides, and more
MotionStreaming.cs
Attention
See the following Concept pages for a detailed explanation of this sample: PT Streaming Motion, PVT Streaming Motion, PVAJT Streaming Motion, Streaming Motion Sync Outputs.
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;
using System;
using System.Linq;
#if DOXYGEN // RSI internal documentation use only
#endif
[TestFixture]
[Category("Software")]
public class motionStreaming : SampleAppTestBase
{
[Test]
public void PTmotion()
{
int points = 3; // Specify the total number of streamed points.
int emptyCount = 2; // E-stop generated if there are this number or fewer frames loaded. (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)
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. (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.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void PVTmotion()
{
int points = 3; // Specify the total number of streamed points. (Very Important!)
int emptyCount = 2; // E-stop generated if there are this number or fewer frames loaded. (Typically for PVT 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. (acceleration is calculated by the RMP)
axis.MovePVT(positions, // Specify the positions that you want to reach. (it can be n number)
velocities, // Specify the velocities 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. (Typically for PVT 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.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void PVAJTmotion()
{
int points = 3; // Specify the total number of streamed points. (Very Important!)
int emptyCount = 2; // E-stop generated if there aren't at least this many points loaded.
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 jerks 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.
axis.MovePVAJT(positions, // Specify the positions that you want to reach. (it can be n number)
velocities, // Specify the velocities 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 jerks 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. (Typically for PVAJT motion there are two frames per PVAJT point)
false, // Specify whether points are kept, or are not kept.
true); // Specify if this is the last MovePVAJT. (If True, this is the final point. If False, more points expected.)
axis.MotionDoneWait(); // Wait for motion to be completed.
Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void PTmotionWhileStopping()
{
const int points = 3; // Specify how many points per streaming motion method call.
const int emptyCount = 2; // E-stop generated if there aren't at least this many points loaded.
double[] first = { 0.1, 0.2, 0.3 }; // specify the array with position(s) that will go in the first MovePT call.
double[] second = { 0.4, 0.5, 0.6 }; // specify the array with position(s) that will go in the second MovePT call
double[] third = { 0.7, 0.8, 0.9 }; // specify the array with position(s) that will go in the third MovePT call
double[] time1 = { 0.3, 0.3, 0.3 }; // specify the array with time(s) that will go in the first MovePT call.
double[] time2 = { 0.2, 0.2, 0.2 }; // specify the array with time(s) that will go in the second MovePT call.
double[] time3 = { 0.25, 0.25, 0.25 }; // specify the array with time(s) that will go in the third MovePT call.
axis.MovePT(RSIMotionType.RSIMotionTypePT, first, time1, points, emptyCount, false, false); // Start motion and stream a point.
axis.MovePT(RSIMotionType.RSIMotionTypePT, second, time2, points, emptyCount, 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, emptyCount, false, true); // Depending on whether you include Resume() or not this point will be appended or will be starting motion.
}
}
double CommandPositionGet()
Get the current command position.
int32_t MotionDoneWait()
Waits for a move to complete.
void Resume()
Resume an axis.
void MovePVT(const double *const position, const double *const velocity, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
Move commanded by list of positions, velocities, and times.
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
void MovePVAJT(const double *const position, const double *const velocity, const double *const acceleration, const double *const jerk, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
RSIMotionType
PT and PVT streaming motion types.
Definition rsienums.h:998