Control Systems Background - The Regulation Problem
Control Systems Background - The Regulation Problem
In a regulated system, an input signal called the setpoint specifies the desired response level at the system output. The output could be a
of a cutting tool, to name just a few possibilities. In a perfect world, you would provide the setpoint signal to the system input, and it w
This configuration, sometimes called open loop control, is illustrated in Figure 1.
Very often, real processes cannot be operated in this way. The output may drift away from the setpoint for a variety of reasons, or may
much in response to transient changes. In these situations, the output of the system can be measured and processed by a separate contro
compares the system output to the setpoint level to determine a new control input for the system. This configuration, called closed loop
Various strategies have been used to implement the controller. Three of the most common are:
(P) Proportional error correction. The difference between the setpoint and actual system output is amplified and fed back to pr
from the setpoint, the larger the correction signal.
(I) Integral error correction. Persistent differences between the setpoint and actual system output accumulate over time, until t
back toward the setpoint.
(D) Derivative error correction. The correction signal opposes rapid deviations in system output, reducing the response to dist
There is nothing that requires these strategies to be utilized in isolation. Usually, some combination provides better performance. The m
each of the correction terms affects the controller's output. Figure 3 shows a simplified block diagram of a PID controller.
Figure 3. Simplified block diagram of the DAPL PID1 controller.
Another common nomenclature for PID control parameters is given below. The configuration is the same as Figure 3, with parameter c
P = Kc I = Kc / Ti D = Kc Td
Kc = P Ti = P / I Td = D / P
The DAPL implementation of PID in the PID1 command is slightly different from a conventional PID controller. The Data Acquisition
operating directly on voltage signals, it actually operates on digitized samples using fixed-point arithmetic. A detailed block diagram of
A DAP requires an external sensor to measure the system output and signal conditioning electronics to convert the measurement to an a
signal conditioning are represented in Figure 4 by the Si scaling factor. The voltage is typically a single-ended voltage in the range -5 to
control of a DAPL input procedure.
The numerical output of the PID1 task is converted to an output voltage by a D/A converter. The output voltage range is typically -5 to
as an explicit limiter block. External electronics may be required to convert the output voltage into a signal suitable for driving the syst
external electronics is represented by the multiplier So in Figure 4. If possible, the output scaling should take advantage of the output r
excessive control signal drive. For good transient response, the scaling also should allow some room for short-term control signal level
The PID controller calculations proceed at the rate that data samples are placed into the PID input pipe. The sampling rate should allow
samples, but should be sufficiently fast for observing system changes as they are happening. In the examples at the end of this note, the
respond to input changes, so the PID samples are captured at tenth of a second intervals. The T notation in Figure 4 represents sampling
The Integral and Derivative control calculations do not include the element of time, which must be introduced by scaling the PID coeff
how the scaled coefficients Ps and Ds shown in Figure 4 are related to the P and D parameters in Figure 3.
The integral operation is approximated by summing the values of the error input, and then applying the Is multiplier. The relationship b
sampled coefficient Is is
Is = I * T
To understand what this represents, suppose that the sample time T is reduced by half, causing the sample rate to double. The summati
twice as often, causing it to grow twice as fast. Without any correction, this increased growth would lead to a doubling of the integral c
for the faster growth.
The derivative is approximated by differences of consecutive inputs. The relationship between the real time Derivative coefficient and
Ds = D / T
Again suppose that the sample rate is doubled. The Derivative term observes the input twice as often, so it sees changes of roughly half
compensation it will produce about half the effective control response. The 1/T term in Ds above compensates for the smaller change o
Ps = P
Selecting optimal values for the P and D parameters of a closed loop control system is usually an iterative process. This process is calle
Before tuning begins, verify that all components of the control loop operate correctly. Test input processing tasks to verify that the mea
Test output procedures to verify that the control output is correctly scaled. Verify that the PID controller processes the sampled input an
with the input. If possible, verify that the system responds correctly to its control input.
Knowing that the components work individually still does not guarantee that they will work together. How do you establish initial para
without driving the actual system? You can use the multi-tasking capabilities of DAPL to simulate the essential characteristics of your
parameters that you specify. Then, when you are satisfied that the settings are reasonable, you can disconnect the simulated system and
The DAPL commands provided in Listing 1 at the end of this note simulate the response of an inertial third-order linear system under c
samples its control input from analog input channel 0 and sends its output level to analog output channel 0. The PID controller samples
a control output on analog output channel 1. A sample time of 1/10 second is used both for the PID controller and for the simulated sys
Some simple hardware connections are required to run the simulation. Connect an MSTB 003-01 termination board to a Data Acquisiti
S0, to route the output of the simulated system to the input of the PID control. Connect input pin S1 to output pin DAC0, to connect th
PID. After your tuning is completed, remove the connections to S1 and DAC1. Replace them with connections from your system outpu
control input.
You will want to edit some of the coefficients in Listing 1 to configure the operation of your PID controller and simulated system. The
system, in the form of a Laplace transform
(A2 s2 + A1 s + A0) / (B3 s3 + B2 s2 + B1 s + B0)
(Don't worry if you are unfamiliar with Laplace transforms and the s variable; you can use and modify the coefficient values from the t
variable specifies the setpoint. The variables PV, IV and DV specify the PID response characteristics, and the variable RAMP sets the
That's all you need. Download the edited DAPL program, run it under DAPview, and display PSET, PIDIN, and PIDOUT. The setpo
will plot as a red line, and the PID control output will plot as a green line on your DAPview display.
Test Cases
The following test cases illustrate PID control for three typical systems. These cases show the capabilities and the side effects of each o
the vertical scale of the output plots shown in Figures 5 through 15 represent the digital values provided to the D/A output stage. In the
line, and the PID control output is plotted as a thin line. The controller is limited to the range -20,000 to 20,000 in the test cases. You ca
variables as you wish, but the rest of the listing should require no changes.
One of the figures for each test case shows the response of the system without PID control. To replicate these graphs, you must overrid
command VIN=PIDOUT with the command VIN = SETPT.
10
-----------
100s + 10
Applying PID control with the settings given at the beginning of this test case, we get the response shown in Figure 6. The Proportiona
response is still sluggish. Each unit that the system approaches the setpoint produces a unit drop in control effort. The system and contr
not a very acceptable result! Note that a sustained control effort is required to maintain systems such as this one at any nonzero operati
require a sustained flow of power to a heating element.
To reduce the difference between the setpoint and output, we first try increasing the Proportional control gain to 8, by setting PV=800.
control effort moves the system output much more quickly. Notice that the PID control effort jumps immediately to maximum and stay
higher gain would therefore have little effect: maximum effort is maximum effort at any gain setting. If we wished, we could raise the e
input, output, and setpoint to avoid saturation. On the negative side, higher gains can be seen to cause increased noise in the control sig
If you examine Figure 7, you will notice that the system still does not reach the setpoint level of 10,000. As the system approaches the
correct this problem by introducing some Integral correction. Setting IV=300, we obtain the response curve shown in Figure 8. As long
Integral correction increases until the system reaches the setpoint.
6
-----------------------
2 s**3 + 5 s**2 + 5 s
This system will stay at the setpoint without any control effort. But getting it there can be interesting, because once this system starts to
unstable response without PID control.
Figure 9. Integrating system goes unstable without controller
To get the system to the setpoint quickly, the usual strategy is to apply Proportional control. Using the coefficients given at the beginnin
causes the system to overshoot the setpoint of 10,000. The system oscillates for a significant time, as shown in Figure 10.
Increasing the gain to PV=150 only makes the oscillations worse, as shown in Figure 11.
Figure 11. Increasing proportional gain worsens oscillations.
For this kind of system, a large control effort is not necessary to reach the setpoint. The best strategy is to reduce the proportional gain,
oscillations. Setting the proportional gain to PV=65 and the derivative gain to DV=425, we see the response shown in Figure 12. Deriv
oscillations, but too much makes the system sensitive to noise, and slows the approach to setpoint.
Note that the Integral correction term was not used. For natural integrating systems such as this one, Proportional correction is all that i
tendency to oscillate, as this one does, the Integral correction will tend to increase the oscillation. As an experiment, you might want to
in response.
s**2 + 11 s + 3
------------------------------
15 s**3 + 18 s**2 + 25 s + 3
The open loop response of this difficult system is shown in Figure 13. The system is very slow to approach the setpoint, yet at the same
almost impossible to operate without using feedback control.
Using the PID parameter values given at the beginning of this test case, the low value of Proportional correction allows the system outp
system of Test Case #1. Applying more Proportional error correction, and setting PV=600, we get closer to the setpoint, but also excite
Adding a large Derivative correction, we can both reduce the oscillations and allow a higher value of Proportional gain, at the expense
Also notice that like Test Case #1, this system also tends to settle to an output level different from the setpoint. Integral gain can correc
and derivative settings. Adjusting the gain settings to the values PV=500 , IV=6000 , and DV=2000 , we get the output response shown
Conclusion
With the unsurpassed flexibility provided by a Data Acquisition Processor-based system, and with the control capabilities provided by
reason to settle for control systems with lesser capability. Under DAPL, one Data Acquisition Processor can control one PID process lo
rack full of specialized controller modules. Adding a new control loop is simple by using DAPL to specify the input channel, the outpu
The Data Acquisition Processor can perform exceptionally high-speed or exceptionally low-speed PID control tasks beyond the capabi
Data Acquisition Processor can take care of the monitoring and data functions that must normally be provided by separate data logging
With conventional PID controllers, it can be difficult to know what control system performance to expect without actually building and
Data Acquisition Processor, however, DAPL can simulate closed-loop system response, using the PID control strategy that you specify
note to simulate some of the essential features of your system's response -- sustained control effort, response time, and tendency to osci
evaluate the effects of control limits, get some valuable practice at fine-tuning control parameters, and obtain a high degree of assuranc
behaved.
; **********************************************
; DAPL Closed loop simulation of 3rd order
; inertial system and feedback control using
; the PID1 command.
; **********************************************
RESET
OPTION SCHEDULING=FIXED
; **********************************************
; **********************************************
; **********************************************
; PID control.
PDEFINE CONTRL
SKIP(SYNC,0,1,19,PIDX)
PIDIN = PIDX * VOUT ; Feedback from system
PID1( PIDIN, SETPT, PV, IV, DV, \
LOCK, PIDOUT, -5000, 20000, RAMP)
VIN = PIDOUT
PSET= PIDX * SETPT
MERGE(PSET,PIDIN,PIDOUT,$binout)
END
; **********************************************
; End of simulation
The DAPL system has supported PID controls since its very earliest versions. The reason for doing this was to enable developers to us
command used, for building customized controller commands. The reason that this maybe wasn't such a good idea, it limited develope
Actually, a system interface with multiple service functions is not necessary to support PID. As you will see, practical PID controls onl
put in the same 20 or so lines into your processing command and you will have all of the same capabilities, plus easy access for modif
PID state
Your PID controller needs two kinds of data: configuration and state. The configuration contains the adjustable settings that persist ove
class PID_params
{
// Gain parameters
public:
float Kgain; // Loop gain parameter
float Ti; // Integrator time constant
float Td; // Differentiator time constant
float delT; // Update time interval
// Setpoint parameters
float setpt; // Regulated level to maintain
};
The internal state variables change from sample to sample depending on what happens in the feedback.
class PID_state
{
// Controller state
public:
float integral; // Summation of setpoint errors
float deriv; // Previous setpoint error
};
The main reason for organizing the data in this manner is convenient addressing. State and gain settings are used together all the time a
encapsulation principles to merge the structures into one common PID_data object.
PID Initializations
Before the PID computations begin, set up the PID parameter and state objects, and initialize all of the terms.
PID_params Params;
PID_state State;
// Initialize these...
When approximating the integral using rectangular rule integration, the integral adjustment at each time step becomes the integrand (se
approximating the derivative using a first difference, the deriviative estimate is the difference in successive setpoint error values divide
PID Computations
The PID computations compare the actual system output to the setpoint to determine the setpoint tracking error. This difference drives
The derivative of the setpoint error is needed next. The actual derivative is seldom available, so the PID controller estimates the deriva
calculation requires keeping one previous value in state memory.
pidout *= -PID_state.Kgain;
// drive controller output
When somebody says they are using PID control, this is the complete story. So far, only 8 lines of run-time code are used to implemen
few common modifications, and these are covered next.
Most software-driven PID controllers will need to convert the computed gains into a fixed-point value and use this to drive a digital to
on the value that the PID control could compute, but there is a definite limit on the fixed point number range to which output converter
to limit the output to that range.
There can be good reasons for more restrictive limits: amplifiers that are unipolar and can't respond to negative values, systems that res
can add two additional configuration parameters and force outputs to be limited to the specified range.
Avoiding Windup
After limits are applied, linear PID controls become nonlinear, and this has some side effects. Consider what happens when a controlle
regulating at a high level. While the controller is driving hard toward the new level, the system is still far away from the target setpoint
even though the desired output level is reached, and passed, the integral effects by themselves are enough to continue driving ahead at
the extended transient time required to correct the integrator imbalance is known as unwinding. Various strategies to counter windup ef
1. Integrator Latching. Since accumulation problems occur predominantly while the control output is at a limit, do not allow in
updating the integrator state until after limits are checked.
A reduction factor of 0 is the same as the clamping anti-windup strategy. A reduction factor of 1 is the same as no anti-wind
3. Integrator Rate Limiting. Presuming that the error integral is intended for final settling, not for rapid response to large trans
integral can change. An additional configuration parameter is required for the independent integrator rate limiter.
ichange = seterr;
if (ichange > PID_params.rate_limit)
ichange = PID_params.rate_limit;
else if (ichange < -PID_params.rate_limit)
ichange = -PID_params.rate_limit;
pidout += PID_state.integral * PID_params.delT / PID_params.Ti;
PID_state.integral += ichange;
For computing the derivative estimate, the current and previous setpoint errors are subtracted. When regulating a constant setpoint, this
current and previous feedback values. When the setpoint is changed, however, the change in the setpoint looks like an instantaneous, "
For applications where the command level changes continuously and smoothly, the basic derivative scheme works fine. For regulation
level spikes and use the differences between current and previous feedback explicitly, all of the time.
Derivative control action should oppose rapid changes and should therefore be beneficial — but it has a bad reputation for being "desta
It introduces a closed loop zero. Closed loop poles, not zeroes, cause instability. Still, the "peaking" gains produced at high fre
with gain margins.
The higher the frequency, the less likely the relevance to the control problem, but the more the derivative term amplifies it. Th
The derivative term is an estimate, and errors in the estimate can in themselves be a source of noise.
The derivative feedback does not play well with time delays. A derivative gain that is fine in a continuous variable controller
delay of a discrete-time control loop.
The problems are worst at the Nyquist frequency, with a tendency to produce a high-to-low rattling that damps slowly.
A derivative frequency response increases monotonically at high frequencies. A lowpass filter can offset this gain and neutralize phase
needs to have minimal effect at the important lower frequencies, while providing attentuation of high frequencies.
1. Averaging filter. This introduces a transmission zero at the Nyquist frequency. One additional state variable is needed.
A lag parameter value of 0.15 to 0.35 usually works well. The lower this cutoff level, the better the high frequency noise rejection but
term is reduced.
Gain Adjustments
Gain changes that are applied automatically and continuously, as in the case of an adaptive tuning scheme, are small and introduced so
changes that are larger can produce an artificial transient. This is an avoidable problem.
No special adjustments are required for the derivative or proportional feedback effects. In steady operation the derivative term does no
the setpoint error is very small and so is the effect of proportional response. During transients the effects of a gain adjustment would no
That leaves the integral term. The loop gain and integral time constant terms act together upon the current integral value to hold the loo
of these two gain terms, there will be an instantaneous level change in the control output. Ordinarily, what you will want instead is that
gain adjustments.
integralold * Kpold/Tiold
To avoid an artificial transient, you must artificially adjust the integral value at the same time as the gains, so that the net effect of the i
After this adjustment, the new values of loop gain Kgain and integral time constant Ti can replace the previous values in the PID_para
It is not uncommon to find that the control loop works against a biased loading. For example, an actuator applies lift, and must work ag
work with gravity to move the load downward. Ordinarily, PID action is the same in both directions, and this leads to pulling downwar
The proportional term is intended for responding quickly to deviations from the setpoint. The amount of adjustment to apply is indicat
setpoint tracking error can be tested to determine whether to increase or decrease proportional response according to the new paramete
// Proportional response
pidout = seterr;
Feedforward Compensation
Sometimes it is necessary to control a system that has a tendency to "ring." The oscillations damp out slowly, and there is not much tha
causing them. Abrupt level changes can contribute energy at the frequency of ringing and excite the oscillations unnecessarily.
1. Adjustable command path gain. The proportional action is split between the feedback response and the setpoint command r
paths. The effect is to shift the transfer function zero that the PID controller introduces, moving it away from the frequency w
might encourage the oscillation. This option requires an additional gain scaling parameter that must be tuned along with the u
0.0 to 1.0. At 1.0, the loop action is the same as classic PID.
The design of the filter is beyond the scope of this paper. The smoothed setpoint signal with gradual level changes is then app
setpoint changes directly. This could be a separate filtering task, but the filter and the PID gains often are closely related and s
If the filter reduces to a simple gain less than 1, this becomes the same as the adjustable command gain strategy.
Conclusions
This note has described how PID software controls work, and how to implement them in custom processing commands. If there is any
speaking, PID controls are linear controls with three gain parameters, but most implementations will apply one or more of the extensio
certain point, it is questionable whether the exotic variants deserve being called PID control.
The variants are shown here in an informal style that should be comfortable both to C and C++ programmers.
While we have covered the 20 or so lines of programming code needed for the PID computations, the real challenges will lie in getting
of the computations, in a manner that will meet real-time requirements. Additional support in the form of fully functional command ex
DAPL.