home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS2.DI$ / HIMAT_X1.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  11.7 KB  |  332 lines

  1.  echo on
  2. %
  3. %    himat_x1
  4. %
  5. %  This MATLAB script file is an example of how to design H-infinity 
  6. %   and mu-synthesis control laws, as applied to pitch axis control 
  7. %   for HIMAT. The purpose of this MATLAB script is to familiarize the
  8. %   user with the MATLAB function files developed for control design
  9. %   in this toolbox.
  10. %
  11. %   These control designs will be compared with a loop-shaping 
  12. %   control design using singular values, mu-analysis tools, the
  13. %   output sensitivity, input complementary sensitivity
  14. %   transfer functions, and time domain responses to step functions.
  15. %   
  16. %
  17. %   The files are set up as follows:
  18.  
  19.  pause    % strike any key to continue
  20. %                                           
  21. %                                              
  22. %   himat_x1    setup file for H-infinity control design, first 
  23. %               mu-synthesis iteration.
  24. %   himat_x2    second iteration of mu-synthesis using d-scales 
  25. %               from himat_x1.
  26. %   himat_x3    third iteration of mu-synthesis using d-scales 
  27. %               from himat_x2.
  28. %   himat_x4     fourth and final iteration of mu-synthesis
  29. %   himat_x5    comparing mu-synthesis control law with loop-shaping 
  30. %               design using singular values and mu.
  31. %   himat_x6    time domain analysis of both control laws.
  32.  
  33.  pause   % strike any key to continue
  34. clc
  35.  
  36. % First load the state space description of the HIMAT plane.
  37. %  This matrix is described in the manual. The states of the
  38. %  plant model are: forward speed (v), angle-of-attack (alpha),
  39. %  pitch rate (q) and pitch angle (theta). The inputs 
  40. %  are the elevon position and the canard position. The outputs 
  41. %  that are to be kept small are angle-of-attack (alpha) and pitch 
  42. %  angle (theta).
  43.  
  44.  pause   % strike any key to continue
  45.  mkhimat;
  46.  minfo(himat)
  47.  
  48. %    Next construct the weights associated with the multiplicative
  49. %      input uncertainty, using the command ND2SYS
  50. %                             50(s+100)
  51. %                   wdel  =   ---------
  52. %                             (s+10000)
  53.  
  54. wdel = nd2sys([50,5000],[1,10000]);
  55.  
  56. pause % strike any key to continue
  57. clc
  58.  
  59. %
  60. %    and the output error weight (performance),
  61. %             .5*(s+3)
  62. %       wp  =   --------
  63. %           (s+.03)
  64.  
  65. wp = nd2sys([0.5,1.5],[1,0.03]);
  66.  
  67. pause % strike any key to continue
  68. clc
  69.  
  70. %  Do a frequency_response of each weight and plot them on
  71. %   the same graph for comparison purposes. Evaluate each transfer
  72. %   function from 1e-4 to 1e+4 for a total of 40 points.
  73. %   On the graph the solid line is the uncertainty weight and
  74. %   the dashed line is the performance weight.
  75.  
  76.  om1 = logspace(-3,3,40);     % frequency vector
  77.  wdelg = frsp(wdel,om1);      % frsp of disturbance weight
  78.  wpg = frsp(wp,om1);          % frsp of performance weight
  79.  wghts = sbs(wdelg,wpg);      % place responses "side-by-side"
  80.  clg;
  81.  vplot('liv,lm',wghts);
  82.  echo off;
  83.  title('Uncertainty Weight and Performance Weight for HIMAT');
  84.  xlabel('Frequency (rad/s)');
  85.  ylabel('Magnitude');
  86.  pause   % strike any key to continue
  87.  clear wdelg wpg wghts
  88.  echo on;
  89.  pause   % strike any key to continue
  90.  
  91. %  Construct a two input/two-output weight for both the 
  92. %   uncertainty weight, WDEL and the output error weight,
  93. %   WP. These weights are associated with each channel 
  94. %   of the multivariable system. Each weight has 2 states, 
  95. %   2 inputs and 2 outputs as one can see using MINFO.
  96.  
  97.  wdel = daug(wdel,wdel);
  98.  wp = daug(wp,wp);
  99.  minfo(wdel)
  100.  minfo(wp)
  101.  pause   % strike any key to continue
  102.  
  103. %  Now that the plant and the weights have been defined, 
  104. %   construct the interconnection structure, HIMAT_IC, 
  105. %   based on the diagram provided. A MATLAB function file, 
  106. %   HIMATIC, has been written to do this for you.
  107. %   SYSIC is used to formulate the interconnection structure.
  108. %   HIMAT_IC has 8 states, 6 inputs and 6 outputs. The 
  109. %   first two inputs and outputs [1 2] correspond to the 
  110. %   multiplicative input uncertainty block, 
  111. %   the second two inputs and outputs [3 4] correspond to
  112. %   the disturbance inputs and error outputs. Inputs and 
  113. %   outputs [5 6] are the measurements and controls being 
  114. %   sent to and received from the controller.
  115.  
  116.  himatic
  117.  minfo(himat_ic)
  118.  clear wp wdel 
  119.  pause   % strike any key to continue
  120.  
  121. % The next step is to design a H-infinity control law for HIMAT.
  122. %  The function HINF designs a H-infinity control law based
  123. %  on the interconnection structure provided. HINF requires 
  124. %  the system interconnection structure (p), number of 
  125. %  measurements (nmeas), number of controls (ncon), a lower bound on 
  126. %  gamma (gmin), an upper bound on gamma (gmax), a tolerance for 
  127. %  the  gamma iteration (tol)  and which method to use in solving 
  128. %  the Riccati equations (ricmethd). Optional input arguments are the
  129. %  epsilon for Hamiltionian jw-axis eigenvalues (epr) and the epsilon
  130. %  for the Riccati solution positive definite tests (epp).  The two 
  131. %  methods are via eigenvalue or Schur  decomposition. HINF returns 
  132. %  the control law, k, the closed loop system, g, and the gamma 
  133. %  value achieved, gf.
  134. %
  135. %      [k,g,gf]=hinfsyn(p,nmeas,ncon,gmin,gmax,tol,ricmethd,epr,epp)
  136.  
  137.  pause   % strike any key to continue
  138.  
  139. % In this example, the system interconnection structure is 
  140. %  HIMAT_IC, with 2 measurements, 2 controls, a gamma low of 0.8, 
  141. %  gamma upper of 6, a tolerance on the gamma iteration of .1, 
  142. %  and we'll use the Schur decomposition method (2) to solve the 
  143. %  Riccati equations. The default values of epr (1e-10) and epp (1e-6)
  144. %  will be used for the epsilon tests.
  145.  
  146.  [k1,g1,gf1]=hinfsyn(himat_ic,2,2,0.8,6,0.05,2);
  147.  
  148. % A H-infinity control law has been designed which achieves an
  149. %  infinity norm of 1.6938 for the interconnection structure
  150. %  provided. First, we will examine aspects of the controller
  151. %  that was just designed, starting with the controller POLES.
  152.  
  153. rifd(spoles(k1))
  154. pause % strike any key to continue 
  155. clc
  156.  
  157. %  Next, a magnitude plot of the frequency response of k1
  158.  
  159. om2=logspace(0,4,16);
  160. k1_g = frsp(k1,om2);
  161. vplot('liv,lm',k1_g)
  162. echo off
  163. title('Magnitude plot of controller, k1')
  164. xlabel('strike any key to continue')
  165. pause
  166. echo on
  167. pause   % strike any key to continue
  168. format short e
  169. clc
  170.  
  171. %  Onto the closed loop, first checking that it is stable.
  172. %   Use the command SPOLES and RIFD.
  173.  
  174.  rifd(spoles(g1))
  175.  pause   % strike any key to continue
  176.  
  177. %  Now calculate a closed loop frequency response. This results in
  178. %  a 4x4 varying matrix G1G
  179.  
  180.  g1g=frsp(g1,om2);
  181.  
  182. %  Next, find the peak norm of the frequency response, using
  183. %   PKVNORM. This corresponds to the maximum singular of the
  184. %   closed loop system.
  185.  
  186.  g1pk=pkvnorm(g1g);
  187.  echo off
  188.  fprintf( '\n final gamma %g, \n max singular value %g \n \n',gf1,g1pk)
  189.  echo on
  190.  g1gs=vsvd(g1g);
  191.  vplot('liv,m',g1gs)
  192.  echo off
  193.  title('Singular value plot of the H_infinity closed loop');
  194.  xlabel('Frequency (rad/s)');
  195.  ylabel('Magnitude');
  196.  grid;
  197.  pause
  198.  echo on
  199.  pause   % strike any key to continue
  200.  
  201. % The H-infinity control law can be analyzed using mu-analysis.
  202. %  The closed-loop system, G1, has 4 inputs and 4 outputs. 
  203. %  The first two inputs and outputs correspond to the 
  204. %  uncertainty block, and the second two correspond to the 
  205. %  disturbance rejection block, or performance block.
  206. %  Therefore, we can define the uncertainty inputs and outputs
  207. %  as a full 2x2 uncertainty block and the disturbance 
  208. %  rejection inputs and outputs as a full 2x2 performance 
  209. %  block. If the mu value for this control design is 1, then
  210. %  we are able to achieve robust performance 
  211. %  for the set of defined weights and this control design.
  212.  
  213.  pause   % strike any key to continue
  214.  
  215. %   mu  -  usage: [bnds,row_d,sens,row_p] = mu(matin,blk,'opt')
  216.  
  217. %  The mu-analysis program, MU, requires a frequency response
  218. %  or constant matrix and a block structure. In this example,
  219. %  the frequency response is G1G and the block structure is
  220. %  two, 2x2 full blocks. MU returns the upper and lower 
  221. %  bounds for mu in BNDS1, the frequency
  222. %  varying d-scales DV1, the rational perturbation which 
  223. %  destabilizes the closed-loop plant RP1 and the 
  224. %  sensitivity of mu to the d-scales SENS1.
  225.  
  226.  blk=[2 2;2 2];
  227.  [bnds1,dv1,sens1,rp1]=mu(g1g,blk);
  228.  
  229. % Plot the maximum singular value and mu on the same plot
  230. %   solid line - maximum singular value
  231. %   dashed line - mu
  232.  
  233.  both=sbs(sel(g1gs,1,1),bnds1);
  234.  vplot('liv,m',both)
  235.  echo off
  236.  title('Max. singular value and mu for the  H-infinity Control Law');
  237.  xlabel('Frequency (rad/s)');
  238.  ylabel('Magnitude');
  239.  grid;
  240.  pause   % strike any key to continue
  241.  echo on
  242.  
  243. % clear variables not used and pack the memory space 
  244. %  due to the limitations on the Mac and PC's.
  245.  
  246.  clear g1g g1gs both 
  247.  pack
  248.  
  249. % This concludes the H-infinity control design portion of this
  250. %   demonstration program. If all you wanted was the H-infinity 
  251. %   control law, you can stop here just type in the number 1.
  252. %   Otherwise, we'll precede with the first iteration of 
  253. %   mu-synthesis.
  254.  
  255. echo off
  256.  fini = input(' Enter the number 1 to stop this program ');
  257.  if fini == 1
  258.    return
  259.  end
  260. echo on
  261.  
  262. % Designing an H-infinity control law is the first step in 
  263. %   mu-synthesis. The next step is to fit the d-scales which
  264. %   are output from the MU program. The MUSYNFIT function
  265. %   is designed to fit the d-scales for each individual block. 
  266. %   If there are n full blocks in the mu-problem, n-1 d-scales 
  267. %   are fit, since the d-scales are normalized to make 
  268. %   the last one 1.
  269.  
  270.  pause   % strike any key to continue
  271.  
  272.  musynfit 
  273.  
  274. %  MUSYNFIT requires the left d-scale from the previous 
  275. %   mu-synthesis iteration (PRE_DSYSL), the d-scales from the 
  276. %   mu-analysis problem (DDATA), and the sensitivity of 
  277. %   the d-scales (SENS), along with the block
  278. %   structure (BLK), number of controller inputs (NMEAS) 
  279. %   and outputs (NCNTRL). Since this is the first mu-synthesis 
  280. %   iteration, the left d-scale is input as 'first'.
  281. %   This creates an identity matrix of the correct size for dsysl.
  282. %   Output from MUSYNFIT is the left d-scale (DSYSL) and  
  283. %   right d-scale (DSYSR) to be multiplied into the 
  284. %   interconnection structure.
  285.  
  286.  pause    % strike any key to continue
  287.  
  288. %   The previous d-scale is required since if new d-scales
  289. %   are continuously generated of a given order, the number
  290. %   of states in the interconnection structure will grow 
  291. %   dramatically with each iteration. Therefore, the
  292. %   previous d-scale is normalized output of the new 
  293. %   d-scale data, and the new d-scale is wrapped around
  294. %   the original interconnection structure.
  295. %   For the first iteration, there are no d-scales in the problem.
  296.  
  297. %   We recommend a a 3rd order transfer function. This increases 
  298. %   the number of states in the interconnection structure to
  299. %   3*(size of full block)*2. If one selects a different order
  300. %   for the d-scale weight, the gamma iteration will converge
  301. %   to a different value.
  302.  
  303.  [dsysl,dsysr]=musynfit('first',dv1,sens1,blk,2,2);
  304.  
  305. % Now, wrap the new d-scales around the original 
  306. %  interconnection structure.
  307. %
  308. %          himat_ic2 = dsysl*himat_ic*(dsysr)^-1
  309.  
  310.  pause    % strike any key to continue
  311.  himat_ic2=mmult(dsysl,mmult(himat_ic,minv(dsysr)));
  312.  
  313.  minfo(himat_ic2)
  314. echo off
  315.  clear a b c dsysr fini g1 g1pk
  316.  pack;
  317. echo on
  318.  
  319. % Thus ends the first iteration of mu-synthesis. Notice that 
  320. %   the new interconnection structure has 20 states, 12 more 
  321. %   states than the original interconnection structure. These 
  322. %   12  states are due the frequency varying d-scales which 
  323. %   were fit. (Note, this is if you fit the d-scales using a 
  324. %   3rd order system.)
  325.  
  326. %  Type in 'himat_x2' to continue the mu-synthesis iteration
  327. %    procedure.
  328. %
  329. % Copyright MUSYN INC 1991,  All Rights Reserved
  330.