Your Turn: Use the Feedback Signals

Did You Know: The Scripts Work Anyway

Even before being updated, the cyber:bot scripts will actually run.  Reason being, the Feedback 360° servos do respond to normal servo signals! Without changing anything, the Feedback 360 servos will also exhibit typical continuous rotation servo behaviors, like needing adjustments to speeds to straighten the cyber:bot robot’s path.  In contrast, following the instructions below will incorporate the cyber:bot robot board’s feedback360 control system and automatically make the servos turn at the same speeds.

Your Turn: Use the Feedback Signals

This example demonstrates how to update for servo_speed calls that use variables instead of constants.  It will start with the script from the Tethered Terminal Control Script page in Cybersecurity: Navigation Control from a Keyboard.  The example with drive.speed(int( vL/2), -int(vR/2) ) will approximately match the wheel speeds to the previous servos.  After verifying that it works, we will adjust it to rely on the full Feedback 360° speed range using drive.speed( vL, -vR ), and enter speeds in the -128 to 128 range into the terminal.  

You will probably find that the USB cable doesn’t give the cyber:bot with Feedback 360° servos enough range at higher speeds.  So, after learning the procedure here, you can also try your hand at updating the scripts from Terminal Control — Go Wireless!  

  • Set the PWR switch to 0, and make sure the cyber:bot is connected to your computer with a USB cable.
  • Right-click the  feedback_360_template.hex link and choose Save As, then open it with the micro:bit Python Editor.

feedback_360_template.hex

  • Enter the terminal_controlled_bot_tethered_intro_for_fb360 script shown below.
  • Update the project's name, and then click Save.

Example Script: terminal_controlled_bot_tethered_intro

# terminal_controlled_bot_tethered_intro_for_fb360

from cyberbot import *
from feedback360 import *                         # <-- add

drive.connect()                                   # <-- add

sleep(1000)

print("\nSpeeds are -100 to 100\n")

while(True):
    text = input("Enter left speed: ")
    vL = int(text)

    text = input("Enter right speed: ")
    vR = int(text)

    text = input("Enter ms to run: ")
    ms = int(text)

    # bot(18).servo_speed(vL)                      # <-- comment  
    # bot(19).servo_speed(-vR)                     # <-- comment
    drive.speed( int(vL/2), -int(-vR/2) )          # <-- add
    sleep(ms)
    # bot(18).servo_speed(None)                    # <-- comment
    # bot(19).servo_speed(None)                    # <-- comment
    drive.speed( 0, 0 )                            # <-- add

    print()

 

  • Click Send to micro:bit:
  • Set the PWR switch to 2.
  • Do not disconnect from USB; this is a “tethered application.”
  • Click Show serial, then click inside the serial monitor.  
  • Type 50 in response to the Enter right speed: prompt, then press Enter.
  • Type 50 in response to the Enter left speed: prompt, then press Enter.
  • Type 2000 in response to the Enter ms to run: prompt, and press Enter.
  • Verify that your cyber:bot rolled forward for about ¾ of a second.

 

Next, let’s modify the script so that it makes use of the Feedback 360 servos' entire speed range.

  • Change print("\nSpeeds are -100 to 100\n") to print("\nSpeeds are -128 to 128\n").
  • Change drive.speed( int(vL/2), -int(-vR/2) ) to drive.speed(vL, vR), and keep in mind that vR is positive because there were two negatives in the -int(-vR/2) term.
  • Flash the modified script and repeat the tests again, but this time, use values in the -128 to 128 range.