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

  1. # Copyright (C) 1996,1998 Kai Mueller
  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. #
  10. # Octave is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13. # for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Octave; see the file COPYING.  If not, write to the Free
  17. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. # ------------------------------------------------------------
  20. # dhinfdemo   Design of a discrete H_infinity controller.
  21. #             This is not a true discrete design. The design
  22. #             is carried out in continuous time while the
  23. #             effect of sampling is described by a bilinear
  24. #             transformation of the sampled system.
  25. #             This method works quite well if the sampling
  26. #             period is "small" compared to the plant time
  27. #             constants.
  28. #
  29. # This is a script file for OCTAVE.
  30. # ------------------------------------------------------------
  31. #
  32. # continuous plant:
  33. #                 1
  34. #    G(s) = --------------
  35. #           (s + 2)(s + 1)
  36. #
  37. # discretised plant with ZOH (Sampling period = Ts = 1 second)
  38. #
  39. #               0.39958z + 0.14700
  40. #    G(s) = --------------------------
  41. #           (z - 0.36788)(z - 0.13533)
  42. #
  43. #                             +----+
  44. #        -------------------->| W1 |---> v1
  45. #    z   |                    +----+
  46. #    ----|-------------+                   || T   ||     => min.
  47. #        |             |                       vz   infty
  48. #        |    +---+    v      +----+
  49. #        *--->| G |--->O--*-->| W2 |---> v2
  50. #        |    +---+       |   +----+
  51. #        |                |
  52. #        |    +---+       |
  53. #        -----| K |<-------
  54. #             +---+
  55. #
  56. #    W1 and W2 are the robustness and performancs weighting
  57. #       functions
  58.  
  59. # K. Mueller, <mueller@ifr.ing.tu-bs.de>
  60. # Technical University of Braunschweig, IfR
  61.  
  62. echo off
  63. disp(" ");
  64. disp("    --------------------------------------------------");
  65. disp("    Discrete H_infinity optimal control for the plant:");
  66. disp(" ");
  67. disp("                       0.39958z + 0.14700");
  68. disp("            G(s) = --------------------------");
  69. disp("                   (z - 0.36788)(z - 0.13533)");
  70. disp("    --------------------------------------------------");
  71. disp(" ");
  72.  
  73. disp("sampling time:")
  74. cmd = "Ts = 1.0;";
  75. disp(cmd);
  76. eval(cmd);
  77. disp("weighting on actuator value u");
  78. cmd = "W1 = wgt1o(0.1, 200.0, 50.0);";
  79. disp(cmd);
  80. eval(cmd);
  81. disp("weighting on controlled variable y");
  82. cmd = "W2 = wgt1o(350.0, 0.05, 0.0002);";
  83. disp(cmd);
  84. eval(cmd);
  85. # omega axis (column vector)
  86. ww = vec(logspace(-4.99, 3.99, 100));
  87.  
  88. disp("Create ZOH equivalent model of a continuous plant");
  89. cmd = "G = tf2sys(2,[1 3 2]);  Gd = c2d(G, Ts);";
  90. run_cmd
  91.  
  92. # w-plane (continuous representation of the sampled system)
  93. disp("W-plane transform of discrete time system:");
  94. cmd = "Gw = d2c(Gd, \"bi\");";
  95. run_cmd
  96.  
  97. disp(" ");
  98. disp(" o building P...");
  99. # need One as the pseudo transfer function One = 1
  100. cmd = "One = ugain(1);";
  101. disp(cmd);
  102. eval(cmd);
  103. cmd = " psys = buildssic([1 4;2 4;3 1],[3],[2 3 5],[3 4],Gw,W1,W2,One);";
  104. run_cmd;
  105. disp(" o controller design...");
  106. cmd = "[K, gfin, GWC] = hinfsyn(psys, 1, 1, 0.1, 10.0, 0.02);";
  107. run_cmd
  108.  
  109. disp(" ");
  110. fig_n = 1;
  111. yn = input(" * Plot magnitudes of W1KS and W2S? [n]: ","S");
  112. if (length(yn) >= 1)
  113.   if ((yn(1) == "y") || (yn(1) == 'Y'))
  114.     disp(" o magnitudes of W1KS and W2S...");
  115.     gwx = sysprune(GWC, 1, 1);
  116.     mag1 = bode(gwx, ww);
  117.     if (columns(mag1) > 1);  mag1 = mag1';  endif
  118.     gwx = sysprune(GWC, 2, 1);
  119.     mag2 = bode(gwx, ww);
  120.     if (columns(mag2) > 1);  mag2 = mag2';  endif
  121.     figure(fig_n)
  122.     fig_n = fig_n + 1;
  123.     gset grid
  124.     loglog(ww, [mag1 mag2]);
  125.   endif
  126. endif
  127.  
  128. Kd = c2d(K, "bi", Ts);
  129. GG = buildssic([1 2; 2 1], [], [1 2], [-2], Gd, Kd);
  130. disp(" o closed loop poles...");
  131. damp(GG);
  132.  
  133. disp(" ");
  134. yn = input(" * Plot closed loop step responses? [n]: ","S");
  135. if (length(yn) >= 1)
  136.   if ((yn(1) == "y") || (yn(1) == 'Y'))
  137.     disp(" o step responses of T and KS...");
  138.     figure(fig_n)
  139.     step(GG, 1, 10);
  140.   endif
  141. endif
  142.  
  143. # --------- End of dhinfdemo/kpm
  144.