Update the Receiver cyber:bot Script

The transmitter micro:bit should still be running the same script from the previous activity.  That’s radio_tilt_controller_w_stop_range.

Now for the new cyber:bot receiver script!

Example script: radio_tilt_bot_fb_lr_with_stop_range

  • Set the receiver cyber:bot board PWR switch to 1.
  • If you are in a classroom, adjust the channel= in the script to your assigned channel.
  • Enter, save, and flash radio_tilt_bot_fb_lr_with_stop_range into the micro:bit that’s in the receiver cyber:bot.  
# radio_tilt_bot_fb_lr_with_stop_range

from cyberbot import *
import radio

radio.on()
radio.config(channel=7, queue=1, length=64)

while True:

    packet = radio.receive()

    if packet:

        dictionary = eval(packet)

        x = dictionary.get('x')
        y = dictionary.get('y')
        needle = dictionary.get('needle')
        
        fb = y / 10
        lr = x / 10

        if abs(fb) > 8:
            display.show(Image.ALL_CLOCKS[needle])
            vL = fb
            vR = -fb

            if(fb < 0): lr = -lr
            vL = vL - lr
            vR = vR - lr

        else:
            display.show(Image.DIAMOND_SMALL)

        bot(18).servo_speed(vL)
        bot(19).servo_speed(vR)   
  • Set the cyber:bot board PWR switch to 1.
  • Repeat the needle/diamond display tests from the previous activity.
  • Set the cyber:bot board PWR switch to 2.
  • Now, tilt the micro:bit transmitter in the directions shown in the table, and verify that the cyber:bot moves as expected:

 

Tilt the micro:bit transmitter Verify the cyber:bot maneuver
Level Stay still
Slightly away from you Forward slowly
Further away from you Forward faster
Slightly toward you Slowly backward
Further toward you Faster backward
Away from you and to the left Curve forward and to the left
Away from you and to the right Curve forward and to the right
Toward you and to the left Curve backward and to the left
Toward you and to the right Curve backward and to the right