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 cyber:bot board’s PWR switch to 0.
- Make sure you are working in the browser with the micro:bit Python Editor that is connected to the radio tilt controlled cyber:bot.
- If the radio_tilt_bot_fb_with_stop_range script isn’t already open, click Open, and find and open it.
- Change the project name to radio_tilt_bot_fb_lr_with_stop_range.
- Update the script to match the one below.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
# 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 |