[From Bill Powers (950517.1400 MDT)]
The program appended to this post, simpsys1.pas, is similar to sumpsys.pas,
but it incorporates the ideas I talked about in the previous post on this
subject.
In the initialization routine, the system output gain "gain", the system time
constant tc, the physical time of an iteration dt, the maximum possible
output omax, and the maximum possible perceptual signal pmax (as well as omin
and pmin) are defined.
Reference signal = 1000 units
omax = 1050 units
pmax = 1200 units
omin, pmin = 0
dt = 0.005 sec
tc = 4.0 sec
gain = 300.0
Note that dt must be less than or equal to tc/(1+gain) to avoid computational
artifacts. In this case dt must be less than or equal to 4.0/301.0 or 0.0133,
which it is.
Some disturbances, except for the 6th disturbance, change instantly when
there are steps. This produces transient errors because the disturbance is
outside the bandwidth of control. The control system recovers as fast as it
can. The recovery time constant is not 4.0 sec, but more like 4.0/gain
seconds.
There are six disturbances, many similar to those that Hans Blom proposed.
When you start the program, the first disturbance is applied and the run is
plotted. The simulated time of a run is 50 sec and the actual computer time
is 5 sec or so. Pressing the space bar will start a new run with the next
disturbance, or exit after the last one. Note that the controlled variable qi
is always plotted last in white so it will overlay other variables when it is
in the same position. The gray line indicates zero for all variables.
Discussion of operation
Disturbance 1
An alternating series of square waves with amplitudes of -300 and 300
units. Disturbances are plotted in green.
With the reference signal set to 1000 and the maximum output set to
1050, the white controlled variable is maintained close to the red
reference signal by an output o in cyan or blue-green, nearly at its
maximum positive value. A disturbance that acts upward (aiding the
output) will result in the output becoming less positive, and the
controlled variable will be held at the reference level. But for
disturbances that tend to drive the controlled quantity negative, the
output must increase by the same amount, for a total of 300 units -- but
that is 250 units more than the output can produce. As a result, the
controlled variable will be driven below the reference level by about
250 units. You will see the white line fall below the red reference
signal line on alternate square waves.
Disturbance 2
A sawtooth wave that rises from 0 to about 800 units every 100 pixels.
Since the disturbance acts in the positive direction only, it is
counteracted by a fall in the output variable o. When the sawtooth
wave falls back to zero (in one iteration), there is a transient
departure of the controlled variable from the reference level. The
recovery time can be slowed by increasing tc. It can be speeded up by
decreasing tc, but the time interval dt must be adjusted to fit the
critical condition defined above, if necessary. Changing these
parameters required editing and recompiling.
During the positive ramp of the disturbance, the controlled variable qi
remains essentially at the reference level, its white trace overlaying
the red reference signal trace.
Disturbance 3
A ramp that rises steadily during the run.
Note that the disturbance becomes larger than the reference signal near
the end of the run, and the output variable, which declines during the
run, reaches zero where it is stopped by the minimum output limit, omin.
The controlled quantity, which remains at the reference level until
then, starts to rise at the the same rate as the disturbance, its white
trace overlaying the green disturbance trace.
Disturbance 4
A parabola that rises as the square of time during the run.
This disturbance, too, exceeds the reference level during the run. The
output stops decreasing at zero, and the white controlled-variable trace
rises, overlaying the rising green disturbance trace.
Disturbance 5
A sine-wave of amplitude 1100 units, which goes above and below zero.
The display takes a little study. When the disturbance goes positive,
the output, as usual, decreases toward zero. However, the disturbance is
so large that the output hits the zero limit, and while the disturbance
is greater than the reference level, the controlled variable is
deflected upward. So every time the disturbance goes negative, the
controlled quantity remains near the reference level except for a bump
in the middle where the output is limited at zero and control is
momentarily lost.
When the disturbance goes negative, the output goes positive, but since
it begins only 50 units below the positive limit, it soon stops
increasing. At that point the controlled variable is driven negative,
close to zero, by the disturbance. So this system is controlling only
for positive values of the disturbance, and even then only while the
disturbance is less than the maximum that can be resisted by the output.
This would be called a "large" disturbance, since it drives the control
system outside its control range.
Disturbance 6
A slightly smoothed random waveform. The smoothing time constant is 0.2
seconds.
The smoothing creates a waveform with a positive average value and quite
rapid random variations about that value. After the initial startup
transient, the output falls below the reference level, and the
controlled variable appears as a white band of high-frequency noise
centered on the reference level.
The fluctuations in the output signal are quite rapid; they remove the
low-frequency parts of the disturbance noise (including the average
value of the disturbance). This is why the controlled variable shows
only the higher-frequency noise. Note that the envelope of the
controlled variable shows a smaller spread than either the disturbance
variations or the output variations. The smoothing of the random
disturbance was selected to show this effect, with part of the noise
spectrum being cancelled by the control action, and the remainder, above
the control bandwidth, being uncontrolled. This works with an unsmoothed
random disturbance, but the extreme scatter of the points makes this
effect impossible to see by eye.
Discussion
This demonstration does not show what is meant by a "fast" disturbance,
except implicitly in the sixth run. A "fast" disturbance is one that changes
faster than the maximum speed with which the maximum change in output can
affect the controlled variable. Here that speed is set by the output time
constant as reduced by the loop gain. The external part of the loop is just a
proportional effect, so is not limited in speed (except by the value of dt,
which can be decreased as much as desired).
The meaning of a "large" disturbance and a "large" error (difference between
controlled variable qi and the reference level) are illustrated directly. A
large disturbance is one that drives the system just to the limits of output
or perceptual signal. In the demo, the perceptual signal limit is set high
enough so it doesn't come into play. You might want to experiment with lower
limits to see what happens (sorry, this requires editing the source code and
recompiling). The size of the error is judged in terms of the span of the
control range, as a percentage of the largest feasible setting of the
reference level, in the presence of the largest and fastest disturbance that
lies within the control range. Here that maximum error is about 5% of the
range (a somewhat fuzzy judgement).
Have fun.
···
---------------------------------------------------------------------
Best to all,
Bill P.
program simpsys1;
{
A simple integrating control system, with physical time
}
uses dos,crt,graph,grutils;
var
MaxX, MaxY, Xcenter, Ycenter: integer;
p,qi,r,e,o,d,dt,tc,gain,u: real;
pmax,pmin,omax,omin,maxtime: real;
time: real;
i,j,x: integer;
ch: char;
procedure InitScreen;
begin
ClrScr;
InitGraphics;
MaxX := GetMaxX; MaxY := GetMaxY;
Xcenter := (MaxX+1) div 2;
Ycenter := (MaxY+1) div 2;
end;
procedure initsys;
begin
omax := 1050; omin := 0;
pmax := 1200; pmin := 0;
dt := 0.005; {sec}
tc := 4.0; {sec}
maxtime := 50.0; {sec}
gain := 300.0;
u := 0.0;
end;
procedure ctsys;
begin
p := qi;
if p > pmax then p := pmax else
if p < pmin then p := pmin;
e := r - p;
o := o + (gain * e - o)*dt/tc;
if o > omax then o := omax else
if o < omin then o := omin;
qi := o + d;
end;
begin
Initscreen;
Initsys;
r := 1000.0;
for j := 1 to 6 do
begin
setcolor(lightred);
outtextxy(0,maxy - 90,'Reference level (1000)');
setcolor(white);
outtextxy(0,maxy - 70,'p and qi');
setcolor(lightgreen);
outtextxy(0,maxy - 50,'Disturbance');
setcolor(lightcyan);
outtextxy(0,maxy - 30,'Output');
setcolor(white);
outtextxy(0,maxy - 10,'PRESS SPACE TO CONTINUE');
time := 0.0;
while time < maxtime do
begin
x := round(640.0*time/maxtime);
case j of
1: begin
d := 300 * round(sin(0.02*time/maxtime*640.0));
if time = 0.0 then
outtextxy(0,0,'d := 10 * round(sin(0.3*i))');
end;
2: begin
d := 4*((round(time/maxtime*1280) - 10) mod 200);
if time = 0.0 then
outtextxy(0,0,'d := (i - 10) mod 10');
end;
3: begin
d := time/maxtime*1200.0;
if time = 0.0 then
outtextxy(0,0,'d := i;');
end;
4: begin
d := time/maxtime*64;
d := d*d/2.0;
if time = 0.0 then
outtextxy(0,0,'d := time*time/64');
end;
5: begin
d := 1050*sin(6*pi*time/maxtime);
if time = 0.0 then
outtextxy(0,0,'d := 1200*sin(6*pi*time/maxtime)');
end;
6: begin
u := u + (random*3000 - u)*dt/0.2;
d := u - 1200;
if time = 0.0 then
outtextxy(0,0,'d := d + (random*3000 - d)*dt/0.2');
end;
end;
ctsys;
putpixel(x,maxy - ycenter - round(0.2*r),lightred);
putpixel(x,maxy - ycenter - round(0.2*o),lightcyan);
putpixel(x,maxy - ycenter - round(0.2*d),lightgreen);
putpixel(x,maxy - ycenter - round(0.2*qi),white);
putpixel(x,maxy - ycenter,lightgray);
time := time + dt;
end;
ch :=readkey;
clearviewport;
end;
restorecrtmode;
closegraph;
end.