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

조회 수: 20 (최근 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 CenterFile Exchange에서 Robust Control Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by