Seeing more · Robot club · about 15 min
The line detector: cx and angle, and the empty list.
[1 mark]With set_cv("line") on, what does line() give when a line is in view?
[cx, angle][cx, cy, distance][id, cx, cy, distance][cx, cy, area, x0, y0, x1, y1, aspect][1 mark]The robot turns right by 20 degrees while looking at a line that runs straight ahead. What happens to the line's angle?
[][1 mark]Ten centimetres ahead, one pixel is about 0.108 cm. A line has cx = 197. About how many cm to the right of centre is it, to one decimal place?
[1 mark]The detector sees about 35 cm across the strip 10 cm ahead. About how many cm to the side can the line be before it drops out of view?
line() is [].[1 mark]What does this program print?
for seen in [[197, 5], []]:
if seen:
cx, angle = seen
print(f"line at cx {cx}, angle {angle}")
else:
print("no line")line at cx 197, angle 5 no line
An empty list counts as false, so the second reading prints the fallback. Every line program has to cope with [].
[1 mark]The task starter just calls print(line()). What is it missing?
set_cv("line"), to switch on the line detectorset_cv("apriltag")forward(50), because the line detector only works when movingline() always worksPrint line at cx <cx>, angle <angle> from the detector. Do not drive.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() print(line())
The hint students can ask for: Switch the camera to the line detector and print where the line is, like line at cx 197, angle 0.0. Do not drive.
from bugbot import *
connect()
set_cv('line')
cx, angle = line()
print(f'line at cx {cx}, angle {angle}')
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.