Now that the servos are centered, the CR servo PIN speed blocks can set rotation speeds and directions. This test will make the right servo turn at half speed counterclockwise, then half speed clockwise, then stop.
After testing the right servo that’s connected to P27, you will change all the PIN values from 27 to 26 to test the left servo. You can also try increasing and decreasing the +/- 50 speed values to increase or decrease the wheel speeds.
For this test, we’ll keep the SumoBot WX face down on the table so that the wheels can spin freely. With the POWER switch set to 2 and the program running, the robot’s right wheel should turn counterclockwise for 3 seconds, then clockwise for three seconds, then stop.
If the other wheel turns, it means that the servo cables connected to P26 and P27 are reversed and need to be swapped.
The Propeller FLiP executes blocks starting at the top and works its way downward. So, the first block it executes is CR servo PIN 27 speed 50, which makes the servo turn at about half speed counterclockwise.
The pause (ms) 3000 makes the Propeller FLiP do nothing for 3 seconds. During that time, the wheel continues to turn.
Next, CR servo PIN 27 speed -50 makes the servo turn at half speed clockwise, and the pause (ms) 3000 block below it allows it to continue turning for another 3 seconds.
Last but not least, CR servo PIN 27 speed 0 makes the servo turn at 0 speed, and since there’s nothing after it, it continues to hold that (zero) speed indefinitely.
When the Propeller executes code from a CR servo PIN….speed… block, another one of the Propeller microcontroller’s 8 cores steps in and starts sending repeated signals to make a continuous rotation servo turn at a certain speed. It will keep sending those signals and the servo will keep turning until another CR servo PIN...speed… block asks for a different speed. At that point, the Propeller core that is sending the servo control signals updates them for the new behavior.
This “set it and forget it” response to CR servo PIN...speed… blocks is very useful. Your program can do other things while the servos are turning, like check sensors, calculate, decide, and more. Instead of doing that here, the program uses pause (ms) 3000 blocks to just do nothing for 3 seconds. Those pause (ms) blocks allow you to see the servos turn one direction, and then the other before stopping. Without the pause (ms) blocks, all you’d see would be a twitch, and the program would be over in the blink of an eye.
Full speed for a Parallax CR servo powered by 5 V is typically a little over 50 RPM, so 50% speed would be about 25 RPM. We can use these numbers to calculate roughly how far the wheel should turn.
Keep in mind that 1.25 revolutions is an approximate value. It will vary with how fresh your batteries are, and even which direction the servo turns. So long as each servo turns somewhere in the 1.1 to 1.6 revolutions range, you’re in good shape.
As with the center signal from the previous activity, the brief high times still repeat every 20 ms. The difference is that for 50% of full speed counterclockwise, the brief high signals last for 1.55 ms instead of 1.50 ms. For clockwise, instead of the high times lasting 0.05 ms longer than the 1.50 ms center signal, they last 1.45 ms, which is 0.05 ms shorter.
.
This graph is called a transfer function. It shows typical servo speed vs. pulse duration. The pulse durations are in terms of μs (millionths of a second) instead of ms (thousandths of a second). So, instead of 1.5 ms, the graph shows 1500 μs.
Those percent-of-full-speed x axis values actually describe how many microseconds above or below 1.5 ms each control pulse lasts. The graph shows the servo rotational velocity response in terms of RPM. The graph speeds do not exactly match % full speed, but it’s close enough to use as a way of thinking about how the numbers from -100 to 0 to 100 correspond result in certain servo speeds.
Now, let’s test the right wheel.
Each servo is unique. Even though 100 is approximately 100% of full speed, it varies from one servo to the next. A speed of 200 essentially ensures that the servo will turn at top speed.