Advertisement
HvrdlS

IFT-3 BOOSTER LANDING(BOOSTBACK AND LANDING BURN HAS SEVERAL ENGINES CUTOFFS ON PURPOSE)

Jul 8th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.28 KB | None | 0 0
  1. clearscreen.
  2. settings().
  3. boostback().
  4. entry().
  5. landing().
  6.  
  7.  
  8. function settings {
  9. unlock all.
  10. set ship:control:pilotmainthrottle to 0.
  11. set errorScalling to 1.
  12. set landingZone to latlng(-6.1, -83.5).
  13. set altit to ship:altitude - 37.
  14. set lngoff to (landingZone:lng - addons:tr:impactpos:lng)*10472.
  15. set latoff to (landingZone:lat - addons:tr:impactpos:lat)*10472.
  16. set tlng to 500.
  17. set fte to ship:partstagged("fte")[0].
  18. set bt to ship:partsdubbed("bts")[0].
  19. set rb1 to bt:resources.
  20. set rb2 to rb1[0].
  21. set rb3 to rb1[1].
  22. set rb2:enabled to false.
  23. set rb3:enabled to false.
  24. set engList to list().
  25. set i to -1.
  26. until i >= 32 {
  27. set i to i + 1.
  28. engList:add(ship:partstagged("Vector" + i)[0]).
  29. }
  30.  
  31. sas off.
  32. rcs on.
  33. }
  34.  
  35.  
  36. function boostbackvars {
  37. set deg to max(3.4, (min(35, abs(latoff/1000)))*2).
  38. set sign to abs(latoff)/latoff.
  39. set degf to deg*sign.
  40. }
  41.  
  42.  
  43. function boostback {
  44. when min(35, abs(latoff/1000))*2 = 0 then {
  45. set sign to 0.
  46. set degf to 0.
  47. }
  48.  
  49. set n to time:seconds.
  50. set t to time:seconds - n.
  51. set sstatus to "Boostback burn starting, T+ " + round(t,1) + " Seconds".
  52. boostbackvars().
  53. set steeringManager:maxstoppingtime to 0.35.
  54. set steeringManager:yawts to 0.5.
  55. set steeringManager:pitchts to 0.5.
  56. lock steering to heading(270+degf, 0).
  57. lock throttle to 0.4.
  58. set now1 to time:seconds.
  59. lock ti to time:seconds - now1.
  60. until ti > 2 {
  61. printing().
  62. boostbackvars().
  63. }
  64.  
  65. set ship:partstagged("Vector0")[0]:thrustlimit to 100.
  66. set ship:partstagged("Vector1")[0]:thrustlimit to 100.
  67. set ship:partstagged("Vector2")[0]:thrustlimit to 100.
  68. ship:partstagged("Vector6")[0]:activate.
  69. ship:partstagged("Vector11")[0]:activate.
  70. until ti > 2.2 {
  71. printing().
  72. boostbackvars().
  73. }
  74.  
  75. ship:partstagged("Vector7")[0]:activate.
  76. ship:partstagged("Vector12")[0]:activate.
  77. until ti > 2.6 {
  78. printing().
  79. boostbackvars().
  80. }
  81.  
  82. ship:partstagged("Vector4")[0]:activate.
  83. ship:partstagged("Vector9")[0]:activate.
  84. until ti > 2.8 {
  85. printing().
  86. boostbackvars().
  87. }
  88.  
  89. ship:partstagged("Vector3")[0]:activate.
  90. ship:partstagged("Vector8")[0]:activate.
  91. until ti > 3.2 {
  92. printing().
  93. boostbackvars().
  94. }
  95.  
  96. ship:partstagged("Vector5")[0]:activate.
  97. ship:partstagged("Vector10")[0]:activate.
  98. until ti > 6 {
  99. printing().
  100. boostbackvars().
  101. }
  102.  
  103. lock throttle to 1.
  104. set sstatus to "Superheavy boostback burn has started, T+ " + round(t,1) + " Seconds".
  105. until altit > 50700 {
  106. printing().
  107. boostbackvars().
  108. }
  109.  
  110. ship:partstagged("Vector9")[0]:shutdown.
  111. set now1 to time:seconds.
  112. lock ti to time:seconds - now1.
  113. until ti > 0.5 {
  114. printing().
  115. boostbackvars().
  116. }
  117.  
  118. ship:partstagged("Vector10")[0]:shutdown.
  119. until ti > 0.7 {
  120. printing().
  121. boostbackvars().
  122. }
  123.  
  124. ship:partstagged("Vector8")[0]:shutdown.
  125. until ti > 1.1 {
  126. printing().
  127. boostbackvars().
  128. }
  129.  
  130. ship:partstagged("Vector11")[0]:shutdown.
  131. until ti > 1.5 {
  132. printing().
  133. boostbackvars().
  134. }
  135.  
  136. ship:partstagged("Vector7")[0]:shutdown.
  137. until ti > 1.9 {
  138. printing().
  139. boostbackvars().
  140. }
  141.  
  142. ship:partstagged("Vector12")[0]:shutdown.
  143. until ti > 4 {
  144. printing().
  145. boostbackvars().
  146. }
  147.  
  148. ship:partstagged("Vector3")[0]:shutdown.
  149. ship:partstagged("Vector4")[0]:shutdown.
  150. ship:partstagged("Vector5")[0]:shutdown.
  151. ship:partstagged("Vector6")[0]:shutdown.
  152. set sstatus to "Boostback burn is ending".
  153. until ti > 8 {
  154. printing().
  155. boostbackvars().
  156. }
  157.  
  158. set sstatus to "Boostback burn shutdown, T+ " + round(t,1) + " Seconds".
  159. lock throttle to 0.
  160. wait 2.
  161. toggle brakes.
  162. unlock steering.
  163. unlock throttle.
  164. ship:partstagged("Vector3")[0]:activate.
  165. ship:partstagged("Vector4")[0]:activate.
  166. ship:partstagged("Vector5")[0]:activate.
  167. ship:partstagged("Vector6")[0]:activate.
  168. ship:partstagged("Vector7")[0]:activate.
  169. ship:partstagged("Vector8")[0]:activate.
  170. ship:partstagged("Vector9")[0]:activate.
  171. ship:partstagged("Vector10")[0]:activate.
  172. ship:partstagged("Vector11")[0]:activate.
  173. ship:partstagged("Vector12")[0]:activate.
  174. fte:getmodule("ModuleResourceDrain"):doaction("слить",true).
  175. ag6 off.
  176. rcs on.
  177. set sstatus to "Coast, grid fins are enabled, draining fuel T+ " + round(t,1) + " Seconds".
  178. }
  179.  
  180.  
  181. function entry {
  182. when ship:verticalspeed <= 0 then {
  183. set sstatus to "Superheavy has reached apoapsis, T+ " + round(t,1) + " Seconds".
  184. }
  185.  
  186. when ship:liquidfuel < 500 then {
  187. fte:getmodule("ModuleResourceDrain"):doaction("остановить слив",true).
  188. print "Fuel is drained, activating landing tank".
  189. ag6 on.
  190. set rb2:enabled to true.
  191. set rb3:enabled to true.
  192. wait 2.
  193. }
  194.  
  195. set steeringManager:maxstoppingtime to 0.04.
  196. lock steering to heading(270,90).
  197. until vang(up:vector, ship:facing:vector) < 3 and ship:verticalspeed < -20 {
  198. printing().
  199. }
  200.  
  201. set sstatus to "Superheavy has reached apoapsis, orienting retrograde, T+ " + round(t,1) + " Seconds".
  202. lock steering to srfretrograde.
  203. until altit < 25000 {
  204. printing().
  205. }
  206.  
  207. set sstatus to "Controlled descent, T+ " + round(t,1) + " Seconds".
  208. set steeringManager:maxstoppingtime to 5.
  209. set steeringManager:yawts to 1.
  210. set steeringManager:pitchts to 1.
  211. set aoa to 60.
  212. lock steering to Steer().
  213. when lngoff < 200 and lngoff > -200 and latoff < 200 and latoff > -200 and altitude > 3000 then {
  214. set aoa to 25.
  215. }
  216.  
  217. until myvel:mag < 220 {
  218. printing().
  219. }
  220.  
  221. set sstatus to "Superheavy is transonic, getting ready for landing burn, T+ " + round(t,1) + " Seconds".
  222. set engnum to 13.
  223. until altit < 3500 {
  224. printing().
  225. lbcalc(engnum).
  226. }
  227.  
  228. set sstatus to "Controlled descend, getting ready for landing burn, T+ " + round(t,1) + " Seconds".
  229. }
  230.  
  231.  
  232. function landing {
  233. until altit < lbcalc(engnum)+350 and altit < 2000 {
  234. printing().
  235. lbcalc(engnum).
  236. }
  237.  
  238. lock aoa to -5.
  239. ship:partstagged("Vector0")[0]:shutdown.
  240. ship:partstagged("Vector1")[0]:shutdown.
  241. ship:partstagged("Vector2")[0]:activate.
  242. ship:partstagged("Vector3")[0]:shutdown.
  243. ship:partstagged("Vector3")[0]:shutdown.
  244. ship:partstagged("Vector4")[0]:shutdown.
  245. ship:partstagged("Vector5")[0]:shutdown.
  246. ship:partstagged("Vector6")[0]:shutdown.
  247. ship:partstagged("Vector7")[0]:shutdown.
  248. ship:partstagged("Vector8")[0]:shutdown.
  249. ship:partstagged("Vector9")[0]:shutdown.
  250. ship:partstagged("Vector10")[0]:shutdown.
  251. ship:partstagged("Vector11")[0]:shutdown.
  252. ship:partstagged("Vector12")[0]:shutdown.
  253. wait 0.01.
  254. lock throttle to 1.
  255. print "Superheavy Landing Burn has started.".
  256. set now1 to time:seconds.
  257. lock ti1 to time:seconds - now1.
  258. until ti1 > 0.8 {
  259. printing().
  260. }
  261.  
  262. ship:partstagged("Vector5")[0]:activate.
  263. ship:partstagged("Vector3")[0]:activate.
  264. until ti1 > 1.5 {
  265. printing().
  266. }
  267.  
  268. ship:partstagged("Vector3")[0]:shutdown.
  269. until ti1 > 3.7 {
  270. printing().
  271. }
  272.  
  273. ship:partstagged("Vector5")[0]:shutdown.
  274. set engnum to 3.
  275. until altit < lbcalc(engnum) {
  276. printing().
  277. lbcalc(engnum).
  278. }
  279.  
  280. lock throttle to Thr.
  281. until altit < 100 {
  282. printing().
  283. thrustcalc().
  284. }
  285.  
  286. set sstatus to "Landing burn, orienting retrograde, T+ " + round(t,1) + " Seconds".
  287. lock steering to lookdirup(-ship:velocity:surface,ship:facing:topvector).
  288. until vang(up:vector, -ship:velocity:surface)<2 {
  289. printing().
  290. thrustcalc().
  291. }
  292.  
  293. set sstatus to "Landing burn, orienting up, T+ " + round(t,1) + " Seconds".
  294. lock steering to lookdirup(up:vector,ship:facing:topvector).
  295. until ship:verticalspeed > -1 and ImpactTime < 0.1 {
  296. printing().
  297. thrustcalc().
  298. }
  299.  
  300. set sstatus to "Touchdown, T+ " + round(t,1) + " Seconds".
  301. set now1 to time:seconds.
  302. lock ti1 to time:seconds-now1.
  303. lock throttle to max(0.05, 0.5-ti1).
  304. print "Lngoff(M): " + lngoff.
  305. print "Latoff(M): " + latoff.
  306. until ship:status = "Landed" or ship:status = "Splashed" {
  307. printing().
  308. thrustcalc().
  309. }
  310.  
  311. set t to t.
  312. unlock steering.
  313. set sstatus to "Landing confirmed, T+ " + round(t,1) + " Seconds".
  314. print sstatus.
  315. lock throttle to 0.05.
  316. wait 1.
  317. lock throttle to 0.
  318. print "Superheavy, landing confirmed, getting ready for post landing procedures, T+ " + round(t,1) + " Seconds".
  319. set now1 to time:seconds.
  320. lock ti to time:seconds - now1.
  321. until ti > 20 {
  322. printing().
  323. }
  324.  
  325. set sstatus to "Shutting down all systems, unlocking controls, T+ " + round(t,1) + " Seconds".
  326. print sstatus.
  327. unlock steering.
  328. unlock throttle.
  329. sas off.
  330. rcs off.
  331. toggle brakes.
  332. }
  333.  
  334.  
  335. function abortofscript {
  336. clearscreen.
  337. print "Program aborted".
  338. wait 2.
  339. print 3/0.
  340. }
  341.  
  342.  
  343. function printing {
  344. clearscreen.
  345. set t to time:seconds - n.
  346. set myvel to ship:velocity:surface.
  347. set altit to ship:altitude - 37.
  348. set lngoff to (landingZone:lng - getImpact:lng)*10472.
  349. set latoff to (landingZone:lat - getImpact:lat)*10472.
  350. print "Welcome to Superheavy Landing Software V1.".
  351. print "Status: " + sstatus.
  352. print "T+ since start of script to landing: " + round(t,1) + " Seconds".
  353. print "Latoff(M): " + latoff.
  354. print "Lngoff(M): " + lngoff.
  355. if altit < 3000 and myvel:mag < 219 {
  356. print "Landing burn altitude: " + LBCalc(engnum) + " Meters".
  357. }
  358.  
  359. print "Press 10 to abort current program".
  360. }
  361.  
  362.  
  363. function LBCalc {
  364. parameter engnum.
  365. set grav to constant:g * body:mass / body:radius^2.
  366. set maxAccel to (engnum*ship:partstagged("Vector0")[0]:maxthrust / ship:mass) - grav.
  367. set LBAlt to ship:verticalspeed^2 / (2 * maxAccel).
  368. return LBAlt.
  369. }
  370.  
  371.  
  372. function thrustcalc {
  373. set Thr to LBcalc(engnum) / altit.
  374. return Thr.
  375. }
  376.  
  377. function errorVector {
  378. return getImpact():position - landingZone:position.
  379. }
  380.  
  381. function Steer {
  382. local errorVector is errorVector().
  383. local velVector is -ship:velocity:surface.
  384. local result is velVector + errorVector*errorScalling.
  385.  
  386. if vang(result, velVector) > aoa
  387. {
  388. set result to velVector:normalized + tan(aoa)*errorVector:normalized.
  389. }
  390.  
  391. return lookdirup(result, ship:facing:topvector).
  392. }
  393.  
  394. function getImpact {
  395. if addons:tr:hasimpact {
  396. return addons:tr:impactpos.
  397. } else {
  398. return ship:geoposition.
  399. }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement