Advertisement
Guest User

launch_ssm_x2

a guest
Dec 23rd, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.60 KB | None | 0 0
  1. set lorb to 80000.
  2. set incl to 0.
  3. set g_roll_correction to -90.
  4.  
  5. set ha to 59000.
  6. set vac to 70000.
  7. set angle to 5.
  8. set gt0 to 800.
  9. set gt1 to 45000.//48
  10. set maxq to 8000.
  11.  
  12.  
  13. lock correctRoll to R(0,0,g_roll_correction).
  14. lock t_h to SHIP:GEOPOSITION:TERRAINHEIGHT.
  15. lock radar_alt to SHIP:ALTITUDE-( (t_h + sqrt(t_h*t_h)) / 2 ).
  16. set prog_mode to 1.
  17. set tset to 1.
  18. lock throttle to tset.
  19. set pitch to 0.
  20.  
  21. FUNCTION eng_out {
  22.  
  23.     local numOut to 0.
  24.     LIST ENGINES IN eng_list.
  25.     FOR eng IN eng_list
  26.         IF eng:FLAMEOUT
  27.             SET numOut TO numOut + 1.
  28.     return numOut.
  29. }
  30.  
  31. lock angle1 to arcsin(max(-1,min(1,cos(180+incl)/cos(ship:latitude)))).
  32. lock vlaunchx to (1600 * sin(angle1*-1))-(174.9422*sin(90)).
  33. lock vlaunchy to (1600 * cos(angle1*-1))-(174.9422*cos(90)).
  34. lock newangle to 90-arctan(vlaunchx/vlaunchy).
  35. lock steering to HEADING(arcsin(max(-1,min(1,cos(180+newangle)/max(0.001,cos(ship:latitude))))), 90-pitch ) + R(0,0,90)+ correctRoll.
  36.  
  37. print "Ignition".
  38. stage.
  39.  
  40. when radar_alt > gt0 or not (prog_mode = 1) then {
  41.     SET WARP TO 2.
  42.     if not ( prog_mode = 1) {return false.}
  43.     print "T+" + round(missiontime) + " begin turn.".
  44.     lock pitch to max(-90,min(-angle,((altitude-gt0)*19.9/body:atm:height)^0.55*-23)).
  45.  
  46.     when radar_alt > gt1 or altitude > ha or apoapsis > lorb or not (prog_mode = 1) then {
  47.         if not ( prog_mode = 1) {return false.}
  48.         print "T+" + round(missiontime) + " end turn.".
  49.         set pitch to -90.
  50.     }
  51. }
  52.  
  53. when not((eng_out() = 0)) or ( not ( prog_mode = 1)) then {
  54.     if not(prog_mode = 1) return false.
  55.  
  56.     if not((eng_out() = 0)) {
  57.         print eng_out().
  58.         stage.
  59.     }
  60.     return true.
  61. }
  62.  
  63. on round(time:seconds,1) {
  64.  
  65.     if not ( prog_mode = 1) {return false.}
  66.  
  67.     if altitude > ha or apoapsis > lorb {
  68.         return false.
  69.     }
  70.  
  71.     // dynamic pressure q
  72.     set vsm to velocity:surface:mag.
  73.     set exp to -altitude/5000.
  74.     set ad to 1.2230948554874 * 2.718281828^exp.    // atmospheric density
  75.     set q to 0.5 * ad * vsm^2.
  76.     // calculate target velocity
  77.     set vl to maxq*0.9.
  78.     set vh to maxq*1.1.
  79.     if q < vl { set tset to 1. }
  80.     if q > vl and q < vh { set tset to (vh-q)/(vh-vl). }
  81.     if q > vh { set tset to 0.25. }
  82.  
  83.     if abs(STEERINGMANAGER:ANGLEERROR) > 1 {set tset to tset*abs(STEERINGMANAGER:ANGLEERROR). }
  84.     if tset < 0.25 { set tset to 0.25. } //only in lower atmo
  85.  
  86.     if ship:velocity:surface:mag < 520 { set tset to 1. }
  87.     print "pitch: " + round(pitch,2) + "  " at (0,25).
  88.     print "alt:radar: " + round(radar_alt) + "  " at (0,26).
  89.     print "q: " + round(q) + "  " at (0,27).
  90.     print "throttle: " + round(tset,2) + "   " at (0,28).
  91.     print "apoapis: " + round(apoapsis/1000,2) at (0,29).
  92.     print "periapis: " + round(periapsis/1000,2) at (0,30).
  93.  
  94.     return true.
  95. }
  96.  
  97. when altitude > 16000 or not (prog_mode = 1) then {
  98.  
  99.     if not ( prog_mode = 1) {return false.}
  100.  
  101.     set maxq to 7000.
  102.  
  103.     when altitude > 26000 or not (prog_mode = 1) then {
  104.  
  105.         if not ( prog_mode = 1) {return false.}
  106.  
  107.         lock steering to lookdirup(ship:srfprograde:vector, ship:facing:topvector).
  108.  
  109.     }
  110. }
  111.  
  112. when (altitude > ha or apoapsis > lorb) or not (prog_mode = 1) then {
  113.  
  114.     if not ( prog_mode = 1) {return false.}
  115.  
  116.     print "stage2-part".
  117.     set tset to 0.
  118.  
  119.     if altitude < vac {
  120.  
  121.         print "T+" + round(missiontime) + " Waiting to leave atmosphere".
  122.  
  123.         LOCK STEERING TO SHIP:PROGRADE.
  124.  
  125.         on round(time:seconds,1) {
  126.  
  127.             if (altitude > vac) or not (prog_mode = 1) {
  128.                 return false.
  129.             }
  130.  
  131.             if apoapsis < lorb { set tset to (lorb-apoapsis)/(lorb*0.01). }
  132.             else
  133.             {
  134.                 set tset to 0.
  135.             }
  136.             set vsm to velocity:surface:mag.
  137.             set exp to -altitude/5000.
  138.             set ad to 1.2230948554874 * 2.718281828^exp.    // atmospheric density
  139.             set q to 0.5 * ad * vsm^2.
  140.             print "pitch: " + round(pitch,2) + "  " at (0,25).
  141.             print "alt:radar: " + round(radar_alt) + "  " at (0,26).
  142.             print "q: " + round(q) + "  " at (0,27).
  143.             print "throttle: " + round(tset,2) + "   " at (0,28).
  144.             print "apoapis: " + round(apoapsis/1000,2) at (0,29).
  145.             print "periapis: " + round(periapsis/1000,2) at (0,30).
  146.  
  147.             return true.
  148.         }
  149.     }
  150. }
  151.  
  152. when (altitude > vac) or not ( prog_mode = 1) then {
  153.  
  154.     if not ( prog_mode = 1) {return false.}
  155.  
  156.     print "stage3-part".
  157.  
  158.     unlock steering.
  159.     SET WARP TO 0.
  160.     set tset to 0.
  161.     SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
  162.     unlock throttle.
  163.  
  164.     set mu to 3.5316000*10^12.  // gravitational parameter, mu = G mass
  165.     set rb to 600000.           // radius of body [m]
  166.     set vom to velocity:orbit:mag.  // actual velocity
  167.     set r to rb + altitude.         // actual distance to body
  168.     set ra to rb + apoapsis.        // radius in apoapsis
  169.     set va to sqrt( vom^2 + 2*mu*(1/ra - 1/r) ). // velocity in apoapsis
  170.     set a to (periapsis + 2*rb + apoapsis)/2. // semi major axis present orbit
  171.     // future orbit properties
  172.     set r2 to rb + apoapsis.    // distance after burn at apoapsis
  173.     set a2 to (lorb + 2*rb + apoapsis)/2. // semi major axis target orbit
  174.     set v2 to sqrt( vom^2 + (mu * (2/r2 - 2/r + 1/a - 1/a2 ) ) ).
  175.     // setup node
  176.     set deltav to v2 - va.
  177.     print "T+" + round(missiontime) + " Apoapsis burn: " + round(va) + ", dv:" + round(deltav) + " -> " + round(v2) + "m/s".
  178.     set nd to node(time:seconds + eta:apoapsis, 0, 0, deltav).
  179.     add nd.
  180.  
  181. }
  182.  
  183. wait until false.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement