# Engineering background¶

## PID controller¶

PID controller continuously calculates an error value 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.

### Standard form¶

where:

the proportional gain, a tuning parameter,

is the integral gain, a tuning parameter,

is the derivative gain, a tuning parameter,

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

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

### Ideal form¶

gain is applied to the , and terms, yielding:

where:

is the integral time and is the derivative time

the gain parameters are related to the parameters of the standard form through and

### 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


[PIDcontr]