Seeing more · Robot club · about 20 min
Two sightings give a velocity: give way to a robot crossing your path.
[1 mark]Robot 102's bearing sweeps from -36 to 33 degrees while its distance only goes from 58 cm down to 40 cm and back out. What is it doing?
[1 mark]What does this program print?
last = None
for bearing in [-30.0, -20.0, -8.0, 5.0, 18.0]:
if last is not None:
print(bearing, "coming" if abs(bearing) < abs(last) else "leaving")
last = bearing-20.0 coming -8.0 coming 5.0 coming 18.0 leaving
Comparing sizes with abs ignores which side it is on. The bearing shrinks until it crosses the middle, then grows.
[1 mark]The first give way rule stops whenever robot 102 is close and in front. What is wrong with it?
[1 mark]The rule is tags and tags[0][3] < 30 and abs(bearing_of(tags[0][1])) < 35. Robot 102 is 25 cm away at a bearing of -40. Does the robot stop?
abs makes the bearing 0[1 mark]When robot 102 is out of view, the prediction code sets last = None. Why?
None makes the robot stop[1 mark]waited goes up by 1 on every tick the robot stops, at ten ticks a second. At the end waited is 23. What does waited / 10 print?
[1 mark]What does the general version of prediction, used by cars and ships, do?
Tick every answer that is true.
Reach the green zone without touching the red robot.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # drive forward at 50 for 80 cm, then stop forward(50, distance=80)
The hint students can ask for: A robot with a red dome shuttles back and forth across your path. Watch where it is going, wait when it is about to cross in front of you, and reach the goal without touching it.
from bugbot import *
connect()
for tick in range(390):
x, y = position()
if y > 80:
break
seen = [r for r in robots() if r[0] == 'red']
in_the_way = False
if seen:
cx, dist = seen[0][1], seen[0][3]
bearing = (cx - 160) * 120 / 320
if dist < 40 and abs(bearing) < 40: # close and in front of me
in_the_way = True
if in_the_way:
stop() # give way: let it pass
else:
forward(50)
wait(0.1)
stop()
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.