PID theory: What is PID?
Imagine I give you an electric kettle filled with water and with a thermometer sticking out of it. The kettle is wired up via a dimmer or a Variac, so you have a knob to control the heater power. I challenge you to heat the water up to 80ºC as fast as possible but without overshooting by more than 1ºC, then maintain it at 80ºC.
Maybe on your first attempt you decide to be a thermostat. So you turn up the knob to full power, and wait for the water to heat up. At first nothing seems to happen. Then, gradually at first, the thermometer starts to move. After 4 minutes it gets to 80ºC and you turn the knob back to zero. But lo and behold, the water continues to heat up beyond 80ºC. In fact, gets up to 87ºC before it starts to slowly cool down. As it gets down to 80ºC you turn the power on full again. But what's this, the temperature keeps dropping! Only at 76ºC does it turn around and start heading up again. After 30 minutes of this you finally conclude that the best you can achieve by being an on/off thermostat is to keep the water temperature between 76ºC and 86ºC. What you have been doing here is simple on/off control, sometimes called bang-bang control.
Let's empty out the kettle and refill it with cold water.
On the second run you decide to get smart and start turning down the power as the temperature approaches the 80ºC setpoint (setpoint is what we call the target temperature). So, you start out with full power. As the water heats up beyond 60ºC you start to slowly wind down the power. At 80ºC you have judged it perfectly so the power is zero. Guess what happens? It still overshoots! Not by as much, it peaks at only 84ºC, but it certainly overshoots. In this case you are being a simple proportional controller. You apply power to the kettle in direct proportion to how far it is away from the desired temperature. What is frustrating you is the fact that the kettle and water and thermometer, as a system, contain several delaying elements. It takes time for the heating element to heat up. It takes time for the water to heat up. It takes time for the heated water at the bottom of the kettle to raise up to the thermometer. And finally the thermometer, fast as it is, takes some finite time to heat up and register the change. What all this means is that by the time you apply a proportional correction, it's far too late. The die was cast maybe 5 or 10 seconds ago. And you can only sit there and helplessly watch the mercury heading north.
OK, back to the cold water tap (faucet if you are American)!
On the third run you decide to be very smart (not gonna let this damned thing get the better of us!) and anticipate the temperature. So, as before you start winding back the power, but you start sooner. In fact, on run 2 you got 4ºC overshoot, so if you can time it to hit zero power at 76ºC, you have a jolly good chance of it coasting nicely up to 80ºC and stopping there. And it works! Well, for a while at least. But as the temperature peaks at 80ºC it starts to drop back again and you now get caught up in trying to maintain it on station.
Let's stop playing with the kettle and think about this for a while.
In run 2 we applied a heating power proportional to the error between the setpoint (where we want to be) and the actual temperature (the Controlled Value or CV) where we actually are. This is the factor that gives PID the 'P'. This is something fairly simple to understand intuitively. We worked the knob so the power would be full up to 60ºC and then drop off smoothly to 0 over the next 20ºC. If the kettle has a 2000W heating element that means we apply power at the rate of 100W/ºC of temperature error (though it maxes out at 2000W). Please ignore for now the fact that if the water is too hot, we can't suck heat out of it (apply negative power)! Imagine now that we somehow discover that it requires 200W to hold the water at the 80ºC setpoint. To get 200W of power from the proportional correction alone, at a ratio of 100W/ºC, means we need an error of 2ºC to "drive" the system. If the ambient temperature is 20ºC, 80ºC represents 60ºC worth of heating from a 2ºC error. That's a ratio of 30:1 which is our "proportional gain", and we call it Ap (A-subscript-p).
We need a 2ºC error to "drive" the outcome?! Hmmm... better get back to that one later.
In run 3 we decided to anticipate where the temperature was heading to. Now, you may have to take this on trust: The mathematics for this is that we apply a moderating effect proportional to the rate of change of the Controlled Variable. The faster the CV is changing the more we will tend to back off on the power control (or advance the power control if the temperature is falling). In maths Rate of Change is called "derivative with respect to time" or simply "Derivative". That's where the 'D' in PID comes from. Sometimes derivative is called the "rate term". There are two parameters associated with Derivative, a time setting Td (a variant of how much action to apply for a given rate of change of the CV), and a gain term Ad, which is normally set as a constant and never changed. More about the time setting later.
That accounts for the P and the D. What about the I?
OK, remember how a couple of paragraphs ago we deduced that we needed some error in the end result so it could get multiplied by Ap and provide the steady state power to maintain the temperature? Imagine now that we have diligently applied our power proportional to error strategy, and our back-off according to rate of change, and the temperature is sitting nice and steady at 78°C (the best we can do with just proportional and derivative, at least with Ap=30°C/°C). We now look at the temperature and say "let's wind up the knob, ever so slowly, at a speed proportional to the error". So we set to, let's say every 10 seconds, to look at the temperature, calculate the error and then give the knob a minuscule nudge proportional to the error. Slowly, every so slowly, we will inch the temperature up towards 80°C, but at a rate that slows as it approaches the setpoint. The effect of all the tiny nudges of the knob is cumulative: 10mW for the first, 9.99mW for the 2nd (less because the error is a tiny bit less), 9.98mW for the 3rd, etc. But they all add up! 10, 19.99, 29.97, etc. This cumulative effect is mathematically called integration. That is where the 'I' comes from in PID. Integral is specified as an Integrator Time, referred to as Ti. Ti is the time it will take for the integral action to move the control action an amount equal to the prevailing error. For example, if the integral time is 25 seconds, and the controller error is 3%, then the output of the controller will ramp by 3% every 25 seconds.The neat thing about integration is that as long as Ti is non-zero, the integral action will keep on working until it cancels out the whole error, and we wind up dead bang on the setpoint.
Neat, heh?
Well, that all looks fine in theory. In practice we have to find suitable values for Ap, Ti and Td, and that can be difficult. With a bad set of values we will get a plain old mess that oscillates all over the place. In addition, many of the processes we may wish to control have nasties like sticky valves, backlash, noise, non-linearities, saturation and asymmetry. Many of these things are impossible to analyse and predict even if you have a Ph.D. in maths. If, like me, you are challenged by a mere set of simultaneous nonlinear differential equations, the problems may seem insurmountable. The answer lies in trying to get an intuitive feel for what is going on, and to use simulation and other tools to get a handle on the problem.
In the next section we will study the dynamics a little more closely, to get a feel for how things change with time.