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

  1. function [ac,bc,cc,dc] = reg(a,b,c,d,k,l,e,f,g)
  2. %REG Form continuous LQG controller.
  3. %    [Ac,Bc,Cc,Dc] = REG(A,B,C,D,K,L) produces the LQG controller based
  4. %    on the continuous system (A,B,C,D) with feedback gain matrix, K,
  5. %    and Kalman gain matrix L, assuming all the inputs of the system 
  6. %    are control inputs and all the outputs of the system are sensor 
  7. %    outputs.  The resulting state-space controller is
  8. %         .
  9. %        xHat = [A-BK-LC+LDK] xHat + Ly
  10. %        uHat = [K] xHat
  11. %
  12. %    and has control feedback commands uHat as outputs and sensors y as
  13. %    inputs.  The controller should be connected to the plant using 
  14. %    negative feedback.
  15. %
  16. %    [Ac,Bc,Cc,Dc] = REG(A,B,C,D,K,L,SENSORS,KNOWN,CONTROLS) forms the
  17. %    LQG controller using the sensors specified by SENSORS, the 
  18. %    additional known inputs specified by KNOWN, and the control inputs
  19. %    specified by CONTROLS. The resulting system has control feedback
  20. %    commands as outputs and the known inputs and sensors as inputs. 
  21. %    The KNOWN inputs are non-stochastic inputs of the plant and are 
  22. %    usually additional control inputs or command inputs.
  23. %
  24. %     See also: DREG,ESTIM,DESTIM,LQR,DLQR,LQE and DLQE.
  25.  
  26. %    Clay M. Thompson 6-29-90
  27. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  28.  
  29. error(nargchk(6,9,nargin));
  30. if ~((nargin==6)|(nargin==9)), error('Wrong number of input arguments.'); end
  31.  
  32. error(abcdchk(a,b,c,d));
  33.  
  34. [nx,na] = size(a);
  35. [ny,nu] = size(d);
  36.  
  37. if (nargin==6)
  38.   sensors = [1:ny]; known = []; controls = [1:nu];
  39. end
  40. if (nargin==9)
  41.   sensors = e; known = f; controls = g;
  42. end
  43.  
  44. nsens = length(sensors); nknown = length(known); nfb = length(controls);
  45.  
  46. % Check size of K and L with number of states, sensors and controls
  47. [nk,mk] = size(k); [nl,ml] = size(l);
  48. if (nk~=nfb)
  49.   error('Number of controls and size of K matrix don''t match.'); end
  50. if (mk~=nx)
  51.   error('The A and K matrices must have the same number of columns.'); end
  52. if (ml~=nsens)
  53.   error('Number of sensors and size of L matrix don''t match.'); end
  54. if (nl~=nx)
  55.   error('The A and L matrices must have the same number of rows.'); end
  56.  
  57. fdbk = [1:nfb] + ny; inputs = [1:nsens] + nu;
  58.  
  59. % --- Form continuous LQG controller ---
  60. ac = a;
  61. bc = [b,l];
  62. cc = [c;k];
  63. dc = [d, zeros(ny,nsens);zeros(nfb,nu), zeros(nfb,nsens)];
  64.  
  65. % close sensor and internal control feedback loops
  66. [ac,bc,cc,dc] = cloop(ac,bc,cc,dc,[fdbk,sensors],-[controls,inputs]);
  67. [ac,bc,cc,dc] = ssselect(ac,bc,cc,dc,[known,inputs],fdbk);
  68.