wirawafiy1

Landing guidance

Oct 27th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. clearscreen.
  2. print "Falcon 9 landing software v4.1".
  3. parameter landingsite is latlng(-0.0556882365026111,-74.5090489030054).//Input the landing latlng() here
  4. set radarOffset to 45.2.//the radar altitude Kerbal Engineer (or kOS itself gives) when landed with he legs extended.
  5. lock trueRadar to alt:radar - radarOffset.//this is all the suicide burn calculation
  6. lock g to constant:g * body:mass / body:radius^2.
  7. lock maxDecel to (ship:availablethrust / ship:mass) - g.
  8. lock stopDist to ship:verticalspeed^2 / (2 * maxDecel).
  9. lock idealThrottle to stopDist / trueRadar.
  10. lock impactTime to trueRadar / abs(ship:verticalspeed).
  11. lock aoa to 10. //the mazimum angle you want your ship to angle itself at to move the impact position towards the landingsite.
  12. lock errorScaling to 1. //all the functions are here
  13. function getImpact {
  14. if addons:tr:hasimpact { return addons:tr:impactpos. } //looks for the impact position given by Trajectories
  15. return ship:geoposition.
  16. }
  17. function lngError { //giving the lat and lng error values a vector so the ship can correct it for this.
  18. return getImpact():lng - landingsite:lng.
  19. }
  20. function latError {
  21. return getImpact():lat - landingsite:lat.
  22. }
  23.  
  24. function errorVector {
  25. return getImpact():position - landingSite:position.
  26. }
  27.  
  28. function getSteering { //the function for steering is here, the functions and vectors are calculated here and used elsewhere.
  29.  
  30. local errorVector is errorVector().
  31. local velVector is -ship:velocity:surface.
  32. local result is velVector + errorVector*errorScaling.
  33. if vang(result, velVector) > aoa
  34. {
  35. set result to velVector:normalized
  36. + tan(aoa)*errorVector:normalized.
  37. }
  38.  
  39. return lookdirup(result, facing:topvector).
  40. }
  41. RCS on.//entry burn starts here, change the verticalspeed to your desired values.
  42. lock steering to srfretrograde.
  43. wait until ship:verticalspeed <-700.
  44. lock throttle to 1.
  45. print "Stage 1 Entry burn startup".
  46. RCS off.
  47.  
  48. wait until ship:verticalspeed > -310.
  49. lock throttle to 0.
  50. print "Stage 1 Entry burn shutdown".
  51. print "Performing glide maneuver".
  52. lock steering to getSteering().
  53.  
  54. wait until alt:radar < 12000.//reduces angle of attack to change with the increasing ambient air pressure to prevent overcorrecting.
  55. lock aoa to 7.5.
  56.  
  57. wait until alt:radar < 7000. //again, reduces AOA for accuracy for the changine ambient air pressure.
  58. lock aoa to 5.
  59.  
  60. WAIT UNTIL ship:verticalspeed < -10.
  61. rcs on.
  62. brakes on.
  63. when impactTime < 3.5 then {gear on.} //gear deployment variable, change it to whatever you'd like.
  64.  
  65. WAIT UNTIL trueRadar < stopDist. //suicide burn starts here
  66. lock throttle to idealThrottle.
  67. print "Performing hoverslam".
  68. lock aoa to -3. //Negative AOA means the vessel will make the small correction maneuvers on the opposite hemisphere of the navball rather than when the engine isn't burning due to the thrust from the engine pushing it upwards and horizontally depending on the horizontal speed.
  69. lock steering to getSteering().//lock steering to the required correction maneuvers.
  70. when impactTime <3.5 then lock steering to lookDirUp( up:forevector, ship:facing:topvector).//locks steering to surface retrograde to stop correcting for impact potition when very close to surface.
  71.  
  72. WAIT UNTIL ship:verticalspeed > -0.1. //there you go, The falcon has landed.
  73. print "The Falcon has landed".
  74. set ship:control:pilotmainthrottle to 0.
  75. RCS off.
  76.  
Add Comment
Please, Sign In to add comment