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 comentarios

Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
Please look at my answer below.
Jan Schellekens
Jan Schellekens el 22 de En. de 2014
Editada: Jan Schellekens el 22 de En. de 2014
"eig(Ai+Bi*K)" is wrong, it should be "eig(Ai-Bi*K)" for negative feedback, which is used by the lqr function of Matlab. For eig(Ai-Bi*K) all real parts of the eigenvalues become negative:-)
raja m
raja m el 31 de Jul. de 2014
There are some techniques to select value of Q and R in literature.please see to that............
Jose Almeida
Jose Almeida el 20 de Jun. de 2015
Can you reference some literature? Thank you

Iniciar sesión para comentar.

 Respuesta aceptada

Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013

1 voto

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 comentarios

cmcm
cmcm el 9 de Feb. de 2013
yes there is 2 eigen values always positive i could minimize them to small values but they still positive and i also changes my Q and R lot of times but these 2 values either be bigger or smaller but NOT NEGATIVE :(
Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
You most definitely have an uncontrollable mode. Try the ctrb command to see if it is full rank.
Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
Hmm, its interesting that you can you can minimize them to small value, will have to look into it further.
cmcm
cmcm el 9 de Feb. de 2013
i do check the controllability and its ok no thing wrong with it ... i post the states and the LQR values
Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
Editada: Shashank Prasanna el 9 de Feb. de 2013
the control law is -Ku, since this is just gain feedback stabilization and not a servo, you should be taking
A-BK
eig(feedback(p,K))
eig(Ai-Bi*K)
ans =
-0.450724167061847
-0.177749095282113 + 0.389392734713362i
-0.177749095282113 - 0.389392734713362i
-0.271246093581801 + 0.234773549822464i
-0.271246093581801 - 0.234773549822464i
-0.187258672958968
-0.0970318364794837 + 0.164088173179111i
-0.0970318364794837 - 0.164088173179111i
LQR always returns a stabilizing control by construction, as long as you have all controllable modes to be stable. C matrix in not involved in LQR observability is not required.
cmcm
cmcm el 9 de Feb. de 2013
you mean that the step eig(Ai+Bi*K) should be eig(Ai-Bi*K)
Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
yes,
You have a negative feedback and this is not LQR Servo. You have to be careful with convention. LQR 'ALWAYS' returns a stabilizing gain matrix, as long as all modes are controllable. This is by construction. LQR does not care about your outputs i.e. C and D and it stabilizes the closed loop plant with the feedback gain K that gives you good properties at the plant input u
cmcm
cmcm el 9 de Feb. de 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

Iniciar sesión para comentar.

Más respuestas (3)

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Feb. de 2013
Editada: Azzi Abdelmalek el 8 de Feb. de 2013

2 votos

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 comentarios

cmcm
cmcm el 8 de Feb. de 2013
i have a simulation for my system and i need to enter the values of Q anr R of the controller ... i entered it manually but when i check if it is ok or not (mean the value of Q and R ) i use the eigen value (for checking) which it must be all values have a negative sign .. but i have 2 of them with positive sign .... so i changes the values of Q and R again and again and there is no hope to get all eigen values with negative sign .... so my question was ... is there any way to know the right values of Q and R instead of try and error!!! .... because i already will use the lqr function ... i just need the right valeus for Q and R .... i think i explain it better now :)
cmcm
cmcm el 8 de Feb. de 2013
and also i do have an integrator ... it gives better results
Azzi Abdelmalek
Azzi Abdelmalek el 8 de Feb. de 2013
Post your system, and the states you want to control
Shashank Prasanna
Shashank Prasanna el 9 de Feb. de 2013
shahad, you are trusting one or the other. I recon the model with no background is not of much value to anyone.
cmcm
cmcm el 9 de Feb. de 2013
ok am sorry i will post it

Iniciar sesión para comentar.

Fatma Yörük
Fatma Yörük el 21 de Nov. de 2020

1 voto

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.

2 comentarios

Victory Friday
Victory Friday el 31 de En. de 2022
Please can you help me with one of the pso for A and RN matrix
manohar sahu
manohar sahu el 8 de Nov. de 2022
Can you please let me know how to implement pso for lqr controller

Iniciar sesión para comentar.

cmcm
cmcm el 9 de Feb. de 2013
Editada: Azzi Abdelmalek el 9 de Feb. de 2013

0 votos

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 comentarios

cmcm
cmcm el 9 de Feb. de 2013
Editada: cmcm el 9 de Feb. de 2013
these values of Q and R are the best what i get ... it minimize these 2 positive numbers
Azzi Abdelmalek
Azzi Abdelmalek el 9 de Feb. de 2013
You can' control three outputs with two inputs. The LQR function calculate the gain K which minimize your 8 states and your two inputs. If you want to obtains all your states equals to zero it's ok. But if you want your three outputs to fellow certain references, you can't.
cmcm
cmcm el 9 de Feb. de 2013
why ???
Azzi Abdelmalek
Azzi Abdelmalek el 9 de Feb. de 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.

Iniciar sesión para comentar.

Preguntada:

el 8 de Feb. de 2013

Comentada:

el 8 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by