This simulator is up for review at r/controlengineering , r/PLC and r/thermodynamics . The PID algorithim is here.
A PID controller is a type of closed loop controller that uses a combination of Proportional, Integral and Derivative calculations to produce a Control Variable based on the error between your Setpoint and the Process Variable to produce a Control Variable.
Take a heating system for example. The Setpoint is your target temperature. The Process Variable is the actual temperature of whatever you are heating. The error is the temperature difference between the Setpoint and the Process Variable. The Control Variable is the fuel flow rate for a burner.
The following content is based on my understanding of the PID controller. This is my attempt at explaining PID control to anyone unfamiliar with the topic or anyone looking for a more easy to digest explanation.
This documentation focuses on the following equations. Each equation will be discussed in greater detail in the following sections.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
e(t) = sp(t) - pv(t)
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
PID control loops work as follows:
PID controllers repeat the steps above continuously. The time between these calculations is the cycle time.
Note that dt is the cycle time because the change in time is the time between PID calculations. This fact is used later in the programming side of the PID.
t is the reference time, or the present, or the current cycle.
t-cycle time or t-dt is the time at the previous cycle
t=0 depends on context, but in the integral action of the PID, t=0 means the moment the error starts to be accumulated. In my simulation, t=0 is when my simulation starts. For other PID controllers with manual/auto modes, t=0 may be the time when the PID is switched to auto.
e(t) = sp(t) - pv(t)
The setpoint is your target, or what measure you want your system to reach. It could be:
Its unit depends on the parameter you are controlling. It would be °C if your target is temperature, for example.
e(t) = sp(t) - pv(t)
The process variable is constantly compared with the setpoint so that the PID controller can determine the appropriate change to the controller variable so that the difference between the setpoint and the process variable becomes zero and stays zero. Its unit is the same as the setpoint.
e(t) = sp(t) - pv(t)
The error is the difference between the setpoint and the process variable. A PID's purpose is to reduce this value to zero and return it to zero if disturbances in the system cause the process variable to change unintentionally. Its unit is the same as the setpoint.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
This is the result of the PID calculations. This value can be sent to a control device for example, a fuel flow controller in a heating system. In this example, as the controller value increases, the fuel flow increases.
Technically, its unit is still the same as error and Process Variable. It can't be used by the controlling device directly. It has to be scaled to match the operating range of the control device.
Since sp(t), pv(t), e(t) are all °C, for example, the output cv(t) is technically still °C. This is inconsistent with the function of cv(t) since it is supposed to be fed to the control device. One option is to scale it by a factor:
cv(t)liters/min = ScaleFactor·cv(t)°C
Another way is to change the inputs of the PID into a percentage of predefined process variable limits, then the precentage controller value output can be scaled to the predefined control variable limits:
Siemens PLC PID's do this internally. My simulation will do this as well.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
This is a tuning parameter that lets you adjust the effect of the proportional action. The larger it is, the more aggressive is the proportional action.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
The proportional action is the control variable directly in proportion to the current error.
cv(t) = Kp·e(t)
The proportional action is the control variable directly in proportion to the current error.
Proportional only controllers are possible but they have some drawbacks:
Proportional action is proportional to error. If there's no error, then the Control Variable is zero. For systems that regulate temperature for example, once the setpoint is reached and the error is zero, then the heating will be zero as well. This causes the system to cool down, only to heat up again when there's the presence of error.
If there are external forces affecting the system which cause a steady error, then the controller might stabilize at this point, never reaching zero error. Air temperature heaters might be cooled continuously by the fresh air intake. Specifically:
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
This is a tuning parameter that lets you adjust the effect of the integral action. The larger it is, the more aggressive is the integral action.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
The integral action is basically the control variable based on the accumulation of errors with respect to the passing of time.
This is so that even if the error is at steady state or very small as time passes, the accumulation of these errors continue to increase the control variable over time until the error reaches zero.
If we plot a graph with time on the x-axis and the errors at the y-axis we can trace an error curve. The integral action is simply the area under this curve. We can calculate the area under this curve by dividing it into small rectangles, calculating the area of each rectangle and adding them up.
Specifically, we can divide the the time between time=0t equally spaced spans of time called cycle/sample time dt. Knowing the error at each of these points in time aka e(t), we can get the area at this point by: e(t)dt. If we add all the rectangles between t=0 to t=current then we are actually getting the definite integral, or the area between e(t) (y-axis) and dt (x-axis) from t = 0 to t = current, represented by the equation:
0∫te(t)dt
Multiply this by the integral gain and you'll have:
Ki·0∫te(t)dt
cv(t) = Kp·e(t) + Ki·0∫te(t)dt
Proportional-Integral controllers are the most commonly used controllers because they do the job of reducing the error to zero with the least amount of complexity in terms of tuning and programming. Here's a look at the benefits of the integral action:
From the proportional-only controller example above, if there's no error, then the control variable is zero. PI controllers maintain the control variable because at zero error, P-action is zero but I-action generates its control variable based on accumulated errors. The fact that there is zero error simply means that the accumulated error no longer increases, therefore the controller action also stops increasing.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
This is a tuning parameter that lets you adjust the effect of the derivative action. The larger it is, the more aggressive is the derivative action.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
The derivative action is basically the Control Variable based on the slope between two points of error OR Process Variable at two points in time.
To illustrate the derivative action, let us convert the original equation Kd·(de/dt) to Kd·(-dpv/dt).
PID programs usually assume the dsp = 0 because most of the time the sp is the same, and at times when sp changes, it producess an unwanted derivative response due to the suddenly large difference in sp.
The original PID equation:
cv(t) = Kp·e(t) + Ki·0∫te(t)dt + Kd·(de/dt)
...can therefore be written as:
cv(t) = Kp·e(t) + Ki·0∫te(t)dt - Kd·(dpv/dt)
As we can see, the larger the change in the pv, the more the Derivative action subtracts from the total Control Variable. This is the damping effect of the derivative action.
cv(t) = Kp·e(t) + Ki·0∫te(t)dt - Kd·(dpv/dt)
Proportional-Integral-Derivative controllers are less common because as previously mentioned, PI-controllers often do a satisfactory job without the added layer of complexity brought by derivative controllers.
PID controllers allow aggressive Proportional and Integral action usually means faster error reduction to zero, but the resulting oscillation is usually unacceptable. The damping effect of the Derivative action reduces these oscillations while keeping the aggressive PI-action.
The damping effect may cause system instability for systems with noisy process variable measurements. If the difference in process variable is large, the derivative action is large. If the the process variable fluctuates, the derivative action fluctuates.