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).
Rotating in Place
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.
Example: forward_left_right_backward.py
- Enter, save, and flash forward_left_right_backward.py.
- Verify that the cyber:bot makes the forward-left-right-backward motions.
# forward_left_right_backward.py 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.
Pivot Turns
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
Try This: pivot_tests.py
- Save forward_left_right_backward.py as pivot_tests.py.
- Change the v parameter value in each servo_speed call so the script will perform all four pivot maneuvers: forward, left, right, backward.
- Run the modified script and verify that the different pivot actions work.
- Try experimenting with the sleep calls for each maneuver so that each one runs long enough to execute a 90° turn.
Your Turn: Arcs
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:
- Try writing and test-driving a script to make your cyber:bot drive in a tight arc.
- Try writing and test-driving a script to make your cyber:bot drive in a wide arc.