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)