Jump to content

[Updated] Aerobraking Calculator


Recommended Posts

lQ3fON9.png

http://alterbaron.github.io/ksp_aerocalc/

New Updates!

  1. Fixed a bug that would screw up results for retrograde encounters with Jool.
  2. Added circularization delta-V prediction.

Updates (Aug. 5th)

  1. Now more accurate! The calculator can now make use of orbit direction information to calculate a much more accurate result.
  2. Unit support! Enter your orbit data in km or Mm for convenience. (Thanks to retoo on GitHub for this feature.)
  3. Minor formatting changes.

Source Code

https://github.com/alterbaron/ksp_aerocalc

Photo Album

http://imgur.com/a/tB3H9


Quick Guide

To use the calculator, first drop your periapsis somewhere just above the atmosphere of the target body. This helps the calculator find a better manouever. Then, enter your orbit data into the form, and the apoapsis you want to have. It will then calculate a constant-velocity manoeuver to get you there.

Note: I used to suggest dropping your periapsis all the way inside of the target body's atmosphere. This is not a good idea, as the calculator may have trouble finding a solution if you set it too low.

By "constant-velocity", what I mean is that your orbital velocity should not change (much) after the manoeuver. Instead, only the direction of your velocity will be different. To achieve this, the direction in which to thrust will be located exactly between the prograde and retrograde markers on your navball. On the calculator, this is given as an angle from the top of the navball.

Don't worry if the orbital velocity is a bit off. What's much more important is to get your periapsis to the right altitude. Once that's set, just coast through the atmosphere.

Note that sometimes, due to some buggy behaviour with orbits in the game, the periapsis will jump around as you approach the target body. If this happens to you, just re-run the calculator with the new orbit data to make a correction.

If you ever get the message "No Solution!" using the calculator,try raising your periapsis height.

Edited by alterbaron
New updates!
Link to comment
Share on other sites

  • 3 weeks later...

Wow, this looks great! This will be extremely useful when I go to do large-scale Jool missions.

Great idea! This should solve the problem of having to go quicksave-setup-try-fail-load-setup-try-fail-load-setup-try-suceed a little.

Link to comment
Share on other sites

  • 3 weeks later...

Hm... whatever I do, I come up with "No solution"

In this case, my altitude is 750624m above Kerbin, my velocity is 1291m/s, periapsis is at 48000, I want to get to 100000m Apoapsis...

Am I doing something wrong?

Link to comment
Share on other sites

First of all, thanks for the feedback! It's really easy to let bugs slipped by unnoticed, so your comments are appreciated.

I just looked into this:

I need to revise my instructions that say to put your periapsis inside the planet's atmosphere. It turns out that this advise is flawed: you should put your periapsis at least a little bit outside the planet's atmosphere, or else the calculator may have problems.

If you put your periapsis at around 80,000m before running the calculator, you should be fine.

Details:

The problem here is that the calculator looks for maneuvers that keep the magnitude of your velocity the same (this is an arbitrary constraint that makes searching for a solution easier).

When your craft doesn't have a high enough velocity to get a PE high enough in the atmosphere without changing the magnitude of its velocity, then the calculator can't find a solution.

Edited by alterbaron
Link to comment
Share on other sites

  • 1 month later...

I must not be doing something right. I think my problem is finding the angle for the burn. I had a Kethane probe around Minmus and it was done so I thought I'd send it back to map Kerbin (maybe a little backwords, should have started with Kerbin first). The probe is ion powered so fuel isn't that much of an issue, but thought I'd get some aerobraking practice in, as I've got a ton of kethane miner landing practice lately.

I've got my start PE at 77,740, orbital speed is 70m/s, altitude is ~30,353,843 (depending on the time obviously) and I want the probes AP to end up around 109,972m. The calculator tells me to put my pe at 34,167.24 with a thrust angle of -8.64 and a deltav of 14.49. Like I mentioned above I think my problem is figuring out where the -8.64 angle should be, and when I should start the burn (if it matters). So far every attempt my resulting AP is around 450,000m - 500,000m.

Any help would be great. :) I can provide screenshots if needed. I'm sure it's something simple that I'm not doing right. I'll keep at it though :)

In a side note, I've left my solar panels out, the biggest stock ones, and have been surprised that they didn't break off during the aerobraking attempts. Makes for interesting re-entry effects though. :)

Update: Almost 24 hours later (not constantly playing obviously :P) I got it figured out. I set my PE to roughly 33,200m with roughly the same angle the calculator gave me and it worked. I got my desired AP to around 115,000. So I just hve to raise my PE to the 109,972m then lower my AP to that as well. I'm gonna guess the calculator was made before .20, I think I remember hearing something about the atmosphere or something being changed but I could be wrong. Of course it could also be because I wasn't at the exact altitude I gave the calculator before I started my burn. :)

Edited by Sma
Link to comment
Share on other sites

Ah, I'm glad you were able to sort out your issue.

