The answersDownload the PDF
Worksheet

6.1 Lines

Seeing more · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

The line detector: cx and angle, and the empty list.

Questions 6 marks in all

  1. [1 mark]With set_cv("line") on, what does line() give when a line is in view?

    1. A[cx, angle]
    2. B[cx, cy, distance]
    3. C[id, cx, cy, distance]
    4. D[cx, cy, area, x0, y0, x1, y1, aspect]
  2. [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. AIt goes negative: the line seems to swing left
    2. BIt goes positive: the line seems to swing right
    3. CIt stays 0
    4. DIt becomes []
  3. [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?

  4. [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?

  5. [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")
  6. [1 mark]The task starter just calls print(line()). What is it missing?

    1. Aset_cv("line"), to switch on the line detector
    2. Bset_cv("apriltag")
    3. Cforward(50), because the line detector only works when moving
    4. DNothing, line() always works

The task: see the line

Print 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())

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/6-1-lines/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print cx as a distance in centimetres. Ten centimetres ahead, one pixel is about 0.108 cm.
  2. Turn left in steps of 5 degrees and print the angle each time. When does the line leave the view?
  3. Drive forward 30 cm and print the line reading every 5 cm.