Advertisement
B25Mitch

Kerbin to Mun and Back

Sep 26th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. --
  2. --         Kerbin to Mun and Back by B25Mich
  3. --                    Version 1.0
  4. --
  5. --                 for MechJeb 1.9.1
  6. --
  7. --------------------------------------------------------
  8. -- Usage: * save to KSP/PluginData/mumechlib/kerbintomun.lua
  9. --        * in game, open autom8
  10. --        * enter: dofile("kerbintomun.lua")
  11. --        * and follow the instructions.
  12. --------------------------------------------------------
  13.  
  14. function GoMunDriver(lat, lon)
  15.  
  16.     print "Launching..."
  17.         mechjeb.launchTo(125000, 0)
  18.         wait(mechjeb.free)
  19.         mechjeb.autoStageActivate()
  20.         print "TMI..."
  21.         mechjeb.transfer("Mun", 200000)
  22.         wait(mechjeb.free)
  23.         print "Warping to SoI..."
  24.         mechjeb.warpToEvent("soi")
  25.         wait(mechjeb.free)
  26.         print "Warping to Pe..."
  27.         mechjeb.warpToEvent("pe", 30)
  28.         wait(mechjeb.free)
  29.         print "Circularizing orbit..."
  30.         mechjeb.circularize()
  31.         wait(mechjeb.free)
  32.         print "Landing..."
  33.         if (lat == nil or lon == nil) then
  34.         mechjeb.landAt(0, 14)
  35.      else
  36.             mechjeb.landAt(lat, lon)
  37.         end
  38.         wait(mechjeb.free)
  39.         mechjeb.autoStageDeactivate()
  40.         print "Landed!"
  41. end
  42.  
  43. function GoKerbinDriver(lat, lon)
  44.        
  45.     print "Lifting off..."
  46.     mechjeb.attitudeTo("up", "SURFACE_NORTH") -- vertical ascent
  47.     mechjeb.thrustActivate(100)
  48.     while vessel.altitudeTrue < 300 do
  49.         wait(0.25)
  50.     end
  51.    
  52.     print "Escaping the Mun..."
  53.     -- this needs to be optimized. figure out an escape vector
  54.     -- that is as close as possible to the opposite of Mun's orbital velocity
  55.     -- but not lower than 0¬∞ to the surface
  56.     mechjeb.attitudeTo("right", "SURFACE_NORTH") -- heading east
  57.     while vessel.orbitEccentricity < 1 do
  58.         wait(0.25)
  59.     end
  60.     mechjeb.thrustDeactivate()
  61.    
  62.     print "Coasting to Mun escape, hang on."
  63.     mechjeb.warpToEvent("soi")
  64.     wait(mechjeb.free)
  65.    
  66.     print("Lowering Kerbin periapsis to 100 km...")
  67.     mechjeb.changePe(100 * 1000)
  68.     wait(mechjeb.free)
  69.    
  70.     print "Warping to Pe..."
  71.         mechjeb.warpToEvent("pe", 30)
  72.         wait(mechjeb.free)
  73.  
  74.         print "Circularizing orbit..."
  75.         mechjeb.circularize()
  76.         wait(mechjeb.free)
  77.    
  78.     print "Re-entry... hold onto something."
  79.         mechjeb.landAt(-0.103, -74.575)
  80.         wait(mechjeb.free)
  81.         mechjeb.autoStageDeactivate()
  82.         print "Landed!"
  83. end
  84.  
  85. function WaitForLandingDriver(lat, lon)
  86.     wait(30)
  87.     while vessel.altitudeBottom > 5 do
  88.         wait(5)
  89.     end
  90.     print "Prepare for launch."
  91.     wait(30)
  92.     local co = coroutine.create(GoKerbinDriver)
  93.     coroutine.resume(co, lat, lon)
  94. end
  95.  
  96. function GoKerbin(lat, lon)
  97.     local co = coroutine.create(GoKerbinDriver)
  98.         coroutine.resume(co, lat, lon)
  99. end
  100.  
  101. function GoMun(lat, lon)
  102.     local co = coroutine.create(GoMunDriver)
  103.     coroutine.resume(co, lat, lon)
  104. end
  105.  
  106. function RoundTrip(munlat, munlon, kerblat, kerblon)
  107.     local co1 = coroutine.create(GoMunDriver)
  108.     coroutine.resume(co1, munlat, munlon)
  109.         local co2 = coroutine.create(WaitForLandingDriver)
  110.     coroutine.resume(co2, kerblat, kerblon)
  111. end
  112.  
  113. print "Usage: GoMun(lat, lon)"
  114. print "Usage: GoKerbin(lat, lon)"
  115. print "Usage: RoundTrip(munlat, munlon, kerbinlat, kerbinlon)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement