The cyber:bot board’s Feedback 360° servo driver measures distance in 64ths of a turn. That’s equivalent to half way between two of the smallest spokes in the cyber:bot wheel. For simplicity, we’ll call 1/64th of a rotation a ‘tick’. Since the diameter of the cyber:bot wheel is 66.2 mm, we can use Ω x diameter to calculate that the circumference is 208 mm. Then, 1/64th of that is 3.25 mm, the distance the wheel travels when it rotates one tick.
The feedback360 module has a method named drive.goto(), which you supply with two distances in ticks, one for each wheel. In this example, drive.goto(64, 64) results in both wheels turning forward 64 ticks x 3.25 mm/tick = 28 mm, the circumference of the wheel. Converting to inches, that would be 208 mm x 1 in/ 25.4 mm ≈ 8.2 in. Using 32 ticks would get the cyber:bot about half that far, about 4.1 in.
In this activity, you will use drive.goto to make the cyber:bot travel certain distances, and incorporate calculations into your script to make the cyber:bot travel a specified distance in inches. You will use distance values that will make the cyber:bot turn in place, pivot, and arc.
This script will perform the forward, left, right, left, backward pattern, and the cyber:bot should return much closer to its starting point. In fact, with drive.goto, you can mark the spoke on each wheel that’s pointing straight up when the script starts, and it should be pointing up again when the script completes.
distances_forward_left_right_left_backward.hex [1]
Like the previous script, this one uses the Feedback 360° servos, so it has to import both the cyberbot and feedback360 modules. It also has to call drive.connect before calling any other drive methods. Unlike the previous script, the drive methods in this script are not the set-and-forget kind. Keep that in mind while reading!
# distances_forward_left_right_left_backward from cyberbot import * from feedback360 import * drive.connect()
Forward 196 ticks is a total of three revolutions for a distance of approximately 192 x 3.25 / 25.4 ≈ 24.6 inches. Unlike drive.speed, the drive.goto() method waits for the maneuver to be completed before it allows the next line to be executed. The sleep(1000) is just there to provide a delay to see that the cyber:bot stopped before moving on to the next maneuver.
drive.goto(192, 192) # Forward 3 turns sleep(1000)
With turning by distance, a full circle is about +/- 104 ticks. That makes +/-52 ticks a half turn and +/- 26 ticks a quarter turn. You might need to tun this for your cyber:bot since the distance between wheels determines the robots ‘turning radius’.
drive.goto(-26, 26) # 90 degrees left sleep(1000) drive.goto(52, -52) # 180 degrees right sleep(1000) drive.goto(-26, 26) # 90 degrees left sleep(1000)
This makes the cyber:bot go backwards 192 ticks = 3 turns. The sleep(1000) is there just in case you decide to add more maneuvers.
drive.goto(-192, -192) # Backward 3 turns sleep(1000)
Let’s say that your application needs the cyber:bot to pivot by 90° instead of rotating in place. For a pivot left, instead of drive.goto(-26, 26), your script would need drive.goto(0, 52). Note that to make the 90° turn, the right wheel has to make up for the left wheel by turning twice as far!
With the servos mounted on the inside of the chassis, the distance between the cyber:bot robot’s wheels is about 107.6 mm. To make the cyber:bot pivot (not rotate!) in a full circle, we can think about that 107.6 mm as the radius of a circle, the turning radius.
How much distance would the outer wheel have to travel to do a full circle? That would be:
c = 2 x π x r
...with a result of about 676 mm. The turning radius in ticks is just that number of mm divided by 3.25 mm, for 208 ticks. Also, it doesn’t matter whether it’s a pivot turn with drive.goto(0, 208) or a rotating turn with drive.goto(104, 104), the cyber:bot will still turn 360°.
Here is a function to convert inches of distance to ticks:
def in_to_ticks(inches): return int(inches * 25.4 / 3.25)
Links
[1] https://learn.parallax.com/sites/default/files/content/cyberbot/F360/distances_forward_left_right_left_backward.hex
[2] http://python.microbit.org/v/2