The answersDownload the PDF
Worksheet

4.2 Where is it?

Vision · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Pixels to degrees, and a controller that turns to face a tag.

Questions 6 marks in all

  1. [1 mark]Using bearing = (cx - 160) * 120 / 320, what is the bearing in degrees of a tag at cx = 240?

  2. [1 mark]Using bearing = (cx - 160) * 120 / 320, where is a tag at cx = 100?

    1. ATo the left, about 22 degrees
    2. BTo the right, about 22 degrees
    3. CStraight ahead
    4. DTo the left, about 100 degrees
  3. [1 mark]What does this program print?

    def bearing_of(cx):
        return (cx - 160) * 120 / 320
    
    for cx in [0, 160, 320]:
        print(bearing_of(cx))
  4. [1 mark]The loop runs drive(0, 0, bearing_of(cx) * 3) and the tag is at cx = 220. What does the robot do?

    1. ATurns clockwise, towards the tag
    2. BTurns anticlockwise, away from the tag
    3. CDrives forward
    4. DSlides right without turning
  5. [1 mark]A student writes error = (160 - cx) * 120 / 320 and uses drive(0, 0, error * 3). What happens?

    1. AThe robot turns away from the tag until it loses it
    2. BThe robot faces the tag, just more slowly
    3. CNothing different, because the sign does not matter
    4. DThe robot drives towards the tag
  6. [1 mark]Once the error is under 1.5 degrees, the program stops, waits 0.3 s and checks again. Why check again?

    1. AThe robot coasts after stopping, so the tag may have slid off centre
    2. BThe camera needs 0.3 s to switch on
    3. CThe tag might have changed its id
    4. DTo let the battery recover

The task: face the marker

Turn until marker 3 is in the middle of the picture, then print centred. Do not drive.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

# camera: the tag detector
set_cv("apriltag")
print(apriltags())

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

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

Challenges

  1. Print the heading before and after, and compare the change with the bearing you computed.
  2. Face the marker, then turn 180 away from it and face it again.
  3. Work out the bearing exactly with math.degrees(math.atan((cx - 160) / 92.4)) (after import math). What does it give for marker 3? Compare the two formulas at cx 160, 200, 240, 280 and 320: where is the difference biggest?