The answersDownload the PDF
Worksheet

2.5 Drift and correction

Sensing · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

Why the robot wanders, and the first closed loop.

Questions 7 marks in all

  1. [1 mark]Which of these programs is closed loop?

    1. AOne that checks position() after each leg and slides back to the line
    2. Bforward(70), wait(3), stop()
    3. Cforward(70, distance=64) on its own
    4. DA for loop that drives the same square every time
  2. [1 mark]Why does the robot slide sideways when it drives forward? Choose all that apply.

    Tick every answer that is true.

    1. AThe four feet do not push exactly equally
    2. BThe mat is not perfectly even
    3. CTiny errors add up over a long drive
    4. DThere is a bug in forward()
    5. Eposition() resets itself as it drives
  3. [1 mark]After a 10 cm leg, position() says x is 2.5. What does the correcting program do?

    x, y = position()
    if x > 1:
        left(40, distance=x)
    elif x < -1:
        right(40, distance=-x)
    1. ASlides left 2.5 cm
    2. BSlides right 2.5 cm
    3. CNothing, because 2.5 is too small
    4. DTurns left 2.5 degrees
  4. [1 mark]What does this program print?

    error = 355
    if error > 180:
        error = error - 360
    print(error)
  5. [1 mark]In drive(70, -x * 15, 0), x is 2. What is the sideways value? Give a whole number.

  6. [1 mark]You change -x * 15 to -x * 40. What do you expect?

    1. AIt settles closer to the line
    2. BIt drifts further off the line
    3. CIt drives faster
    4. DNothing changes
  7. [1 mark]Why is it worth correcting the heading as well as x?

    1. AA wrong heading turns into a sideways error on the next leg
    2. Bheading() is the only thing that drifts
    3. CCorrecting x resets the heading
    4. DIt is not, x is all that matters

The task: straight and true

Drive about 64 cm and finish inside the small square, still facing 0 within 6 degrees. Correct as you go.

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

# drive forward at 70 for 64 cm, then stop
forward(70, distance=64)

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

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

Challenges

  1. Make the straight-line task pass at speed 100.
  2. Combine heading correction and sideways correction in one loop and time it against the two-step version.
  3. Print the largest x error you saw during the drive.