Advertisement
Guest User

Untitled

a guest
May 28th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. //New version of the ascent script! Now in lower-case and metric units!
  2. //Program 110
  3. //1st program of flight, number 10 - so I have space for 10 pre-programs, and 90 post-programs, all for phase 1 of flight - initial launch. First program of phase two would be 2##. Of phase 3, 3##, etc.
  4.  
  5. clearscreen.
  6.  
  7. set terminal:width to 37.
  8. set terminal:height to 37.
  9.  
  10. local tgt_hdot is 0. // For use in other, non-circular orbit versions.
  11. local tgt_h is 114000. // 85 nmi - initial "climb to this during ascent" altitude
  12. local tgt_ap is 114000. // triggers engine cut-off.
  13. local tgt_apo is 160000.
  14. local tgt_xdot is sqrt( body:mu / (body:radius + altitude) ).
  15. local pitch_limit is 30.
  16. local cmd_pitch is 90.
  17. local cmd_throttle is 1.0.
  18. //local g_limit is 3.5*9.8. // For smooth ride.
  19. local g_limit is 3.5*9.8. // For smooth ride.
  20. local throttle_floor is 0.21.
  21. local range is 0.
  22. local tower_height is 180. // Saturn V was ~100 meters tall. We can climb for a bit until rolling, no prob.
  23. local wait_time is 0.1.
  24. local transition_h is 36576. // 120,000 ft. Altitude to cease pitch program and use interactive guidance.
  25. local min_turn_speed is 60. // Somewhat arbitrarily chosen minimum speed to begin pitch program.
  26. local nullify_time is 15.
  27. local pitch_increment is 0.3. // divide by wait_time to get degrees/second on aposeek program.
  28. local throttle_increment is 0.01. // divide by wait_time to get throttle/second.
  29. local R_mag is 0.2. // controls how hard we turn to align orbits.
  30. local t is 0.
  31. local tzero is 0.
  32. local timer_on is false.
  33.  
  34. local ap_window is 926.
  35.  
  36. local throttle_min is 0.59. // range from 0 to 1! This is minimum throttle engines are capable of! 0.76 is J-2S. .07 RL-10 CECE.
  37. local azimuth is 90.
  38. local dogleg is true.
  39. local t_dogleg is 240. // time to begin dogleg turn
  40. local dogleg_length is 10. //how long for the main part of the dogleg turn.
  41.  
  42. // To be defined later
  43. local est_time_for_hdot_seek is 30. // est. time to CO to begin hdot seek. Will need to tweak for higher tgt_hdot.
  44. local status is "STANDBY.".
  45. local status_detail is " ".
  46. local hddot is 0.
  47. local aposeek is 0.
  48. local apodot is 0.
  49. local ap_to_go_plus is 0.
  50. local ap_to_go_minus is 0.
  51. local g_eff is 0.
  52. local g_inertial is 0.
  53. local xddot is 0.
  54. local est_tto_co is 1. // keep it larger than est_tto_tgt_hdot to keep from skipping null hdot routine.
  55. local pitch_program_running is false.
  56.  
  57. local trelease is 6.
  58. local tsrbsep is 148.
  59. local tfairingjettison is 160.
  60. local tmeco is 354.
  61.  
  62. declare function print_us_telemetry
  63. {
  64.  
  65. clearscreen.
  66.  
  67. print "=====================================" at (0,0).
  68.  
  69. if hastarget = false {
  70. print "SLS 1B ASCENT. EUS+TLI. NO TGT." at (0,1).
  71. }
  72.  
  73. if hastarget = true {
  74. print "SLS 1B ASCENT. EUS+TLI. HAS TGT." at (0,1).
  75. }
  76.  
  77. print "=====================================" at (0,2).
  78. print "STATE: " + status at (0,3).
  79. print status_detail at (0,4).
  80.  
  81. print "T+ " + round(t - trelease) at (0,6).
  82. print "CMD PITCH: " + round(cmd_pitch) at (0,7).
  83. print "ALTITUDE: " + (round(altitude*0.0539957)/100) + " NMI." at (0,8).
  84. print "ALTITUDE: " + round(altitude*3.28084) + " FT." at (0,9).
  85. print "VELOCITY: " + round(velocity:orbit:mag*3.28084) + " FPS." at (0,10).
  86. print "VELOCITY TGO: " + round((tgt_xdot - velocity:orbit:mag)*3.28084) + " FPS." at (0,11).
  87. print "HDOT: " + round(verticalspeed*3.28084) + " FPS." at (0,12).
  88. print "HDDOT: " + round(hddot*3.28084) + " FPS." at (0,13).
  89.  
  90. print "RANGE: " + round(range*0.00539957) + " NMI." at (0,14).
  91.  
  92. print "T: " + round(cmd_throttle*100) at (0,22).
  93. print "G: " + (round(100*g_inertial/9.82)/100) at (0,23).
  94.  
  95. if t < tsrbsep
  96. {
  97.  
  98. print "SRB SEP T -" + round((tsrbsep - t)) at (0, 25).
  99.  
  100. }
  101. else if t < tfairingjettison
  102. {
  103.  
  104. print "FAIRING JETT IN T -" + round((tfairingjettison - t)) at (0, 25).
  105.  
  106. }
  107. else if t < tmeco
  108. {
  109.  
  110. print "MECO IN T -" + round((tmeco - t)) at (0, 25).
  111.  
  112. }
  113.  
  114. if t + 10 > tsrbsep and t < tsrbsep
  115. {
  116.  
  117. print "STANDBY FOR SRB SEP..." at (0, 26).
  118.  
  119. }
  120.  
  121. if t + 10 > tfairingjettison and t < tfairingjettison
  122. {
  123.  
  124. print "STANDBY FOR FAIRING JETTISON..." at (0, 26).
  125.  
  126. }
  127.  
  128. if t + 10 > tmeco and t < tmeco
  129. {
  130.  
  131. print "STANDBY FOR STAGING..." at (0, 26).
  132.  
  133. }
  134.  
  135. }
  136.  
  137. declare function engage_steering
  138. {
  139.  
  140. local is_on_same_side_of_planet is true.
  141.  
  142. if hastarget = false and pitch_program_running = false
  143. {
  144. local p is vectorexclude(body:position,velocity:orbit).
  145. local phat is p:normalized.
  146. local u is (-body:position).
  147. local uhat is u:normalized.
  148. local h is (uhat*sin(cmd_pitch) + phat*cos(cmd_pitch)).
  149.  
  150. lock steering to lookdirup(h,u).
  151. }
  152.  
  153. // else if hastarget = true
  154. // {
  155. // local p is vectorexclude(body:position,target:velocity:orbit).
  156. // local phat is p:normalized.
  157. // local u is (-body:position).
  158. // local uhat is u:normalized.
  159. // local h is (uhat*sin(cmd_pitch) + phat*cos(cmd_pitch)).
  160. //
  161. // lock steering to lookdirup(h,u).
  162. // }
  163.  
  164. if hastarget = true and pitch_program_running = false
  165. {
  166. local p is vectorexclude(body:position,target:velocity:orbit).
  167. local phat is p:normalized.
  168. local u is (-body:position).
  169. local uhat is u:normalized.
  170.  
  171. local L_tgt is vcrs(target:velocity:orbit,(body:position - target:position)).
  172. local L is vcrs(velocity:orbit,body:position).
  173. local L_rel is (L_tgt:normalized - L:normalized).
  174. local L_relhat is L_rel:normalized.
  175.  
  176. local turn_angle is (L_relhat * velocity:orbit:normalized). // ranges from -1 to 1, so just use it.
  177. // square rooted for mapping. Want small numbers to try to hone in on zero, but not asymptotically!
  178. local R is vcrs(body:position,velocity:orbit).
  179. local Rhat is R:normalized.
  180.  
  181. local R_mult is 1.
  182.  
  183. local h is (phat + R_mult*R_mag*turn_angle*Rhat).
  184.  
  185. local hhat is h:normalized.
  186.  
  187. local go is (uhat*sin(cmd_pitch) + hhat*cos(cmd_pitch)).
  188. lock steering to lookdirup(go,u).
  189. }
  190.  
  191. else
  192. {
  193. lock steering to heading(azimuth,cmd_pitch).
  194. }
  195.  
  196. }
  197.  
  198. declare function normal_close
  199. {
  200. set range to (range + groundspeed*wait_time).
  201. set xddot to groundspeed.
  202. set hddot to verticalspeed.
  203. wait wait_time.
  204. set hddot to (verticalspeed - hddot)/wait_time.
  205. set xddot to (groundspeed - xddot)/wait_time.
  206. set g_eff to ((velocity:orbit:sqrmagnitude / body:position:mag) - body:mu / body:position:sqrmagnitude).
  207. set g_inertial to sqrt(xddot^2 + (hddot-g_eff)^2).
  208.  
  209. if g_inertial > g_limit
  210. {
  211. set cmd_throttle to cmd_throttle - throttle_increment.
  212. }
  213.  
  214. if availablethrust/mass < g_limit and cmd_throttle < 1.0
  215. {
  216. set cmd_throttle to 1.0.
  217. }
  218.  
  219. if cmd_throttle < throttle_floor
  220. {
  221. set cmd_throttle to throttle_floor.
  222. set status_detail to "G WARNING.".
  223. }
  224.  
  225. print_us_telemetry.
  226.  
  227. if timer_on = true
  228. {
  229. set t to (time:seconds - tzero).
  230. }
  231.  
  232. lock throttle to cmd_throttle.
  233. }
  234.  
  235. declare function sI_ascent_program
  236. {
  237. set cmd_pitch to (0.017 * (t - 220) * (t - 220) + 100) / 10.
  238.  
  239. if cmd_pitch > pitch_limit
  240. {
  241. set cmd_pitch to pitch_limit.
  242. }
  243.  
  244. engage_steering.
  245.  
  246. set status to "SI ADV PITCH PROGRAM.".
  247. set status_detail to "NOMINAL.".
  248.  
  249. normal_close.
  250. }
  251.  
  252. //
  253. //
  254. // BEGIN SCRIPT
  255. //
  256. //
  257.  
  258. until availablethrust > 0
  259. {
  260. set status to "STANDBY.".
  261. set status_detail to "IGNITE TO START.".
  262.  
  263. normal_close.
  264. }
  265.  
  266. set timer_on to true.
  267. set tzero to time:seconds.
  268.  
  269. until t > trelease
  270. {
  271. set status to "RS25 SPOOL-UP.".
  272. set status_detail to "MAIN ENGINE START.".
  273.  
  274. normal_close.
  275. }
  276.  
  277. STAGE.
  278.  
  279. until alt:radar > tower_height
  280. {
  281.  
  282. if availablethrust > 0 and timer_on = false
  283. {
  284. set timer_on to true.
  285. set tzero to time:seconds.
  286. }
  287.  
  288. lock steering to lookdirup(ship:facing:forevector,ship:up:forevector). // should just lock the craft inertially.
  289.  
  290. set status to "LIFTOFF.".
  291. set status_detail to "AWAITING TOWER CLEARANCE.".
  292.  
  293. normal_close.
  294. }
  295.  
  296. set pitch_program_running to true.
  297.  
  298. until altitude > transition_h
  299. {
  300. set cmd_pitch to (90 - 60*altitude/transition_h).
  301.  
  302. engage_steering.
  303.  
  304. set status to "PITCH PROGRAM.".
  305. set status_detail to "NOMINAL.".
  306.  
  307. normal_close.
  308. }
  309.  
  310. set pitch_program_running to false.
  311.  
  312. until t > tsrbsep
  313. {
  314. sI_ascent_program.
  315. }
  316.  
  317. STAGE.
  318.  
  319. until t > tfairingjettison
  320. {
  321. sI_ascent_program.
  322. }
  323.  
  324. STAGE.
  325.  
  326. until t > tmeco
  327. {
  328. sI_ascent_program.
  329. }
  330.  
  331. lock throttle to 0.0.
  332.  
  333. WAIT 0.5.
  334.  
  335. STAGE.
  336.  
  337. until t > tmeco + 2
  338. {
  339. sI_ascent_program.
  340. }
  341.  
  342. STAGE.
  343.  
  344. until t > tmeco + 5
  345. {
  346. sI_ascent_program.
  347. }
  348.  
  349. until t > 720
  350. {
  351. set cmd_pitch to (0.0007 * (t - 350) * (t - 350) + 160) / 10.
  352.  
  353. if cmd_pitch > pitch_limit
  354. {
  355. set cmd_pitch to pitch_limit.
  356. }
  357.  
  358. engage_steering.
  359.  
  360. set status to "SII ADV PITCH PROGRAM.".
  361. set status_detail to "NOMINAL.".
  362.  
  363. normal_close.
  364. }
  365.  
  366. local lower_limit is -5.
  367.  
  368. until periapsis > tgt_apo
  369. {
  370. set status to "NULL HDOT.".
  371. set status_detail to "NOMINAL.".
  372.  
  373. set est_tto_co to (tgt_xdot - velocity:orbit:mag)/g_inertial.
  374.  
  375. local use_acc is (throttle_min + ((1 - throttle_min)*cmd_throttle))*(availablethrust/mass).
  376.  
  377. if g_inertial > g_limit
  378. {
  379. set use_acc to g_limit.
  380. }
  381.  
  382. local term is 0.
  383.  
  384. if use_acc > 0
  385. {
  386. set term to ((((tgt_hdot-verticalspeed)/nullify_time)-g_eff)/use_acc).
  387. }
  388.  
  389. if term < 0.5 AND term > -0.5
  390. {
  391. set cmd_pitch to arcsin(term).
  392. }
  393. else if term > 0.5
  394. {
  395. set cmd_pitch to pitch_limit.
  396. }
  397. else if term < -0.5
  398. {
  399. set cmd_pitch to -pitch_limit.
  400. }
  401.  
  402. if cmd_pitch < lower_limit
  403. {
  404. set cmd_pitch to lower_limit.
  405. }
  406.  
  407. engage_steering.
  408.  
  409. normal_close.
  410.  
  411. }
  412.  
  413. lock throttle to 0.0.
  414.  
  415.  
  416. set status to "ENGINE CUTOFF AT TIME " + t.
  417. set status_detail to "PROGRAM COMPLETE. ASCENT NOMINAL.".
  418.  
  419. print "STATE: " + status at (0,3).
  420. print status_detail at (0,4).
  421.  
  422. wait 7.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement