Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Le système non linéaire converge vers une trajectoire différente de celle désirait cela est du au choix

arbitraire du point de la linearization, de plus les conditions initiales ainsi que le temps de calcul joue
un rôle tres important et l faut constaté que ce system est difficile à stabiliser ;

On a mis un cout eleve pour s’approcher du zero mais ça donne aucun effet

Tu dois parler du compromis entre Q et R

On doit faire en sorte que les pôles instable de A soit contrôlé par le B

It's important to note that the perturbation term p should be small compared to the linear
component represented by Ax + bu. The analysis of the system can then be performed by considering
the linear dynamics first and then incorporating the effects of the perturbation term.

La reponse depend fortement des condition initiales lorsque je met une petite valeur de x1 je me
rapproche de zero et je m’éloigne en vitesse.
clear all
clc

A = [0 1 0 0 0 0 0 0 0 0;
1 0 1 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0;
0 0 0 0 1 0 0 0 0 0;
0 0 0 0 1 0 0 1 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 1 0 0 0 0 0 1;
0 0 0 0 0 0 0 0 1 0];

B = [0 0 0;
1 0 0;
0 0 0;
0 1 0;
0 0 0;
0 0 1;
1 0 0;
0 0 0;
0 0 0;
0 0 0];

syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10;
mu = 398600;

x0 = [69.78; 0.0075; 138.56; -0.151; 104.67; 0.015; 6972; 7.5; 0.348;


0.0005];
mu = 398600;

syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10;

% Define the perturbation vector


p = [0;
2*x10*x4 + (-2*x8*x10/x7)*x1 + x10^2*x1 + (mu/x7^2) -
mu*(x7+x1)/((x7+x1)^2+x3^2+x5^2)^1.5 - x1 - x3;
0;
-2*x10*x2 + (-2*x8*x10/x7)*x1 + x10^2*x3 -
mu*x3/((x7+x1)^2+x3^2+x5^2)^1.5 - x3;
0;
-mu*x5/((x7+x1)^2+x3^2+x5^2)^1.5 - x5;
-x5;
x7*x10^2 - mu/x7^2 - x7;
-x4;
-2*x8*x10/x7 - x9];

% Substitute numerical values into the perturbation vector


