Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Mun to Kerbin Return Script by olex
- -- Version 1.0
- --
- -- for MechJeb 1.9.1
- --
- --------------------------------------------------------
- -- Usage: * save to KSP/PluginData/mumechlib/GoHome.lua
- -- * in game, open autom8
- -- * enter: dofile("GoHome.lua")
- -- * and follow the instructions.
- --
- -- Quicksave before using.
- -- If an "coroutine out of sync" error pops up, load the save and try again.
- --
- -- No guarantees, but it should work :) Have fun!
- --------------------------------------------------------
- function KerbinReturnDriver(pe)
- if pe == nil then
- pe = 20.0
- end
- if pe > 70 then
- print "Final periapsis not in atmosphere, no automatic landing."
- end
- print "Lifting off..."
- mechjeb.attitudeTo("up", "SURFACE_NORTH") -- vertical ascent
- mechjeb.thrustActivate(100)
- while vessel.altitudeTrue < 300 do
- wait(0.25)
- end
- print "Escaping the Mun..."
- -- this needs to be optimized. figure out an escape vector
- -- that is as close as possible to the opposite of Mun's orbital velocity
- -- but not lower than 0° to the surface
- mechjeb.attitudeTo("right", "SURFACE_NORTH") -- heading east
- while vessel.orbitEccentricity < 1 do
- wait(0.25)
- end
- mechjeb.thrustDeactivate()
- print "Coasting to Mun escape, hang on."
- mechjeb.warpToEvent("soi")
- wait(mechjeb.free)
- print("Lowering Kerbin periapsis to "..pe.."km...")
- mechjeb.changePe(pe * 1000)
- wait(mechjeb.free)
- print "Coasting to Kerbin, stand by."
- mechjeb.warpToEvent("pe")
- while vessel.atmosphericDensity <= 0 and (not mechjeb.free()) do
- wait(0.25)
- end
- mechjeb.controlRelease()
- if vessel.atmosphericDensity > 0 then
- print "Re-entry... hold onto something."
- mechjeb.attitudeTo("back", "ORBIT")
- while vessel.speedSurface > 250 do
- wait(0.1)
- end
- print "Landing."
- mechjeb.autoStageActivate()
- mechjeb.land()
- wait(mechjeb.free)
- mechjeb.autoStageDeactivate()
- print "Welcome home!"
- else
- print "Not in atmosphere at periapsis. We're done here."
- end
- end
- function GoHome(pe)
- local co = coroutine.create(KerbinReturnDriver)
- coroutine.resume(co, pe)
- end
- print "Usage: GoHome(<desired Kerbin periapsis in km, default 20>)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement