Implementing PID on a microcontroller BJ Furman ME
Implementing PID on a microcontroller BJ Furman ME 190 Mechatronics Engineering Design 11 NOV 2015 (adapted from: http: //brettbeauregard. com/blog/2011/04/improving-the-beginners-pid-introduction/)
PID equation Figure from Matlab Help (Designing PID Controllers with the PID Tuner) Parallel form u= = r(t) – y(t) Standard form u= l let l l l
Important considerations o Sample Time o Derivative Kick o On-The-Fly Tuning Changes o Reset Windup Mitigation o On/Off (Auto/Manual) o Initialization (bump-less transfer) o Controller Direction
(Way too) simple algorithm
Sample Time o Need to call at a regular interval o Use millis() or an interrupt (cont. )
Sample Time, cont.
Derivative Kick The problem l Derivative Spikes
Derivative Kick, cont.
Derivative Kick, cont.
On-the-fly tuning changes When things go ‘bump’…
On-the-fly tuning changes, cont. Calculate the contribution for the integral term differently: • Before • After
On-the-fly tuning changes, cont.
Integrator windup The problem
Integrator windup, cont.
Integrator windup, cont. (same as before)
Integrator windup, cont. The result
On/Off (automatic or ‘manual’) The problem
On/Off, cont.
On/Off, cont. (same as before)
Initialization The problem
Initialization, cont. (same as before)
Initialization, cont. ‘Bumpless’ transfer
Direction The problem: should an increase in y (the output) lead to an increase or a decrease in the manipulating variable (u, the output of the controller)? l l Direct acting (Kp, Ki, Kd should be positive) Reverse acting (Kp, Ki, Kd should be negative)
Direction, cont.
Direction, cont. (same as before)
- Slides: 25