7.5. PID Control#

PID stands for Proportional-Integral-Derivative, the three terms combined to generate control action. A PID controller continuously calculates an error value (difference between the desired setpoint and the measured output), and then applies corrections based on three perspectives: the present, the past, and the future.

PID control continuously adjusts an actuator to minimise the error between the set point and the process variable. This improves upon bang-bang control by creating a smoother response with potentially smaller oscillations. However it introduces tuning parameters that one must set to achieve desired system response.

PID control works best for actuators that can be continuously adjusted such as a fan speed between 0-100%. In cases where the actuator is only ON/OFF it may be possible to use PWM to pulse the actuator e.g. pulsing an electric heating element.

7.5.1. Control Function#

A PID controller has three terms that are summed to set the actuator value. Mathematically we write it as:

\[a(t) = K_p p(t) + K_i i(t)+ K_d d(t)\]

where:

  • \(a(t)\) is the actuator value at time \(t\)

  • \(p(t)\) is the proportional error at time \(t\)

  • \(i(t)\) is the integral error at time \(t\)

  • \(d(t)\) is the derivative error at time \(t\)

  • \(K_p\), \(K_i\) and \(K_d\) are the “gains” i.e. tuneable parameters that control relative influence of each term on the final output

Hint

We can set any of the \(K\) terms to zero to get different forms of control e.g. setting \(K_i\) and \(K_d\) to zero leaves only the proportional term and we get a “Proportional Controller” and setting \(K_d\) to zero gives us a “PD Controller”.

7.5.2. Proportional-Integral-Derivative Terms#

Proportional (p): This term accounts for the current error, or rather the error since the last loop update.

\[p(t) = \text{SP}(t) - \text{PV}(t)\]

where \(\text{SP}(t)\) and \(\text{PV}(t)\) are the setpoint and process variable values at time \(t\).

Integral (i): This term accounts for errors that accumulate over time, which happens when there are changes in the environment.

\[i(t) = \sum_{k=0}^{t} \text{SP}(k) - \text{PV}(k)\]

Derivative (d): This term accounts for rates of change in the error and helps prevent overshooting the setpoint. In effect it “dampens” the actuator as it gets closer to the setpoint.

\[d(t) = \frac{ p(t) - p(t-1) }{\Delta_t}\]

where \(\Delta_t\) is the elapsed time between \(t\) and \(t-1\).