MATLAB Answers

how to choose LQR

262 views (last 30 days)
cmcm
cmcm on 8 Feb 2013
Answered: Fatma Yörük on 21 Nov 2020
hello everyone i am trying to use LQR controller i simulate my system and have my A and B matrix ,, used theme in m-file and use the lqr function to control this system,,, is there any way to know what is the right value for Q and R ?? i try a lot of values for them but the results give me 2 positive values and that is wrong, all values must be negative depending on the choice of the Q and R. so is there any way make me know what is the right values for them instead of try and error ? please help
  4 Comments
Jose Almeida
Jose Almeida on 20 Jun 2015
Can you reference some literature? Thank you

Sign in to comment.

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 9 Feb 2013
LQR always returns a stabilizing feedback gain.
Are there 1 or 2 eigen values that are always show up positive?
You most likely have an uncontrollable mode in your system. As Azzi mentioned you have to just try different weights, choosing Q and R is part art, part science.
If you can provide the state space (A,B,C,D) for your plant, it would be useful.
  8 Comments
cmcm
cmcm on 9 Feb 2013
thank you soooo much for your notes ... that was a mistake from me that i did not notice the sign ... all my problem was about sign :) thanx again

Sign in to comment.

More Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 8 Feb 2013
Edited: Azzi Abdelmalek on 8 Feb 2013
There is no systematic method to choose Q and R. You can start with
Q=eye(n) % n: number of states
R=eye(m) % m: number of inputs
Simulate your system in closed loop, then try to adjust your weighting coefficient Q and R. You have just to know, that more the weighting parameter is great, more the weighted signal is minimized.
You have to know, also, that you will need to insert integrators, if you want to correctly control your system
  5 Comments
cmcm
cmcm on 9 Feb 2013
ok am sorry i will post it

Sign in to comment.


cmcm
cmcm on 9 Feb 2013
Edited: Azzi Abdelmalek on 9 Feb 2013
clear all;
gi=1;
% initial condition
a=2.9975;
b1=0.034025;
b2=0.034025;
b3=0.5606;
b4=-b3;
Am =[ 0 1.0 0 0 0 0;
0 0 -a 0 0.0000 0;
0 0 0 1.0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 1.0;
0 0 0 0 0 0];
Bm =[ 0 0;
0 0;
0 0;
b3 b4;
0 0;
b1 b2];
Cm=[1 0 0 0 0 0;0 0 1 0 0 0;0 0 0 0 1 0];
Dm=[0 0;0 0;0 0];
Ai = Am;
Ai(7,5) = 1;
Ai(8,1) = 1;
Ai(8,8) = 0;
Bi = Bm;
Bi(8,2) = 0;
co=ctrb(Ai,Bi);
rank(co)
unc=length(Ai)-rank(co)
Q = diag([0 0.05 0 0 2 1 1 0.001]);
R = 50*diag([1 1]);
K = lqr( Ai, Bi, Q, R );
disp( ' ' )
disp( 'Calculated LQR controller gain elements: ' )
K
eig(Ai+Bi*K)
CMD_RATE_LIMIT = 45.0 * pi / 180;
  4 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 9 Feb 2013
Shahad, explain what you want to control. What are your references? And you can't control 3 output with 2 inputs, unless you want them to tend towards zero.

Sign in to comment.


Fatma Yörük
Fatma Yörük on 21 Nov 2020
There are some optimization methods to find the best Q and R so that you achieve your desired performance. Most literature uses GA or PSO algorithms for it. However, some comparisons with the descent algorithm takes also part in. So, rather than the trial and error, trying to develop some optimisation-based algorithms might be more proper way.

Community Treasure Hunt

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

Start Hunting!