implementing pid on a microcontroller bj furman me 190 mechatronics engineering design 11nov2015...
TRANSCRIPT
Implementing PID on a microcontroller
BJ FurmanME 190 Mechatronics Engineering Design
11NOV2015
(adapted from: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/)
PID equation
Standard form
Parallel form
𝐾 𝑝=𝐾 𝐾 𝑖=𝐾𝑇 𝑖
𝐾 𝑑=𝐾𝑇 𝑑let
𝑂𝑢𝑡𝑝𝑢𝑡=𝐾 ¿
Figure from Matlab Help (Designing PID Controllers with the PID Tuner)
u=
u=
= r(t) – y(t)
Important considerations
o Sample Timeo Derivative Kicko On-The-Fly Tuning Changeso Reset Windup Mitigationo 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 intervalo Use millis() or an interrupt
(cont.)
Sample Time, cont.
Derivative Kick
The problem
𝑂𝑢𝑡𝑝𝑢𝑡=𝐾 ¿
dttdy
dttde
dttdy
dttde
dttdy
dttdr
dttde
)()(
)(0
)(
constant is r(t) if
)()()(
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)?
Direct acting (Kp, Ki, Kd should be positive) Reverse acting (Kp, Ki, Kd should be negative)
Direction, cont.
Direction, cont.(same as before)