home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / susball.m < prev    next >
Text File  |  1999-03-05  |  3KB  |  96 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17.     cmd = "ballsys = margetsys(""disc"")";
  18.     eval(cmd);
  19.     
  20.     disp("Design LQG controller");
  21.     cmd = "sysout(ballsys)";
  22.     run_cmd
  23.     disp("add noise inputs to system...")
  24.  
  25.     disp("discrete system:")
  26.     [nn,nz,mm,pp] = sysdimensions(ballsys);
  27.     cmd = "ballsys = sysappend(ballsys,nz);";
  28.     run_cmd 
  29.  
  30.     cmd = "sysout(ballsys)";
  31.     run_cmd
  32.  
  33.     disp("Notice the two additional inputs, u_2, and u_3.  These are the ");
  34.     disp("""entry points"" for the gaussian noise disturbance.");
  35.     disp(" ");
  36.     disp("We'll design the controller to use only position feedback:")
  37.  
  38.     cmd = "ballsys=sysprune(ballsys,1,[]);";
  39.     run_cmd
  40.     cmd = "sysout(ballsys)";
  41.     run_cmd
  42.  
  43.     disp("Now design an LQG controller: Sigw: input noise")
  44.     Sigw = eye(2)
  45.     disp("Now design an LQG controller: Sigv: measurement noise")
  46.     Sigv = eye(pp);
  47.  
  48.     disp("State and input penalties:")
  49.     Q = eye(2)
  50.     R = 1
  51.     disp("Controlled input is input 1");
  52.  
  53.     cmd="Ksys = lqg(ballsys,Sigw,Sigv,Q,R,1);";
  54.     run_cmd
  55.  
  56.     disp("sysout(Ksys);");
  57.     sysout(Ksys);
  58.  
  59.     disp("\nGet rid of the disturbance inputs");
  60.     cmd = "ballsys = sysprune(ballsys,1,1);"
  61.     run_cmd;
  62.     sysout(ballsys);
  63.     sysout(ballsys,"zp");
  64.  
  65.     disp("\nGrouping the plant and the controller");
  66.     cmd = "closed_loop = sysgroup(ballsys,Ksys);"
  67.     run_cmd;
  68.     sysout(closed_loop);
  69.  
  70.     disp("\nduplicating the plant input");
  71.     cmd = "closed_loop = sysdup(closed_loop,[],1);"
  72.     run_cmd;
  73.     sysout(closed_loop);
  74.  
  75. #    disp("\nscaling the duplicated input by -1");
  76. #    cmd = "closed_loop = sysscale(closed_loop,[],diag([1,1,1]));"
  77. #    run_cmd;
  78. #    sysout(closed_loop);
  79.  
  80.     disp("\nconnecting plant output to controller input and controller output");
  81.     disp("to the duplicated plant input");
  82.     cmd = "closed_loop = sysconnect(closed_loop,[1 2],[2 3]);"
  83.     run_cmd;
  84.     sysout(closed_loop);
  85.  
  86.     disp("\nkeeping only the original plant input and plant output");
  87.     cmd = "closed_loop = sysprune(closed_loop,1,1);"
  88.     run_cmd;
  89.     sysout(closed_loop);
  90.  
  91.     sysout(closed_loop,"zp");
  92.  
  93.  
  94.