RizzoTheRat

Gravity turn maths

Recommended Posts

I've started fiddling with kOS and my usual programming technique is to look at what other people have done first and then pinch bits of various people's ideas to do what I want.  So far all the launch scripts I've seen work by pointing the ship at a specific angle rather than doing a real gravity turn.

I would like to programme a proper gravity turn, and then keep the ship pointing prograde, only making adjustments if it falls outside specified thresholds, which is kind of what I do when launching manually.  My understanding is the initial turn will be dependant on TWR and drag.  TWR I can easily calculate, presumably I could calculate a drag factor by comparing actually acceleration with the acceleration my TWR would produce in a vacuum?

Anyone done anything similar?  Anyone got any thoughts on working out the relationship between TWR, drag and the initial turn angle?

 

Share this post


Link to post
Share on other sites

There is a mod that does a primary tipping initially and then adjusts throttle to try to keep a gravity turn going and only when that is not enough will it try to use control surfaces. That might be a good start.

Edited by John FX

Share this post


Link to post
Share on other sites

Here's my attempt at doing the GravityTurn mods approach in kOS:

https://gist.github.com/lamont-granquist/e26279492ec020f711d2

I believe if you want to do the most optimized gravity turn that the problem you are trying to solve is that you want to dump as much delta-V as possible while you are horizontal to minimize the gravity drag losses.

If you're too low and you burn horizontal you burn up, so you first have to reach an altitude of around 40,000-45,000m

If your horizontal velocity is too low when you reach an apoapsis of around 40,000m then you won't be able to circularize and maintain your 45,000m apoapsis, so you need to have some significant horizontal delta-v there.

The way that GT does this is by keeping the apoapsis around 30 seconds ahead of you.

There's probably an optimal trajectory where at the apoapsis you have a horizontal velocity of around 600-800m/s at around 40,000m-ish.

Ideally you would burn your fuel in a single instant (at infinite TWR) to shoot yourself into that trajectory (taking account for how much drag you'll have, which alone is a hard problem to solve -- it'd be simpler on an airless world -- although the GT module itself shows that drag is not that large of a loss with most halfway sanely constructed rockets).

So the problem to solve is to burn at full throttle, and immediately tip over just enough so that when your heading is locked to your surface vector, and after drag is subtracted that you wind up on that trajectory that takes you to around 600-800m/s at 40-45k

Then once you can burn horizontal, burn all your fuel to circularize (at a safe altitude without burning up), and then further burn to raise your apoapsis up to your target orbit.

One problem to solve is that high altitude circularization burn at around 45k needs to be a bit more controlled so that you don't exceed certain speeds at certain altitudes (but you do punch it up to the max that you can).  Instead of trying to solve the problem of steering a rocket analytically to hit that curve there's probably a way to write down function of max velocity as it depends on height (or air density which you then plug in the bodies air density as a function of height) and then write a PID controller that feathers the throttle and/or attitude to try to hit that curve.

Then I think on an airless world you could actually work backwards from a desired trajectory and work out the GT starting angle that would get you there for a given TWR.  

http://www.amazon.com/Introduction-Space-Dynamics-Aeronautical-Engineering/dp/0486651134/

There's some math in there which is about as accessible as I've found so far.

Share this post


Link to post
Share on other sites
12 hours ago, Jim DiGriz said:

Here's my attempt at doing the GravityTurn mods approach in kOS:

https://gist.github.com/lamont-granquist/e26279492ec020f711d2

Interesting, thanks.  So if I'm reading that right, you're setting of at a TWR of 2.8 (so presumably always designing for a bit more than that?), climbing straight up to 50m/s, then pitching down 17 degrees and then trying to maintain 40 seconds to Ap?

I can't quite work out what the end_surface bit is about, you're sticking to prograde when within the Q bounds, but how does that tie in with the ETA to Ap?

Share this post


Link to post
Share on other sites
5 hours ago, RizzoTheRat said:

Interesting, thanks.  So if I'm reading that right, you're setting of at a TWR of 2.8 (so presumably always designing for a bit more than that?), climbing straight up to 50m/s, then pitching down 17 degrees and then trying to maintain 40 seconds to Ap?

I can't quite work out what the end_surface bit is about, you're sticking to prograde when within the Q bounds, but how does that tie in with the ETA to Ap?

All the code that depends on TWR is commented out so at one point I was playing around with a rocket with 2.8 TWR and was using those startSpeed and startTurn calculations.  But yeah you're right that's the initiation of the gravity turn and its just hardcoded.  Those are the numbers that last worked for the last rocket I was playing with.  I don't know why all of the Ascent Guidance autopilots use a startSpeed and don't just tip over a bit right at the start, I keep shaving that down and it doesn't seem to make a difference, but I never played with it at exactly zero.  I think we're may be trying to act like real rocket launches but there's no reason in kerbal to do that?  Not sure...

The end_surface bit is when we stop setting our steering locked to the surface vector (AoA is zero) and when we start tracking prograde instead.   We do that when Q is less than 2.5 kPa which happens when we start hitting the upper atmosphere and I think are pretty much horizontal.  Of course Q is also less than 2.5 kPa at the start of the launch so we need to make sure that we're coming down off of max Q rather than climbing up to it, which is what the check is that Q is less than max Q / 2 -- on ascent Q is very unlikely to be half of the max Q that we've already seen since we don't throttle back for quite some time.

And we end_surface because Q has dropped enough that drag has dropped enough that we're basically 'out' of the atmosphere and drag is low and we no longer care about drag loss, and we don't care about the possibility that we might flip over if our AoA isn't zero.

I'm pretty sure that "maintaining time to Ap" is a bit of a (useful) hack -- what its trying to do is make it so that you burn a lot of fuel immediately to push that Ap out, and then by maintaining the Ap slightly ahead of you when you hit horizontal flight it minimizes your gravity losses there.  It keeps you burning horizontal so that you don't pass through the Ap and start having a large deviation between your prograde and your burn (which causes losses) and you don't get too ahead of yourself and push the Ap out too far and again your burn would not be in line with your prograde which would not be horizontal.   There's dV losses that come in when you don't burn horizontal and dV losses that come in when you don't burn along your prograde vector -- when your prograde vector is horizontal and you're burning along it is when you have zero dV losses.

And if you want to see improvements in delta-V getting to orbit build some bigger rockets using jumbo-64s and plenty of TWR (like 2.8 or so).  If you build a 1.25m rocket with a 1.4 TWR you won't see much improvement because your drag losses will be higher (bigger rockets punch through the atmosphere better -- kerbal gets this right).  Also if you build upper stages without enough TWR this code doesn't do any pitching up, so you'll just fail to maintain time to Ap and crash.  Upper stages for this code need a decent amount of TWR.

(and the drag losses in this code are all wrong, its a long story....)

Share this post


Link to post
Share on other sites

If you turn right off the pad presumably you're having you use the reaction wheels to keep it pointed in a sensible direction, if you let it get up some speed first the aerodynamics will keep it pointed the right way. 

I'm thinking I might just spend some time experimenting with turn altitudes and angles for different TWR/drag craft and see if there's any obvious relationship.

Share this post


Link to post
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.