Guest User

Untitled

a guest
Dec 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. parameter desired_roll is 0.
  2. parameter desired_heading is 90.
  3. parameter target_apoapsis is body:atm:height + 10000.
  4. parameter g_turn_target_altitude is target_apoapsis + 20000. // slightly higher than target AP
  5. parameter throttle_down_altitude is target_apoapsis - 20000.
  6.  
  7. run once "logging.ks".
  8. run once "util.ks".
  9.  
  10. log_message("=== ascent ===").
  11.  
  12. lock throttle to 1.
  13. sas off.
  14.  
  15. function g_turn {
  16. parameter target_altitude is g_turn_target_altitude.
  17. parameter exponent is 0.5.
  18. lock steering to R(0, 0, desired_roll) * heading(desired_heading, max(0, 90*(1-(apoapsis/target_altitude)^exponent))).
  19. }
  20.  
  21. g_turn().
  22.  
  23. local old_thrust to ship:maxthrustat(0).
  24.  
  25. local tanks_by_stage to list().
  26. from { local i to 0. } until i = stage:number+1 step {set i to i+1.} do {
  27. tanks_by_stage:add(list()).
  28. }
  29.  
  30. local all_parts to list().
  31. list parts in all_parts.
  32. for p in all_parts {
  33. if (p:stage >= 0) {
  34. for r in p:resources {
  35. if (r:name = "liquidfuel" and r:enabled) {
  36. tanks_by_stage[p:stage]:add(p).
  37. break.
  38. }
  39. }
  40. }
  41. }
  42.  
  43. log_debug(tanks_by_stage).
  44.  
  45. lock gravity to body:mu/(altitude+body:radius)^2.
  46. lock twr to (ship:availablethrust / ship:mass / gravity).
  47.  
  48. when apoapsis > throttle_down_altitude and twr > 1 then lock throttle to 0.5.
  49.  
  50. until apoapsis > target_apoapsis {
  51. local should_stage to false.
  52.  
  53. if ship:maxthrustat(0) < old_thrust {
  54. set should_stage to true.
  55. }
  56.  
  57. if stage:number > 1 and not tanks_by_stage[stage:number-1]:empty {
  58. local fuel_in_stage to 0.
  59. for t in tanks_by_stage[stage:number-1] {
  60. for r in t:resources {
  61. if r:name = "liquidfuel" {
  62. set fuel_in_stage to fuel_in_stage + r:amount.
  63. break.
  64. }
  65. }
  66. }
  67. if (fuel_in_stage < 0.001) {
  68. log_message("empty fuel tank detected.").
  69. set should_stage to true.
  70. }
  71. }
  72.  
  73. if should_stage {
  74. if (body:atm:exists and body:atm:altitudepressure(altitude) > 0.01) {
  75. lock steering to srfprograde.
  76. log_message("turning prograde for staging").
  77. local start_stage_time to time:seconds.
  78. wait until vang(ship:facing:vector, srfprograde:vector) < 1 or time:seconds - start_stage_time > 5.
  79. }
  80. stage_to_next_engine().
  81. set old_thrust to ship:maxthrustat(0).
  82. wait 1.
  83. log_message("resuming g-turn").
  84. g_turn().
  85. }
  86. wait 0.5.
  87. }
  88.  
  89. // TODO: fairings
  90.  
  91. lock throttle to 0.
  92. wait 0.
  93.  
  94. wait until altitude > body:atm:height.
Add Comment
Please, Sign In to add comment