two layer system

Bill,

More of my fumbling with email. This time there ought to be something in h2.pas.

Unless I'm mistaken a single level system can not, however high the gain,
generate a condition of zero steady state error. What I intended the two level
system to demonstrate was the use of two low gain componates to create a
composite unit with effectively infinite gain. I won't know untill I have a
demo running, but I think there is a class of problems to which a simple two
layer control system can be applied.

Bill

···

______________________________________________________________________
Do you want a free e-mail for life ? Get it at http://www.email.ro/

program h2; (* two level control Bill Williams 6 August 2001 *)
     uses
       dos, crt, graph, grutils;

  var
        ch,

    e, r, p, inter_L : real;
      g, d, o, s : real;

    ee, rr, gg, inter_U, ss, oo : real;

    gain, slow, damping : real;
    cycle, b, bes, be, bi, bg, cl, bl : real;
    step, length, jump : real;
    key : char;
    i, c, rep, space, count : integer;

    gain_str : string;

procedure controller;
    begin

        { upper level loop }
        ee := rr - p;
        inter_U := ee * gg;
        oo := oo + ( inter_U - oo )/ss;
        r := r + oo/30;

        { lower level loop }
        e := r - p;
        inter_L := e * g;
        o := o + ( inter_L - o )/s;
        p := o + d;

      end;

procedure display1;
   begin

     putpixel(hcenter - round(p), count, lightred);
     putpixel(hcenter - round(r), count, yellow );
     putpixel(hcenter - round(o), count, lightgreen);
     putpixel(hcenter - round(D), count, brown);

     setcolor(lightgray);
     line(319,1,319,479);
     line(321,1,321,479);

     outtextXY(350,10, 'Perception: lightred');
     outtextXY(350,20, 'Output: lightgreen');
     outtextXY(350,30, 'Disturbance: brown');
     outtextXY(350,40, 'Lower level reference: yellow');
     setcolor(black);
     outtextXY(550,50,gain_str);
     str(g:0:0,gain_str);
     setcolor(lightgray);
     outtextXY(350,50, 'Gain lower level loop = ');
     outtextXY(550,50,gain_str);

     outtextXY(10,10, 'Press any key to run. ');
     outtextXY(10,20, 'Press 1 to increase disturbance.');
     outtextXY(10,30, 'Press ! to decreaese disturbance.');
     outtextXY(10,40, 'Press q to quit. ');

    end;

  procedure set_variable_values;
     begin

       ch := 0;
       rr := 0;
       gg := 3;
       ss := 20;
       d := 0;
       g := 10;
       s := 50;
       r := 0;
     end;

begin
     initgraphics;
     set_variable_values;
     count := 1;

     setcolor(lightgray);
     line(319,1,319,479);
     line(321,1,321,479);

repeat
          controller; (* Consumption and Budget control loops *)
            display1;

      key := readkey;

      case key of
       '1' : D := D - 5;
       '!' : D := D + 5;
       'g' : g := g - 1;
       'G' : G := G + 1;
       'c' : clearviewport;
       end;
       inc(count);

       if count > 479 then count := 1;

     until key in ['q','Q'];
   closegraph;
end.