HvrdlS

land.ks

Jul 23rd, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. //Settings
  2. clearscreen.
  3. set preset to "My Mum Wonders About Me".
  4. lock alt to ship:altitude - 23.
  5. set landingZone to vessel("My Mum Wonders About Me"):geoposition.
  6. set entryburnalt to 35000.
  7. lock lngoff to (landingZone:LNG - ADDONS:TR:IMPACTPOS:LNG)*10472.
  8. lock latoff to (landingZone:LAT - ADDONS:TR:IMPACTPOS:LAT)*10472.
  9. lock myvel to ship:velocity:surface:mag.
  10. lock g to constant:g * body:mass / body:radius^2.
  11. lock maxDecel to (ship:availablethrust / ship:mass) - g.
  12. lock stopDist to ship:verticalspeed^2 / (2 * maxDecel).
  13. lock idealThrottle to stopDist / alt.
  14. lock impactTime to alt / abs(ship:verticalspeed).
  15. set errorScaling to 1.
  16. lock steering to heading(90, 90).
  17. sas off.
  18. rcs on.
  19. set rm to 1.
  20. set done to false.
  21. until done {
  22. //Ascent to Apoapsis and orient for entry burn
  23. if rm = 1 {
  24. print "Welcome to Falcon 9 Landing Software V4".
  25. print "Your preset is " + preset.
  26. wait until ship:verticalspeed < -200.
  27. lock steering to srfretrograde.
  28. set rm to 2.
  29. }
  30.  
  31. //Entry burn performing
  32. if rm = 2 {
  33. wait until alt < entryburnalt + 7000.
  34. set ship:control:fore to 1.
  35. wait 4.
  36. set ship:control:fore to 0.
  37.  
  38. wait until alt < entryburnalt + 50.
  39. set targetspeedonentry to ship:velocity:surface:mag - 275.
  40. lock throttle to 1.
  41. lock aoa to -10.
  42. lock steering to getSteering().
  43. wait 2.
  44. toggle ag6.
  45.  
  46. wait until myvel < targetspeedonentry.
  47. lock throttle to 0.
  48. lock aoa to 45.
  49. lock steering to getSteering().
  50.  
  51. wait until alt < 6000.
  52. lock aoa to 35.
  53.  
  54. wait until alt < 3500.
  55. set rm to 3.
  56. }
  57.  
  58. //Hoverslam
  59. wait 0.
  60. if rm = 3 {
  61. wait 0.
  62. wait until alt < stopDist.
  63. lock throttle to idealThrottle.
  64. lock aoa to -10.
  65.  
  66. wait until alt < 140.
  67. lock steering to ship:srfretrograde.
  68.  
  69. wait until alt < 90.
  70. lock steering to up.
  71. toggle gear.
  72. set rm to 4.
  73. wait 0.
  74. }
  75.  
  76. wait 0.
  77. if rm = 4 {
  78. wait 0.
  79. wait until ship:verticalspeed > -1.
  80. lock throttle to 0.01.
  81. wait 4.
  82. lock throttle to 0.
  83. print "Landing confirmed!".
  84. print landingZone.
  85. print ship:geoposition.
  86. wait 20.
  87. unlock steering.
  88. unlock throttle.
  89. sas off.
  90. rcs off.
  91. toggle brakes.
  92. set done to true.
  93. }
  94. }
  95.  
  96. //Functions
  97. function getImpact {
  98. if addons:tr:hasimpact { return addons:tr:impactpos. }
  99. return ship:geoposition.
  100. }
  101.  
  102. function lngError {
  103. return getImpact():lng - landingZone:lng.
  104. }
  105.  
  106. function latError {
  107. return getImpact():lat - landingZone:lat.
  108. }
  109.  
  110. function errorVector {
  111. return getImpact():position - landingZone:position.
  112. }
  113.  
  114. function getSteering {
  115. local errorVector is errorVector().
  116. local velVector is -ship:velocity:surface.
  117. local result is velVector + errorVector*errorScaling.
  118.  
  119. if vang(result, velVector) > aoa
  120. {
  121. set result to velVector:normalized + tan(aoa)*errorVector:normalized.
  122. }
  123.  
  124. return lookdirup(result, facing:topvector).
  125. }
Advertisement
Add Comment
Please, Sign In to add comment