Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Kerbin to Mun and Back by B25Mich
- -- Version 1.0
- --
- -- for MechJeb 1.9.1
- --
- --------------------------------------------------------
- -- Usage: * save to KSP/PluginData/mumechlib/kerbintomun.lua
- -- * in game, open autom8
- -- * enter: dofile("kerbintomun.lua")
- -- * and follow the instructions.
- --------------------------------------------------------
- function GoMunDriver(lat, lon)
- print "Launching..."
- mechjeb.launchTo(125000, 0)
- wait(mechjeb.free)
- mechjeb.autoStageActivate()
- print "TMI..."
- mechjeb.transfer("Mun", 200000)
- wait(mechjeb.free)
- print "Warping to SoI..."
- mechjeb.warpToEvent("soi")
- wait(mechjeb.free)
- print "Warping to Pe..."
- mechjeb.warpToEvent("pe", 30)
- wait(mechjeb.free)
- print "Circularizing orbit..."
- mechjeb.circularize()
- wait(mechjeb.free)
- print "Landing..."
- if (lat == nil or lon == nil) then
- mechjeb.landAt(0, 14)
- else
- mechjeb.landAt(lat, lon)
- end
- wait(mechjeb.free)
- mechjeb.autoStageDeactivate()
- print "Landed!"
- end
- function GoKerbinDriver(lat, lon)
- 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 100 km...")
- mechjeb.changePe(100 * 1000)
- wait(mechjeb.free)
- print "Warping to Pe..."
- mechjeb.warpToEvent("pe", 30)
- wait(mechjeb.free)
- print "Circularizing orbit..."
- mechjeb.circularize()
- wait(mechjeb.free)
- print "Re-entry... hold onto something."
- mechjeb.landAt(-0.103, -74.575)
- wait(mechjeb.free)
- mechjeb.autoStageDeactivate()
- print "Landed!"
- end
- function WaitForLandingDriver(lat, lon)
- wait(30)
- while vessel.altitudeBottom > 5 do
- wait(5)
- end
- print "Prepare for launch."
- wait(30)
- local co = coroutine.create(GoKerbinDriver)
- coroutine.resume(co, lat, lon)
- end
- function GoKerbin(lat, lon)
- local co = coroutine.create(GoKerbinDriver)
- coroutine.resume(co, lat, lon)
- end
- function GoMun(lat, lon)
- local co = coroutine.create(GoMunDriver)
- coroutine.resume(co, lat, lon)
- end
- function RoundTrip(munlat, munlon, kerblat, kerblon)
- local co1 = coroutine.create(GoMunDriver)
- coroutine.resume(co1, munlat, munlon)
- local co2 = coroutine.create(WaitForLandingDriver)
- coroutine.resume(co2, kerblat, kerblon)
- end
- print "Usage: GoMun(lat, lon)"
- print "Usage: GoKerbin(lat, lon)"
- print "Usage: RoundTrip(munlat, munlon, kerbinlat, kerbinlon)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement