APIs, concepts, guides, and more
Motion.cs
1
62using RSI.RapidCode.dotNET; // Import our RapidCode Library.
63using NUnit.Framework;
64
66[TestFixture]
67[Category("Software")]
68public class Motion : SampleAppTestBase
69 {
70 [Test, Timeout(Constants.MAX_TEST_TIME)]
71 public void AbsoluteMotion()
72 {
75 axis.MoveTrapezoidal(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION);// Command simple trapezoidal motion.
76 axis.MotionDoneWait();// Wait for motion to be done
78
80 Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
81 }
82
83 [Test, Timeout(Constants.MAX_TEST_TIME)]
84 public void SCurveMotion()
85 {
87 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.
88 axis.MotionDoneWait(); // Wait for motion to finish
90
92 Assert.That(axis.CommandPositionGet(), Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
93 }
94
95 [Test, Timeout(Constants.MAX_TEST_TIME)]
96 public void FinalVelocity()
97 {
99 int finalVelocity = 5;
100
102 axis.MoveSCurve(Constants.POSITION, // Command an SCurve move with a final velocity of FINAL_VELOCITY.
103 Constants.VELOCITY,
104 Constants.ACCELERATION,
105 Constants.DECELERATION,
106 Constants.JERK_PERCENT,
107 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.
109
110 if (axis.CommandPositionGet() >= Constants.POSITION)
111 {
112 Assert.That(axis.CommandVelocityGet(), Is.EqualTo(finalVelocity), "The command velocity should be equal to FINAL_VELOCITY");
113 TearDown();
114
115 }
116 }
117
118 [Test, Timeout(Constants.MAX_TEST_TIME)]
119 public void RelativeMotion()
120 {
122 axis.MoveRelative(Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT); // Command a relative to the current position
123 axis.MotionDoneWait(); // Wait for motion to finish. (the motion should take 2.5 seconds)
124
125 var cmdPositionAfterMove = axis.CommandPositionGet(); // The command position should be equal to Constants.POSITION
126
127 // Move back to the start position by moving negative relative to current position
128 axis.MoveRelative(-1 * Constants.POSITION, Constants.VELOCITY, Constants.ACCELERATION, Constants.DECELERATION, Constants.JERK_PERCENT);
129 axis.MotionDoneWait();
131
133 Assert.That(cmdPositionAfterMove, Is.EqualTo(Constants.POSITION), "The command position should be equal to POSITION");
134 }
135
136 [Test]
137 public void MoveVelocity()
138 {
140 // Command a velocity move
141 axis.MoveVelocity(Constants.VELOCITY, Constants.ACCELERATION);
143
144 if (axis.CommandPositionGet() >= Constants.POSITION)
145 {
146 Assert.That(axis.CommandVelocityGet(), Is.EqualTo(Constants.VELOCITY), "The command velocity should be equal to FINAL_VELOCITY");
147 TearDown();
148 }
149 }
150 }
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.