Advertisement
Guest User

kspkoscode

a guest
Apr 25th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. wait 3.
  2. clearScreen.
  3. local tel is true.
  4. set line to 0.
  5. set width to 26.
  6. when tel = true then {
  7. terminaldisplay (line, width).
  8. preserve.
  9. }
  10. wait 0.
  11.  
  12. actguid(orbitdata).
  13.  
  14. /////////////////////////////////////
  15.  
  16. global function actguid {
  17. parameter orbdata.
  18.  
  19. wait 0.
  20. set actmode to 1.
  21. set brnmode to actmode.
  22. local met is 45.
  23. local radalt is alt:radar.
  24. local canstage is false.
  25. local finalp is 2.5.
  26. local desiredpitch is 90.
  27. local azimuth is 0.
  28. local rcsact is true.
  29. local orbalt is orbdata[1].
  30. local gravityturnvel is orbdata[2].
  31. local tarinc is orbdata[3].
  32. local jtsfar is orbdata[4].
  33. local stgrcs is orbdata [5].
  34. local corrections is true.
  35. local shipmaxq is false.
  36.  
  37.  
  38. lock steering to heading (azimuth,desiredpitch).
  39.  
  40. wait until alt:radar > radalt*3.
  41.  
  42. set azimuth to flightaz(launchdata).
  43.  
  44. set tarp to desiredpitch.
  45. set message to round(azimuth) + "° Launch Azimuth".
  46.  
  47. wait until missionTime>10.
  48. set desiredpitch to 85.
  49. set tarp to desiredpitch.
  50.  
  51. wait until ship:velocity:surface:mag >= gravityturnvel.
  52.  
  53. set message to "Starting guideance".
  54.  
  55.  
  56. local wantthrottle is 1.
  57. lock throttle to wantthrottle.
  58. local tgtpitch is desiredpitch.
  59. set jtsfar to true.
  60. local oldthrust is ship:availablethrust.
  61. local q1 is ship:q.
  62. local time1 is time:seconds.
  63.  
  64. set actmode to 2.
  65. set brnmode to actmode.
  66.  
  67. until actmode <>2 {
  68.  
  69. if missionTime>=met and canstage=false{
  70. set oldthrust to ship:availablethrust.
  71. set canstage to true.
  72. }
  73.  
  74. if ship:availablethrust < (oldthrust-5) and canstage = true and missionTime>met{
  75. dostage().
  76. set message to "Staging "+stage:number.
  77. wait 0.
  78. set oldthrust to ship:availablethrust.
  79. wait 0.
  80. }
  81.  
  82. local time2 is time:seconds.
  83. local q2 is ship:q.
  84. local a is ship:thrust/ship:mass.
  85. local vs is verticalSpeed.
  86. local h is (ship:body:atm:height+5000)-ship:altitude.
  87. local av is max(0.0000001,(a*(sin(tgtpitch)))).
  88. local timetofinalalt is ((-vs) + sqrt(max(0,vs^2 +2*av*h)))/(av).
  89. local pitchrate is (finalp-tgtpitch)/timetofinalalt.
  90. local dt is time2-time1.
  91. set deltatime to round(dt).
  92.  
  93. set tgtpitch to min(85,max(finalp,(tgtpitch + dt*pitchrate))).
  94. set desiredpitch to min(85,max((90-(vang(srfprograde:vector,up:vector))-4),(tgtpitch + dt*pitchrate))).
  95. set tarp to round(tgtpitch).
  96.  
  97. if q1 > q2 and shipmaxq=false{
  98. set message to "Max Q " + round(ship:q*constant:atmtokpa,3)+ " kPa".
  99. set shipmaxq to true.
  100. }
  101.  
  102. if abs(orbit:inclination)<tarinc and corrections=true {
  103. set azimuth to flightaz(launchdata).
  104. }
  105. else {
  106. wait 0.
  107. set corrections to false.
  108. wait 0.
  109. set azimuth to heading_of_vector(ship:prograde:vector).
  110. wait 0.
  111.  
  112. }
  113.  
  114. if ship:q*constant:atmtokpa<5.5 and shipmaxq=true{
  115. set actmode to 3.
  116. }
  117. set time1 to time2.
  118. set q1 to q2.
  119. wait 0.
  120. }
  121. set brnmode to actmode.
  122. set throttlepid to pidLoop(0.1, 0.1, 0.01, (2/3), 1).
  123. set throttlepid:setpoint to 60.
  124. set wantthrottle to throttlepid:update(time:seconds, eta:apoapsis).
  125. until actmode <>3 {
  126.  
  127. if ship:availablethrust < (oldthrust-5) and canstage = true and missionTime>met{
  128. dostage().
  129. set message to "Staging "+stage:number.
  130. wait 0.
  131. set oldthrust to ship:availablethrust.
  132. wait 0.
  133. }
  134.  
  135. local time2 is time:seconds.
  136. local currentpitch is (90-(vang(up:vector,facing:vector))).
  137. local a is ship:thrust/ship:mass.
  138. local vs is verticalSpeed.
  139. local h is (ship:body:atm:height+5000)-ship:altitude.
  140. local av is max(0.0000001,(a*(sin(currentpitch)))).
  141. local timetofinalalt is ((-vs) + sqrt(max(0,vs^2 +2*av*h)))/(av).
  142. local pitchrate is (finalp-desiredpitch)/timetofinalalt.
  143. local dt is time2-time1.
  144. set deltatime to round(dt).
  145.  
  146. set desiredpitch to max(finalp,(desiredpitch + dt*pitchrate)).
  147. set tarp to round(desiredpitch).
  148. set wantthrottle to throttlepid:update(time:seconds, eta:apoapsis).
  149.  
  150. if currentpitch <= finalp+1 or eta:apoapsis < 45 set actmode to 4.
  151. if ship:periapsis >=0 set actmode to 5.
  152.  
  153. if abs(orbit:inclination)<tarinc and corrections=true and corrections=true {
  154. set azimuth to flightaz(launchdata).
  155. }
  156. else {
  157. wait 0.
  158. set corrections to false.
  159. wait 0.
  160. set azimuth to heading_of_vector(ship:prograde:vector).
  161. wait 0.
  162.  
  163. }
  164.  
  165. if ship:altitude >= 60_000 and jtsfar = true and ship:q*constant:atmtokpa <0.4{
  166. wait until stage:ready.
  167. jetfairing("far").
  168. extendpanels("far").
  169. deployantenna("far").
  170. set jtsfar to false.
  171. }
  172.  
  173. if stage:number=stgrcs and rcsact=true{
  174. rcs on.
  175. set rcsact to false.
  176. }
  177.  
  178. set time1 to time2.
  179. wait 0.
  180. }
  181.  
  182. set brnmode to actmode.
  183. set wantthrottle to throttlepid:update(time:seconds, eta:apoapsis).
  184. until actmode <>4 {
  185.  
  186. local time2 to time:seconds.
  187. local g is body:mu / (altitude + body:radius)^2.
  188. local dt is time2-time1.
  189. set deltatime to round(dt).
  190.  
  191. if ship:availablethrust < (oldthrust-5) and canstage = true and missionTime>met{
  192. dostage().
  193. set message to "Staging "+stage:number.
  194. wait 0.
  195. set oldthrust to ship:availablethrust.
  196. wait 0.
  197. }
  198.  
  199. set desiredpitch to min(max(((arcsin(g/velocity:orbit:mag)+2*(60-eta:apoapsis))+finalp),0),45).
  200.  
  201. set tarp to round(desiredpitch).
  202. set wantthrottle to throttlepid:update(time:seconds, eta:apoapsis).
  203.  
  204. if ship:periapsis >=0 set actmode to 5.
  205.  
  206. if abs(orbit:inclination)<tarinc and corrections=true and corrections=true {
  207. set azimuth to flightaz(launchdata).
  208. }
  209. else {
  210. wait 0.
  211. set corrections to false.
  212. wait 0.
  213. set azimuth to heading_of_vector(ship:prograde:vector).
  214. wait 0.
  215. set message to corrections.
  216.  
  217. }
  218.  
  219. if ship:altitude >= 60_000 and jtsfar = true and ship:q*constant:atmtokpa <0.4{
  220. wait until stage:ready.
  221. jetfairing("far").
  222. extendpanels("far").
  223. deployantenna("far").
  224. set jtsfar to false.
  225. }
  226.  
  227. if stage:number=stgrcs and rcsact=true{
  228. rcs on.
  229. set rcsact to false.
  230. }
  231.  
  232. set time1 to time2.
  233. wait 0.
  234. }
  235.  
  236.  
  237. set brnmode to actmode.
  238. set throttlepid to pidLoop(0.1, 0.1, 0.01, 1/3, 1).
  239. set throttlepid:setpoint to 30.
  240. until actmode <>5 {
  241.  
  242. if ship:availablethrust < (oldthrust-5) and canstage = true and missionTime>met{
  243. dostage().
  244. set message to "Staging "+stage:number.
  245. wait 0.
  246. set oldthrust to ship:availablethrust.
  247. wait 0.
  248. }
  249.  
  250. set time2 to time:seconds.
  251. set dt to time2-time1.
  252. set deltatime to round(dt).
  253.  
  254. set desiredpitch to (90-vang(prograde:vector,up:vector)).
  255. set wantthrottle to throttlepid:update(time:seconds, eta:apoapsis).
  256.  
  257. if abs(orbit:inclination)<tarinc and corrections=true and corrections=true {
  258. set azimuth to flightaz(launchdata).
  259. }
  260. else {
  261. wait 0.
  262. set corrections to false.
  263. wait 0.
  264. set azimuth to heading_of_vector(ship:prograde:vector).
  265. wait 0.
  266.  
  267. }
  268.  
  269. if ship:altitude >= 60_000 and jtsfar = true and ship:q*constant:atmtokpa <0.4{
  270. wait until stage:ready.
  271. jetfairing("far").
  272. extendpanels("far").
  273. deployantenna("far").
  274. set jtsfar to false.
  275. }
  276.  
  277. if stage:number=stgrcs and rcsact=true{
  278. rcs on.
  279. set rcsact to false.
  280. }
  281.  
  282. if ship:altitude>ship:orbit:body:atm:height+100 and ship:orbit:apoapsis>=orbalt-100{
  283. set actmode to 6.
  284. }
  285.  
  286. set time1 to time2.
  287. wait 0.
  288.  
  289. }
  290. set bnrmode to "Complete".
  291. lock throttle to 0.
  292. set canstage to false.
  293. }
  294.  
  295.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement