design error of closed loop linear quadratic gaussian(LQG) regulator

3 views (last 30 days)
%% defining LSSM
A=[ 0.6348 0.2593 0.4600
0.5413 0.4619 -2.1551
0.3717 -0.2875 -0.2284];
B=[-0.000373884261537862
-0.000282628577356680
6.75556005562987e-06];
C=[0.775419018631805 -0.351536834549575 -2.22055248727544
-1.06763937573713 1.60044239999917 2.15337710223348
-0.0104624868533414 -0.872193358462870 1.95243821622811
0.169459415037054 -2.05534089971536 3.53024245136833];
D=[0
0
0
0];
[k n]=size(C); %dimension index
Qw=C*C';
r_w=[1];
Rw=diag(r_w);
w=wgn(n,1,0);
v=wgn(k,1,0);
Q=w'*w; %
R=v'*v; %
% N=w*v';
% E|[ w [w.' v.']|=|Q N|
% | v] | |N.' R|
SYS=ss(A,B,C,D);
[K,~]=lqry(SYS,Qw,Rw); % u = -Kx minimizes J(u) % [A,B] controllable
%lqry is the Create a linear-second-order (LQ)
%state-feedback regulator with output weighting using [A,B,C,D]
%Design of Kalman estimator
[Kest,L,~]=kalman(SYS,Q,R); % [A,C] observable
% Form LQG regulator = LQ gain + Kalman filter.
F=lqgreg(Kest,K);
%Closed loop
cl_sys=feedback(SYS,F); %error point
With a given LSSM condition [A,B,C,D]
I want to implement a closed loop with feedback by designing an LQG regulator.
LSSM is a data driven IO model that satisfies both controllability and observability.
An error occurs because the dimensions of SYS and F in the last code do not match.
Could you please explain what problem in control theory is causing this issue and how to fix the code?
  1 Comment
GUS
GUS on 12 May 2022
Edited: GUS on 12 May 2022
%% defining LSSM
A=[ 0.6348 0.2593 0.4600
0.5413 0.4619 -2.1551
0.3717 -0.2875 -0.2284];
B=[-0.000373884261537862
-0.000282628577356680
6.75556005562987e-06];
C=[0.775419018631805 -0.351536834549575 -2.22055248727544
-1.06763937573713 1.60044239999917 2.15337710223348
-0.0104624868533414 -0.872193358462870 1.95243821622811
0.169459415037054 -2.05534089971536 3.53024245136833];
D=[0
0
0
0];
[A,B,C,D,~]=idssdata(LSSM);
[k n]=size(C); %dimension index
Qw=C'*C;
r_w=[1];
Rw=diag(r_w);
w=wgn(n,1,0);
v=wgn(k,1,0);
Q=w'*w; % ??
R=v'*v; % ??
% E|[ w [w.' v.']|=|Q N|
% | v] | |N.' R|
SYS=ss(A,B,C,D,1); %nargin 5 is discrete time step
%Design of Kalman estimator
[Kest,L,P,Mx,Z,My]=kalman(SYS,Q,R); % [A,C] observable
%calculating the LQ gain
[K,~]=lqr(SYS,Qw,Rw); % u = -Kx minimizes J(u) % [A,B] controllable
% SYS2=ss(Kest.A,Kest.B,Kest.C,Kest.D);
% [K,~]=lqr(SYS2,Qw,Rw);
% Form LQG regulator = LQ gain + Kalman filter.
F=lqgreg(Kest,K);
%Closed loop
cl_sys=feedback(SYS,F); % closed loop

Sign in to comment.

Accepted Answer

Paul
Paul on 22 Apr 2022
I think there are a few issues with the code. First, the plant should have at least one input for the control and one input for the process noise. Second, the feedback() command to form clsys needs to use positive feedback, and it probably needs to use additional input arguments to specify the inputs/outputs of the the plant to connect to F.
This link has an example of the entire process. Feel free to post back with any additional questions after checking it out.
Also, there is a function called lqg() that might be of interest.
A few additional comments. Is that form for Qw really what's intended? I'm only asking because setting Q = C'*C (the transponse of Qw) is common for LQR designs when the cost function includes x'*Q*x, which is then y'*y. So maybe this problem really intends to use Qw = 1? Also, it's not clear why Q and R would be based on random numbers?
  2 Comments
GUS
GUS on 12 May 2022
Edited: GUS on 12 May 2022
There has been an update on the LQG regulator I want to implement.
I want to make an LQG regulator that controls state: x, and I have confirmed that the appropriate function for this is lqr, not lqry.
I understand that Q and R random numbers can be set as random numbers for using kalman filter.
What I'm curious about is all the processes after [%calculating the LQ gain] of the newly updated code.
Through the theoretical background, it is understood that when generating the LQG regulator, it is necessary to obtain the LQ gain by re-creating the coefficients [A,B,C,D] of the state space model updated through the kalman filter into a system. (not u=-kx, but u=-kx_e)
1) Does this mean that we need to get LQ-gain [K] from [A.B.C.D] of Kest, rather than get LQ-gain [K] from the initially defined SYS?
And, regardless of which one of them is correct, it was confirmed that Kest is a system that encompasses both x_e and y_e.
However, it is expected that only the items related to x_e need to be extracted to create closed loop feedback that controls state x.
However, I'm still not sure how to implement this in code.
2) i.e. F=lqgreg(Kest,K); There is also an unmatching dimension issue in .
Could you tell me how to solve this?
Paul
Paul on 13 May 2022
Edited: Paul on 13 May 2022
Hi JS,
Q and R for designing the Kalman filter can be random numbers, but there is not mathemmatical justification that I can think of. Using cov() on a large sample of random numbers may be sensible.
The dimension of Q is based on the number of process noise inputs, which are not defined in the plant. See below.
The LQR feedback gain is computed from SYS, not Kest.
The plant model in the original code has one input. Seems like it should have at least two, one for the control input and one for the process noise. However, only the portion of the sys.b for the control is to be used for the LQR design.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!