LQG controller design with LQR
11 views (last 30 days)
Show older comments
I am using lqg command and got a b c and d value for the controller. And from lqr I have k value. But how to incorporate them in my system together? I mean what is my final optimal systems A, B, C and D value that can be obtained from lqg controller and LQR gain?
0 Comments
Answers (1)
Pavl M.
on 8 Nov 2024 at 18:49
Edited: Pavl M.
on 8 Nov 2024 at 18:59
clc
clear all
close all
n_states = 5;
n_controls = 5;
n_outputs = 5;
A = [-0.4628, 0.3217, 0.5789, -0.3823, -0.0507;
0.7593, 1.0396, -0.2008, -0.2438, -0.0678;
0.2106, 0.6490, 0.3973, 0.8735, 0.2070;
0.3128, 0.3380, 0.1524, 0.0914, -0.1088;
0.0353, 0.0419, -0.0355, 0.0682, 0.7576];
B = [0.0026;
0.0088;
-0.0036;
0.0490;
-0.1443];
C = [1.1099, 1.3983, 0.8999, -0.0136, 0.0652];
D = 0;
dt = 0.02;
aug_level = 0;
gain = 4;
sys = ss(A, B, C, D, dt,'InputName','u','OutputName',{'y'});
% define your control, cross and state cost matrices:
R = 1;
N = 1;
Q = [1 0 0 0 0 0;0 2 0 0 0 0;0 0 5 4 0 0;0 0 0 5 0 0; 0 1 0 0 5 1;0 0 0 0 0 1];
Q1 = (Q+Q')/2
A = rand(n_states+1, n_states+1);
A_symmetric = tril(A) + triu(A', 1);
Q2 = A_symmetric
QXU = blkdiag(0.1*eye(n_states),sqrt(Q))
QWV = blkdiag(Q,0.01)
QI = 1 ; %eye(ny)
KLQG1 = lqg(sys,Q1,Q,QI,'1dof')
KLQG2 = lqg(sys,Q1,Q,QI,'2dof')
%csys = ss(A-B*K,B,C,D)
figure
step(KLQG1)
title('1DOF Servo Controller designed')
figure
step(KLQG2)
title('2DOF Servo Controller designed')
%Constructing closed-loop system after designing:
%Ther are many similar questions this answer will fit(answer) to:
%https://www.mathworks.com/matlabcentral/answers/484846-how-to-use-the-generated-lqg-controller
C=KLQG1;
P = sys;
set(C,'InputName','e')
set(C,'OutputName','u')
set(P,'OutputName','y')
set(P,'InputName','u')
Sum_Error = sumblk('e = r - y');
clsys = tf(connect(C,P,Sum_Error,'r','y'))
clsys_m = minreal(clsys)
figure
step(clsys_m)
title('Constructed closed loop system response')
%Constructed from needing help code by:
%https://join.skype.com/invite/oXnJhbgys7oW
%https://independent.academia.edu/PMazniker
%+380990535261
%https://diag.net/u/u6r3ondjie0w0l8138bafm095b
%https://github.com/goodengineer
%https://orcid.org/0000-0001-8184-8166
%https://willwork781147312.wordpress.com/portfolio/cp/
%https://www.youtube.com/channel/UCC__7jMOAHak0MVkUFtmO-w
%https://nanohub.org/members/130066
%https://pangian.com/user/hiretoserve/
%https://substack.com/profile/191772642-paul-m
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!