A Decorated PID Controller

In our article Scilab Recipe 4: GUI Basics, we discuss the process of designing a simple GUI for our PID feedback simulation. The prime function of this PIDGUI window is to allow easy adjustment of the controller parameters and saturation limits, then update the corresponding variables in Scilab workspace. The actual simulation and response plots are performed in the Xcos model.

Figure 1 shows a more complicated Xcos PID diagram advpid.zcos used for simulation. The diagram has 2 feedback loops for comparison. The upper loop contains a simple PID block provided by Xcos. The controller used in the lower loop, on the other hand, is an advanced PID with the following additional features

  • To lessen the effect of measurement noise, derivative part is implemented as a filter with parameter N
  • Back calculation anti-windup scheme is implemented with tracking gain K_t
  • Setpoint weightings for proportional and derivative paths can be adjusted via W_p and W_d, respectively



Figure 1 Advanced PID diagram [advpid.zcos]

Together with the 3 original PID gains, there are a total of 7 adjustable parameters in the advanced PID controller. Moreover, it would be nice if we could easily adjust the limits of saturation blocks to see the integrator windup effects. It is therefore convenient to handle all these 9 parameters by a GUI window.

Our PIDGUI application is shown in Figure 2. This window is created by executing the script pidgui.sce. The design is discussed in Scilab Recipe 4: GUI Basics on our Scilab Ninja website.



Figure 2 the PIDGUI window used for parameter adjustments

-->exec('pidgui.sce',-1);

The user interface should appear, with some default values for the parameters and their ranges. You can edit the script file to put in your choice of values. Note also that running the script file closes all other graphic windows. If that is undesirable, remove the command xdel(winsid()); at the top.

A nicer way to override the parameter values is to create another setup file with your plant and parameters tailored to that plant. The script advpid.sce contains the following commands that create a plant and parameters tuned by ZNFD method.

s = poly(0,'s');
// plant used in Astrom and Hagglund book
P = syslin('c',1/(s+1)^3);
 
// pid gains for above plant
// tuned by ziegler nichols frequency response method
ku = 8;   // ultimate gain
tu = 3.5;  // ultimate period
kp = 0.6*ku;
ki = kp/(0.5*tu);
kd = 0.125*kp*tu;
N = 10;
//
kt = 1.2;  // back calculation gain for anti-windup

Launch this script

-->exec('advpid.sce',-1);

and import parameter values into PIDGUI by clicking the [Restore] button.

Now launch the Xcos model advpid.zcos in Figure 1. Click Simulation-Start. We would see a response comparison between the upper loop (standard PID) and lower loop (advanced PID) . They do not differ much at this time because the saturation limits are large. Try reducing them to, say, a limit for 12-bit DAC. In the Saturation Limits section of PIDGUI, put -2047 and 2047 to the lower and upper edit boxes, respectively. Run the simulation again. You ‘d see the result shown in Figure 3.



Figure 3 PIDGUI in action

Here we list some experiments that could be done more conveniently with PIDGUI.
Change the variable names in Scilab To Workspace blocks for each simulation run, and plot them after finished.

Saturation Effects

At first launch, the saturation limits are set to +/- 1e6, which are so high like there is virtually no limit. Reduce them to +/- 10000, 5000, 2000, 1500, while maintaining other parameters. Figure 4 shows that saturation effects in this case does not cause larger overshoot, but introduce lags in the response.



Figure 4 effects from saturation limits

Anti-Windup Performance

The plot shown in Figure 6 of our article PID Anti Windup Schemes can be observed by adjusting the back calculation gain K_t, click [update] and run the simulation.

Proportional Setpoint Weighting

In a sense, setpoint weighting can be thought of as a modest feedforward control. In the Xcos diagram, the error input to the proportional section of the controller is

(1)   \begin{equation*} e_p = W_pr - y \end{equation*}

i.e., the command is weighted by W_p, with range 0 – 1. Figure 5 shows the responses with 5 values of W_p: 1, 0.75, 0.5, 0.25, 0. We see that decreasing W_p could improve overshoot, though too small a value worsens the rise time.



Figure 5 step responses versus changes in proportional weight W_p

Derivative Setpoint Weighting

Similar to the proportional case above, the error input entering the derivative part is given by

(2)   \begin{equation*} e_d = W_dr - y \end{equation*}

with W_d ranges between 0 – 1 as well. Figure 6 shows the responses with W_d = 1, 0.75, 0.5, 0.25, 0. From this result, the advantage of using derivative weight on this plant and PID gain setup is not obvious.



Figure 6 step responses versus changes in derivative weight W_d

It is left as an exercise for the reader to simulate responses from combination of these parameters.

Conclusion

We call this controller a decorated PID because it contains a couple more features than standard PID controller. The anti-windup function makes this controller nonlinear. This fact makes feedback analysis more challenging, but at least simulation results could help with the learning process.

PIDGUI is a simple user interface designed to aid parameter adjustments before simulation, so the reader could concentrate more on feedback system behavior. All files are provided below for you to download and experiment by yourself. The Xcos file accepts any continuous-time plant transfer function P created by syslin command.

Supplement

Scilab and Xcos files used in this article

Download all as zip file: pidgui.zip

Comments

comments

Comments are closed.