Linear Quadratic Regulator (LQR) controller for time-varying matrix B

8 visualizaciones (últimos 30 días)
Hey, I am here to ask for help in the coding for LQR controller. The code is provided as follow.
t = linspace(0, 5640); % default 100 points
i = 83*pi/180; % inclination angle in rad
w0 = 0.0011; % angular velocity in rad/s
b_1 = sin(i)*cos(w0*t);
b_2 = -cos(i)*ones(size(t));
b_3 = 2*sin(i)*sin(w0*t);
J1 = 4;
J2 = 4.2;
J3 = 4;
% choose Q & R
Q = diag([0.001 0.001 0.001 0.001 0.001 0.001]);
R = diag([1e3 1e3 1e3]);
% Define system
dfw = [0 0 w0*(-J1+J2-J3)/J1; 0 0 0; w0*(J1-J2+J3)/J3 0 0];
dfq = [2*(w0^2)*(J3-J2)/J1 0 0; 0 0 0; 0 0 2*(w0^2)*(J1-J2)/J3];
ZERO = zeros(1,1,numel(b_1));
b1 = reshape(b_1, 1,1,[]);
b2 = reshape(b_2, 1,1,[]);
b3 = reshape(b_3, 1,1,[]);
A = [dfw dfq; 0.5*eye(3) zeros(3)];
C = eye(6);
D = zeros(6,3);
for n = 1:length(t)
B = [ ZERO b3/J1 b2/J1;
-b3/J2 ZERO b1/J2;
b2/J3 -b1/J3 ZERO;
zeros(3,3,numel(b_1))]
[K, S, e] = lqr(A,B,Q,R);
end
The state-space model has constant A, C and D matrices but B matrix is varying with time.
When I computed this code, error coming out by saying that "Error using lqr (line 43): The "lqr" command operates on a single model."
Can any expert on LQR controller help me to solve this question?

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 19 de Abr. de 2020
Since your matrix B has 100 slices in the 3rd dimension, you will have 100 K, S, and e matrices. Replace your for loop with
B = [ ZERO b3/J1 b2/J1;
-b3/J2 ZERO b1/J2;
b2/J3 -b1/J3 ZERO;
zeros(3,3,numel(b_1))];
for n = 1:length(t)
[K(:,:,n), S(:,:,n), e(:,:,n)] = lqr(A,B(:,:,n),Q,R);
end
  4 comentarios
Linee Teh
Linee Teh el 20 de Abr. de 2020
Noted with thanks. By ignoring the disturbance, the coding that you have provided is very useful and easy to understand!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre State-Space Control Design and Estimation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by