MechJeb2

MechJeb2

4M Downloads

Auto landing on Kerbin / in an atmosphere doesn't work :(

SuperFire101 opened this issue ยท 14 comments

commented

I'm trying to replicate a Falcon 9 crew mission (with powered pod landing).
After the de-orbit burn, the craft starts to do "micro-burns" over and over again, and then it starts the suicide burn way earlier than it should. If I pause the auto-pilot until it gets close to the ground, it does a great suicide burn, but it landed way short of the target.
I don't know much, but that seems to me like MechJeb isn't taking in account the drag/atmosphere. The (MechJeb provided) landing prediction is on target, but the one from the Trajectories mod states the actual landing spot.

TL;DR - AutoLand doesn't work for me on Kerbin, starts burning way too early, and lands off target.
Am I doing something wrong? Is there a way to configure MechJeb for atmospheric landings?

I'm playing on KSP 1.4.4, MJ Ver. 2.7.3.0 (from CKAN).
Thanks in advance! :)

commented

closing in favor of #1052

commented

I haven't tackled landing yet. I'm more familiar with ascents and free space maneuvering.

An introductory text to optimal control theory applied to rocket trajectories would be this book:

https://www.amazon.com/Optimal-Control-Aerospace-Applications-Technology/dp/146148944X

That is the branch of optimization that is optimal control theory / calculus of variations / "indirect method" based on Pontryagin's minimum principle. Specifically I've been using "Lawden's Primer Vector Theory".

What most research probably post-1980 is on is "direct methods" which use some form of collocation (and current research is built on top of pseudospectral collocation with convex optimization). I don't have a good introductory textbook to these kinds of methods. A directly applicable current example would be: https://arc.aiaa.org/doi/10.2514/1.G002818. Matlab's TPBVP solver uses collocation. The book uses that TPBVP solver to solve calculus of variations problems which confused me for awhile until I abandoned doing that -- for primer vector theory generally you want to solve the IVP using a normal ODE solver like ode45 and then use a root finder like either levenburg-marquardt or powell's dogleg in fsolve.

You can see what I've tried to do here:

https://space.stackexchange.com/questions/24643/improvements-to-script-for-finite-burn-trajectory-optimization-with-matlab/25956#25956

But there are multiple bugs in that script that I haven't circled back on and fixed (that I can't even quite recall what they are today, I haven't played with Matlab in months).

My bibliography for Primer Vector Theory might look like:

Jezewski's papers:

https://arc.aiaa.org/doi/abs/10.2514/3.4949
https://arc.aiaa.org/doi/abs/10.2514/3.50176?journalCode=aiaaj
https://arc.aiaa.org/doi/abs/10.2514/3.50595?journalCode=aiaaj

Vinh's primer vector theory applied to atmospheric flight:

https://link.springer.com/article/10.1007/BF00935883

Brown's OPGUID and SWITCH programs and related papers:

https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19690027061.pdf
https://ieeexplore.ieee.org/abstract/document/1098718
https://arc.aiaa.org/doi/abs/10.2514/3.50575

Ping Lu and coauthors more recent series of papers which use Primer Vector theory:

https://arc.aiaa.org/doi/abs/10.2514/2.5045
https://arc.aiaa.org/doi/abs/10.2514/1.36084?journalCode=jgcd
https://arc.aiaa.org/doi/abs/10.2514/6.2009-6105
https://arc.aiaa.org/doi/abs/10.2514/6.2012-4843
https://arc.aiaa.org/doi/abs/10.2514/1.60181

A lot of the research there is on analytic solutions. I skip that and do fully numerical integration with rkf45 (roughly Mathlab's ODE45, although I need to upgrade to Dormand-Prince. I also use Levenburg-Marquardt rather than Powell's Dogleg simply because I have a fairly robust LM implementation that I didn't have to write myself (most of the literature uses the dogleg method). I also use a numerical jacobian that does finite differences that I also did not have to write myself (as opposed to some references that analytically compute the jacobian or the OPGUID/SWITCH approach of numerically integrating the jacobian with rkf45). I even numerically integrate the coast phases with rkf45 instead of using an analytical solution there (which is entirely just laziness and not wanting to reduce the footprint of the amount of numerical code I need to debug). The result is sort of a lazy hybrid of Ping Lu's papers (which uses numerical jacobians) with SWITCH/OPGUID (which uses rkf45 instead of analytical thrust integrals) and replacing the root finder with Levenberg-Marquardt. At any rate my own answer to myself in that space stack exchange question is more or less what i still use.

commented

Note that I somewhat regret going the indirect-method route. I didn't have a grad school advisor to suggest that was all old.

A better introduction to the direct method than i could give is here: https://space.stackexchange.com/a/29805/14420

At the same time I've hit problems with the indirect method where I've later found answers to my problems in the literature. Very specifically the last article by Brown addresses issues that I was having with writing the node executor:

https://space.stackexchange.com/questions/32393/proper-handling-of-terminal-guidance-of-finite-burn-closed-loop-execution-for-re

"the state constraints in Eq. (12) are inappropriate for orbit transfer missions" -- well Eq. (12) was exactly what I was beating my head against and they published the solution to that 45 years ago, I just had to find it. Whereas I'm worried there will be issues with convex optimization that the professionals have omitted in the current published papers and which won't appear for another 5-10 years in the literature but use "obvious" tricks-of-the-trade to solve engineering problems with the algorithms (that would be way over my head). So for now I'm sticking with the old stuff for now.

commented

Hey @lamont-granquist ! How are you?
I'm trying to make a MatLab model of the solution for (preferably fuel optimal) rocket landing for a school project. Since you've already done it, I thought maybe you can share with me some helpful articles about the equations and physics needed for this task, please?
I'm aiming for a 2D solution, and maybe include aero drag, but that's not a must if it complicates stuff too much.
Thanks in advance :)

commented

Oh ok :(
Maybe for next versions, it could use the Trajectories mod to get the correct coordinates?
Thx for the reply!
EDIT: where can I find the FAQ?

commented

Uh? The atmo model is up-to-date and has been for a long time. It may have some errors but it uses the current model.

commented

This is a FAQ. MJs landing autopilot's atmospheric drag model is for the pre-1.0 atmosphere so it won't work now for F9 landings. There is no configuration option to make it work.

commented

after several tries, it managed to come close to the target, but it used all the fuel that was meant for landing. It does a pretty substantial deceleration burn, despite the fact that I have a good heat shield.

Maybe it has something with the fact that I stage in the process? Can I configure MJ to land with stage #X? It also doesn't autostage while landing.
I can provide a video clip if it would help you solve the problem

commented

can someone please help me?

commented

You strongly overestimate how intelligent this module is. It does not understand staging and does not properly estimate when it should brake if there is am atmosphere.
Unfortunately I do not currently have the will/time to fix any of this so this will have to wait for someone to submit a patch.

commented

Ok, thank you

commented

The trajectory optimizer I'm working on should support staging in the atmosphere once I get everything wired up and get the atmospheric EOMs working, and it'll even hoverslam perfectly without deep throttling.... But that's months + months + months of work, its not a bugfix.

commented

Wow! sounds great! I'm glad to hear that someone is working on it ๐Ÿฅ‡
I'm not a modder but I would love to help in any way possible!
I have a bit of knowledge of Java alongside physics, and I would like to get into modding, so if there is anything I can do - hmu, please :)
I'm willing to learn anything that is necessary
EDIT: I made an auto hoverslam sim in JavaScript. It's quite basic, but it works!