APIs, concepts, guides, and more
MotionStreaming.cs
1
54using RSI.RapidCode.dotNET; // Import our RapidCode Library.
55using NUnit.Framework;
56using System;
57using System.Linq;
58
59#if DOXYGEN // RSI internal documentation use only
60using RSI.RapidCode;
61#endif
62
64[TestFixture]
65[Category("Software")]
66public class motionStreaming : SampleAppTestBase
67 {
68 [Test]
69 public void PTmotion()
70 {
71
73 int points = 3; // Specify the total number of streamed points.
74 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)
75 double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
76 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)
77
79 axis.MovePT(RSIMotionType.RSIMotionTypePT, // Specify the type of PT Motion that you want to perform. (RSIMotionType.RSIMotionTypePT, RSIMotionType.RSIMotionTypeBSPLINE, RSIMotionType.RSIMotionTypeBSPLINE2)
80 positions, // Specify the positions that you want to reach. (it can be n number)
81 times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
82 points, // Specify the total number of streamed points.
83 emptyCount, // E-stop generated if there are this number or fewer frames loaded. (Typically for PT motion there are two frames per PT point)
84 false, // Specify whether points are kept, or are not kept.
85 true); // Specify if this is the last MovePT. (If True, this is the final point. If False, more points expected.)
86
87 axis.MotionDoneWait(); // Wait for motion to be completed.
89
91 Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
92 }
93
94 [Test, Timeout(Constants.MAX_TEST_TIME)]
95 public void PVTmotion()
96 {
98 int points = 3; // Specify the total number of streamed points. (Very Important!)
99 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)
100
101 double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
102 double[] velocities = { 12.0, 10.0, 6.0 }; // Specify the velocities that you want to use to reach your position.
103 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)
104
105 axis.MovePVT(positions, // Specify the positions that you want to reach. (it can be n number)
106 velocities, // Specify the velocities that you want to reach. (it can be n number)
107 times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
108 points, // Specify the total number of streamed points.
109 emptyCount, // E-stop generated if there are this number or fewer frames loaded. (Typically for PVT motion there are two frames per PT point)
110 false, // Specify whether points are kept, or are not kept.
111 true); // Specify if this is the last MovePT. (If True, this is the final point. If False, more points expected.)
112
113 axis.MotionDoneWait(); // Wait for motion to be completed.
115
117 Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
118 }
119
120 [Test, Timeout(Constants.MAX_TEST_TIME)]
121 public void PVAJTmotion()
122 {
124 int points = 3; // Specify the total number of streamed points. (Very Important!)
125 int emptyCount = 2; // E-stop generated if there aren't at least this many points loaded.
126
127 double[] positions = { 1.0, 0.5, 0.75 }; // Specify the positions that you want to reach. (it can be n number)
128 double[] velocities = { 10.0, 20.0, 40.0 }; // Specify the velocities that you want to use to reach your position.
129 double[] accelerations = { 4, 4, 4 }; // Specify the accelerations that you want to use to reach your position.
130 double[] jerks = { 50, 50, 50 }; // Specify the jerks that you want to use in each move.
131 double[] times = { 0.4, 0.2, 0.1 }; // Specify the times in which you want to reach each position.
132
133 axis.MovePVAJT(positions, // Specify the positions that you want to reach. (it can be n number)
134 velocities, // Specify the velocities that you want to reach. (it can be n number)
135 accelerations, // Specify the accelerations that you want to use during every move.
136 jerks, // Specify the jerks that you want to use during every move.
137 times, // Specify the times in which you want to reach each position. (velocity and acceleration is calculated by the RMP)
138 points, // Specify the total number of streamed points.
139 emptyCount, // E-stop generated if there are this number or fewer frames loaded. (Typically for PVAJT motion there are two frames per PVAJT point)
140 false, // Specify whether points are kept, or are not kept.
141 true); // Specify if this is the last MovePVAJT. (If True, this is the final point. If False, more points expected.)
142
143 axis.MotionDoneWait(); // Wait for motion to be completed.
145
147 Assert.That(axis.CommandPositionGet(), Is.EqualTo(positions.Last()), "The command position should be equal to last position in the array");
148 }
149
150 [Test, Timeout(Constants.MAX_TEST_TIME)]
151 public void PTmotionWhileStopping()
152 {
154 const int points = 3; // Specify how many points per streaming motion method call.
155 const int emptyCount = 2; // E-stop generated if there aren't at least this many points loaded.
156
157 double[] first = { 0.1, 0.2, 0.3 }; // specify the array with position(s) that will go in the first MovePT call.
158 double[] second = { 0.4, 0.5, 0.6 }; // specify the array with position(s) that will go in the second MovePT call
159 double[] third = { 0.7, 0.8, 0.9 }; // specify the array with position(s) that will go in the third MovePT call
160
161 double[] time1 = { 0.3, 0.3, 0.3 }; // specify the array with time(s) that will go in the first MovePT call.
162 double[] time2 = { 0.2, 0.2, 0.2 }; // specify the array with time(s) that will go in the second MovePT call.
163 double[] time3 = { 0.25, 0.25, 0.25 }; // specify the array with time(s) that will go in the third MovePT call.
164
165 axis.MovePT(RSIMotionType.RSIMotionTypePT, first, time1, points, emptyCount, false, false); // Start motion and stream a point.
166 axis.MovePT(RSIMotionType.RSIMotionTypePT, second, time2, points, emptyCount, false, false); // Append a point.
167
168 // After you Stop() a streaming motion, you can do 2 things.
169 // 1. You can either RESUME motion and continue to append.
170 // 2. Or you can DISCARD the points before the stop and start new motion.
171
172 axis.Stop(); // Calling Stop() after streaming motion will put you in an STOPPED state.
173
174 //axis.EStop(); // Calling EStop() after streaming motion will put you in an ERROR state.
175 // Therefore, you must ClearFaults() before taking any action.
176
177 //axis.Abort(); // Calling Abort() after streaming motion will put you in an ERROR state and trigger an AmpEnable(false).
178 // Therefore, you must call AmpEnable(true) before taking action.
179
180 axis.MotionDoneWait(); // Wait for axis to come to a stop.
181 axis.Resume(); // Resume() is the key here.
182 // If you include Resume() you will append all next streaming points to the old ones.
183 // If you do not include Resume() you will discard all previous points and start with new motion with the new points.
184
185 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.
187 }
188 }
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
Streaming motion types.
Definition rsienums.h:989