Advertisement
Guest User

Untitled

a guest
May 28th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.78 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. //M means "mode", 150 indicates a 150x150km orbit. "NO" means OMS is not required. "LOW G" is that. A smooth ride.
  5.  
  6. clearscreen.
  7.  
  8. set terminal:width to 37.
  9. set terminal:height to 37.
  10.  
  11. local tgt_hdot is 0. // For use in other, non-circular orbit versions.
  12. local tgt_h is 157420. // 85 nmi - initial "climb to this during ascent" altitude
  13. local tgt_ap is 157420. // triggers engine cut-off.
  14. local tgt_xdot is sqrt(body:mu / (body:radius+tgt_h)). // For use in other, non-circular orbit versions.
  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.76. // 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 110.
  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. //debug variables
  58. local debuga is 0.
  59. local debugb is 0.
  60. local debugc is 0.
  61. local debugd is 0.
  62. local debuge is 0.
  63.  
  64. declare function print_us_telemetry
  65. {
  66.  
  67. clearscreen.
  68.  
  69. print "=====================================" at (0,0).
  70. print "URSALV.P110.M85-85.NO OMS.LOW-G." at (0,1).
  71. print "=====================================" at (0,2).
  72. print "STATE: " + status at (0,3).
  73. print status_detail at (0,4).
  74.  
  75. print "T+ " + round(t) at (0,6).
  76. print "CMD PITCH: " + round(cmd_pitch) at (0,7).
  77. print "ALTITUDE: " + (round(altitude*0.0539957)/100) + " NMI." at (0,8).
  78. print "ALTITUDE: " + round(altitude*3.28084) + " FT." at (0,9).
  79. print "VELOCITY: " + round(velocity:orbit:mag*3.28084) + " FPS." at (0,10).
  80. print "VELOCITY TGO: " + round((tgt_xdot - velocity:orbit:mag)*3.28084) + " FPS." at (0,11).
  81. print "HDOT: " + round(verticalspeed*3.28084) + " FPS." at (0,12).
  82. print "HDDOT: " + round(hddot*3.28084) + " FPS." at (0,13).
  83.  
  84. print "RANGE: " + round(range*0.00539957) + " NMI." at (0,14).
  85.  
  86. if aposeek = 1
  87. {
  88. print "APOSEEK ENGAGED." at (0,17).
  89. print "APOAPSIS: " + (round(apoapsis*0.0539957)/100) + " NMI." at (0,18).
  90. print "TGT APO: " + (round(tgt_h*0.0539957)/100) + " NMI." at (0,19).
  91. print "APODOT: " + (round(apodot*0.0539957)/100) + " NMI." at (0,20).
  92. }
  93. else if aposeek = 2
  94. {
  95. print "APOSEEK COMPLETE." at (0,17).
  96. }
  97. else
  98. {
  99. }
  100.  
  101. print "T: " + round(cmd_throttle*100) at (0,22).
  102. print "G: " + (round(100*g_inertial/9.82)/100) at (0,23).
  103.  
  104. }
  105.  
  106. declare function engage_steering
  107. {
  108.  
  109. local is_on_same_side_of_planet is true.
  110.  
  111. if hastarget = false and pitch_program_running = false
  112. {
  113. local p is vectorexclude(body:position,velocity:orbit).
  114. local phat is p:normalized.
  115. local u is (-body:position).
  116. local uhat is u:normalized.
  117. local h is (uhat*sin(cmd_pitch) + phat*cos(cmd_pitch)).
  118.  
  119. lock steering to lookdirup(h,u).
  120. }
  121.  
  122. // else if hastarget = true
  123. // {
  124. // local p is vectorexclude(body:position,target:velocity:orbit).
  125. // local phat is p:normalized.
  126. // local u is (-body:position).
  127. // local uhat is u:normalized.
  128. // local h is (uhat*sin(cmd_pitch) + phat*cos(cmd_pitch)).
  129. //
  130. // lock steering to lookdirup(h,u).
  131. // }
  132.  
  133. if hastarget = true and pitch_program_running = false
  134. {
  135. local p is vectorexclude(body:position,target:velocity:orbit).
  136. local phat is p:normalized.
  137. local u is (-body:position).
  138. local uhat is u:normalized.
  139.  
  140. local L_tgt is vcrs(target:velocity:orbit,(body:position - target:position)).
  141. local L is vcrs(velocity:orbit,body:position).
  142. local L_rel is (L_tgt:normalized - L:normalized).
  143. local L_relhat is L_rel:normalized.
  144.  
  145. local turn_angle is (L_relhat * velocity:orbit:normalized). // ranges from -1 to 1, so just use it.
  146. // square rooted for mapping. Want small numbers to try to hone in on zero, but not asymptotically!
  147. local R is vcrs(body:position,velocity:orbit).
  148. local Rhat is R:normalized.
  149.  
  150. set debuga to L.
  151. set debugb to L:normalized.
  152. set debugc to L_relhat.
  153. set debugd to R.
  154.  
  155. local R_mult is 1.
  156.  
  157. if dogleg = true
  158. {
  159. set R_mult to ((1+(1/90)*arctan((t-t_dogleg+dogleg_length)/dogleg_length))/2).
  160. }
  161.  
  162. local h is (phat + R_mult*R_mag*turn_angle*Rhat).
  163.  
  164. local hhat is h:normalized.
  165.  
  166. local go is (uhat*sin(cmd_pitch) + hhat*cos(cmd_pitch)).
  167. lock steering to lookdirup(go,u).
  168. }
  169.  
  170. else
  171. {
  172. lock steering to heading(azimuth,cmd_pitch).
  173. }
  174.  
  175. }
  176.  
  177. declare function normal_close
  178. {
  179. set range to (range + groundspeed*wait_time).
  180. set xddot to groundspeed.
  181. set hddot to verticalspeed.
  182. wait wait_time.
  183. set hddot to (verticalspeed - hddot)/wait_time.
  184. set xddot to (groundspeed - xddot)/wait_time.
  185. set g_eff to ((velocity:orbit:sqrmagnitude / body:position:mag) - body:mu / body:position:sqrmagnitude).
  186. set g_inertial to sqrt(xddot^2 + (hddot-g_eff)^2).
  187.  
  188. if g_inertial > g_limit
  189. {
  190. set cmd_throttle to cmd_throttle - throttle_increment.
  191. }
  192.  
  193. if availablethrust/mass < g_limit and cmd_throttle < 1.0
  194. {
  195. set cmd_throttle to 1.0.
  196. }
  197.  
  198. if cmd_throttle < throttle_floor
  199. {
  200. set cmd_throttle to throttle_floor.
  201. set status_detail to "G WARNING.".
  202. }
  203.  
  204. print_us_telemetry.
  205.  
  206. if timer_on = true
  207. {
  208. set t to (time:seconds - tzero).
  209. }
  210.  
  211. lock throttle to cmd_throttle.
  212. }
  213.  
  214. //
  215. //
  216. // BEGIN SCRIPT
  217. //
  218. //
  219.  
  220. until alt:radar > tower_height
  221. {
  222.  
  223. if availablethrust > 0 and timer_on = false
  224. {
  225. set timer_on to true.
  226. set tzero to time:seconds.
  227. }
  228.  
  229. lock steering to lookdirup(ship:facing:forevector,ship:up:forevector). // should just lock the craft inertially.
  230.  
  231. set status to "LIFTOFF.".
  232. set status_detail to "AWAITING TOWER CLEARANCE.".
  233.  
  234. normal_close.
  235. }
  236.  
  237. set pitch_program_running to true.
  238.  
  239. until altitude > transition_h
  240. {
  241. set cmd_pitch to (90 - 60*altitude/transition_h).
  242.  
  243. engage_steering.
  244.  
  245. set status to "PITCH PROGRAM.".
  246. set status_detail to "NOMINAL.".
  247.  
  248. normal_close.
  249. }
  250.  
  251. set pitch_program_running to false.
  252.  
  253. set aposeek to 1.
  254.  
  255. until verticalspeed <= 0
  256. {
  257. set status to "APOAPSIS SEEK.".
  258. set status_detail to "NOMINAL.".
  259.  
  260. local tempdot is apoapsis.
  261.  
  262. normal_close.
  263.  
  264. set apodot to ((apoapsis - tempdot)/wait_time).
  265.  
  266. set ap_to_go_plus to (tgt_h + ap_window - apoapsis)/nullify_time.
  267. set ap_to_go_minus to (tgt_h - ap_window - apoapsis)/nullify_time.
  268.  
  269. if ap_to_go_minus > apodot
  270. {
  271. set cmd_pitch to cmd_pitch + pitch_increment.
  272. }
  273. else if ap_to_go_plus < apodot
  274. {
  275. set cmd_pitch to cmd_pitch - pitch_increment.
  276. }
  277.  
  278. if cmd_pitch > pitch_limit
  279. {
  280. set cmd_pitch to pitch_limit.
  281. }
  282. else if cmd_pitch < -pitch_limit
  283. {
  284. set cmd_pitch to -pitch_limit.
  285. }
  286.  
  287. engage_steering.
  288.  
  289. }
  290.  
  291. set aposeek to 2.
  292.  
  293. until est_time_for_hdot_seek > est_tto_co
  294. {
  295. set status to "NULL HDOT.".
  296. set status_detail to "NOMINAL.".
  297.  
  298. set est_tto_co to (tgt_xdot - velocity:orbit:mag)/g_inertial.
  299.  
  300. local use_acc is (throttle_min + ((1 - throttle_min)*cmd_throttle))*(availablethrust/mass).
  301.  
  302. if g_inertial > g_limit
  303. {
  304. set use_acc to g_limit.
  305. }
  306.  
  307. local term is 0.
  308.  
  309. if use_acc > 0
  310. {
  311. set term to ((((tgt_hdot-verticalspeed)/nullify_time)-g_eff)/use_acc).
  312. }
  313.  
  314. if term < 0.5 AND term > -0.5
  315. {
  316. set cmd_pitch to arcsin(term).
  317. }
  318. else if term > 0.5
  319. {
  320. set cmd_pitch to pitch_limit.
  321. }
  322. else if term < -0.5
  323. {
  324. set cmd_pitch to -pitch_limit.
  325. }
  326.  
  327. engage_steering.
  328.  
  329. normal_close.
  330.  
  331. }
  332.  
  333. until velocity:orbit:mag > tgt_xdot
  334. {
  335.  
  336. if tgt_hdot = 0
  337. {
  338. set status to "NULL HDOT.".
  339. }
  340. else
  341. {
  342. set status to "TGT HDOT: " + (tgt_hdot*3.28084).
  343. }
  344. set status_detail to "NOMINAL.".
  345.  
  346. local use_acc is (throttle_min + ((1 - throttle_min)*cmd_throttle))*(availablethrust/mass).
  347.  
  348. if g_inertial > g_limit
  349. {
  350. set use_acc to g_limit.
  351. }
  352.  
  353. local term is 0.
  354.  
  355. if use_acc > 0
  356. {
  357. set term to ((((tgt_hdot-verticalspeed)/nullify_time)-g_eff)/use_acc).
  358. }
  359.  
  360. if term < 0.5 AND term > -0.5
  361. {
  362. set cmd_pitch to arcsin(term).
  363. }
  364. else if term > 0.5
  365. {
  366. set cmd_pitch to pitch_limit.
  367. }
  368. else if term < -0.5
  369. {
  370. set cmd_pitch to -pitch_limit.
  371. }
  372.  
  373. engage_steering.
  374.  
  375. normal_close.
  376.  
  377. }
  378.  
  379. lock throttle to 0.0.
  380.  
  381.  
  382. set status to "ENGINE CUTOFF AT TIME " + t.
  383. set status_detail to "PROGRAM COMPLETE. ASCENT NOMINAL.".
  384.  
  385. print "STATE: " + status at (0,3).
  386. print status_detail at (0,4).
  387.  
  388. wait 7.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement