Project: the relay
Drive to the handover, then and only then say go.
Do this lesson in the simulatorA 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
- Drive into the handover zone and stop.
- Only then, send
go. - 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())
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)
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
- Send
goonly whenvelocity()says you have stopped. - Print how long the Runner took, from your
goto itsfinished. - Send
goa 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.