sumguytwitches

Piggyback runway to orbit SG Ride Lab IV

Apr 13th, 2023 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lock liquidmatched to min(ship:oxidizer * 9 / 11, ship:liquidfuel).
  2. lock NukeLiquid to max(0, ship:liquidfuel-liquidmatched).
  3. lock nukedv to Round(800 * 9.81 * ln(ship:mass / (ship:mass - (NukeLiquid * 0.005))), 5).
  4.  
  5. lock oxidizermatched to min(ship:oxidizer, ship:liquidfuel * 11 / 9).
  6. lock vectordv to Round(315 * 9.81 * ln((ship:mass - (NukeLiquid * 0.005)) / ((ship:mass - (NukeLiquid * 0.005)) - (liquidmatched * 0.005) - (oxidizermatched * 0.005))), 5).
  7.  
  8. bays off. brakes off. rcs on.
  9. function SetEngines {
  10. parameter targetMode to "Activate Engine".
  11. parameter engines to ship:partsdubbedpattern("vector").
  12. for engine in engines {
  13. if engine:hasmodule("ModuleEnginesFx") set m to engine:getmodule("ModuleEnginesFx").
  14. if engine:hasmodule("ModuleEngines") set m to engine:getmodule("ModuleEngines").
  15. if m:hasaction(targetMode) m:doaction(targetMode, true).
  16. }
  17. }
  18.  
  19. function ThrustLimit {
  20. parameter targetEngines.
  21. parameter targetThrust.
  22. for eng in targetEngines set eng:thrustlimit to targetThrust.
  23. }
  24.  
  25. function SetAngle {
  26. parameter targetangle.
  27. for s in servos if s:hasfield("target angle") s:setfield("target angle", targetangle).
  28. }
  29.  
  30. function info {
  31. parameter message.
  32.  
  33. set logmessage to round(missionTime,1) + ": " + message.
  34. print logmessage.
  35. }
  36.  
  37.  
  38. copypath("0:","1:").
  39. for i in range(terminal:height-3) Print "":padright(terminal:width).
  40.  
  41. set steeringmanager:rollcontrolanglerange to 180.
  42.  
  43. set takeoffspeed to 100.
  44. set targetOrbitAltitude to 101e3.
  45.  
  46. set vectors to ship:partsdubbedpattern("vector").
  47. set nukes to ship:partsdubbedpattern("nuc").
  48. set servos to ship:modulesnamed("ModuleRoboticRotationServo").
  49. lock p to choose 0 if airspeed < takeoffspeed else min(25,max(0,groundspeed/7.5)).
  50. lock steering to heading(90,p).
  51.  
  52. SetEngines("Activate Engine", vectors).
  53. lock throttle to targetOrbitAltitude-apoapsis.
  54. lock angletarget to 0.
  55. when altitude > 72 then {
  56. gear off.
  57. info("engage dynamic servo").
  58. lock angletarget to max(0, min(90,100 - ((-verticalspeed + (80-altitude)/1.5)*100))).
  59. //set p to 10.
  60. }
  61.  
  62. info("initialize vtols").
  63. lock vlimit to (-verticalspeed + (80-altitude))*100.
  64. set vlimitcopy to vlimit.
  65. set anglecopy to angletarget.
  66.  
  67. when abs(vang(ship:facing:vector, heading(90,0):vector)) < 5 then {
  68. SetEngines("Activate Engine", ship:partsdubbedpattern("turbofan")).
  69. }
  70.  
  71. until vlimit < 0 {
  72. set vlimitcopy to vlimit.
  73. set anglecopy to angletarget.
  74. ThrustLimit(vectors, vlimitcopy).
  75. SetAngle(anglecopy).
  76. print " v thrust: " + vlimitcopy at (0,0).
  77. print "servo angle: " + anglecopy at (0,1).
  78. print " p: " + p at (0,2).
  79. wait 0.
  80. }
  81.  
  82. info("store vtols").
  83. SetEngines("Shutdown Engine", vectors).
  84.  
  85. SetAngle(90).
  86. print " v thrust: " + vlimitcopy at (0,0).
  87. print "servo angle: " + anglecopy at (0,1).
  88. info("gain speed").
  89. lock aoa to vang(srfprograde:vector, ship:facing:vector).
  90. lock p to max(aoa+0.5,min(45, aoa+(airspeed-400)/5 )).
  91.  
  92. when altitude > 8000 then {
  93. info("go faster").
  94. lock p to vang(srfprograde:vector,heading(90,0):vector).
  95. }
  96. when altitude > 8000 and p < 10 then set p to 10.
  97.  
  98. when altitude > 14000 then {
  99. info("engage nukes").
  100. SetEngines("Activate Engine", nukes).
  101. set p to 15.
  102. }
  103.  
  104. when altitude > 20000 then {
  105. info("push to orbit").
  106. lock p to airspeed/50.
  107. SetEngines("Activate Engine", vectors).
  108. ThrustLimit(vectors, 100).
  109. }
  110. when altitude > 20000 and p > 30 then lock p to 30.
  111.  
  112.  
  113. when ship:oxidizer < 500 then {
  114. info("preserve landing fuel").
  115. SetEngines("Shutdown Engine", vectors).
  116. }
  117.  
  118. when apoapsis >= targetOrbitAltitude-5e3 then {
  119. info("lock surface prograde").
  120. lock p to vang(srfprograde:vector,heading(90,0):vector).
  121. }
  122.  
  123. when altitude > 50e3 then {
  124. lock p to vang(prograde:vector,heading(90,0):vector).
  125. }
  126.  
  127. when apoapsis >= targetOrbitAltitude then {
  128. info("warping to space").
  129.  
  130. SetEngines("Shutdown Engine", ship:partsdubbedpattern("turbofan")).
  131.  
  132. lock throttle to 0.
  133. set warpmode to "physics".
  134. set warp to 3.
  135. }
  136.  
  137. when (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
  138.  
  139. steeringManager:resettodefault().
  140. set warp to 0.
  141. wait until kuniverse:timewarp:issettled.
  142. set warpmode to "rails".
  143. info("adjusting apoapsis").
  144. lock throttle to choose (targetOrbitAltitude - apoapsis)/10 if apoapsis - periapsis > 10 else 0.
  145. }
  146.  
  147. when apoapsis >= targetOrbitAltitude and (altitude >= body:atm:height and (periapsis > body:atm:height or ship:verticalspeed > 0)) then {
  148.  
  149. lock throttle to 0.
  150. list engines in es. for e in es e:shutdown().
  151. SetEngines("Activate Engine", nukes).
  152. if(apoapsis - periapsis > 10) {
  153. info("need to circularize").
  154. set warpmode to "rails".
  155. set warp to 1.
  156. wait 1.
  157. warpto(time:Seconds + eta:apoapsis - 50).
  158. wait until eta:apoapsis < 50.
  159. info("circularizing").
  160. set circularizing to true.
  161. lock desiredVel to vxcl(up:vector,velocity:orbit):normalized * sqrt(body:MU/(body:Radius + altitude)).
  162. lock dV to desiredVel - velocity:orbit.
  163. lock steering to lookdirup(dV, ship:facing:topvector).
  164. when circularizing then {
  165. if vang(facing:vector,dV) > 10 {
  166. lock throttle to 0.
  167. } else {
  168. lock throttle to dv:mag / 2.
  169. }
  170. if dv:mag > 0.3 {
  171. return true.
  172. } else {
  173. info("circularize complete").
  174. lock throttle to 0.
  175. set circularizing to false.
  176. }
  177. }
  178. return circularizing.
  179. }
  180.  
  181. }
  182.  
  183. function landnoatmo {
  184. info("reducing groundspeed").
  185. lock steering to -velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5.
  186. lock throttle to choose groundspeed - 200 if abs(steeringmanager:angleerror) < 5 else 0.
  187. when ship:liquidfuel < (ship:oxidizer * 9 / 11) + 0.4 then
  188. {
  189. info("switching to rockets").
  190. list engines in es. for e in es e:shutdown().
  191. SetEngines("Activate Engine", vectors).
  192. }
  193.  
  194. wait until groundspeed < 201.
  195. info("preparing final form").
  196. lock throttle to 0.
  197. list engines in es. for e in es e:shutdown().
  198. SetEngines("Activate Engine", vectors).
  199. SetAngle(0).
  200. rcs on.
  201.  
  202. toggle ag10.
  203. brakes on.
  204. gear on.
  205. lights on.
  206.  
  207. wait until abs(steeringmanager:angleerror) < 5.
  208. set complete to false.
  209. info("begin final landing sequence").
  210.  
  211. lock throttle to (-verticalspeed-1)-sqrt(2*max(1,(max(0.1,vdot(up:vector,facing:vector))* availablethrust*0.9)/mass-body:mu/(body:radius^2))*max(altitude-geoposition:terrainheight-50+verticalspeed*0.5,0.1)).
  212. when verticalspeed>0 and alt:radar < 1000 then {
  213. lock throttle to 0.
  214. lock steering to heading(90,90).
  215. set complete to true.
  216. }
  217.  
  218. lock steering to lookdirup(-velocity:surface+vxcl(up:vector,-velocity:surface*0.3)+up:vector*5,heading(270,0):vector).
  219.  
  220.  
  221. wait until complete.
  222. info("welcome to mun").
  223. }
Add Comment
Please, Sign In to add comment