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

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

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

Really thanks for your help!!
But I have another question. I want to introduce some disturbances in my system. Do you know how to edit the LQR coding in order for me to define the disturbances as shown in the figure below?
If you have disturbance in your syetem, then you will need to use lqg(): https://www.mathworks.com/help/releases/R2020a/control/ref/ss.lqg.html
Noted with thanks. By ignoring the disturbance, the coding that you have provided is very useful and easy to understand!
I am glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 19 de Abr. de 2020

Comentada:

el 20 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by