home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / control / demomarsyas.m < prev    next >
Text File  |  1999-03-05  |  4KB  |  117 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. page_screen_output = 1;
  18. opt = 0;
  19. QUITOPT = 7;
  20. while (opt != QUITOPT)
  21.   opt = menu("Marsyas interface update demo:", ...
  22.     "run Marsyas on the magnetically suspended ball example", ...
  23.         "load continuous time marsyas example system", ...
  24.     "load discrete-time marsyas example system", ...
  25.     "bode plot of loaded system (MIMO)", ...
  26.         "bode plot of loaded system (SISO)", ...
  27.     "Design example", ...
  28.     "Quit");
  29.  
  30.   if(opt == 1)
  31.     cmd = "system(""marsyas mag1d.mar"")";
  32.     run_cmd
  33.     cmd = "system(""marplot -i"")";
  34.     run_cmd
  35.   elseif(opt == 2)
  36.     cmd = "ballsys = margetsys();";
  37.     run_cmd;
  38.     cmd = "sysout(ballsys);"
  39.     run_cmd
  40.   elseif(opt == 3)
  41.     cmd = "ballsys = margetsys(""disc"");";
  42.     run_cmd
  43.     cmd = "sysout(ballsys);"
  44.     run_cmd
  45.   elseif(opt == 4)
  46.     cmd = "bode(ballsys);";
  47.     run_cmd
  48.   elseif(opt == 5)
  49.     cmd = "bode(ballsys,[],1,1);";
  50.     run_cmd
  51.   elseif(opt == 6)
  52.     if(!exist("ballsys"))
  53.       warning("You didn't load a system yet (option 2 or 3)");
  54.     else
  55.       disp("Design LQG controller");
  56.       cmd = "sysout(ballsys)";
  57.       run_cmd
  58.       disp("add noise inputs to system...")
  59.       if(ballsys.n)
  60.         disp("continuous system:")
  61.         cmd = "ballsys1 = sysappend(ballsys,eye(ballsys.n));";
  62.       else
  63.         disp("discrete system:")
  64.         cmd = "ballsys1 = sysappend(ballsys,eye(ballsys.nz));";
  65.       endif
  66.       run_cmd
  67.       cmd = "sysout(ballsys1)";
  68.       run_cmd
  69.       disp("Notice the two additional inputs, u_2, and u_3.  These are the ");
  70.       disp("""entry points"" for the gaussian noise disturbance.");
  71.       disp(" ");
  72.       disp("We'll design the controller to use only position feedback:")
  73.       cmd = "ballsys1=sysprune(ballsys1,1,[]);";
  74.       run_cmd
  75.       cmd = "sysout(ballsys1)";
  76.       run_cmd
  77.       disp("Now design an LQG controller: Sigw: input noise")
  78.       Sigw = eye(2)
  79.       disp("Now design an LQG controller: Sigv: measurement noise")
  80.       Sigv = eye(rows(ballsys1.c))
  81.       disp("State and input penalties:")
  82.       Q = eye(2)
  83.       R = 1
  84.       disp("Controlled input is input 1");
  85.       cmd="Ksys = lqg(ballsys1,Sigw,Sigv,Q,R,1);";
  86.       run_cmd
  87.       disp("sysout(Ksys);");
  88.       sysout(Ksys);
  89.       
  90.       disp("marsyas conversion: output in scalar form:")
  91.       cmd = "maroutsys(Ksys, ""ball_controller"",""scalar"");";
  92.       run_cmd
  93.       disp("here's the output file:")
  94.       prompt
  95.       system("more ball_controller.mar");
  96.       
  97.       disp("marsyas conversion: output in state space form: (default option;")
  98.       disp("the ""ss"" in the command below is not needed)")
  99.       cmd = "maroutsys(Ksys, ""ball_controller_ss"",""ss"");";
  100.       run_cmd
  101.       disp("here's the output file:")
  102.       prompt
  103.       system("more ball_controller_ss.mar");
  104.       
  105.       disp("marsyas conversion: output in transfer function form:")
  106.       cmd = "maroutsys(Ksys, ""ball_controller_tf"",""tf"")"
  107.       run_cmd
  108.       disp("here's the output file:")
  109.       prompt
  110.       system("more ball_controller_tf.mar");
  111.   
  112.     endif
  113.   endif
  114. endwhile
  115.