The worksheetDownload the PDF
Answers

U5.3 The derivative term

Feedback control · University · about 30 min

BugBotLab

What this lesson is about

Damping the overshoot, and why D on a noisy signal needs a filter or it is useless.

Questions 6 marks in all

  1. [1 mark]The distance sensor in the lesson wobbles by about 1 cm, so two readings 0.1 s apart can differ by 4 cm with the robot all but still. What approach speed, in cm/s, does a differenced derivative report?

    Answer: 40. 4 cm / 0.1 s = 40 cm/s of motion that is not happening, about three times the robot's speed at 70 percent. Multiplied by Kd, that is what makes the motors kick.
  2. [1 mark]One tick of the PD controller from the lesson. What does it print?

    KP, KD, DT = 3.0, 1.2, 0.1
    last, error = 20.0, 14.0
    d = (error - last) / DT
    cmd = max(-70, min(70, KP * error + KD * d))
    print(round(d, 1), round(cmd, 1))
    Answer:
    -60.0 -30.0

    The error fell by 6 cm in 0.1 s, so d = -60 cm/s. The command is 3 x 14 + 1.2 x (-60) = 42 - 72 = -30: the controller is already braking before it arrives.

  3. [1 mark]The robot is approaching the target quickly, so the error is shrinking fast. What does the D term do?

    1. AIt is negative and subtracts from the command, easing off before arrival
    2. BIt is positive and adds to the command
    3. CIt is zero until the error changes sign
    4. DIt accumulates the error over time
    Answer: A. A fast-shrinking error has a large negative derivative, so Kd x d reduces the command. That is damping.
  4. [1 mark]The setpoint jumps from 30 to 40 cm and the command spikes hugely for one tick. What is the standard fix?

    1. ADifferentiate the measurement instead of the error
    2. BLower Kp
    3. CFilter the error
    4. DClamp the integral
    Answer: A. The error jumps with the setpoint, and the derivative of a jump is enormous. The measurement does not jump, so differentiating it gives the same damping without the kick.
  5. [1 mark]Which is the best treatment for derivative noise on this robot, according to the lesson?

    1. AUse the measured speed from flow() instead of differencing distance()
    2. BFilter distance() heavily before differencing
    3. CLower the loop rate so the differences are bigger
    4. DRaise Kd until the noise averages out
    Answer: A. A measured rate is far better behaved than a computed one and adds no filter delay, which is why serious systems put a rate sensor on anything they differentiate.
  6. [1 mark]On the quarter turn, Kp = 4 alone overshoots by about 20 degrees. With a D term added, the response has no overshoot, a slower approach, and stops about 1.4 degrees short. What does that say about Kd?

    1. AIt is on the high side: a lot of D
    2. BThere is no D at all
    3. CIt is too small to matter
    4. DIt is making the loop wind up
    Answer: A. Heavy damping removes the overshoot and slows the approach, and braking that early leaves the last push inside the dead band. A little D, 0.8 in the lesson, keeps the speed and loses the overshoot.

The task: damp the overshoot

This robot is carrying a load, so it takes about three times as long to speed up and to slow down. That extra lag is exactly the job the D term is for. Turn to face 90 degrees and be within 3 degrees of it from three seconds onwards. Plot error and d term. On this robot P alone cannot do it, whatever the gain and however fast the loop runs: a gain low enough not to swing past arrives too late, and a gain high enough to arrive in time swings past and is still swinging at three seconds. Start from KP = 4 and find a KD that brakes it in time.

from bugbot import *
connect()

KP, KD = 4.0, 0.0
DT = 0.25
last = 90.0          # the error at the start

The hint students can ask for: This robot is carrying a load, so it takes about three times as long to speed up and slow down. With P alone it either creeps in too slowly or swings past, whatever the gain. Add a term that pushes against how fast the error is shrinking, so the robot starts braking before it arrives.

A solution

from bugbot import *
connect()

KP, KD = 4.0, 1.6
DT = 0.25
last = 90.0          # the error at the start

for tick in range(40):
    error = (90 - heading() + 180) % 360 - 180
    d = (error - last) / DT
    last = error
    plot("error", error)
    plot("d term", KD * d)
    drive(0, 0, KP * error + KD * d)
    wait(DT)
stop()

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.