Lab 6 — Feedback Control — P / PI / PID¶
Practical focus¶
Now introduce feedback. Use encoder speed or measured stopping distance; desired vs actual value; P first, then PI/PID; experimental tuning.
Background¶
Discrete PID at fixed timestep \(\Delta t\):
where \(e_k = \text{desired} - \text{actual}\).
TODO — expand. Cover integral windup explicitly: the motor dead zone you measured in Lab 2 means small errors produce no motion at all, so the integral term charges up with nowhere to go and then overshoots hard. Clamping the integral is the fix, and it is worth letting students hit the bug before you name it.
Objectives¶
- State a control problem as desired value, actual value, and error.
- Implement proportional control and observe steady-state error.
- Add integral action and observe both the benefit and the windup failure.
- Add derivative action and observe noise amplification.
- Tune experimentally against a stated performance target.
Procedure outline¶
TODO — expand. Suggested arc, in this order:
- P only. Watch it settle short of target. Measure the steady-state error.
- Add I. Watch the error go to zero — then watch it overshoot badly after a stall. That is windup.
- Clamp the integral. Watch the overshoot disappear.
- Add D. Watch it get twitchy on noisy encoder data, then filter the derivative.
- Tune to spec and record the final gains.
| Controller | \(K_p\) | \(K_i\) | \(K_d\) | Settling time | Steady-state error | Overshoot |
|---|---|---|---|---|---|---|
| P | — | — | ||||
| PI | — | |||||
| PID |
Fix the timestep
Run the controller on a fixed interval with millis(), not once per loop().
A variable \(\Delta t\) makes \(K_i\) and \(K_d\) meaningless and the tuning
irreproducible.
Deliverable¶
Closed-loop speed or stopping controller with measured error.