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

조회 수: 13 (최근 30일)
Linee Teh
Linee Teh 2020년 4월 19일
댓글: Ameer Hamza 2020년 4월 20일
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?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 19일
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
Linee Teh
Linee Teh 2020년 4월 20일
Noted with thanks. By ignoring the disturbance, the coding that you have provided is very useful and easy to understand!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 State-Space Control Design and Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by