Aerobraking into an orbit with a large AP reliably can be quite tough, since the final AP is extremely sensitive to small changes in the aerobraking PE. This is a mathematical fact that comes out of the physics of aerobraking, so there's no real way around it (unless you use an in-game plugin that can gather perfect orbital info, of course, and even that won't be exact due to numerical stability issues.) The larger your final PE, the more careful you have to be when plugging in your numbers.

The whole angle thing is confusing, I'll agree. Pretty much, you want to draw an imaginary circle on the navball that passes through the prograde and retrograde markers. The direction to thrust at lies on that circle, and at the given angle away from the top of the navball. Really, what you're doing is thrusting at 90 degrees between the prograde and retrograde markers. I should update the info on the page to make this more clear.

Link to comment
Share on other sites

Yeah, that was my other thought, being further out means its more sensitive to small changes. At any rate, the calc was enough to get my close, I just had to figure out how to adjust it. :) It could all be because my high AP changed by 1000m or more between inputting the numbers and getting it all setup in the game, even with it paused (time between adjusting the angle and what not).

An update for the angle could help some more. Maybe an example using the navbal, saying "calc gives an angle of 14.235 degrees, here it is on the navball" sort of thing. :) If that doesn't give away too much anyway. lol

I've pretty much got the angles figured out, i think, though it would be cool if I learned how to navigate more using the navball and heading with out looking at the map so much, similar to how they do, or did, in early aircraft. Though I guess it would also require a compass, which doesn't work as well in space depending on where you are/how far out you are. Meh...oh well. :)

Link to comment
Share on other sites

  • 2 weeks later...

Warning: math post. Might be a bit long . . .


The calculator works off of a simple principle: given the current orbital velocity, the current altitude, and the periapsis height, it is possible to figure out the shape of your orbit in the plane of orbit, along with a bunch of relevant orbital data.

Here's a snippet of MATLAB code that does just that:


function [ ep ec a hmag rpe rap ] = get_orbit_params( r, v, mu )
% Get useful orbit parameters from position vector, velocity vector, and
% gravitational parameter.

% specific orbital energy
ep = dot(v, v)/2 - mu/norm(r);

%specific angular momentum
r3d = [r(1) r(2) 0];
v3d = [v(1) v(2) 0];
hmag = cross(r3d, v3d);
hmag = hmag(3);

%eccentricity
ec = sqrt(1+2*ep*hmag.^2./(mu.^2));

%semi-major axis
a = -mu/(2*ep);

%periapse distance
rpe = -a*(ec-1);

% Apoapse distance (valid iff ec < 0)
rap = (1+ec)*a;

end

Note that r and v are vectors, and have X and Y components. Mu is the gravitational parameter for the body (taken from the wiki).

There's an ambiguity in orientation, so we can set the azimuthal (angular) position of r as we please.

I use r = [orbit_altitude + planet_radius, 0] for simplicity.

Some quick geometry gives the following expressions for the x and y components of the velocity:


vy = (rpe/r)*sqrt(v^2+2*mu*(1/rpe-1/r));
vx = sqrt(v^2-vy^2);

Of course, v = [vx, vy]. Now we can plug in r, v and mu into the earlier code to get all that other good stuff.

Using this data, we can figure out the magnitude and direction of the ship's velocity when we hit the planet's atmosphere:


% Calculate vcontact and rcontact where the orbit intersects the
% atmosphere.

cos_theta_contact = (1/ec)*(a*(1-ec^2)/Ratm - 1);
theta_contact = acos(cos_theta_contact);

vcontact_mag = sqrt(2*(ep + mu/Ratm));
theta_1 = asin(hmag/(Ratm*vcontact_mag));

vcontact = vcontact_mag * [-cos(theta_1+theta_contact), -sin(theta_1+theta_contact)];
rcontact = Ratm * [cos(theta_contact), sin(theta_contact)];

