%--------------------------------------------------------------------------
%
% PURPOSE: Compute gains for the Altex Sway/Yaw control loop.
% AUTHOR:  Rob McEwen
% DATE:    99/6/25
% ASSUMPTIONS: linear.m has been previously run.
%
%--------------------------------------------------------------------------
%
 if 1
%
%  Place the poles
   PP1 = [.7683 .98 .98 .99 .99]';
   K   = acker(PhiA, GammaA, PP1);
%
 else
%
%  LQ Design
   QQ = eye(5);
   RR = 1000;
   K = dlqr(PhiA, GammaA, QQ, RR)   
%
 end
%
 disp(' The closed-loop e-values are:')
 zrootinfo(PhiA-GammaA*K,Ts)
 ssloop = series(ssoldi,ss(0,0*K,0,K,Ts));
 [Gm Pm] = margin(ssloop);
 disp(sprintf(' Gain  Margin = %-15f dB', Gm))
 disp(sprintf(' Phase Margin = %-15f Degrees', Pm))
%
 Kvh = -K(1);
 Krh = -K(2);
 Kph = -K(4);
 Kiwp = -K(5)/Kph/Ts;
 Kwp  = -K(3)/Kph - Ts*Kiwp;
%
 disp(' The control gains are:')
 disp(sprintf(' Kph = %-15f', Kph))
 disp(sprintf(' Krh = %-15f', Krh))
 disp(sprintf(' Kvh = %-15f', Kvh))
 disp(sprintf(' Kwp = %-15f', Kwp))
 disp(sprintf(' Kiwp= %-15f', Kiwp))

