The answersDownload the PDF
Worksheet

3.3 Tuning the gain

Control · Robot club · about 20 min

BugBotLab
NameClassDate

What this lesson is about

Sluggish, good, oscillating. Loop speed and driving speed.

Questions 7 marks in all

  1. [1 mark]With a gain of 1 on the curving robot, what happens?

    1. AThe correction is too weak: the error grows and the robot ends well off the line
    2. BThe robot snakes from side to side
    3. CThe robot holds the heading perfectly
    4. DThe robot spins on the spot
  2. [1 mark]With a gain of 40, the robot snakes. What is that called?

    1. AOscillation
    2. BCoasting
    3. CDrift
    4. DThe dead band
  3. [1 mark]Rotation is capped at 100. With a gain of 40, above what heading error is the controller just bang-bang again? Give the number of degrees.

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

    errors = [5, 2, -1, -3, 1, 4, -2]
    worst, flips, last = 0, 0, 0
    for error in errors:
        worst = max(worst, abs(error))
        if error * last < 0:
            flips += 1
        last = error
    print("worst", worst, "and", flips, "sign changes")
  5. [1 mark]Why is a high gain with a slow loop the worst combination?

    1. AA big correction keeps running for too long before the next look
    2. BA slow loop makes the gain smaller
    3. CThe robot cannot drive while waiting
    4. DThe sensor stops working
  6. [1 mark]In a sweep of gains, where is the good gain?

    1. AJust before the sign changes start climbing
    2. BThe highest gain you can type
    3. CThe lowest gain, 1
    4. DWherever the worst error is biggest
  7. [1 mark]A gain works well at speed 50. What might happen at speed 100?

    1. AIt may be sluggish, because the fault acts faster
    2. BIt will oscillate more, because speed makes the gain bigger
    3. CNothing, the gain does not care about speed
    4. DThe robot will drive backwards

The task: hold the heading, fast

The zone is narrower and you have six seconds. The starter's gain of 40 wobbles and wastes time, and its speed is too low. Tune both.

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

def wrapped(h):
    return (h + 180) % 360 - 180

while position()[1] < 72:
    error = wrapped(0 - heading())
    # forward, sideways, rotation: -100 to 100 each, until the next command
    drive(60, 0, error * 40)
    # pause 0.05 s (the robot keeps doing what it was told)
    wait(0.05)
# all motors off
stop()

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

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

Challenges

  1. Find the largest gain that gives at most one sign change at speed 100.
  2. Make the gain depend on the speed: gain = 4 * speed / 70.
  3. Log the error every tick into a list and print the list at the end. Where does it peak?