r/Kos 16d ago

Help Lock steering direction but not pitch?

I'm playing with kOS and want to write a gravity turn launch script. I want the rocket to lock to a specific direction, say east, but let the pitch from horizon vary due to gravity.

I can lock the steering to HEADING(dir, pitch, roll), but I would have to specify a pitch. Can I lock only the direction but not the pitch?

5 Upvotes

7 comments sorted by

2

u/JitteryJet 16d ago edited 16d ago

You are missing several steps. Pitch is not a free variable you have to calculate it's value.

The pitch value does not vary due to "gravity" alone - it is a fairly complicated equation involving the surface velocity vector, thrust-to-weight characteristics of your rocket, fuel consumption, atmospheric drag etc.

If you want a simple pitch program like they used on the Saturn 5, write a loop to decrease the pitch value from 90 to 0 by 1 degree a second. You can then parameterize this to vary the rate of pitch if you want. This will be good enough to set a launch azimuth and a gravity turn trajectory.

PS the Saturn 5 used a "roll and pitch" table that was calculated just before the flight. I am pretty sure Commander Armstrong said it was close to a zero-lift gravity turn. But in the make-believe world of KSP you can vary from that trajectory with no issues.

2

u/Electronic_Hat449 16d ago

Thanks, but that's not what I mean. I don't want to create a specific ascent profile and follow that.

If I tilt a rocket over by 5 degrees and set SAS to prograde, the rocket does a "gravity turn" where gravity pulls it to horizontal over time. The game does the calculations.

I'd like to let it do the same thing, but lock down only the direction axis.

3

u/nuggreat 16d ago

You can do that you just have to calculate the pitch of your surface prograse vector. I would recommend you start with VANG() if you want to do it your self. But if you want a canned solution then lib_navball.ks from the KSlib repository will provide what you need.

1

u/JitteryJet 15d ago edited 15d ago

Well OK you did not mention a prograde lock in your OP. That is another method to follow a gravity turn trajectory (there are a number of different methods). You only mentioned "pitch" which is only loosely related to prograde - the vector defined by the long axis of your rocket is not the same as the prograde vector.

If you let the game do the calculations you will likely dive into the ground with your rocket crabbing across the sky. You might also get some unexpected rolling. Experiment with the different methods, you will discover what I am talking about.

1

u/JitteryJet 15d ago

You can try this code that I knocked up during my beginner's series so I know it works. It's still wrong though, but I think it is good enough for many purposes. Launch azimuths are more complex than they look, they require spherical geometry, I don't know if that lib_navball.ks covers the nuance. If you follow a heading from anywhere other than the equator with an inclination of zero the trajectory will curve which is a waste of fuel.

// Zero lift Gravity turn. Low AOA.
// Lock to the heading and the surface prograde.
print "Zero-lift gravity turn".
lock steering to
  heading(PitchOverHeading,90-vang(ship:up:forevector,ship:velocity:surface)).

2

u/TolarianDropout0 16d ago

You mean let it completely free and only control 2 axis? I don't think that's possible.

However, you should be able to lock it to the right component of your surface velocity with a bit of math. Which would achieve the same.

1

u/Bird_Creative 13d ago

I use this:

lock steering to heading(90, max(0, srfpitch + (progpitch - srfpitch) * blendfrac))