The worksheetDownload the PDF
Answers

9.7 Project: the relay

Talking to each other · Robot club · about 25 min

BugBotLab

What this lesson is about

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

Questions 6 marks in all

  1. [1 mark]Put the relay handover in order.

    Number the lines 1 to 5 to put them in the right order.

    1. wait(0.5) to settle
    2. send("go")
    3. Stay put and listen for finished
    4. stop()
    5. Drive into the handover zone
    Answer:
    Drive into the handover zone
    stop()
    wait(0.5) to settle
    send("go")
    Stay put and listen for finished

    Arrive, stop, settle, and only then hand over the baton.

  2. [1 mark]The starter code sends go before driving. What happens?

    1. AThe Runner leaves before you arrive: a false start
    2. BNothing, the Runner waits for you anyway
    3. CThe message is queued until you reach the zone
    4. DThe Runner never leaves
    Answer: A. The rule that makes it a relay is that go is sent while you are inside the zone.
  3. [1 mark]The handover zone starts 32 cm ahead and is 16 cm deep. How many cm ahead is its middle?

    Answer: 40. 32 + 16 / 2 = 40, which is where the example stops.
  4. [1 mark]What does this program print?

    def in_zone(y):
        return 32 <= y <= 48
    
    for y in [30, 40, 49]:
        print(y, in_zone(y))
    Answer:
    30 False
    40 True
    49 False

    The zone runs from 32 to 48. 30 has not arrived yet and 49 has gone past.

  5. [1 mark]Why is there a wait(0.5) between stop() and send("go")?

    1. AIt lets the robot settle, so it is not still rolling when it hands over
    2. BThe radio needs half a second to switch on
    3. CThe Runner cannot hear sooner
    4. Dstop() only works after a wait
    Answer: A. A robot still rolling could drift out of the zone as it sends.
  6. [1 mark]You sent go and have heard nothing for two seconds. What is a sensible thing to do?

    1. ASend go again, in case the first was missed
    2. BDrive after the Runner
    3. CWait forever without sending
    4. DLeave the zone to look for the Runner
    Answer: A. Radios miss things. Repeating the message, from inside the zone, is safe.

The 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)

The hint students can ask for: Drive into the handover zone, stop there, and only then send go. The Runner sets off when it hears it and says finished at the far end. Stay in the zone.

A solution

from bugbot import *
connect()
while position()[1] < 40:
    forward(60)
    wait(0.1)
stop()
wait(0.5)
send("go")
for tick in range(80):
    for sender, text in messages():
        print(sender, "says:", text)
        if "finished" in text:
            break
    wait(0.1)

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.