Seeing more · Robot club · about 20 min
Two controllers that never finish: chase a moving tag at a set distance.
[1 mark]What does this program print?
for dist in [50, 30, 20, 12]:
speed = max(0, min(70, (dist - 20) * 4))
print(dist, speed)[1 mark]Why is the lowest speed in the follower 0, the max(0, ...)?
[1 mark]With speed = max(0, min(70, (dist - 20) * 4)), what speed does the follower use when the leader is 26 cm away?
[1 mark]How is following a robot different from docking at a marker?
[1 mark]When the leader goes out of view, the lesson just turns right. What is a better recovery?
[1 mark]The task starter always drives at 60 towards robot 101. What goes wrong?
Stay 12 to 35 cm behind the green robot for at least 80% of the run, without touching it. The starter drives at the leader at a fixed speed and rams it. Add the distance controller.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# do this 390 times (tick counts from 0)
for tick in range(390):
seen = [r for r in robots() if r[0] == "green"]
if seen:
# forward, sideways, rotation: -100 to 100 each, until the next command
drive(60, 0, (seen[0][1] - 160) * 120 / 320 * 3)
# pause 0.1 s (the robot keeps doing what it was told)
wait(0.1)
# all motors off
stop()Plan your program here, then type it in and press Run.