Help! I'm having trouble plotting hamiltonian and LQR.

15 ビュー (過去 30 日間)
Damian Prashad
Damian Prashad 2019 年 11 月 6 日
コメント済み: Damian Prashad 2019 年 11 月 10 日
Hi,
I'm attempting to land a rocket using state space equations. I'm using optimal controls LQR and Hamiltonian. I have an example of a smaller matrix attached but I can't seem to get Matlab code enough to expand it to the dimensions of my Matrix.
Please help! Here is my code:
clc, clear all, close all
syms u(t) x(t) x1 x2 x3 x4 x5 x6 u1 u2 u3 lambda1 lambda2 lambda3 lambda4 lambda5 lambda6 lambda Q R
Q = eye(6);
R = 5;
x0 = [241500 0].';
t0 = 0;
tf = 5;
l1=35; % meters
l2=35;% meters
ln=1; % 1 meter nozzle length
m=30000; %kg, mass of the rocket
J=m*(l1+l2)^2/12; %moment of inertia
g=9.5; %m/s
theta = pi;
phi = pi/12;
Fe=64860; %Newtons
Fs=130;%Newtons
N=0;
F=eye();
u=[Fe theta phi].';
x=[x1 x2 x3 x4 x5 x6].';
A = [0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 0 g 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0]
B = [0 0 0; 0 0 0; 0 0 0; theta/m 1 m*g; theta/m -m -g*theta; 1-phi*(l1+ln)/J l2/J -Fe*(l1+ln)/J]
% A_transpose = A.';
% B_transpose = B.';
% %ode1 = diff(x_dot) == A_transpose*x + B_transpose*u;
H=0.5*x.'*Q*x+.5*u.'*R*u+lambda1.'*A*x+ lambda2.'*B*u; %Hamiltonian Function
[K,S,P] = lqr(A,B,Q,R,N)

回答 (6 件)

Pavel Osipov
Pavel Osipov 2019 年 11 月 7 日
Damian Prashad, good afternoon. Looked up Your code. Everything works well. What matrices Would you like to change to larger sizes? Where do difficulties arise? You are probably hampered by the loss of precision in matrix transformations whose elements differ by 10^11 times (B). This may well lead to a loss of computational stability.
All the best, Paul.
  1 件のコメント
Damian Prashad
Damian Prashad 2019 年 11 月 7 日
Pavel Osipov, thanks for the response. I'm with my A,B,Q, and R matrices. I'm not sure how to get the code to run when I have a 6X6 A, 3X3 B, 6X6 Q, and 1X1 R.
Hope to hear from you soon.
Thanks,
Damian

サインインしてコメントする。


Pavel Osipov
Pavel Osipov 2019 年 11 月 7 日
Damian, is this the task You set?
system.JPG

Damian Prashad
Damian Prashad 2019 年 11 月 7 日
Pavel,
Thanks for the question. Yes that's the form that I have however, my understanding is that I don't need the y=C*X+D*U because I'm looking for the LQR which normally doens't have that form.
Please see the code. I'm able to run the code now with the expanded matrices, however the data isn't coming out correctly.
Please advise at your earliest conveneince.
Thank you,
-Damian

Pavel Osipov
Pavel Osipov 2019 年 11 月 8 日
Damian, Hello! Putting matrices C =diag(1,...,1) and D=zeros(.,.) get Your system of equations. Simulink State-Space block allows you to solve linear control problems without much hassle. I can send a training file where the problem of oscillations of a double spring pendulum is solved by Simulink. Matrix A: Size [4x4]. I hope You solve Your problem by analogy. Simulink also has nonlinear blocks x'=f (x, u, t) to solve your control. While there is little free time to learn more about your script. Don't take offense at me. Advice is much easier to give than to program.
Sincerely Yours, Pavel Osipov.
  1 件のコメント
Damian Prashad
Damian Prashad 2019 年 11 月 8 日
Pavel,
Yes, please send me the link, I haven't completly solved my problem yet. I got the matlab code to run, but my data is not good.
Please post the information when you havea moment.
Thank you,
-Damian

サインインしてコメントする。


Pavel Osipov
Pavel Osipov 2019 年 11 月 9 日
Version.JPG
MySimulModel.JPG

Pavel Osipov
Pavel Osipov 2019 年 11 月 9 日
  1 件のコメント
Damian Prashad
Damian Prashad 2019 年 11 月 10 日
Pavel, Thank you! I translated the PDF and I'm reviewing it. Have a nice day!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRobust Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by