Scroll back to top
The proportional-integral-derivative or PID controller is a simple, widely-used, and often very effective way to make a dynamic system do what you want.
Suppose this dynamic system has exactly one real-valued input
The PID controller is
for some choice of constant gains
We assume the controller is given
is just arithmetic.
To compute the term
we need to find the integral
at the current time
for some time step
Here is another way of thinking about this. Suppose we define a new variable
to contain the integral of the error. It is equivalent to say that
with the initial condition
Then, it is common to use the backward Euler method
to compute an approximation to
To implement the backward Euler method with code, you need to define a variable to store the prior value
To compute the term
we need to find the derivative
at the current time
To implement the backward finite difference method with code, you need to define a variable to store the prior value