HvrdlS

IFT-3 REENTRY AND LANDING(STEERING FUNCTIONS ARE DISABLED CAUSE OF REAL FLIGHT PROFILE)

Jul 8th, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. clearscreen.
  2. set h to 25.
  3. set altit to alt:radar - h.
  4. set now to time:seconds - 1190.
  5. lock testtime to time:seconds - now.
  6. set teststatus to "Transfer back complete, awaiting for PEZ door to close, T+: " + round(testtime,1) + " Seconds".
  7. prep().
  8. reentryprep().
  9. reentry().
  10. descending().
  11. landing().
  12.  
  13.  
  14. function prep {
  15. set h1 to ship:partsdubbed("h1")[0].
  16. set h2 to ship:partsdubbed("h2")[0].
  17. set h3 to ship:partsdubbed("h3")[0].
  18. set h4 to ship:partsdubbed("h4")[0].
  19. set lockstatus to 1.
  20. hingeslock().
  21. wait 1.
  22. set lockstatus to 0.
  23. hingeslock().
  24. set hts to ship:partsnamed("externalTankRound").
  25. set rs1 to hts[0].
  26. set rs2 to hts[1].
  27. set rs3 to rs1:resources.
  28. set rs4 to rs2:resources.
  29. set rs5 to rs3[0].
  30. set rs6 to rs3[1].
  31. set rs7 to rs4[0].
  32. set rs8 to rs4[1].
  33. set rs5:enabled to false.
  34. set rs6:enabled to false.
  35. set rs7:enabled to false.
  36. set rs8:enabled to false.
  37. set eng1 to ship:partstagged("VectorS1")[0].
  38. set eng2 to ship:partstagged("VectorS2")[0].
  39. set eng3 to ship:partstagged("VectorS3")[0].
  40. set steeringManager:maxstoppingtime to 0.02.
  41. set landingZone to impactpos().
  42. set reentered to 0.
  43. set descend to 0.
  44. set landingburn to 0.
  45. }
  46.  
  47.  
  48. function reentryprep {
  49. until altit < 75000 {
  50. printing().
  51. }
  52.  
  53. set tophingeleftang to 15.
  54. set tophingerightang to 15.
  55. set afthingesang to -35.
  56. hingesmove().
  57. set P1 to 0.15.
  58. set P2 to 0.1.
  59. set I to 0.
  60. set D to 0.05.
  61. set minpitch to 70.
  62. set maxpitch to 85.
  63. set minroll to -30.
  64. set maxroll to 30.
  65. descendcontrol().
  66. set rs5:enabled to true.
  67. set rs6:enabled to true.
  68. set rs7:enabled to true.
  69. set rs8:enabled to true.
  70. rcs on.
  71. set teststatus to "Flaps are configured for reentry, orienting for reentry, T+: " + round(testtime,1) + " Seconds".
  72. until altit < 70000 {
  73. printing().
  74. }
  75.  
  76. set teststatus to "Starship has reentered the atmosphere, T+: " + round(testtime,1) + " Seconds".
  77. set reentered to 1.
  78. }
  79.  
  80.  
  81. function reentry {
  82. set oldq to ship:q.
  83. wait 0.1.
  84. set newq to ship:q.
  85. set steeringManager:maxstoppingtime to 0.1.
  86. set lockstatus to 1.
  87. hingeslock().
  88. until newq < oldq and altit < 35000 {
  89. set oldq to ship:q.
  90. wait 0.001.
  91. set newq to ship:q.
  92. printing().
  93. descendcontrol().
  94. }
  95.  
  96. set teststatus to "Max-Q, awaiting for landing burn, " + round(newq*constant:atmtokpa,3) + " kPa, T+: " + round(testtime,1) + " Seconds".
  97. }
  98.  
  99.  
  100. function descendcontrol {
  101. pitchpid().
  102. rollpid().
  103. }
  104.  
  105.  
  106. function pitchpid {
  107. set pid1 to pidloop(P1, I, D, minpitch,maxpitch).
  108. set pid1:setpoint to 0.
  109. set pitchang to pid1:update(time:seconds, lngoff).
  110. return pitchang.
  111. }
  112.  
  113.  
  114. function rollpid {
  115. set pid2 to pidloop(P2, I, D, minroll,maxroll).
  116. set pid2:setpoint to 0.
  117. set rollang to pid2:update(time:seconds, latoff).
  118. return rollang.
  119. }
  120.  
  121.  
  122. function descending {
  123. set minpitch to -50.
  124. set maxpitch to 50.
  125. set minroll to -70.
  126. set maxroll to 70.
  127. set P1 to 0.03.
  128. set P2 to 0.12.
  129. set I to 0.
  130. set D to 0.01.
  131. set latoff to 0.
  132. set lngoff to 0.
  133. descendcontrol().
  134. set steeringManager:maxstoppingtime to 1.
  135. set steeringManager:rollts to 0.5.
  136. set steeringManager:pitchts to 0.5.
  137. set descend to 1.
  138. eng1:activate.
  139. eng2:activate.
  140. eng3:activate.
  141. set rollang to 0.
  142. set engnum to 3.
  143. lock steering to heading(90,pitchang,rollang).
  144. until altit < altitudecalc(engnum) + 250 and altit < 1500 {
  145. printing().
  146. descendcontrol().
  147. altitudecalc(engnum).
  148. }
  149.  
  150. eng1:shutdown.
  151. eng2:shutdown.
  152. eng3:shutdown.
  153. }
  154.  
  155. function landing {
  156. set teststatus to "Landing burn starting, T+: " + round(testtime,1) + " Seconds".
  157. set steeringManager:maxstoppingtime to 0.15.
  158. eng3:activate.
  159. set lockstatus to 0.
  160. hingeslock().
  161. set reentered to 0.
  162. set now1 to time:seconds.
  163. lock ti1 to time:seconds - now1.
  164. set afthingesang to -90.
  165. hingesmove().
  166. set topvector to facing:topvector.
  167. lock steering to lookdirup(-ship:velocity:surface,topvector).
  168. lock throttle to min(0.5, ti1/1).
  169. wait 0.2.
  170. eng2:activate.
  171. wait 0.2.
  172. eng1:activate.
  173. set tophingerightang to 15.
  174. set tophingeleftang to 15.
  175. hingesmove().
  176. until vang(ship:facing:vector, -velocity:surface) < 4 {
  177. printing().
  178. }
  179.  
  180. set aoa to -5.
  181. set tophingerightang to -35.
  182. set tophingeleftang to -35.
  183. set afthingesang to -35.
  184. hingesmove().
  185. lock throttle to 1.
  186. lock steering to Steer().
  187. set teststatus to "All sea level engines are lit, T+: " + round(testtime,1) + " Seconds".
  188. set engnum to 1.
  189. until altitudecalc(engnum) < altit {
  190. printing().
  191. altitudecalc(engnum).
  192. }
  193.  
  194. set aoa to -3.
  195. eng3:shutdown.
  196. wait 0.2.
  197. eng2:shutdown.
  198. thrustcalc().
  199. set landingburn to 1.
  200. lock throttle to thrustcalc().
  201. until altit < 100 {
  202. printing().
  203. }
  204.  
  205. lock steering to lookdirup(-ship:velocity:surface,topvector).
  206. until altit < 40 {
  207. printing().
  208. }
  209.  
  210. lock steering to lookdirup(up:vector,topvector).
  211. until ship:status = "Landed" or ship:status = "Splashed" {
  212. printing().
  213. }
  214.  
  215. set teststatus to "Touchdown confirmed".
  216. set now1 to time:seconds.
  217. lock ti1 to time:seconds - now1.
  218. lock throttle to max(0.05, 1-(ti1/0.5*1)).
  219. set landingburn to 0.
  220. set descend to 0.
  221. set reentered to 0.
  222. until ti1 > 1 {
  223. printing().
  224. }
  225.  
  226. lock throttle to 0.
  227. eng1:shutdown.
  228. eng2:shutdown.
  229. eng3:shutdown.
  230. wait 0.1.
  231. unlock steering.
  232. unlock throttle.
  233. set lockstatus to 1.
  234. hingeslock().
  235. rcs off.
  236. set ship:control:pilotmainthrottle to 0.
  237. set teststatus to "Ship has landed".
  238. until false {
  239. printing().
  240. }
  241. }
  242.  
  243.  
  244. function hingeslock {
  245. h1:getmodule("ModuleRoboticServoHinge"):setfield("Locked", lockstatus).
  246. h2:getmodule("ModuleRoboticServoHinge"):setfield("Locked", lockstatus).
  247. h3:getmodule("ModuleRoboticServoHinge"):setfield("Locked", lockstatus).
  248. h4:getmodule("ModuleRoboticServoHinge"):setfield("Locked", lockstatus).
  249. }
  250.  
  251.  
  252. function hingesmove {
  253. h1:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", tophingeleftang).
  254. h2:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", tophingerightang).
  255. h3:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", afthingesang).
  256. h4:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", afthingesang).
  257. }
  258.  
  259.  
  260. function printing {
  261. clearscreen.
  262. set altit to alt:radar - h.
  263. set lngoff to (landingZone:lng - impactpos:lng)*10472.
  264. set latoff to (landingZone:lat - impactpos:lat)*10472.
  265. print "Status: " + teststatus.
  266. print "T+: " + round(testtime,1) + " Seconds".
  267. print "Longitude difference: " + round(lngoff,2) + " Meters".
  268. print "Latitude difference: " + round(latoff,2) + " Meters".
  269. print "Time(KSC): " + time:clock.
  270. if reentered = 1 {
  271. print "Targeted pitch is " + round(pitchang,2) + " Degrees".
  272. print "Targeted roll is " + round(rollang,2) + " Degrees".
  273. }
  274.  
  275. if descend = 1 {
  276. print "Landing Burn Altitude : " + round(LBAlt,2) + " Meters".
  277. }
  278.  
  279. if landingburn = 1 {
  280. set shipthrust to throttle.
  281. print "Current thrust percentage: " + round(shipthrust*100,2) + "%".
  282. print "Targeted thrust percentage: " + round(Thr*100,2) + "%".
  283. }
  284.  
  285.  
  286. print "Press 10 to abort program".
  287. wait 0.001.
  288. }
  289.  
  290.  
  291. function altitudecalc {
  292. parameter engnum.
  293. set grav to constant:g * body:mass / body:radius^2.
  294. set maxAccel to (engnum*555.35 / ship:mass) - grav.
  295. set LBAlt to ship:verticalspeed^2 / (2 * maxAccel).
  296. return abs(LBAlt).
  297. }
  298.  
  299.  
  300. function thrustcalc {
  301. set Thr to altitudecalc(engnum) / altit.
  302. return Thr.
  303. }
  304.  
  305.  
  306. function errorvector {
  307. set errorvec to Impactpos():position - landingZone:position.
  308. return errorvec.
  309. }
  310.  
  311.  
  312. function Steer {
  313. set result to -velocity:surface + errorvector().
  314.  
  315. if vang(result, -velocity:surface) > aoa
  316. {
  317. set result to -velocity:surface:normalized + tan(aoa)*errorvector():normalized.
  318. }
  319.  
  320. return lookdirup(result, topvector).
  321. }
  322.  
  323.  
  324. function impactpos {
  325. if addons:tr:hasimpact {
  326. return addons:tr:impactpos.
  327. } else {
  328. return ship:geoposition.
  329. }
  330. }
Add Comment
Please, Sign In to add comment