Compute and Simulate Linear Quadratic Regulator (LQR) in MATLAB for Nonzero Set Points

  Рет қаралды 10,505

Aleksandar Haber PhD

Aleksandar Haber PhD

Күн бұрын

Пікірлер: 35
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
It takes a significant amount of time and energy to create these free video tutorials. You can support my efforts by making a PayPal donation or by becoming a Patreon: PayPal: www.paypal.me/AleksandarHaber Patreon: www.patreon.com/user?u=32080176&fan_landing=true
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
The post accompanying this video can be found here: aleksandarhaber.com/compute-and-simulate-linear-quadratic-regulator-lqr-in-matlab-for-set-point-tracking/
@40NoNameFound-100-years-ago
@40NoNameFound-100-years-ago 2 жыл бұрын
thanks for the video, just a small and a quick tip, in case the LQR is used with set points that are not zero, it has another name based on it's nature in this case and that is LQT ( linear quadratic tracker).
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
Thank you for letting me know! Best, A. Haber
@TimiiOwolabi
@TimiiOwolabi Ай бұрын
Thank you so much
@aleksandarhaber
@aleksandarhaber Ай бұрын
No problem
@biteraman9370
@biteraman9370 Жыл бұрын
Hi sir, I have no idea how I stumbled across your channel but it has certainly increased my curiosity and interest in control theory. I'm currently a student from india and am looking to get myself into learning control theory. If you could advice me on how to start for an absolute beginner and work my way through intermediate and advanced concepts. I'm looking to get started with a strong foundation and basics. Thanks in advance :)
@aleksandarhaber
@aleksandarhaber Жыл бұрын
In my opinion two best books that can be used to start with control systems are: (1)Feedback control of Dynamic Systems, by Franklin, Powell, and Emami Naeni (2) Modern Control Engineering, by Ogata You can also watch other tutorials available online. However, I would first start with the textbooks. I am trying to make control engineering tutorials, however, this takes quite some time and effort.
@frihyounes904
@frihyounes904 2 жыл бұрын
thaaaank you very much
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
subscribe and like
@hitman40030
@hitman40030 Жыл бұрын
Hi .. an awesome tutorial on the LQR controller. Can you also suggest some more references to select the Q and R weighting matrices for the best optimisation.
@aleksandarhaber
@aleksandarhaber Жыл бұрын
The best thing to do is to do grid search for Q and R matrices. Parametrize them as diagonal matrices and do the grid search for two parameters, by investigating the performance. Basically, you have to do a form of Monte Carlo. There are some other methods, however, I think that they are not really applicable.
@sohaibullahzarghoon7425
@sohaibullahzarghoon7425 Жыл бұрын
hello, nice video but one question, if we add integral action to the lqr control how would the close loop system code in Matlab.
@aleksandarhaber
@aleksandarhaber Жыл бұрын
I can only help with these free tutorials. I do not have time to help you with your question.
@chengmao7064
@chengmao7064 2 жыл бұрын
Hello sir, here is a question. Since Ud is only the leat square solution, it can not guarantee AXd+BUd = =0. Then the dot of X is not zero at final. Could you explain this?
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
You are computing the steady-state solution of a linear dynamical system. If Ud is constant, and the system is asymptotically stable, such a solution will exist. That is, Xd will exist. The problem is then to solve this equation for Ud. If matrix B has full column rank, then such a solution will exist, and you can compute it as I did. That is, you are simply solving a linear system of equations AXd=-BUd for Ud.
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
Also, the Xd should be such that you can produce it with Ud and under the control structure given by matrix B. This is also related to the controllability of the system. If the matrix B has full column rank, and if the product AXd belongs to the column space of B, then there is the exact solution
@chengmao7064
@chengmao7064 2 жыл бұрын
@@aleksandarhaber Thanks。 So we need also the condition that AXd belongs to the column space of B. Is it right or not?
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
@@chengmao7064 You should think like this. Construct an asymptotically stable linear system. Apply to such a system a steady input. What will happen in the steady state? All the state variables will converge to fixed values. For example, take a mass spring damper system. Apply a constant force. After some time (under the assumption of asymptotic stability), velocity will go to zero and acceleration will go to zero, that is, the steady state is just a position and zero velocity. Then your goal is to solve an inverse problem. Find a force that will produce a desired steady state. HERE YOU HAVE TO MAKE SURE THAT THE STEADY STATE IS FEASIBLE UNDER THE CONSTANT INPUT! IN THE CASE OF THE MASS-SPRING-DAMPER SYSTEM, a steady state cannot have non-zero velocity. A control system designer wants to determine a steady-state input that will produce a physically feasible and controllable desired steady state. Now, from a math point of view, you want to solve the equation AXd=-B Ud. When does such an equation have a unique solution? This is a question for you to think. A,Xd, and B have to satisfy certain conditions. Think about it. A very good book on linear algebra is Prof. Strang's book.
@chengmao7064
@chengmao7064 2 жыл бұрын
@@aleksandarhaber Your reply is the same as what I think. That is, xd has some restriction and can not be any vector. I understand all what you said. So my opnion is right that you need to specify the condition of xd. Anyway, thanks.
@zachdaniel5985
@zachdaniel5985 2 жыл бұрын
I love this video and it's extremely helpful! I have a question though: what if my desired state is not a constant value (like in this case a position of 3 and a velocity of zero), but instead a function of time, for example 4sin(t)?
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
Hi Zach Daniel, You can try something like this: kzbin.info/www/bejne/e3W9XoJtjdqpfMU Design a controller with a pole placement method with integral action, and then see how this controller will act when you send sinusoidal signals or any other type of time-varying signals. Also, you can use the LQ method instead of the pole placement method.
@zachdaniel5985
@zachdaniel5985 2 жыл бұрын
@@aleksandarhaber I'd ideally like to do LQR and have my controller push my system towards a sinusoid. Would it be possible to evaluate the LQR command in a for loop to define a gain for each time step, or is that method too costly?
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
@@zachdaniel5985 You do not need to do that.. Basically, apply the LQR algorithm to the equation (6) in this post I created: aleksandarhaber.com/pole-placement-with-integral-control-action-to-eliminate-steady-state-error-state-space-control-design/ Input U should be an LQR state feedback. When applying the LQR control method, ignore the reference signal. LQR should stabilize the system. Then, you apply to the reference signal a sinusoidal. Note that, you can also add an additional integrator to the system. I only added a single integrator. You can also read this: eng.libretexts.org/Bookshelves/Industrial_and_Systems_Engineering/Book%3A_Introduction_to_Control_Systems_(Iqbal)/04%3A_Control_System_Design_Objectives/4.03%3A_Steady-State_Error_Improvement about the system type and a signal that the control signal can track in order to better understand tracking problems.
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
Excuse me sir, i want to ask another question. If i want to control the rpm on dc motor using lqr control. What i want to ask is : 1. How to control the speed steady on 500rpm? 2. if we got the optimum gain matrix K = [10.648 415.01](after getting the dc motor state space and using lqr = (A,B,Q,R) function on matlab) what is the X1 and the X2 to control the rpm of the DC motor? I hope your response ASAP sir. Thank you
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
Hello, First, a suggestion: Try to invest some time to understand where are control systems and how they are being designed. I created the tutorial page here: aleksandarhaber.com/control-systems-tutorials/ Go over these tutorials and also consult intro books. These tutorials will help you to understand what are control systems, 1.) Your desired set point is the speed that you want to control 2.) X1 and X2 are states of your system. You need to look into the state-space model that you used to design the controller. The answers to these types of questions should be immediately clear if a person has a basic understanding of control systems. So, instead of jumping on advanced topics such as LQR, it is a better idea to first build a knowledge base.
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
​@@aleksandarhaber​ Thanks for the response sir. im sorry that my understanding of the control system is too low. But i've tried my best to understand the control system as good as possible. So back to the topic, my desired set point is the speed that i want to control, and the X1 & X2 are the states of the system. i want to control the dc motor at exactly 500 rpm. What i know from the LQR is we will use the fullstate feedback law (u = -Kx) as the main equation. The u is the input for the motor and the gain matrix K will be multiplied by the state. What i know for choosing the state is what we want to achieve like speed(rpm) and also the K will be 1x1 matrices if we just want to get the speed. What's been bothering me is, if we had the K values by [10.648 415.01] and the state we wanted to get is the speed, 1. Could we just use the 10.648 and multiplies it by the error(desired speed - actual speed) that we get from the sensor to get the best input for the motor? or we need another path to solve this? 2. Or do we have to multiply the K matrix of order 1x2 by the velocity(m/s)(x1) as well as the acceleration (m/s^2)(x2) which comes from the derivatives of the position?
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
Excuse me sir, i want to ask another question. How do we know that X1 and X2 from the state are the distance from the equilibrium (X1), and Velocity (X2)? how do we specify X1 and X2?
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
Generally speaking, X1 and X2 or other state variables in the state vector are not physical variables. They can be if the state-space model comes from Newton's law or some ordinary differential equations that have a physical meaning. Even if they are not physical variables, you can still design a controller. To design the controller on the basis of the state feedback you need an observer to estimate the state of the system. An observer is a similar type of algorithm to a controller and similar design techniques are used to design an observer.
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
Excuse me sir, I want to ask how do I use the matrix value K? Because the results of the LQR control search will produce the matrix value K with the matrices order 1x2, but I don't understand what the meaning of K11 and K12 on the matrices
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
The entries K_{11} and K_{12} are multiplying the entries of the vector (x-x_{D}), look at the equation (17). You can easily form a control law like that.
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
You can also look into this video tutorial: kzbin.info/www/bejne/e3W9XoJtjdqpfMU
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
so what is the next step we take after we got the u value from equation (17)? Because i want to implement it to a dc motor if possible
@aleksandarhaber
@aleksandarhaber 2 жыл бұрын
@@kevingeraldsitanggang9736 If you have a full state information, then this equation gives you the control signal as a function of the state. If you do not have full state feedback, then you need an observer to estimate the state. Also, you need to discretize the controller. I think that the approach I presented is not suitable for control of DC motors, since if you control the position, you have an unstable system. There is a solution for that. I suggest you watch this video and tutorial: kzbin.info/www/bejne/e3W9XoJtjdqpfMU aleksandarhaber.com/pid-controller-discretization-and-implementation-in-arduino/ Sorry that I cannot help more at this point. Thank you very much for your interest!
@kevingeraldsitanggang9736
@kevingeraldsitanggang9736 2 жыл бұрын
@@aleksandarhaber Okay sir, thanks for the explanation. I Appreciate it
Introduction to Linear Quadratic Regulator (LQR) Control
1:36:07
Christopher Lum
Рет қаралды 134 М.
Everything You Need to Know About Control Theory
16:08
MATLAB
Рет қаралды 602 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Control Bootcamp:  Kalman Filter Example in Matlab
22:12
Steve Brunton
Рет қаралды 156 М.
one year of studying (it was a mistake)
12:51
Jeffrey Codes
Рет қаралды 317 М.
Control Bootcamp:  LQG Example in Matlab
13:26
Steve Brunton
Рет қаралды 66 М.
Why the Riccati Equation Is important for LQR Control
14:30
What P vs NP is actually about
17:58
Polylog
Рет қаралды 148 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 279 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.