Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DESCENT_PROGRAM
- // an auxiliary script run by the Munar Module for targeted landing, for use in conjunction with MAIN_PROGRAM
- // by /u/supreme_blorgon, AKA kickpuncher on Discord
- set m_dot to 20000 / 3139.2. // my craft's mass flow rate, which is my thrust divided by the engine's exhaust velocity, (ISP * 9.81).
- set pitch to 0.
- set throt to 0.
- set gain to 0.
- print "Descent phase initiated... ".
- ship:partstagged("MMcab")[0]:controlfrom(). // switching control from the Command Module to the Munar Module
- wait 1.
- ship:partstagged("MMdock")[0]:undock().
- wait 1.
- RCS on.
- set ship:control:fore to -0.5. // quick RCS burst to get some distance between the two
- wait 1.
- set ship:control:fore to 0.
- RCS off.
- stage.
- wait 10.
- lock steering to retrograde.
- lock throttle to throt*gain.
- warpto(time:seconds + ship:orbit:period).
- // this bit here waits until the lattitude/longitude of a point in my orbit 180° from where I am is over a certain spot on the surface of the mun
- // I lead my target landing site by about 7.5° because I need to compensate for both the rotational velocity of the Mun (which will rotate a few degrees by the time I get there)
- // and also the time it will take my craft to kill it's orbital velocity, so that I end up almost directly over my target with very little horizontal speed remaining
- // so once that spot on the other side of my orbit is at the right lat/long I lower my periapsis to 5.5 km (which is actually more like 1.5 km above the terrain)
- until round(periapsis,0) = 5500 {
- set geo to mun:geopositionof(positionat(ship, time:seconds + ship:orbit:period/2)):lng.
- print geo at (0,10).
- if round(geo,0) = -33 kuniverse:timewarp:cancelwarp().
- if round(geo,1) = -29.5 set gain to 1.
- set throt to max(-constant:e^(-0.00025*periapsis + 1.375) + 1, 0). // killing my throttle smoothly, again for precision
- wait 0.
- }
- set throt to 0.
- warpto(time:seconds + (eta:periapsis-30)).
- lock steering to srfretrograde*r(-pitch, 0, 0). // locking steering to retrograde, but with a pitch function that pitches my craft above it based on my vertical speed.
- wait until eta:periapsis < 1.
- until groundspeed < 20 {
- set throt to 1.
- set pitch to -18*min(verticalspeed, 0).
- wait 0.
- }
- wait 1.
- toggle AG6.
- unlock steering.
- set throt to 0.
- set gain to 0.
- wait until ship:facing:yaw - srfretrograde:yaw > -1. // waiting for my velocity vector to line up with the direction my ship is facing so I don't suddenly jolt into position
- lock steering to srfretrograde.
- // my pride and joy
- // here's where that m_dot comes in
- // I'm finding my vertical speed, the acceleration of gravity at my altitude (which changes a not-insignificant amount during the fall),
- // the time it'll take for me to hit the ground, and the time it will take for me to kill my current vertical velocity
- // m_dot again is my mass flow rate, which helps me calculate my change in acceleration as I burn fuel. Change in acceleration, or "jerk" makes finding how long it will
- // take to change your velocity a little bit trickier than it would be with constant acceleration
- // now that I know my time to impact and my instantaneous burn time, I can time my engine ignition so that I start killing my vertical speed at the last possible second
- // doing it this way means that I touch down on the surface theoretically at the same time I kill my vertical speed, but finding that perfect time to start the burn is
- // actually a lot more complicated than that, so I fudge my burn_time a little after running some simulations
- // if you copy my method, you will need to change the coefficient I point out in the comments below
- until ship:status = "landed" {
- set m to 1000*mass.
- set v to abs(verticalspeed).
- set gnd_alt to altitude - geoposition:terrainheight.
- set grav to body:mu/(body:radius + gnd_alt)^2.
- set tti to (v - sqrt(v^2 + 2 * grav * gnd_alt)) / grav.
- set burn_time to (m - m*constant:e^(-v / 3139.2)) / m_dot. // that 3139.2 is specific to the engine on my craft. You will need your own engine's ISP * 9.81 to find this value
- if tti + burn_time*0.6125 > 0 set gain to 1. // that 0.6125 is the coefficient I'm talking about. It will need to be adjusted based on your TWR and the altitude you fall from
- set throt to -constant:e^(-gnd_alt) + 1.
- if gnd_alt < 5 {
- if v < 2 break.
- }
- wait 0.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement