How the Distance Maneuver Tests Work

How distances_forward_left_right_left_backward Works

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)

 

Try This - Time-based Pivot

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!

  • Modify the script as shown below by changing the turns to pivots.
  • Change the Script Name to speeds_forward_left_right_left_backward_try_this.
  • Click Load/Save and select Download Project Hex to save your work.
  • Reconnect your cyber:bot to USB.
  • Set the PWR switch to 1.
  • Flash the script into the cyber:bot.
  • Set the PWR switch to 0.
  • Disconnect the cyber:bot from the USB cable.
  • Set it on the floor and set the PWR switch to 2.
  • Verify that the cyber:bot now makes approximately 90° pivots instead of turning in place.