Talking to each other · Robot club · about 20 min
One robot at a time through a corridor: announce, wait, go.
[1 mark]In the corridor task, which message tells you it is time to go?
corridor clearcorridor busyenteringout[1 mark]The corridor stays clear for about 9 seconds, and you need about 6 seconds to get through. After hearing clear, how many seconds can you afford to delay before setting off?
[1 mark]What does this program print?
batches = [[("Porter", "corridor busy")], [], [("Porter", "corridor clear")]]
clear = False
checks = 0
for batch in batches:
checks += 1
for sender, text in batch:
if "clear" in text:
clear = True
if clear:
break
print("clear" if clear else "waiting", "after", checks, "checks")clear after 3 checks
Each batch is one call to messages(). The first has busy, the second nothing, and the third has clear, so it stops after 3 checks.
[1 mark]Put the steps for getting through the corridor in order.
Number the lines 1 to 4 to put them in the right order.
Drive through, holding the middleWait for corridor clearsend("entering")send("out")Wait for corridor clear
send("entering")
Drive through, holding the middle
send("out")Wait, announce, go, and say when you are through.
[1 mark]The Porter does not listen to messages. Why send entering anyway?
forward only works after a send[1 mark]Driving along the corridor, the robot faces heading 90. Why does it steer from y and not x?
position() only gives yWait for corridor clear, send entering, drive through to the green zone without touching the walls or the Porter.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# radio this to every other robot
send('entering')
# drive forward at 60 for 72 cm, then stop
forward(60, distance=72)
# radio this to every other robot
send('out')The hint students can ask for: The corridor fits one robot. The Porter says corridor busy as it goes in and corridor clear as it comes out. Wait for clear, send entering, drive through to the green zone (72 cm ahead), and do not touch anything.
from bugbot import *
connect()
def wrapped(h):
return (h + 180) % 360 - 180
clear = False
while not clear:
for sender, text in messages():
print(sender, "says:", text)
if "clear" in text:
clear = True
wait(0.1)
send("entering")
while position()[0] < 72:
x, y = position()
drive(60, y * 6, wrapped(90 - heading()) * 3) # straight down the middle of the corridor
wait(0.1)
stop()
send("out")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.