0% found this document useful (0 votes)
22 views16 pages

Assmt 2

Uploaded by

Siddharth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views16 pages

Assmt 2

Uploaded by

Siddharth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Question - 4.

Optimal Ouput Feedback Con-


troller Design
% ro is a scalar design parameter set to 0.1 %
ro = 0.1;

% Q and R are weight matrices for the quadratic cost function


Q = diag([50, 100, 100, 50, 0, 0, 1]);
R = ro* eye(2);

% A_init, B and C are open loop system paramters


A_init = [-0.322 0.064 0.0364 -0.9917 0.0003 0.0008 0; 0 0 1 0.0037
0 0 0; -30.6492 0 -3.6784 0.6646 -0.7333 0.1315 0; 8.5396 0 -0.0254
-0.4764 -0.0319 -0.0620 0; 0 0 0 0 -20.2 0 0; 0 0 0 0 0 -20.2 0; 0 0
0 57.2958 0 0 -1];
B = [0 0; 0 0; 0 0; 0 0; 20.2 0; 0 20.2; 0 0];
C = [0 0 0 57.2958 0 0 -1; 0 0 57.2958 0 0 0 0; 57.2958 0 0 0 0 0 0; 0
57.2958 0 0 0 0 0];

% x_0 is initial state


x_0 = [1; 0; 0; 0; 0; 0; 0];
A = A_init;
% X is the initial autocorrelation matrix of state
X = x_0*(x_0.');

% epsilon is threshold value for convergence of algorithm


epsilon = 0.001;

% alpha is the step size for incrementing K during the iterations


alpha = 0.0000000001;

% K is controller gain
K = [0 0 0 0; 0 0 0 0]; % Set to some initial value

% J_arr = zeros(1000, 1)
flag = 0;

% init_eval is constructed to check whether the guessed K is


stabilizing
init_eval = max(real(eig(A-B*K*C)));
if(init_eval>=0)
fprintf('The guessed initial K is not stabilising. It needs to be
changed')
end
i=0;
while true

A = A - B*K*C;
eval = max(real(eig(A))); % this is the condition for checking
asymptotic stability of the matrix A

1
% A matrix can only be stable if all of its eigenvalues are in
left
% plane

if(eval>=0)

fprintf('A matrix is not stable.')


break;
end

P = lyap(A.', C.'*K.'*R*K*C + Q); % Solved using Algebraic Ricatti


Equation
S = lyap(A, X); % S is the lagrange multiplier matrix
K_del = inv(R)*B.'*P*S*C.'*inv(C*S*C.') - K; % K_del is the change
in K i.e. delta K

if i == 1
J = trace(P*X); % J is the performance index

elseif i>1

if abs(trace(P*X) - J) < epsilon


break
elseif(trace(P*X)-J)>0
fprintf('Cost function increased at some point \n');
break
else
J = trace(P*X);
end
end
K = K + alpha*K_del;
% J_arr(i) = J;
i=i+1;
end

fprintf('The closed loop poles are \n')


disp(eig(A_init - B*K*C))

trange = 0:0.01:10;
[t, x] = ode45(@(t, x) (A_init - B*K*C)*x, trange, x_0);
figure(1);
plot(t, x(:, 1)), legend('Sideslip')
figure(2);
plot(t, x(:, 2)), legend('Bank Angle')
figure(3);
plot(t, x(:, 3)), legend('Roll Rate')
figure(4);
plot(t, x(:, 4)), legend('Yaw Rate')
figure(5);
plot(t, x(:, 5)), legend('\delta_{a}')
figure(6);
plot(t, x(:, 6)), legend('\delta_{r}')
figure(7);
plot(t, x(:, 7)), legend('Washout Filter State')

2
The closed loop poles are
-0.4227 + 3.0634i
-0.4227 - 3.0634i
-3.6153 + 0.0000i
-1.0000 + 0.0000i
-0.0162 + 0.0000i
-20.2000 + 0.0000i
-20.1999 + 0.0000i

3
4
5
Published with MATLAB® R2020a

You might also like