This tutorial is all about the cyber:bot robot’s servo motors. First, you will calibrate or “center” the servo motors. Next, you will learn how control signals make the servos rotate at different speeds and directions. Then, you will be able to write programs to make the robot drive.
You will need:
Once you understand how the servos work, you will be able to write scripts that make the robot drive forward, backward, and turn left or right. You will be ready to combine servo movement with sensor input in the next tutorials, so your cyber:bot can navigate on its own.
The cyber:bot robot's drive motors are called Continuous Rotation Servos. If you received your robot preassembled, these servos might need to be re-centered before moving on to navigation activities.
Before running this test, double check the battery and servo connections.
# both_servos_stay_still from cyberbot import * bot(18).servo_speed(0) bot(19).servo_speed(0)
If a servo has not yet been centered, or if its center setting has drifted, it might turn, vibrate, or make a humming noise when your script tells it to stay still.
Tools You Might Need
If the Procedure checklist says to remove the servo from the cassis, use these tools that come in the cyber:bot Robot kit:
(1) Parallax screwdriver, or a different Phillips #1 point screwdriver with a 1/8″ (3.18 mm) or smaller shaft.
(1) Parallax Combination Wrench (#700-10025), or a 1/4" combination wrench.
Procedure
Your cyber:bot servos need to receive a high (5 volt) signal pulse every 20 milliseconds to keep rotating smoothly. The speed and direction of rotation are determined by how long that high pulse lasts. Take a look at the timing diagrams below.
Full speed clockwise requires 1.3 ms high pulses. To do this, use servo_speed(-75).
Full speed counter-clockwise requires 1.7 ms high pulses. To do this, use servo_speed(75).
Full speed typically falls in the 50 to 60 RPM range.
To center the servos, we used servo_speed(0). This generates high signals that last 1.5 ms — halfway in between — that not only make the servo stay still, also but resist being twisted. This is useful for stopping on slopes, or pausing in the middle of a series of maneuvers.
To stop sending signals to the servos entirely, use servo_speed(None). This will also make the servos stay still, but they will not resist being twisted.
What’s RPM? Revolutions Per Minute—the number of full rotations turned in one minute.
What’s a pulse train? Just as a railroad train is a series of cars, a pulse train is a series of pulses (brief high signals).
# left_servo_clockwise from cyberbot import * bot(18).servo_speed(-75) # 1.3 ms full speed clockwise
Now, try turning the left servo the other direction.
Now, try making the left servo stop, two different ways.
# right_servo_clockwise from cyberbot import * bot(19).servo_speed(-75) # 1.3 ms full speed clockwise
Have you ever thought about what direction a car’s wheels have to turn to propel it forward? The wheels turn opposite directions on opposite sides of the car. Likewise, to make the cyber:bot go forward, its left wheel has to turn counterclockwise, while its right wheel turns clockwise.
Remember that a script can use the servo_speed function to control the speed and direction of each servo. Then, it can use the sleep function to keep the servos running for certain amounts of time before choosing new speeds and directions. Here’s an example that will make the cyber:bot roll forward for about three seconds, and then stop.
# forward_three_seconds from cyberbot import * bot(18).servo_speed(75) # Full speed forward bot(19).servo_speed(-75) sleep(3000) # Wait three seconds bot(18).servo_speed(None) #Stop bot(19).servo_speed(None)
Now, let's try making the cyber:bot travel backwards for three seconds.
# backward_three_seconds from cyberbot import * bot(18).servo_speed(-75) # Full speed backwards bot(19).servo_speed(75) sleep(3000) bot(18).servo_speed(None) # Stop bot(19).servo_speed(None)
All it takes to get other motions out of your cyber:bot are different value combinations in the v parameters in your bot(18) and bot(19) calls to servo_speed(v).
These two calls will make your cyber:bot rotate in place to make a left turn (note these are not complete scripts):
# Turn left in place bot(18).servo_speed(-75) #Left wheel clockwise bot(19).servo_speed(-75) #Right wheel clockwise
These two calls will make your cyber:bot rotate in place for a right turn:
# Turn right in place bot(18).servo_speed(75) #Left wheel counterclockwise bot(19).servo_speed(75) #Right wheel counterclockwise
The turns above can be called rotation turns because the wheel speeds are equal, but velocity is opposite to make the cyber:bot turn about its center. This rotation is great for making the robot face a new direction in a tight place and without changing its position. Imagine a pen going through the center of the cyber:bot's "axle." A rotating turn would not draw any curved lines; it would just rotate on this point making the dot darker! You could think of this as an arc with a radius of zero.
Let’s combine these two commands with a forwards and backwards command into a single script that makes the cyber:bot move forward, turn left, turn right, then move backward.
# forward_left_right_backward from cyberbot import * #Full speed forward bot(18).servo_speed(75) #Left wheel counterclockwise bot(19).servo_speed(-75) #Right wheel clockwise sleep(2000) #...for 2 seconds #Turn left in place bot(18).servo_speed(-75) #Left wheel clockwise bot(19).servo_speed(-75) #Right wheel clockwise sleep(600) #...for 0.6 seconds #Turn right in place bot(18).servo_speed(75) #Left wheel counterclockwise bot(19).servo_speed(75) #Right wheel counterclockwise sleep(600) #...for 0.6 seconds #Full speed backwards bot(18).servo_speed(-75) #Left wheel clockwise bot(19).servo_speed(75) #Right wheel counterclockwise sleep(2000) #...for 2 seconds bot(18).servo_speed(None) #Stop the servos bot(19).servo_speed(None)
PRO TIP: To enter this script quickly, Copy and Paste to make four copies of the four lines that make up a maneuver. Then, modify each one with individual values.
Another option for turning is by pivoting, where one wheel turns forward or backward while the other stays still. Now the center of the circle is the wheel that is not moving, and the cyber:bot pivots about this point. An imaginary pen through the center of the robot would draw a circle with a radius equal to about half of the cyber:bot robot’s wheelbase. The animation below shows a right-wheel forward pivot.
Here are the four routines for forward and backward pivot turns (these are not complete scripts):
# Pivot forward-left bot(18).servo_speed(0) # Left wheel stop bot(19).servo_speed(-75) # Right wheel clockwise # Pivot forward-right bot(18).servo_speed(75) # Left wheel counterclockwise bot(19).servo_speed(0) # Right wheel stop # Pivot backward-left bot(18).servo_speed(0) # Left wheel stop bot(19).servo_speed(75) # Right wheel counterclockwise # Pivot backward-right bot(18).servo_speed(-75) # Left wheel clockwise bot(19).servo_speed(0) # Right wheel stop
So far, our turns have had either one or both servos turning full speed, or not moving at all. What happens when the servos turn at unequal velocities, but neither one is at full speed or stopped? The answer is, the cyber:bot will drive in an arc.
Arcs can be tight, where one wheel turns backward while the other turns forward, but at unequal speeds.
Arcs can be wide, where both wheels turn the same direction, but at unequal speeds:
Links
[1] https://learn.parallax.com/tutorials/robot/cyberbot/navigation-cyberbot/servo-direction
[2] https://learn.parallax.com/tutorials/robot/cyberbot/add-modules-your-microbit
[3] https://learn.parallax.com/tutorials/robot/cyberbot/navigation-cyberbot/are-servos-centered