Where Ratm is the maximum extent of the atmosphere of the body (including the radius of the planet). Theta_contact is the angle with respect to our arbitrary coordinate system where the ship hits the atmosphere. Theta1 is some other angle between the position and velocity vectors, which I use to figure out the x and y components of the velocity (some tricky geometry, you'd need to try it on paper to see how it works).

Anyhow, now that the ship is in the atmosphere, we can simulate its trajectory (affected by both drag and gravitational forces) until it either escapes the atmosphere, or crashes. This is done using a time-stepped method.

Pretty much, at a given point in time, we calculate the gravitational and drag forces affecting the ship. These forces are used to update the velocity of the ship, which is used to update its position. This process is repeated until the ship hits the ground (vector length of r <= the planet radius) or it escapes the atmosphere (||r|| >= Ratm). Here's the simplified model used for the ship:


function [ F ] = in_atmo_force( R0, P0, H0, d, mu, m, A )
% Returns a function which gives the total vector force in atmosphere
% as a function of position and velocity.

Kp = 1.2230948554874*0.008;

% Total force = drag + gravity
F = @(r,v) -0.5*Kp*P0*exp((R0-norm(r))/H0)*norm(v)*d*m*A*v - m*(mu/norm(r).^3)*r;

end

F is a function which takes the position and velocity vectors and returns the vector force due to both drag and gravitation.

(Note that KSP uses an erroneous mass term in the drag part of the force which doesn't exist in real life.)

To step the ship forward in time, one could use a simple approach like Euler's method.

I used a variant of a method known as Velocity Verlet since it gives more accurate results with less computation time.

Here's the code used to simulate the physics (Modified Velocity Verlet):


function [r v t] = integrate_path( F, m, r0, v0, dt, Rmin, Ratm )
% Integrate the equation of motion to find the path in atmosphere.
% Terminate on collision with surface (sea level) or atmosphere escape.

t = 0;
r = r0;
v = v0;

a = @(rin, vin) F(rin, vin)./m;

firstrun = true;

while firstrun || (norm(r) <= Ratm && norm(r) >= Rmin)
r_old = r;
v_old = v;
a_t = a(r_old, v_old);
r = r_old + v_old*dt + 0.5*a_t*dt.^2;
v_est = v_old + 0.5*dt*(a_t + a(r,v_old+dt*a_t));
v = v_old + 0.5*(a_t + a(r,v_est))*dt;
t = t + dt;
firstrun = false;
end

end

Note that F is our force function from before, which takes the position and velocity as arguments, and computes the vector force.

Almost there! Once we've escaped the atmosphere, we simply take our final r and v vectors and plug them in to

get_orbit_params( r, v, mu )

to figure out the apoapsis of our final orbit.

Finally, we run all of this over and over again, varying the periapsis height that we plugged in way back at the start. We keep refining that PE value until the resulting AP is what we wanted.

That's it! Just a little convoluted.


Anyway, if you want to learn more about orbital mechanics, I'd check out the wonderful pages located HERE.

I also have an (incomplete) Guide to Orbital Mechanics for KSP in the wors which I really should get around to finishing. Might help with getting started with orbital mechanics stuff if you want / need to.

I've uploaded some similar code for computing atmospheric landings on Github Gist.

The (awful) source code of the live site is available On Github if you like reading Javascript more than MATLAB.

If you've made it this far, thanks for braving it through and reading!

Link to comment
Share on other sites

New updates!

  1. The calculator can now make use of orbit direction information to calculate a much more accurate result.
  2. Unit support! Enter your orbit data in km or Mm for convenience. (Thanks to retoo on GitHub for this feature.)
  3. Minor formatting improvements.

The new orbit direction feature increases the accuracy of the calculator substantially. In one of my tests, I was able to aerobrake from a hyperbolic Kerbin encounter to a 1000 km orbit to an accuracy of 8000m.

That's an error of only 0.8%!

The orbit direction info works best if you have a more-or-less equatorial encounter. If you're coming in with a polar encounter, you might get better results by choosing "ignore".

Link to comment
Share on other sites

Really? MJ does predictions? I've never seen it. I did about 20 restarts last night because I wanted to aerocapture around Laythe but didn't know what to set my PE too. I found out that 10km was crash-and-burn material and 25km+ failed to capture without me burning extra retro dv. It turned out 22km was best and this would have saved me 20 resets!

Link to comment
Share on other sites

Thank you so much for your efforts making this! I've already used the site twice now and just wow. I've always had issues with getting the aerobraking / aerocapture to work properly but having this calculator handy has made some of my mission planning so much more fun now.

Link to comment
Share on other sites

Oh, maths!

I know mech jeb does everything for you, and that's half the reason I don't like it. A fair amount of KSP's enjoyment comes from piloting things my self.

The most fun I've had has been flying missions IVA. I've seen people do it but most of them run the missions before hand and memorize burn times/target velocities. I'd much rather have the tools in hand, in this case maths, to design the ship in VAB knowing each stage's delta v. (Thanks Kerbal Engineer) And have all the math I need on hand to plot my burns exactly.

I really like the info that MechJeb provides and I think some of it should be available to us by default. But I think MechJeb goes a step too far in to having the game play it self.

Thanks again for the details, I'll likely add this to my collection.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Something I can't believe I've never suggested before:

Would it be possible to implement a "coasting mode" for the calculator? Sometimes I don't really have a specific final apoapsis in mind, but I have a trajectory that already intersects with the atmosphere, and I want to see whether or not that will get me an aerocapture without any input on my part.

Link to comment
Share on other sites

That's not a bad idea.

Since the aerobraking code already exists, it's just a simple matter of throwing together an alternate interface.

It could also give out some other fun/useful stats, like time in atmosphere, max g-force, and final orbit parameters like eccentricity.

Link to comment
Share on other sites

  • 4 weeks later...

Preview of a new "expert mode" interface:

http://alterbaron.github.io/ksp_aerocalc/expert.html

This alternate interface (when done) will tell you your final aerobraking AP or, if the ship crashes into the surface, some other stats like landing phase angle.

I also want to add the ability to generate some simple plots (g-force comes to mind).

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...