The answersDownload the PDF
Worksheet

6.2 Following a line

Seeing more · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

cx to rotation, the angle as a look-ahead, speed on the straights.

Questions 7 marks in all

  1. [1 mark]follow_step uses rotation (cx - 160) * 0.4. What rotation does a line at cx = 100 give?

  2. [1 mark]The rotation for a line at cx = 100 is negative. What does the robot do?

    1. ATurns anticlockwise, towards the line on its left
    2. BTurns clockwise, away from the line
    3. CSlides left without turning
    4. DStops, because the error is negative
  3. [1 mark]A student writes drive(60, 0, (160 - cx) * 0.4). What happens?

    1. AThe robot steers away from the line and loses it
    2. BIt follows the line more smoothly
    3. CIt follows the line backwards
    4. DNothing changes, the order does not matter
  4. [1 mark]What does this program print?

    def rotation(cx, angle):
        return (cx - 160) * 0.3 + angle * 1.5
    
    print(rotation(160, 10))
    print(rotation(200, -8))
  5. [1 mark]Adding angle * 1.5 to the rotation is the beginning of which kind of control?

    1. ADerivative: it reacts to where the error is heading
    2. BBang-bang: full on or full off
    3. CIntegral: it adds up past errors
    4. DOpen loop: it ignores the sensor
  6. [1 mark]At each bend the line swings well off-centre, up to 85 pixels, before the robot has turned. What does that mean?

    1. ANothing is wrong: a P controller only turns once there is an error, and the line is still in view
    2. BThe camera is badly aligned
    3. CThe gain is negative
    4. DThe robot has lost the line
  7. [1 mark]What does this program print?

    for angle in [0, 5, 20, -25]:
        speed = 80 if abs(angle) < 10 else 40
        print(angle, speed)

The task: follow the line

Follow the line to the green zone, staying within 6 cm of it for at least 85% of the run.

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

# drive forward at 60 for 90 cm, then stop
forward(60, distance=90)

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

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

Challenges

  1. Make the speed depend on the angle: 80 when the line is straight, 40 in a bend.
  2. Print the largest cx error you saw during the run.
  3. Follow the line backwards from the end to the start (turn round first).