2. Engineering background

2.1. PID controller

PID controller continuously calculates an error value e(t) as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively), hence the name.

2.1.1. Standard form

U(t) = MV(t) = K_{p}{e(t)}+ K_{i}\int _{0}^{t}{e(\tau )}{d\tau }+ K_{d}{\frac {d}{dt}}e(t)

where:

K_{p} the proportional gain, a tuning parameter,

K_{i} is the integral gain, a tuning parameter,

K_{d} is the derivative gain, a tuning parameter,

e(t)=SP-PV(t) is the error (SP is the setpoint, and PV(t) is the process variable),

t is the time or instantaneous time (the present), τ is the variable of integration (takes on values from time 0 to the present t.

2.1.2. Ideal form

K_{p} gain is applied to the I_{out}, and D_{out} terms, yielding:

MV(t) = K_{p}\left( e(t)+ \frac{1}{T_{i}}\int _{0}^{t}{e(\tau )}\,{d\tau }+ T_{d}{\frac {d}{dt}}e(t) \right)

where:

T_{i} is the integral time and T_{d} is the derivative time

the gain parameters are related to the parameters of the standard form through K_{i}={\frac {K_{p}}{T_{i}}} and K_{d}=K_{p}T_{d}

2.1.3. Algorithm

previous_error = 0
integral = 0
loop:
  error = setpoint - measured_value
  integral = integral + error * dt
  derivative = (error - previous_error) / dt
  output = Kp * error + Ki * integral + Kd * derivative
  previous_error = error
  wait(dt)
  goto loop
../_images/File_PID_en.svg

[PIDcontr]