# What is PID?

PID is a method of feedback control: using information from a sensor to set the output of an actuator in order to accurately reach a target. In this demonstration, the actuator is the position (or velocity, if the Velocity Mode checkbox is checked) of the grey "car" (box). The black box indicates the target position. Since this is a simulation, the position of the car is "sensed" by storing that information.

PID is a simple, but powerful, algorithm for calculating the value to use for the actuator from the sensor input and target.

1. First, the error is calculated by subtracting the sensor value from the target.
2. Next, the integral and derivative of the error are calculated. A simple approximation of the integral can be computed by summing all past error values. The derivative can be approximated by subtracting the most recent error value from the last error value, though this method is very noisy.
3. Finally, the output is set according to P*error + I*integral + D*derivative.

Generally, the P and I terms work together to move the car to the target, while the D term is used to slow the car down and prevent it from overshooting the target (too much). In position mode, the P term is unable to completely eliminate the error (since the position will be proportional to the error, and thus requires a non-zero error to have a non-zero position). Due to this effect, it is often more useful to set the velocity of the car instead.

Some further thoughts on feedback control and PID are available from a presentation I gave: abridged_pid.pdf. Many of the effects discussed there can be observed in this simulation.