From: POWERS_W%FLC@VAXF.COLORADO.EDU (William T. Powers)
Newsgroups: bit.listserv.csg-l
Subject: Primer for modelers: draft
Date: 9 Nov 92 17:25:31 GMT
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
X-Envelope-to: CSG-L@vmd.cso.uiuc.edu
X-VMS-To: @CSG
MIME-version: 1.0
Content-transfer-encoding: 7BIT


               Experimenting with the control paradigm
                   A primer for computer modelers
                        DRAFT: William T. Powers

       PART I: PROPERTIES OF A SIMPLE STABLE CONTROL SYSTEM

 The following is intended to introduce programmers and control-system
 engineers to the terminology and architecture of control theory as
 used under the name PCT, or perceptual control theory. For those who
 have experience with modeling control systems, there are some
 readjustments to be made, because we will divide the system into
 functions in a way that is not standard in control engineering. For
 example, the output of the control system is not the controlled
 variable, but is an influence on the controlled variable. If the
 controlled variable were defined as the rotational speed of a motor,
 the output of the control system would be the torque applied to the
 motor armature, not the speed. The speed would be classified as an
 INPUT quantity, because it is this quantity that is sensed by a
 tachometer, and that can be disturbed by variables in the environment
 such as friction and loads. We define torque as the output because
 torque depends only on the output of the control system -- the
 current going through the motor -- and is not subject to disturbance
 by the environment. If you are an engineer it will take some effort
 to reorganize your thinking in this new way, but even in control
 engineering you might find that there are some considerable benefits
 in doing so. The normal way of presenting control processes to
 students is rather disorganized; the PCT organization brings in a
 standard approach that often makes control problems easier to solve.

 The aim here is to develop some insights into the properties of
 control systems, not through complexity but through simple examples
 and hands-on experience. Watching computer simulations work is the
 next best thing to seeing a real control system work; in some ways it
 is superior because you have time to see the details of what is going
 on. Rather than exhort the reader to run these programs on a computer
 and examine the results, I have decided to make it necessary to do
 this by not presenting any numerical or graphical tables. You will
 have to run the program to see what this discussion is about. Perhaps
 frustration will prove to be an effective motive for actually
 experiencing this simulation in operation.

               Suggestions for standard terminology

 A function is a physical device with an output signal the magnitude
 of which can be computed from the state of its input magnitudes. All
 functions are true mathematical functions: that is, they may have
 multiple inputs (arguments) but they produce only one output (value
 of the function given those arguments). Thus the term function refers
 both to some physical element of the system and to the equivalent
 mathematical function that describes the dependence of its output on
 its input(s) in terms of magnitudes.

 A generic control system consists of an input function, a comparator,
 and an output function. The output of one function generates a
 variable that is an input to another function. Such information- carrying
 variables inside the system are called signals. A signal not
 only represents the value of the function, but serves to carry that
 value to the input of another function in a different physical
 location. All signals have a single measure, magnitude. The name of a
 signal identifies a pathway; the value of the signal indicates the
 momentary magnitude of the signal carried unidirectionally by that
 pathway.

 The environment model

 In the environment of a control system the variables are called
 quantities. The output of the output function is measured in terms of
 an effect on a physical variable called the output quantity. The
 output function in a model of a single control system interacting
 with an environment is therefore a transducer: its input is a signal
 while its output is a quantity. The output quantity is always defined
 so that its magnitude depends only on the output function's value: it
 is always a single variable. If it has multiple effects in the
 environment, each of those effects must be separately indicated in a
 model of the environment.

 The input to the control system is another physical variable called
 the input quantity. The input function senses the state of the input
 quantity and converts it to a perceptual signal. The input function
 is also a transducer in a single system-environment model; its input
 is a physical quantity and its output is a signal. An input function
 may respond to multiple input quantities.

 In the environment, there is a feedback link connecting the output
 quantity to the input quantity. This link is called the environmental
 feedback function, or simply the feedback function.

 Also in the environment there is a link through which independent
 environmental variables called disturbing quantities act on the input
 quantity concurrently with the action of the output quantity on the
 input quantity. Because the number and kind of disturbing quantities
 is immaterial, it is customary, when modeling a single control
 system, to represent all disturbing quantities and their individual
 links to the input quantity as a single equivalent disturbance acting
 through a single equivalent disturbing function.

 The control system model

 The perceptual signal generated by the input quantity enters a
 comparator; also entering the comparator is a reference signal, an
 independent variable. Where possible, the signs of various system
 constants are chosen so that the reference signal has a positive
 effect on the comparator while the perceptual signal has a negative
 effect. The comparator is a function with two arguments and a single
 value. The output value is represented by an error signal, the
 magnitude of which is equal to the reference signal's magnitude minus
 the perceptual signal's magnitude. The error signal enters the output
 function. Often, as shorthand, we speak of subtracting one signal
 from another, or adding signals together. What is meant is that the
 magnitudes are subtracted or added.
 The system-environment diagram

                                sr
                      sp        +|      se
                   -----------> (fc)----------->
                  |           -                 |    CONTROL
                 (fi)                          (fo)   SYSTEM
 ---------------  | --------------------------- | -------------
                 qi <-----------(ff)<--------- qo   ENVIRONMENT
                  ^
                  |
                 (fd)
                  ^
                  |
                 qd

 DEFINITIONS:

 Signals:
 sp = perceptual signal
 sr = reference signal
 se = error signal

 Functions:
 fi = input function
 fc = comparison function or comparator
 fo = output function
 ff = feedback function
 fd = disturbance function

 Quantities:
 qi = input quantity
 qo = output quantity
 qd = disturbing quantity

 THE CONTROL EQUATIONS:

 System:
 sp = fi(qi)
 se = sr - sp

 Interface transducers:
 qo = fo(se)
 sp = fi(qi)

 Environment:
 qi = ff(qo) + fd(qd)

 Combined equations:
 System: qo = fo(sr - fi(qi))
 Env:    qi = ff(qo) + fd(qd)

                   Setting up a working model
 The following discussion assumes that you know a programming language
 like C, Fortran, Pascal, Modula, or Basic. The actual programming
 involved is elementary. The student is advised to write the simplest
 program possible in the most familiar language and experiment with
 it. The most important knowledge to be gained is a feel for the
 relationships among variables in a control system, and for the
 effects of changing various system parameters. There is a temptation
 to tackle some interesting and complex problem first, but without a
 strong intuitive foundation for designing more complex systems the
 most likely result will be confusion and failure. Control systems do
 many surprising things and the effects of changes in the parameters
 are seldom what you would initially guess.

 The simplest control system to model on a digital computer is one in
 which all the functions are simple proportionalities except the
 output function, which is an integrator. Alternatively, the feedback
 function or the input function can be made into an integrator;
 however, only one function should be an integrator and the rest
 should be proportional multipliers. We will use a design with an
 integrator in the output function; you can experiment with the other
 possibilities.

 In computer programs, integration is summation. Because this is a
 closed-loop system, integrations do not need to be precise, so
 advanced methods of numerical integration are not needed. If we make
 the output function into an integrator, the program step for
 computing output becomes (in C notation)

 qo = qo + ko*se*dt;

 where ko is an integration factor determining how much the output
 will change on each iteration for a given magnitude of error signal.
 The constant dt defines the physical time represented by one
 iteration of the program -- it should be set to 0.1 or 0.01
 initially, implying that you should use floating point variables. We
 will use 0.1 sec.

 The central part of a C program for implementing a control system
 would then be (starting with the computation of the perceptual signal
 sp):

 sp = ki*qi;
 se = sr - sp;
 qo = qo + ko*se*dt;
 qi = kf*qo + kd*qd;

 The disturbing, input, and feedback functions are replaced by
 constants kd, ki, and kf. For initial experimentation they can all be
 set to 1. Two variables have to be initialized before the first time
 this series of steps is used: qi and qo. Initializing to zero is
 sufficient. Two independent variables must also be set, sr and qd.
 Using these variables is described below.

 The diagram with constants in place of the general functions:
                                sr
                      sp        +|      se
                   -----------> (fc)----------->
                  |           -                 |
                  ki                       ko*integral(se)
                  |                             |
                  |                             |  CONTROL SYSTEM
 ---------------  | --------------------------- | -------------
                 qi <------------kf<---------- qo   ENVIRONMENT
                  ^
                  |
                  kd
                  ^
                  |
                 qd



 The general flow chart of the program

 1. Initialize variables qo and qi.

 2. Input or set constants ki, kf, kd, and ko.

 3. Input or set the values of the reference signal sr and the
    disturbing quantity qd.

 4. Execute the four program steps above.

 5. Plot or print the values of variables of interest.

 6. Return to step 4 until the desired number of iterations is
    finished. If dt = 0.1, 25 iterations will show 2.5 seconds of
    behavior.

 An alternative is to pre-record an array of values for the reference
 signal or the disturbing quantity or both, and step through this
 array as the iterations proceed. In that case step six would involve
 returning to step 3, and step 3 would advance pointers to the arrays
 of values for sr or qd or both. Below we will use still another way
 of showing the effects of changes in sr and qd.

            Exploring a control system using the model

 /* A SAMPLE PROGRAM IN C: */

 #include "stdio.h"

 void main()
  {
 float sp = 0.0,sr = 20.0,se = 0.0,qo = 0.0,qi = 0.0, qd = 0.0;
 float kd = 1.0,ki = 1.0,ko = 8.0, kf = 1.0, dt = 0.1;
 int i;

 /* you may put statements here to input values of the k-constants */
 printf("\n");
  for(i=0;i<25;++i)
   {
    if(i > 12) qd = 10.0; else qd = 0.0;
    qi = kf*qo + kd*qd;
    sp = ki*qi;
    se = sr - sp;
    qo = qo + ko*se*dt;
    printf(
    "\x0d\x0a qd=%6.2f qi=%6.2f qo=%6.2f sp=%6.2f sr=%6.2f se=%6.2f",
    qd,qi,qo,sp,sr,se);
   }
  (void) getch(); /* pause to view; press key to exit */
 }
 ---------------------------------------------------------------
 In this program, the disturbance remains at zero for the first 12
 iterations, and then jumps to 10.0 for the last 13. The resulting
 table will just fill the screen. You will see the input quantity and
 perceptual signal rise quickly to 20 units, to equal the reference
 signal's setting, and then briefly be disturbed when the disturbing
 quantity changes from 0 to 10. The perceptual signal sp will then
 return within half a second (5 iterations) to the reference value
 again.

 Illuminating experiments with the program

 There are several basic rules of thumb that can be demonstrated with
 this program. The first is the maxim that control systems control
 their own perceptual signals, not the input quantity and not their
 own outputs.

 First, run the program and note that the perceptual signal sp, the
 input quantity qi, and the output quantity qo all rise to 20.0 just
 before the disturbance enters. Note that after the disturbance
 appears, the output drops from 20.0 to 10.0 units; this is because
 the disturbance is trying to make the perceptual signal too large;
 the output automatically drops by the amount needed to bring the
 perceptual signal sp back down to 20.0. The control system clearly
 does not control to produce a specific output. The output quantity
 changes as the disturbing quantity changes.

 Because the input function is a multiplier of 1, the input quantity
 qi and the perceptual signal sp are numerically equal. Change the
 input constant ki from 1.0 to 0.5 and compile and run the program
 again (to save time you may want to insert some lines to read in ki,
 kf, ko, and kd from the keyboard). Intuitively one might expect that
 halving the input sensitivity would halve the perceptual signal. But
 this is a closed-loop system, and that is not what happens.

 The perceptual signal still rises to match the reference signal's
 value of 20.0, although more slowly than before. The input quantity,
 however, rises nearly to 40. It must do this because we have reduced
 the effect of the input quantity on the reference signal -- the input
 quantity must be greater to produce the former amount of perceptual signal.
 This shows that changing the input function alters the input
 quantity, but does not alter the perceptual signal's final value.
 Note also that the output quantity has risen to 40.0 units, as it
 must do to bring the perceptual signal to the reference value of
 20.0. The control system treats a change in the input function as
 just another disturbance, and alters its output to counteract the
 change in the perceptual signal. Both the output quantity qo and the
 input quantity qi are altered by this change in parameter, but the
 final value of the perceptual signal sp is not altered.

 Now restore the input constant ki to 1.0, and change the feedback
 constant kf to 0.5. Note that the output quantity now becomes 40
 instead of 20 as before, while the perceptual signal still rises to
 the same value as the reference signal, 20.0 units. This shows that
 changes in the feedback function will change the final value of the
 output quantity, but not the final value of the input quantity or
 perceptual signal.

 Finally, if you alter the output integration factor ko, you will see
 a change in the speed with which errors are corrected, but the final
 states of all the variables are unaffected. CAUTION: keep the product
 ko*kf*ki*dt less than 1.0. If you make it equal to 1.0 or larger, a
 computer artifact will be introduced and the system will become
 unstable. You can try it to see what "unstable" means, but this is
 not true instability. It's caused by the fact that we're simulating a
 continous system on a digital computer. On an analogue computer this
 kind of instability would not happen, because "dt" is infinitesimal.

 The integration factor is initialized to 8.0. If you use smaller
 values, the computation will remain stable.

 To sum up, when we change the disturbance, the input function, the
 feedback function, or the output function, the perceptual signal
 always returns to a match with the reference signal as long as the
 control system is still working. The only variable that remains under
 control under all these changes in conditions is the perceptual
 signal. That is why we say that control systems control their own
 perceptual signals and not their outputs. They can be said to control
 their input quantities only if the form of the input function does
 not change.

 You may have noticed that when you alter a function, the resulting
 change in the final state of the system variables is not at the
 output of that function but at the input. Changing the input function
 ki does not alter the final value of the output of that function, sp,
 but the input to that function, qi. Changing the feedback function kf
 does not alter the quantity qi, but the quantity qo at the input of
 the feedback function. Causation appears to be working backward.
 Furthermore, the effect of a change is opposite to the direction of
 the change. By halving ki, we caused the final value of qi to double;
 by halving the feedback factor kf, we caused the final value of qo to
 double.

 These strange reversals of causation are typical of control systems,
 and account for most of the difficulty people have in understanding how
 different control systems are from straight-through systems in
 which causation works in the direction we expect. Of course causation
 has not really been reversed here, but the feedback effects make it
 seem that it has.

 Relationship of disturbance to output

 Restore ki and kf to 1.0 and ko to 8.0, recompile, and run. When the
 disturbing quantity jumps from 0 to 10.0 in the middle of the run,
 look at the resulting change in the output quantity. It changes from
 20.0 to 10.0. This relationship is not accidental. The effect of the
 disturbing quantity on the input quantity is just cancelled by the
 change in the effect of the output quantity on the input quantity. 10
 units of disturbance is cancelled by -10 units of change in the
 output quantity.

 Now double the constant representing the disturbance function (change
 kd from 1.0 to 2.0). This doubles the effect of a given change in the
 disturbing quantity on the input quantity. Recompile and run.

 As usual, the perceptual signal returns to 20.0 after the
 disturbance. But look at the output quantity: it drops from 20.0 to
 0.0 when the disturbance turns on. Now a 10-unit change in the
 disturbing quantity results in a negative 20-unit change in the
 output quantity. The reason? One unit of disturbance now has twice as
 much effect on the input quantity as one unit of output from the
 control system. Result: twice as much output is now needed to
 counteract the same disturbance. That is what happens. It happens not
 because something "knows" that twice as much output is needed, but
 simply as the natural result of the operation of the control system.

 The "behavioral illusion"

 If we consider just the disturbing quantity and the output quantity,
 we can see that there is an apparent direct relationship between
 them. It looks as though changing the disturbing quantity causes the
 output quantity to change. If we didn't know about the input quantity
 qi, we might well think that the system was sensing the disturbing
 quantity directly, and responding by altering its output quantity. It
 looks as if a change in the disturbing quantity is a stimulus, which
 causes a response in the form of a change in the output quantity.

 Of course we can see that this relationship holds only because of the
 input quantity and the fact that the perceptual signal is being
 maintained at a particular value. The apparent stimulus would alter
 the input quantity if it were the only influence. But it does not
 alter the input quantity (for long) because the output changes to
 have an equal and opposite effect on the input quantity. That is the
 true explanation of the relationship between the remote disturbing
 quantity and the output action of the system. The appearance of
 stimulus and response is an illusion. There can be, of course, true
 stimulus-response organizations. But an apparent stimulus-response
 relationship is an illusion when the behaving system is really a
 control system.
 Effect of the reference signal

 Right after the bracket following the "for" statement, insert this
 line of code:

 if(i>5 && i < 20) sr = 20.0 else sr = 5.0;

 Recompile and run. Now the reference signal begins at 5.0, and rises
 to 20.0 halfway through the first part of the run. Then the
 disturbance is turned on. Halfway through the second part of the run,
 with the disturbance still present, the reference signal returns to
 5.0.

 Just follow the behavior of the perceptual signal. You will see that
 it rises quickly to 5.0, then rises again to 20.0 before the
 disturbance occurs. When the disturbance rises to 10.0 there is a
 brief excursion of the perceptual signal which immediately returns to
 20.0. Then when the reference signal drops to 5.0 again, so does the
 perceptual signal.

 In fact, the perceptual signal tracks the reference signal in terms
 of magnitude. The reference signal determines the value to which the
 perceptual signal will be brought initially, and at which it will be
 maintained, even if disturbances occur. By varying the reference
 signal, we can make the control system produce physical effects in
 the environment that result in corresponding variations in the
 perceptual signal. Even if disturbances come and go, and even if the
 feedback function and input function characteristics change (over
 some range), the system will still produce just the output needed to
 control the perception at the specified level.

 This is why we identify the reference signal with the commonsense
 notions of intention and purpose.

 Dynamic considerations

 During the program run, the output quantity of the system becomes
 whatever it must be to keep sp matching sr, for all combinations of
 qd and sr. Immediately after sudden changes in these independent
 variables there is an error, but the error is soon corrected --
 sooner if ko is larger.

 In real environments, physical variables can't jump instantly from
 one state to another. Normally the changes are smooth; they are also
 slow enough to allow control processes to begin changing before the
 environmental changes have gone to completion. To illustrate this,
 change the line in the program

    if(i > 12) qd = 10.0; else qd = 0.0;

 to

   if(i >= 5 && i < 15) qd = qd + 1;
 In C this could be shortened but this will work in all languages. The
 effect is to make the disturbance change smoothly instead of in one
 jump.

 Also, "comment out" the line that alters the reference signal sr, or
 delete it. Compile and run.

 Now the perceptual signal sr rises quickly to the default reference
 level of 20.0. When the ramp disturbance begins, it rises slightly
 above 20.0 and remains there until the ramp levels out; then it
 returns quickly to 20.0 again. You will notice the output quantity
 changing during the change in the disturbance.

 If you reduce ko to slow the system, you will find that the ramp
 disturbance has a greater effect. The amount of effect that a
 disturbance has depends on how rapidly it changes in comparison with
 the control system's speed of error-correction.

 By reducing the time interval dt to 0.01 and raising ko to 80, you
 could make the control system work 10 times faster and reduce the
 effect of the disturbing ramp by a factor of 10. You would, however,
 need 10 times as many iterations to cover the same period of 2.5
 seconds, and this would not fit on the screen. If you want to see
 this effect, change the print statement so it prints to the printer,
 and change the limit of the "for" statement to 250. If you can
 program graphics, you could plot these variables on the screen and
 see the behavior in much more detail without using 5 pages of paper.

 ------------------------------------------------------------------
 NOTE: I would appreciate it if programmers versed in BASIC, Pascal,
 and other languages would write versions of the above program, test
 them, and transmit them to me for inclusion in an appendix to this
 primer. Programs should be as generic as possible so as to run on as
 many computers as possible. I especially need versions for mainframes
 and workstations. In the future I will simplify the program and make
 it easier for the user to change parameters from the keyboard. For
 now, I hope that all programmers and would-be programmers will try
 the program as it stands and learn from it, even if you have to get
 some help from a 14-year-old. As this primer evolves I will post
 revisions and again ask for your help.
 ------------------------------------------------------------------
 Best,

 Bill P.