The answersDownload the PDF
Worksheet

3.1 What a controller is

Control · Robot club · about 15 min

BugBotLab
NameClassDate

What this lesson is about

The error and its sign, wrapping headings, bang-bang control, overshoot.

Questions 7 marks in all

  1. [1 mark]What does this program print?

    def wrapped(h):
        return (h + 180) % 360 - 180
    
    print(wrapped(200))
    print(wrapped(350))
  2. [1 mark]A controller uses error = target - measured. The target heading is 90 and the robot faces 60. What is the error? Give a whole number.

  3. [1 mark]What is bang-bang control?

    1. ALooking at the sign of the error and going that way at a fixed speed
    2. BPushing harder the bigger the error is
    3. CDriving into a wall and backing off
    4. DTurning on and off at random
  4. [1 mark]The bang-bang loop calls stop() when the error is under 2 degrees, but the robot ends further off. Why?

    1. AThe robot keeps turning for a moment after stop()
    2. BThe heading sensor is wrong
    3. Cwrapped() gives the wrong answer
    4. Dabs() removes the sign
  5. [1 mark]What does this program print?

    for error in [30, -10]:
        speed = 60 if abs(error) > 25 else 20
        print(error, speed)
  6. [1 mark]What does break do inside while True:?

    1. ALeaves the loop
    2. BStops the robot's motors
    3. CPauses the loop for a moment
    4. DStarts the loop again from the top
  7. [1 mark]What is the problem with the crude fix: fast when far, then short slow bursts with a pause?

    1. AIt works, but it is slow at the end
    2. BIt never gets within 2 degrees
    3. CIt spins the wrong way
    4. DIt only works for heading 0

The task: face north

Spin until the robot faces 0 within 3 degrees, printing error: and the error every time round the loop. Do not drive anywhere.

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

print("heading:", heading())

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

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

Challenges

  1. Count how many times the loop ran and print it at the end.
  2. Face 90, then 180, then 270, then 0 with the same loop and a for over the targets.
  3. Find the fastest spin speed that still stops within 3 degrees using the crude fix.