The PID Controller
The PID controller (an abbreviation of Proportional Integral Differential) is the most widely applied feedback control formula/algorithm. It is applied in a huge variety of ‘things’ to automate them, such as planes, drones, cars, coffeemakers, wind turbines, furnaces, and manufacturing units. It is fair to say that the PID controller is the work horse for automation. The PID formula has three parameters that must be set or tuned in the right way and that is what is the PID Tuner is used for. In this article we will explain a suitable way to program a PID controller yourself (if you do not want to use standard libaries), and we present some background on different tuning methods.
The effect of P, I and D
The PID Controller has three parameters that should be tuned. The proportional term (Kp), the integral term (Ti) and the differential term (Td). The figure below shows the effects of varying Kp and Ti.
The discrete PID equation
The equations below present a PID formula that can be programmed in a control computer (note that we define the output of the PID controller as MV or u, and the controlled variable as PV):
With:
discrete time (0,1,2,..)
Manipulated Variable at time k
Error at time k
Setpoint at time k
Process Variable at time k
Proportional Gain
Integraltime
Derivative time
Sample time
Example code for the discrete PID controller implemented in Matlab can be seen below. Also, you can directly download this code. C-code is also available, for a small fee.
- Matlab: Matlab PID code (1995 downloads )
- C/C++: PID Controller C-Code
PID Tuning
Various methods exist to tune a PID Controller:
- Open loop method, combined with model based (= method used in PID Tuner)
- Closed loop Ziegler and Nichols
Open loop method to tune a PID controller
To tune a PID Controller using the open loop method, the following step approach can be taken:
- Freeze the PID output
- Make a step change on the PID output (MV) in order of 3-10%. Step should be sufficiently big to see its effect on the controlled process variable (PV)
- Log response of MV and PV and fit the model parameters of a First Order Time Delay model to this response.
- Use model based tuning method, such as Table 1 for single PID loops
Table 1: PID Open Loop Tuning Rules based on [1]
Kp | Ti | Td | |
---|---|---|---|
P | — | — | — |
PI | 0.35*Tp / (Tdt * K) | min( 8*Tdt, Tp) | — |
PID | 0.5*Tp / (Tdt*K) | min( 8*Tdt , Tp ) | 0.5*Tdt |
Reference
[1] S. Skogestadt, “Probably the best simple PID tuning rules in the world”, Journal of Process Control, 2001
Closed loop Ziegler and Nichols tuning method
- Switch on proportional control only, i.e. choose:
- Ti = ‘maximum value’
- Td = 0 (unless you know which value to choose here)
- Increase proportional gain until loop oscillations hardly dampen.
- Then note:
- Ultimate gain (KU ) = proportional gain
- To = period of oscillation
- Apply settings from Table 2
Table 2: Closed Loop PI Tuning Rules (Tuning rules for the D-term in the PID controller are not reliable to our opinion).
Kp | Ti | Td | |
---|---|---|---|
PI | 0.45*Ku | T0/1.2 | 0 |
Additions to the PID Controller Formula
In reality the output of a PID controller will be limited, e.g. from 0-100%, and sometimes also the rate-of-change should be limited.
Limit the PID controller output between an upper and lower bound
if u < 0
u = 0
end
if u > 100
u = 100
end
Limit the PID controller output rate-of-change, for instance between -3 and +3
du = min( du, 3)
du = max( du, -3)
Adding a dead-band (with size 1) to the PID controller output
if du < -1
du = 0
end
if du > 1
du = 0
end
PID Tuning Tips
- Tip 1. Oscillations in process variables can have at least three causes, and it’s essential to know which one applies in order to reduce the oscillations.
– External disturbance
– Instability in loop resulting in limit cycle
– Stick-slip-like phenomena in valves or other actuators - Tip 2. Check out our posts on PID control issues and how to resolve them at this link
- Tip 3. If you face any issue with (PID) control, contact us by mail or phone and tell us about it. We might be able to help!
Evaluating the performance
After you have tuned the PID controller, it is essential to check its closed-loop behavior. You can often do that by making a setpoint change, but sometimes (when the PID is in slave mode), it may be better to make a step change on the Perturbed Manipulated Variable (that is signal that you simply add to the MV, i.e. the output of the PID). Then check if the closed loop behaviour is the same as predicted by the closed-loop simulations in the PID Tuner.
More Information?
We, from Dotx Control Solutions, have extensive experience with tuning all sorts of PID controllers. If you want to know more, check out:
- Our training courses to learn more about everything related to PID control
- Our consultancy services: One of our control experts can assist you with solving your control related problems.
Also, we have developed the PID Tuner, which is a software tool that you can use to easily tune PID controllers. Click here to find out more.
If you have any other question, don’t hesitate to send us a mail at info@dotxcontrol.com, or fill in the form below.