Project: the relay

Drive to the handover, then and only then say go.

9.7Talking to each otherRobot club25 min

Do this lesson in the simulator

A relay has a rule that makes it a relay: the second runner may not go until the first one has arrived. Here the first runner is you, the second is the Runner waiting up the mat, and the baton is a radio message.

The plan

  1. Drive into the handover zone and stop.
  2. Only then, send go.
  3. Listen for the Runner's finished, and stay where you are.

The checker is strict about step 2: go must be sent while you are inside the zone. Send it early, as the starter below does, and the Runner leaves before you have arrived, which in the game next is a false start and puts your team out.

Arriving

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

while position()[1] < 40:
    # drive forward at 60 (keeps going until the next command)
    forward(60)
    # pause 0.1 s (the robot keeps doing what it was told)
    wait(0.1)
# all motors off
stop()
# pause 0.5 s (the robot keeps doing what it was told)
wait(0.5)
print("in the zone at", position(), "moving at", velocity())

Run this in the simulator

The zone starts 32 cm ahead and is 16 cm deep; stopping at 40 puts you in the middle of it. wait(0.5) after stop lets the robot settle before the next thing happens.

Handing over

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

while position()[1] < 40:
    # drive forward at 60 (keeps going until the next command)
    forward(60)
    # pause 0.1 s (the robot keeps doing what it was told)
    wait(0.1)
# all motors off
stop()
# pause 0.5 s (the robot keeps doing what it was told)
wait(0.5)
# radio this to every other robot
send("go")
# do this 80 times (tick counts from 0)
for tick in range(80):
    for sender, text in messages():
        print(f"{clock():.1f} s: {sender} says {text}")
    # pause 0.1 s (the robot keeps doing what it was told)
    wait(0.1)

Run this in the simulator

Task: the relay

Drive into the handover zone, stop, send go, and stay there until the Runner says finished.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# radio this to every other robot
send('go')
# drive forward at 60 for 40 cm, then stop
forward(60, distance=40)

Challenges

  1. Send go only when velocity() says you have stopped.
  2. Print how long the Runner took, from your go to its finished.
  3. Send go a second time if nothing is heard within two seconds, in case the first was missed.

Then play the game. In the radio relay you can be either leg, and the other one is a team mate in your room.