HvrdlS

SN8 6.25KM Hop

Nov 19th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. clearscreen.
  2. on ag10 {
  3. aborttest().
  4. }
  5.  
  6. prep().
  7. fuel().
  8. hop().
  9. detanking().
  10.  
  11.  
  12. function prep {
  13. on ag10 {
  14. aborttest().
  15. }
  16.  
  17. print "Welcome to Starship Test Software V4!".
  18. print "Running hardware, preparings for software...".
  19. wait 1.
  20. set teststatus to "Preparations".
  21. wait until teststatus = "Preparations".
  22. set goal to "6.25KM Hop".
  23. set h to alt:radar.
  24. lock altit to alt:radar-h.
  25. lock myvel to ship:velocity:surface:mag.
  26. set targetalt to 6250.
  27. set landingZone to latlng(-5.4655,-84.0333).
  28. set errorScaling to 1.
  29. lock steering to heading(90,90).
  30. set hts to ship:partsnamed("externalTankRound").
  31. set r1 to hts[0].
  32. set r2 to hts[1].
  33. set r3 to r1:resources.
  34. set r4 to r2:resources.
  35. set r5 to r3[0].
  36. set r6 to r3[1].
  37. set r7 to r4[0].
  38. set r8 to r4[1].
  39. set r5:enabled to true.
  40. set r6:enabled to true.
  41. set r7:enabled to true.
  42. set r8:enabled to true.
  43. set partlist to ship:partsnamed("hinge.01").
  44. set eng1 to ship:partstagged("Vector1")[0].
  45. set eng2 to ship:partstagged("Vector2")[0].
  46. set eng3 to ship:partstagged("Vector3")[0].
  47. eng1:activate.
  48. eng2:activate.
  49. eng3:activate.
  50. lock g to constant:g * body:mass / body:radius^2.
  51. set thr to 1040.
  52. lock maxDecel to (thr / ship:mass) - g.
  53. lock stopDist to ship:verticalspeed^2 / (2 * maxDecel).
  54. lock idealThrottle to stopDist / altit.
  55. lock impactTime to altit / abs(ship:verticalspeed).
  56. clearVecDraws().
  57. print "Goal: " + goal.
  58. print "Press 9".
  59. wait 1.
  60. wait until ag9.
  61. set now to time:seconds.
  62. lock testtime to time:seconds - now.
  63. wait 1.
  64. toggle ag9.
  65. set teststatus to "Fueling".
  66. print "Go for test".
  67. }
  68.  
  69. function fuel {
  70. on ag10 {
  71. aborttest().
  72. }
  73.  
  74. print "Beginning fueling".
  75. wait 1.
  76. print "Awaiting for fueling end, press 9 to end".
  77. until ag9 {
  78. printing().
  79. }
  80.  
  81. set teststatus to goal + " preparing".
  82. wait 1.
  83. toggle ag1.
  84. toggle ag2.
  85. toggle ag3.
  86. wait 1.
  87. toggle ag9.
  88. print "Fueling finished, press 9".
  89. wait 1.
  90. until ag9 {
  91. printing().
  92. }
  93.  
  94. set teststatus to goal + " go".
  95. toggle ag1.
  96. toggle ag2.
  97. toggle ag3.
  98. set r5:enabled to false.
  99. set r6:enabled to false.
  100. set r7:enabled to false.
  101. set r8:enabled to false.
  102. wait 5.
  103. }
  104.  
  105. function hop {
  106. on ag10 {
  107. aborttest().
  108. }
  109.  
  110. set l to 1.
  111. set maxthr to ship:maxthrust.
  112. set g to body:mu/(body:radius)^2.
  113. set twr to ship:mass * g / ship:maxthrust.
  114. lock curthr to eng1:thrust + eng2:thrust + eng3:thrust.
  115. toggle ag3.
  116. wait 3.
  117. rcs off.
  118. sas off.
  119. lock throttle to 0.05.
  120. toggle ag3.
  121. eng1:activate.
  122. eng2:activate.
  123. eng3:activate.
  124. wait 1.
  125. set n to time:seconds.
  126. lock t to time:seconds - n.
  127. lock throttle to min(1, t/3).
  128. print "Test began".
  129. lock steering to up + r(0,0,270).
  130. wait until altit>4.
  131. lock steering to up + r(0,0,270).
  132. lock latoff to (landingZone:lat-addons:tr:impactpos:lat)*10472.
  133. lock lngoff to (landingZone:lng-addons:tr:impactpos:lng)*10472.
  134. set thr to 1559.
  135. until ship:verticalspeed > 2 {
  136. hopprinting().
  137. }
  138.  
  139. lock throttle to twr * 1.16.
  140. lock steering to up + r(0,0,270).
  141. until altit > 200 {
  142. hopprinting().
  143. }
  144.  
  145. lock throttle to twr * 1.1.
  146. lock steering to up + r(0,0,270).
  147. until altit > 200 {
  148. hopprinting().
  149. }
  150.  
  151. lock throttle to twr * 1.06.
  152. lock steering to up + r(0,0,270).
  153. until altit > 350 {
  154. hopprinting().
  155. }
  156.  
  157. lock throttle to twr * 1.04.
  158. lock steering to up + r(0,0,270).
  159. until altit > 560 {
  160. hopprinting().
  161. }
  162.  
  163. lock throttle to twr * 1.03.
  164. lock steering to up + r(0,-0.2,270).
  165. until altit > 800 {
  166. hopprinting().
  167. }
  168.  
  169. lock throttle to twr * 1.02.
  170. lock steering to up + r(0,-0.5,270).
  171. until altit > 2200 {
  172. hopprinting().
  173. }
  174.  
  175. eng2:shutdown.
  176. set thr to 1559*0.33.
  177. set twr to ship:mass * g / eng1:availablethrust+eng3:availablethrust.
  178. lock throttle to twr * 0.96.
  179. lock steering to up + r(0.7, 0.4, 270).
  180. wait 2.
  181. lock throttle to twr * 1.04.
  182. until altit > 4100 {
  183. hopprinting().
  184. }
  185.  
  186. lock steering to up + r(0.7,0.4,270).
  187. until altit > 5450 {
  188. hopprinting().
  189. }
  190.  
  191. eng3:shutdown.
  192. set thr to 1559*0.66.
  193. set twr to ship:mass * g / eng1:thrust.
  194. lock steering to up + r(-0.1,3,270).
  195. lock throttle to twr * 0.98.
  196. until ship:verticalspeed < 10 {
  197. hopprinting().
  198. }
  199.  
  200. lock throttle to twr * 0.99.
  201. until altit > targetalt-100 {
  202. hopprinting().
  203. }
  204.  
  205. lock throttle to twr * 0.9.
  206. until ship:verticalspeed < 5 {
  207. hopprinting().
  208. }
  209.  
  210. print "SN8 is in target altitude".
  211. until ship:verticalspeed < 0.1 {
  212. hopprinting().
  213. }
  214.  
  215. ag6 on.
  216. lock throttle to twr * 0.85.
  217. print "SN8 is in apoapsis".
  218. until ship:verticalspeed < -24 {
  219. hopprinting().
  220. }
  221.  
  222. lock throttle to twr * 0.99.
  223. until altit < 5800 {
  224. hopprinting().
  225. }
  226.  
  227. rcs on.
  228. set l to 2.
  229. lock throttle to max(0, 0.9-t/2).
  230. lock steering to up + r(0,-90,270).
  231. toggle ag4.
  232. toggle ag5.
  233. wait 3.
  234. partlist[3]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -20).
  235. partlist[2]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -20).
  236. partlist[0]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", 15).
  237. partlist[1]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", 15).
  238. wait 3.
  239. ag6 off.
  240. eng1:shutdown.
  241. partlist[3]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  242. partlist[2]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  243. partlist[0]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  244. partlist[1]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  245. ag6 off.
  246. lock steering to up + r(0,steerroll1,270+steerpitch1).
  247. wait 3.
  248. toggle ag4.
  249. toggle ag5.
  250. until altit < stopDist+150 {
  251. hopprinting().
  252. }
  253.  
  254. set r5:enabled to true.
  255. set r6:enabled to true.
  256. set r7:enabled to true.
  257. set r8:enabled to true.
  258. eng2:activate.
  259. eng3:activate.
  260. lock throttle to min(0.55, t/0.3).
  261. toggle ag4.
  262. toggle ag5.
  263. wait 0.5.
  264. partlist[3]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -90).
  265. partlist[2]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -90).
  266. partlist[0]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", 15).
  267. partlist[1]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", 15).
  268. wait 0.3.
  269. lock aoa to -7.
  270. lock steering to srfretrograde.
  271. until vang(ship:facing:vector, -ship:velocity:surface)<20 {
  272. hopprinting().
  273. }
  274.  
  275. partlist[3]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  276. partlist[2]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  277. partlist[0]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  278. partlist[1]:getmodule("ModuleRoboticServoHinge"):setfield("Target Angle", -15).
  279. lock throttle to idealThrottle.
  280. lock steering to getSteering().
  281. until altit < 100 {
  282. hopprinting().
  283. }
  284.  
  285. eng3:shutdown.
  286. lock throttle to twr*0.85.
  287. lock steering to srfretrograde.
  288. until ship:verticalspeed > -12 {
  289. hopprinting().
  290. }
  291.  
  292. gears on.
  293. lock steering to up + r(0,0,270).
  294. until ship:verticalspeed > -1 {
  295. hopprinting().
  296. }
  297. ag4 off.
  298. ag5 off.
  299. set latoff to 0.
  300. set lngoff to 0.
  301. lock throttle to 0.1.
  302. print "Test completed".
  303. wait 3.5.
  304. lock throttle to 0.
  305. eng1:shutdown.
  306. eng2:shutdown.
  307. eng3:shutdown.
  308. set teststatus to "Completed".
  309. detanking().
  310. }
  311.  
  312. function hopprinting {
  313. clearscreen.
  314. if l = 2 {
  315. set thr to 1040.
  316. } else if l = 3 or l = 1 {
  317. set thr to ship:availablethrust.
  318. }
  319.  
  320. set twr to ship:mass * g / thr.
  321. print "Test lenght: " + t + " Seconds".
  322. print "Current throttle: " + curthr + "kn".
  323. print "Maximum throttle: " + maxthr + "kn".
  324. if l=2 {
  325. steerroll1().
  326. steerpitch1().
  327. }
  328.  
  329. print "Latoff: " + latoff + "M".
  330. print "Lngoff: " + lngoff + "M".
  331. print "Landing Burn Alt: " + stopDist + "M".
  332. log t + ";" + maxthr + ";" + curthr + ";" + altit + ";" + latoff + ";" + lngoff to starhopper75hop.txt.
  333. }
  334.  
  335. function detanking {
  336. print "Test status: " + teststatus.
  337. ag2 on.
  338. ag3 on.
  339. ag1 on.
  340. wait 1.
  341. toggle ag9.
  342. unlock steering.
  343. unlock throttle.
  344. wait 300.
  345. ag1 off.
  346. ag2 off.
  347. ag3 off.
  348. print 3/0.
  349. }
  350.  
  351. function printing {
  352. clearscreen.
  353. print "Time from test beginning: " + testtime + " Seconds".
  354. print "Test status: " + teststatus.
  355. print "Goal: " + goal.
  356. print "Time(KSC): " + time:clock.
  357. wait 0.1.
  358. }
  359.  
  360. function aborttest {
  361. lock latoff to 0.
  362. lock lngoff to 0.
  363. print "Abort".
  364. eng1:shutdown.
  365. eng2:shutdown.
  366. eng3:shutdown.
  367. ag1 on.
  368. lock throttle to 0.
  369. wait 1.
  370. unlock throttle.
  371. unlock steering.
  372. wait 1.
  373. set teststatus to "Detanking".
  374. detanking().
  375. }
  376.  
  377. function steerroll1 {
  378. wait 0.
  379. set pid to pidloop(0.2, 0.08, 0.1, -20,20).
  380. set pid:setpoint to 0.
  381. set ang to pid:update(time:seconds,lngoff).
  382. if ang < 0 {
  383. set y to ang+(-90).
  384. } else if ang > 0 {
  385. set y to ang-90.
  386. }
  387.  
  388. return y.
  389. }
  390.  
  391. function steerpitch1 {
  392. wait 0.
  393. set pid to pidloop(80,40,40, -15,15).
  394. set pid:setpoint to 0.
  395. set pit to pid:update(time:seconds,latoff).
  396. if pit < 0 {
  397. set p to abs(pit).
  398. } else if pit > 0 {
  399. set p to -pit.
  400. }
  401.  
  402. return p.
  403. }
  404.  
  405. function errorVector {
  406. return getImpact():position - landingZone:position.
  407. }
  408.  
  409. function getSteering {
  410. local errorVector is errorVector().
  411. local velVector is -ship:velocity:surface.
  412. local result is velVector + errorVector*errorScaling.
  413.  
  414. if vang(result, velVector) > aoa
  415. {
  416. set result to velVector:normalized + tan(aoa)*errorVector:normalized.
  417. }
  418.  
  419. return lookdirup(result, facing:topvector).
  420. }
  421.  
  422. function getImpact {
  423. if addons:tr:hasimpact { return addons:tr:impactpos. }
  424. return ship:geoposition.
  425. }
Advertisement
Add Comment
Please, Sign In to add comment