The RMP Motion Controller APIs
Motion.cs
1
55using RSI.RapidCode.dotNET; // Import our RapidCode Library.
56using NUnit.Framework;
57
59[TestFixture]
60[Category("Software")]
61public class Motion : SampleAppTestBase
62 {
63 [Test, Timeout(Constants.MAX_TEST_TIME)]
64 public void AbsoluteMotion()
65 {
68 axis.MoveTrapezoidal(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION);// Command simple trapezoidal motion.
69 axis.MotionDoneWait();// Wait for motion to be done
71
73 Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
74 }
75
76 [Test, Timeout(Constants.MAX_TEST_TIME)]
77 public void SCurveMotion()
78 {
80 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.
81 axis.MotionDoneWait(); // Wait for motion to finish
83
85 Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
86 }
87
88 [Test, Timeout(Constants.MAX_TEST_TIME)]
89 public void FinalVelocity()
90 {
92 int finalVelocity = 5;
93
95 axis.MoveSCurve(Constants.POSITION, // Command an SCurve move with a final velocity of FINAL_VELOCITY.
96 Constants.VELOCITY,
97 Constants.ACCELERATION,
98 Constants.DECELERATION,
99 Constants.JERK_PERCENT,
100 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.
102
103 if (axis.CommandPositionGet() >= Constants.POSITION)
104 {
105 Assert.That(axis.CommandVelocityGet(), Is.EqualTo(finalVelocity), "The command velocity should be equal to FINAL_VELOCITY");
106 TearDown();
107
108 }
109 }
110
111 [Test, Timeout(Constants.MAX_TEST_TIME)]
112 public void RelativeMotion()
113 {
115 axis.MoveRelative(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT); // Command a relative to the current position
116 axis.MotionDoneWait(); // Wait for motion to finish. (the motion should take 2.5 seconds)
117
118 var cmdPositionAfterMove = axis.CommandPositionGet(); // The command position should be equal to Constants.POSITION
119
120 // Move back to the start position by moving negative relative to current position
121 axis.MoveRelative(-1 * Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT);
122 axis.MotionDoneWait();
124
126 Assert.That(cmdPositionAfterMove, Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
127 }
128
129 [Test]
130 public void MoveVelocity()
131 {
133 // Command a velocity move
134 axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
136
137 if (axis.CommandPositionGet() >= Constants.POSITION)
138 {
139 Assert.That(axis.CommandVelocityGet(), Is.EqualTo(Constants.VELOCITY), "The command velocity should be equal to FINAL_VELOCITY");
140 TearDown();
141 }
142 }
143 }
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.