Advertisement
blorgon

Mun Mission descent program

Jul 17th, 2017
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // DESCENT_PROGRAM
  2.  
  3. // an auxiliary script run by the Munar Module for targeted landing, for use in conjunction with MAIN_PROGRAM
  4. // by /u/supreme_blorgon, AKA kickpuncher on Discord
  5.  
  6.  
  7. 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).
  8. set pitch to 0.
  9. set throt to 0.
  10. set gain to 0.
  11.  
  12. print "Descent phase initiated... ".
  13. ship:partstagged("MMcab")[0]:controlfrom().          // switching control from the Command Module to the Munar Module
  14. wait 1.
  15. ship:partstagged("MMdock")[0]:undock().
  16. wait 1.
  17.  
  18. RCS on.
  19. set ship:control:fore to -0.5.          // quick RCS burst to get some distance between the two
  20. wait 1.
  21. set ship:control:fore to 0.
  22. RCS off.
  23.  
  24. stage.
  25. wait 10.
  26.  
  27. lock steering to retrograde.
  28. lock throttle to throt*gain.
  29.  
  30. warpto(time:seconds + ship:orbit:period).
  31.  
  32. // 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
  33. // 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)
  34. // 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
  35. // 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)
  36.  
  37. until round(periapsis,0) = 5500 {
  38.     set geo to mun:geopositionof(positionat(ship, time:seconds + ship:orbit:period/2)):lng.
  39.     print geo at (0,10).
  40.     if round(geo,0) = -33 kuniverse:timewarp:cancelwarp().
  41.     if round(geo,1) = -29.5 set gain to 1.
  42.     set throt to max(-constant:e^(-0.00025*periapsis + 1.375) + 1, 0).          // killing my throttle smoothly, again for precision
  43.     wait 0.
  44. }
  45. set throt to 0.
  46. warpto(time:seconds + (eta:periapsis-30)).
  47. 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.
  48. wait until eta:periapsis < 1.
  49. until groundspeed < 20 {
  50.     set throt to 1.
  51.     set pitch to -18*min(verticalspeed, 0).
  52.     wait 0.
  53. }
  54. wait 1.
  55. toggle AG6.
  56. unlock steering.
  57. set throt to 0.
  58. set gain to 0.
  59. 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
  60. lock steering to srfretrograde.
  61.  
  62. // my pride and joy
  63. // here's where that m_dot comes in
  64. // I'm finding my vertical speed, the acceleration of gravity at my altitude (which changes a not-insignificant amount during the fall),
  65. // 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
  66. // 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
  67. // take to change your velocity a little bit trickier than it would be with constant acceleration
  68. // 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
  69. // 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
  70. // actually a lot more complicated than that, so I fudge my burn_time a little after running some simulations
  71. // if you copy my method, you will need to change the coefficient I point out in the comments below
  72.  
  73. until ship:status = "landed" {
  74.     set m to 1000*mass.
  75.     set v to abs(verticalspeed).
  76.     set gnd_alt to altitude - geoposition:terrainheight.
  77.     set grav to body:mu/(body:radius + gnd_alt)^2.
  78.     set tti to (v - sqrt(v^2 + 2 * grav * gnd_alt)) / grav.
  79.     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
  80.     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
  81.     set throt to -constant:e^(-gnd_alt) + 1.
  82.     if gnd_alt < 5 {
  83.         if v < 2 break.
  84.     }
  85.     wait 0.
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement