Advertisement
olex

MechJeb Spaceplane Orbit to Runway Script

Aug 9th, 2012
4,353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. --
  2. --         Shuttle Autopilot Library by olex
  3. --                    Version 1.0
  4. --
  5. --                 for MechJeb 1.9.1
  6. --
  7. --------------------------------------------------------
  8. -- Usage: * save to KSP/PluginData/mumechlib/Shuttle.lua
  9. --        * in game, open autom8
  10. --        * enter: dofile("Shuttle.lua")
  11. --        * and follow the instructions.
  12. --
  13. -- Quicksave before using any of the functions.
  14. -- If an "coroutine out of sync" error pops up, load the save and try again.
  15. --
  16. -- No guarantees, but it should work :) Have fun!
  17. --------------------------------------------------------
  18. function PlaneLandingDriver(slope, offset)
  19.     -- KSP coordinates
  20.     lat = -0.103
  21.     lon = -74.575
  22.    
  23.     -- "undershoot" offset and glide slope
  24.     if (offset == nil) then
  25.         offset = 40 -- default offset of 40km
  26.     end
  27.     lon = lon - (offset / 10) -- 1° ~= 10km near the KSP
  28.    
  29.     if (slope == nil) then
  30.         slope = 3 -- default ILS glide slope of 3°
  31.     end
  32.    
  33.     -- start re-entry sequence
  34.     print "Deorbiting..."
  35.     mechjeb.landAt(lat, lon, false)
  36.    
  37.     -- at 75km: cancel powered landing sequence, set attitude for aerodymanic flight, wings level
  38.     wait(function() return (vessel.altitudeASL <= 75000) end )
  39.     print "Beginning re-entry, hold onto something..."
  40.     mechjeb.controlRelease()
  41.     wait(3)
  42.     mechjeb.attitudeTo({0,0,0,0}, "ORBIT")
  43.        
  44.     -- at 15km: engage the ILS
  45.     wait(function() return (vessel.altitudeASL <= 15000) end )
  46.     print "Initiating ILS approach, please lower landing gear manually."
  47.     ils = mechjeb.getModule("ils")
  48.     ils.glideslope = slope
  49.     mechjeb.ilsLand()
  50.    
  51.     -- at 2m (immediately before touchdown)
  52.     wait(function() return (vessel.altitudeTrue <= 2.5) end )
  53.     print "Touching down, deploying braking parachutes (if you have any)..."
  54.     mechjeb.controlRelease() -- stop ILS sequence
  55.     mechjeb.attitudeTo({1,0,0,0}, "SURFACE_NORTH")
  56.     mechjeb.stage() -- in case there actually are braking chutes
  57.    
  58.     -- at <5 m/s, we're done
  59.     wait(function() return (vessel.speedSurface < 5) end )
  60.     print "Welcome home. You can hit the brakes now."
  61.     mechjeb.controlRelease()
  62. end
  63.  
  64. function Land(slope)
  65.     local co = coroutine.create(PlaneLandingDriver)
  66.     coroutine.resume(co, slope)
  67. end
  68.  
  69. print "Usage: Land(<glideslope, default 3°>, <glide distance offset, default 40km>)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement