HvrdlS

land

Jun 7th, 2023 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. @lazyglobal on.
  2. @CLOBBERBUILTINS on.
  3. //Settings
  4. set Control to ship:partsnamed("probeStackSmall")[0]:getmodule("ModuleCommand").
  5. Control:doevent("Control from here").
  6. clearscreen.
  7. unlock all.
  8. set errorScalling to 1.
  9. set preset to "BFT". // Your preset where to land
  10. if preset = "LZ-1" {
  11. set landingZone to latlng(-0.195836429065209,-74.484855364316).
  12. } else if preset = "LZ-2" {
  13. set landingZone to latlng(-0.195836429065209,-74.484855364316).
  14. } else if preset = "LZ-4" {
  15. set landingZone to latlng(-0.556128,-88.461235).
  16. } else if preset = "BFT" {
  17. set landingZone to vessel("Big Floating Thing"):geoposition.
  18. } else if preset = "MMWAM" {
  19. set landingZone to vessel("My Mum Wonders About Me"):geoposition.
  20. } else if preset = "LIP" {
  21. set landingZone to vessel("Land In One Piece"):geoposition.
  22. }
  23.  
  24. lock altit to alt:radar - 22.6.
  25. set entryburnalt to 32500.
  26. set speedcancelonentry to 416.
  27. if preset = "LZ-1" or preset = "LZ-4" or preset = "LZ-2" {
  28. set tlng to speedcancelonentry*(ship:apoapsis/12000)+500.
  29. } else {
  30. set tlng to speedcancelonentry*(ship:apoapsis/7000)+500.
  31. }
  32.  
  33. lock lngoff to (landingZone:LNG - ADDONS:TR:IMPACTPOS:LNG)*10472.
  34. lock latoff to (landingZone:LAT - ADDONS:TR:IMPACTPOS:LAT)*10472.
  35. lock myvel to ship:velocity:surface:mag.
  36. lock grav to constant:g * body:mass / body:radius^2.
  37. lock maxAccel to (ship:availablethrust / ship:mass) - grav.
  38. lock LBAlt to ship:verticalspeed^2 / (2 * maxAccel).
  39. lock Thr to LBAlt / altit.
  40. sas off.
  41. rcs on.
  42. set rm to 1.
  43. //Boostback
  44. if rm = 1 {
  45. toggle ag7. //Turn off all engines, but left the center
  46. toggle ag6. //Turn on two aditional engines
  47. set deg to (latoff/70)/3.
  48. lock steering to heading(270+deg, 5).
  49. wait 9.
  50. lock throttle to 1.
  51. print "Stage 1 Boostback burn has started.".
  52.  
  53. until lngoff > -tlng-6000 {
  54. clearscreen.
  55. set deg to (latoff/70)/3.
  56. print "Lngoff: " + lngoff + " M".
  57. print "Latoff: " + latoff + " M".
  58. wait 0.2.
  59. }
  60.  
  61. toggle ag6.
  62. until lngoff > -tlng {
  63. clearscreen.
  64. set deg to (latoff/70)/3.
  65. print "Lngoff: " + lngoff + " M".
  66. print "Latoff: " + latoff + " M".
  67. wait 0.2.
  68. }
  69.  
  70. lock throttle to 0.
  71. wait 2.
  72. toggle brakes.
  73. unlock steering.
  74. unlock throttle.
  75. print "Bb completed!".
  76. rcs on.
  77. set rm to 2.
  78. }
  79. //Ascent to apoapsis and orient for entry burn
  80. if rm = 2 {
  81. clearscreen.
  82. print "Welcome to Falcon 9 Landing Software V5.".
  83. print "Your preset is " + preset.
  84. lock steering to heading(90, 90).
  85. until ship:verticalspeed < -0 {
  86. clearscreen.
  87. print "Latoff(M): " + latoff.
  88. print "Lngoff(M): " + lngoff.
  89. wait 1.
  90. }
  91.  
  92. print "Stage 1 is in apoapsis.".
  93.  
  94. until ship:verticalspeed < -250 {
  95. clearscreen.
  96. print "Latoff(M): " + latoff.
  97. print "Lngoff(M): " + lngoff.
  98. wait 1.
  99. }
  100.  
  101. lock steering to srfretrograde.
  102. set rm to 3.
  103. }
  104.  
  105. //Entry burn performing and descending
  106. if rm = 3 {
  107. until altit < entryburnalt + 7000 {
  108. clearscreen.
  109. print "Latoff(M): " + latoff.
  110. print "Lngoff(M): " + lngoff.
  111. wait 1.
  112. }
  113.  
  114. set ship:control:fore to 1.
  115. wait 4.
  116. set ship:control:fore to 0.
  117. until altit < entryburnalt + 50 {
  118. clearscreen.
  119. print "Latoff(M): " + latoff.
  120. print "Lngoff(M): " + lngoff.
  121. wait 1.
  122. }
  123.  
  124. set targetspeedonentry to ship:velocity:surface:mag - speedcancelonentry.
  125. lock throttle to 1.
  126. print "Stage 1 Entry Burn has started.".
  127. wait 2.
  128. toggle ag6.
  129.  
  130. until myvel < targetspeedonentry {
  131. clearscreen.
  132. print "Latoff(M): " + latoff.
  133. print "Lngoff(M): " + lngoff.
  134. wait 1.
  135. }
  136.  
  137. toggle ag6.
  138. wait 2.
  139. lock throttle to 0.
  140. wait 0.1.
  141. toggle ag6.
  142. print "Stage 1 Entry Burn shutdown.".
  143. lock aoa to 45.
  144. lock steering to Steer().
  145.  
  146. until ship:velocity:surface:mag < 220 {
  147. clearscreen.
  148. print "Latoff(M): " + latoff.
  149. print "Lngoff(M): " + lngoff.
  150. wait 1.
  151. }
  152.  
  153. print "Stage 1 is transonic.".
  154. set rm to 4.
  155. }
  156.  
  157. //Landing Burn
  158. wait 0.
  159. if rm = 4 {
  160. wait 0.
  161. until altit < LBAlt - 600 or altit < 1100 {
  162. clearscreen.
  163. print "Latoff(M): " + latoff.
  164. print "Lngoff(M): " + lngoff.
  165. wait 1.
  166. }
  167.  
  168. lock throttle to Thr.
  169. print "Stage 1 Landing Burn has started.".
  170. lock aoa to -5.
  171. lock steering to Steer().
  172.  
  173. until altit < 80 {
  174. clearscreen.
  175. print "Latoff(M): " + latoff.
  176. print "Lngoff(M): " + lngoff.
  177. wait 1.
  178. }
  179.  
  180. lock steering to lookdirup(-ship:velocity:surface,ship:facing:topvector).
  181. toggle gear.
  182. print "Stage 1 Landing legs deployed.".
  183. until altit < 30 {
  184. clearscreen.
  185. print "Latoff(M): " + latoff.
  186. print "Lngoff(M): " + lngoff.
  187. wait 1.
  188. }
  189.  
  190. lock steering to lookdirup(up:vector,ship:facing:topvector).
  191. set rm to 5.
  192. wait 0.
  193. }
  194.  
  195. if rm = 5 {
  196. wait 0.
  197. until ship:verticalspeed > -1 or altit < 1 {
  198. clearscreen.
  199. print "Latoff(M): " + latoff.
  200. print "Lngoff(M): " + lngoff.
  201. wait 1.
  202. }
  203.  
  204. lock throttle to 0.01.
  205. set latoff to latoff.
  206. set lngoff to lngoff.
  207. print "Lngoff(M): " + lngoff.
  208. print "Latoff(M): " + latoff.
  209. wait 1.
  210. lock throttle to 0.
  211. print preset + ", stage 1 landing confirmed.".
  212. wait 20.
  213. unlock steering.
  214. unlock throttle.
  215. sas off.
  216. rcs off.
  217. toggle brakes.
  218. set done to true.
  219. }
  220.  
  221. //Functions
  222.  
  223. function lngError {
  224. return getImpact():lng - landingZone:lng.
  225. }
  226.  
  227. function latError {
  228. return getImpact():lat - landingZone:lat.
  229. }
  230.  
  231. function errorVector {
  232. return getImpact():position - landingZone:position.
  233. }
  234.  
  235. function Steer {
  236. local errorVector is errorVector().
  237. local velVector is -ship:velocity:surface.
  238. local result is velVector + errorVector*errorScalling.
  239.  
  240. if vang(result, velVector) > aoa
  241. {
  242. set result to velVector:normalized + tan(aoa)*errorVector:normalized.
  243. }
  244.  
  245. return lookdirup(result, ship:facing:topvector).
  246. }
  247.  
  248. function getImpact {
  249. if addons:tr:hasimpact { return addons:tr:impactpos. }
  250. return ship:geoposition.
  251. }
Advertisement
Add Comment
Please, Sign In to add comment