p = subs(p, [x1, x2, x3, x4, x5, x6, x7, x8, x9, x10], x0');

Q = eye(10);
R = 10e9*eye(3);

[k, ~, ~] = lqr(A, B, Q, R);


Ac = A - B*k;

% Define the initial conditions


%x0 = [69.78; 0.0075; 138.56; -0.151; 104.67; 0.015; 6972; 7.5; 0.348;
0.0005];
x0=[-0.906 -0.000267 -0.845 0.0014 -0.906 -0.000267 6900 8.5 0.483 0.005];
% Compute the time vector
t = 0:0.1:100;

% Simulate the closed-loop system


u = zeros(length(t), size(B, 2));
x = zeros(length(t), size(A, 1));
x(1, :) = x0';

for i = 2:length(t)
% Get the current state
current_x = x(i-1, :).';

% Evaluate the perturbation vector


perturbation_value = double(subs(p, [x1, x2, x3, x4, x5, x6, x7, x8,
x9, x10], current_x'));

% Compute the state derivative


x_dot = A * current_x + B * u(i-1, :).' + perturbation_value;

% Compute the control input


u(i, :) = -k * current_x;

% Update the state using Euler's method


x(i, :) = current_x' + x_dot.' * (t(i) - t(i-1));
end

% Compute the output


C = eye(size(A, 1));
D = zeros(10, 3);
y = C * x.' + D * u.';

% Plot the output


for i=1:length(t)
plot(y(2, :), y(1, :));
hold on
drawnow
xlabel('x2');
ylabel('x1');
title('Closed-Loop Response');
end

function dxdt=non_linear(t,x)
mu=398601;
dxdt(1)=x(2);
dxdt(2)=2*x(10)*x(4)-(2*x(8)*x(10)/x(7))*x(3)+x(10)^2*x(1)+...
(mu/x(7)^2)-mu*(x(7)+x(1))/((x(7)+x(1))^2+x(3)^2+x(5)^2)^1.5;
dxdt(3)=x(4);
dxdt(4)=-2*x(10)*x(2)+2*x(8)*x(10)/x(7)*x(1)+x(10)^2*x(3)-...
mu*x(3)/((x(7)+x(1))^2+x(3)^2+x(5)^2)^1.5;
dxdt(5)=x(6);
dxdt(6)=-mu*x(5)/((x(7)+x(1))^2+x(3)^2+x(5)^2)^1.5;
dxdt(7)=x(8);
dxdt(8)=x(7)*x(10)^2-mu/x(7)^2;
dxdt(9)=x(10);
dxdt(10)=-2*x(8)*x(10)/x(7);
dxdt=dxdt';

mu = 398600; % gravitational constant of the Earth (km^3/s^2)


rt = 10000; % radius of the target from the center of the Earth (km)
n = sqrt(mu/rt^3); % mean motion

A = [0 1 0 0 0 0;
3*n^2 0 0 2*n 0 0;
0 0 0 1 0 0;
0 -2*n 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 -n^2 0];

B = [0 0 0;
1 0 0;
0 0 0;
0 1 0;
0 0 1;
0 0 1];

C = eye(6);
D = zeros(6,3);

Q = eye(6);
R = 10e9*eye(3);

sys = ss(A, B, C, D);


%% check the commandability and the observability of the system
co = ctrb(A,B);
ob = obsv(A,C);

if rank(co) == length(A) && rank(ob) == length(A)


disp('Le système est commandable et observable.')
else
disp('Le système n''est pas commandable et/ou observable.')
end

[K, ~, ~] = lqr(sys, Q, R); % Compute the LQR controller gains


% Define the set point
set_point = [0; 0; 0; 0; 0; 0];

% Define the closed-loop system with the controller and set point
Ac = A - B*K;
Bc = B;
Cc = C;
Dc = D;
sys_cl = ss(Ac, Bc, Cc, Dc);

% Define the initial conditions


x0 = [-0.906 -0.000267 -0.845 0.0014 -0.906 -0.000267 ];
%xref = [-2.32 0.00279 8.85 0.00293 5.37 0.00713];
xref=[0 0 0 0 0 0]

% Compute the time vector


t = 0:0.1:1000;

% Simulate the closed-loop system


u = zeros(length(t), size(B,2));
x = zeros(length(t), size(A,1));
x(1,:) = x0';
for i = 2:length(t)
x_dot = A * x(i-1,:)' + B * u(i-1,:)';
u(i,:) = -K * (x(i-1,:)' - xref');
x(i,:) = x(i-1,:) + x_dot' * (t(i) - t(i-1));
end

% Compute the output


y = C * x' + D * u';

%Plot the response of the system and the control input


% figure;
% subplot(4,1,1);
% plot(t, y(1, :));
% xlabel('Time');
% ylabel('x');
% title('Response of x');
% subplot(4,1,2);
% plot(t, y(3, :));
% xlabel('Time');
% ylabel('y');
% title('Response of y');
% subplot(4,1,3);
% plot(t, y(5, :));
% xlabel('Time');
% ylabel('z');
% title('Response of z');
% subplot(4,1,4);
% plot(t, u);
% xlabel('Time');
% ylabel('Control Input');
% title('Control Input');
%
% % Display the controller gains
% disp('Controller Gains (K):');
% disp(K);

%plot(t,y(1,:),t,y(3,:),t,y(5,:))
plot(y(2,:),y(1,:))

Adaptative lqr :
engineers are typically not comfortable to switch over to nonlinear control theory completely,
lqr is the nominal controller.

it's important to note that a nominal controller may not perform optimally or robustly in the
presence of significant changes or uncertainties in the system. It may not be able to handle
large disturbances, variations in system parameters, or unexpected operating conditions. In
such cases, additional techniques like adaptive control or robust control may be necessary to
ensure satisfactory performance.

To summarize, a nominal controller is designed to provide adequate control performance


under expected operating conditions, based on a model of the system and assuming certain
parameter ranges and disturbances. It is an initial controller design that serves as a starting
point but may require further enhancements to handle uncertainties or deviations from the
expected conditions.

You might also like