1. Bot radio v1

This is a simple starter approach for using the radio to steer the bots.

1.1. MoveMotor v3.1 radio v1 files:

Hex Files for the MOVEMotor v3.1 can be loaded via the project:open button at: https://python.microbit.org/v/3
Hex file for the bot MOVEMotor bot_v1 hex file.
Hex file for the hand held controller MOVEMotor controller_v1 hex file.

1.2. Unique groups

Change the group number in radio.config(group=8) to set unique groups in the room.
Make sure all microbits using a bot have the same group number (0-255).
Edit the code below to set the group.
  • MOVEMotor bot code, change radio group to match bot number

  • MOVEMotor_v31 200 + bot number

  • MOVEMotor v2 150 + bot number


1.3. Radio for controller

The code below gives messages based on forwards - backwards tilting and sideways tilting.
The code displays the message on the microbit for testing purposes.
For the forwards and backwards tilting, make sure not to tilt the microbit sideways.
If the microbit is level, -200 <= y_reading <= 200 and -200 <= x_reading <= 200 send an “X”, to stop.
from microbit import *
import radio


radio.config(group=8)  # 0-255
radio.on()

msg=""
while True:
    y_reading = accelerometer.get_y()
    x_reading = accelerometer.get_x()
    # flat
    if -200 <= y_reading <= 200 and -200 <= x_reading <= 200:
        msg = "X"
    # level sideways
    elif -200 <= x_reading <= 200:
        # forwards and back tilting
        if y_reading > 200:
            msg = "B"
        elif y_reading < -200:
            msg = "F"
        else:
            msg = "X"
    else:
        # sideways tilting
        if x_reading > 200:
            msg = "R"
        elif x_reading < -200:
            msg = "L"
        else:
            msg = "X"
    radio.send(msg)
    display.show(msg)

1.4. Radio for microbit on MOVEMotor

The code below moves the MOVEMotor at medium speed, since its top speed is relatively fast.
The radius of 5 gives a tight turn.
from microbit import *
import radio
import MOVEMotor


radio.config(group=8)  # 0-255
radio.on()

buggy = MOVEMotor.MOVEMotorMotors()


while True:
    sleep(100)
    msg = radio.receive()
    if msg is not None:
        display.show(msg)
        if msg == "X":
            buggy.stop()
        elif msg == "B":
            buggy.backwards(speed=5)
        elif msg == "F":
            buggy.forwards(speed=5)
        elif msg == "R":
            buggy.right(speed=2, radius=5)
        elif msg == "L":
            buggy.left(speed=2, radius=5)

1.5. Radio Racing

Tasks

  1. Create an obstacle course and race another bot using radio controls.

  2. Modify the speed settings to suit the obstacle course.

  3. Add a variable to keep track of the last msg sent and only send a new msg if it is different to the last msg.


1.6. Radio for microbit on BitBotXL

The code below moves the BitBotXL at maximum speed, since its top speed is relatively slow.
The tightness of 5 gives a tight turn.
from microbit import *
import radio
import BitBotXL


radio.config(group=8)  # 0-255
radio.on()

buggy = BitBotXL.BitBotXLMotors()


while True:
    msg = radio.receive()
    if msg is not None:
        display.show(msg)
        if msg == "X":
            buggy.stop()
        elif msg == "B":
            buggy.backwards(speed=10)
        elif msg == "F":
            buggy.forwards(speed=10)
        elif msg == "R":
            buggy.right(speed=10, tightness=5)
        elif msg == "L":
            buggy.left(speed=10, tightness=5)

1.7. Radio for microbit on MiniBit

The code below moves the MiniBit at maximum speed, since its top speed is relatively slow.
The tightness of 5 gives a tight turn.
import MiniBit


radio.config(group=8)  # 0-255
radio.on()

buggy = MiniBit.MiniBitMotors()

while True:
    sleep(50)
    msg = radio.receive()
    if msg is not None:
        display.show(msg)
        if msg == "X":
            buggy.stop()
        elif msg == "B":
            buggy.backwards(speed=10)
        elif msg == "F":
            buggy.forwards(speed=10)
        elif msg == "R":
            buggy.right(speed=10, tightness=5)
        elif msg == "L":
            buggy.left(speed=10, tightness=5)