## The PID Control Algorithm – Matthew Lee

Have you seen a line-following robot in action before? These robots zip around by tracing the black-white boundary between the dark line and the lighter ground via negative feedback. If the robot is on the dark line, it veers to the right. If the robot is on the lighter ground, it veers to the left. These two actions both serve to bring the robot back towards the black-white boundary whenever it drives astray, hence, the robot behaves like a control system of the simplest kind.

Control systems form the foundation upon which more complicated systems are often built. Wherever control over the value of a certain variable is required, a control system is used to keep the variable steady at the desired value. Of course, in most cases, the control system used is more sophisticated than the simple system used by the line-following robot.

Take for instance the control of fission reactions in a nuclear power plant. If the fission were to proceed unregulated, boom. Therefore, control rods made of neutron-absorbing elements such as silver are used to reduce the neutron flux and keep the rate of the nuclear reaction below a critical level. However, a fine balancing act is required to ensure that the rate of reaction remains below the safe limit while making sure that there are enough free neutrons to sustain the chain reactions.

A control system is needed to maintain the neutron flux in this narrow happy medium. This control system must not be overly heavy-handed when attempting to regulate the reactor. If the neutron flux is too high, the system will push the control rods deeper into the reaction chamber to absorb more neutrons – but if the rods are pushed in too far, the neutron flux will fall sharply and the reactions will be quenched. If the neutron flux is too low, the system will withdraw the control rods – but if the rods are withdrawn too much, the fission reactions will spiral out of control. Clearly, overreacting to an error is a bad thing. But on the other hand, this control system cannot be too gentle when trying to correct a deviation from the desired neutron flux. If the control rods are not pushed in far enough when the neutron flux is too high, or if the control rods are not withdrawn enough when the neutron flux is too low, the neutron flux will never be brought back to the desired level.

This problem of deciding how much action is enough is the basic problem that all kinds of control systems have to address. When faced with a deviation from the desired state, a control system has to calculate the most appropriate response, an action that is neither too heavy-handed nor too weak to restore the desired state. Ideally, if it were possible to build an accurate physical model of the processes that need to be controlled, it would be possible to calculate exactly the action needed to restore the desired state – for instance, if there were a mathematical equation that exactly relates the length of the control rods to the rate of nuclear fission. However in real life, this is sometimes not an option as the processes are either too complicated to be modeled accurately, or the values of the parameters are unknown. Therefore, other methods of calculating this ‘appropriate response’ have been devised. One such method is the PID algorithm, a control algorithm with good performance that is valued in industrial applications for its simplicity and clear physical meaning.

But first, let’s define some terminology so that we can stop talking in terms of the nuclear reactor example and move on to speaking in general terms. The system that is being controlled (the nuclear reactor) is called the process, and the variable that needs to be kept steady at a desired value (the neutron flux) is the process variable. This desired value we call the set point, the difference between the current value of the process variable and the desired value is called the error, e(t), and the action taken to correct the error and bring the process variable back to the set point is called the output of the control system. Finally, PID stands for Proportional-Integral-Derivative, so named because the output is the summation of three terms: a term that is proportional to the current error, a second term that is proportional to the derivative of the error with respect to time, and a third term that is proportional to the error integrated over time. This is illustrated in the block diagram.

Why did the original designer of the PID algorithm decide to come up with this form? Apparently he was inspired by the behaviour of ship captains as they tried to control the direction of their vessels. Indeed, the PID control algorithm can be understood in an intuitive manner because the actions of each of the three terms are analogous to the actions that humans would carry out when trying to exert control over a process.

The proportional term simply follows the mentality of “if the error is greater, we should try harder to make it go back to the set point”. This is a clear improvement over a control system that has no sense of moderation and can only output two extreme values, like the line-following robot. However, it is not good enough to have a control system with only the ‘P’ term, because the process variable would still oscillate about the set point and only converge after many oscillations, if at all. For instance, if a ‘P’ control system was used to control the displacement of a particle along the x-axis, the particle would oscillate about the set point in simple harmonic motion.

Since the ‘P’ control system would behave like a simple harmonic oscillator, what we need is some damping, so as to make the process variable converge to the set point eventually. The derivative term provides this damping effect. The effect of the derivative term is also intuitive – a human controller would also reduce the output if the process variable was hurtling towards the set point, but would be impatient and up the output if the error was decreasing very slowly. To allow the set point to be reached quickly without oscillations, Kd can be adjusted so that critical damping is achieved. However, it is still not good enough to have a PD control system. If there is a source of constant disturbance, there would be an equilibrium position where the error remains constant, the derivative term remains at zero and the proportional term is equal to the disturbance – meaning that the set point would never be reached. This sort of error persists over long periods of time. For instance, this situation could arise when a ship is sailing in a stiff wind which constantly pushes the ship off course.

If a human were in control, the natural thing to do would be to up the ante if the current effort was not yielding any progress. In effect, a human can remember the past values of the error and therefore can notice if the error is persisting over long periods of time and increase the output accordingly. A purely PD control system cannot do this because neither the proportional term nor the derivative term can provide any information about the history of the process. The proportional term is useless here because only considers the present moment, and although the derivative term can tell whether the error is not decreasing at the current moment, it cannot tell whether this lack of change is momentary or if it has persisted over a long period of time. Oh, bother. This is where the integral term comes in handy. By integrating the error with respect to time, a PID control system can ramp up the magnitude of the output to deal with persistent error.

In summary, the three terms of the PID control algorithm behave much like the double-headed eagle in the Raffles school crest. The integral term looks into the past and uses the information about previous states to make an accumulated effort. The derivative term notices current trends, looks into the near future and makes an effort based on predictions of upcoming states. The proportional term looks at the present state and, based on the current error, acts with a sense of moderation. When combined, these three terms allow for stable control of a huge number of processes, ranging from nuclear reactors to automatic pilots to Segways.