Advertisement
Guest User

Untitled

a guest
Jul 8th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.91 KB | None | 0 0
  1. FUNCTION PRINT_AT {
  2.     PARAMETER DESCRIPTION.
  3.     PARAMETER TEXT.
  4.     PARAMETER STRING_NUM.
  5.  
  6.     PRINT DESCRIPTION AT(0,STRING_NUM) + "          " + TEXT AT(0,STRING_NUM).
  7. }.
  8.  
  9.  
  10. FUNCTION CIRCLING_FROM_PERIAPSIS {
  11.     //At this point, our apoapsis is above 100km and our main loop has ended. Next
  12.     //we'll make sure our throttle is zero and that we're pointed prograde
  13.     PRINT "Disable engine".
  14.     LOCK THROTTLE TO 0.
  15.  
  16.     PRINT "Waiting to rich APOAPSIS".
  17.  
  18.     UNTIL (ETA:APOAPSIS < 30) {
  19.         SET MYSTEER TO HEADING(90,0).
  20.         PRINT "Pitching to 0 degrees" AT(0,15).
  21.         PRINT_AT("APOAPSIS",ROUND(SHIP:APOAPSIS,0),16).
  22.         PRINT_AT("ALTITUDE",ROUND(SHIP:ALTITUDE,0),17).
  23.         PRINT_AT("ETA:APOAPSIS",ETA:APOAPSIS,18).
  24.     }.
  25.  
  26.     PRINT "Pitching to 0 degrees".
  27.     SET MYSTEER TO HEADING(90,0).
  28.     LOCK THROTTLE TO 1.0.
  29.  
  30.     UNTIL (ABS((SHIP:APOAPSIS - SHIP:PERIAPSIS)/SHIP:PERIAPSIS) < 0.05 ) {
  31.         PRINT_AT("SHIP:APOAPSIS",SHIP:APOAPSIS,15).
  32.         PRINT_AT("SHIP:PERIAPSIS",SHIP:PERIAPSIS,17).        
  33.         PRINT_AT("ABS(SHIP:APOAPSIS - SHIP:PERIAPSIS)",ABS(SHIP:APOAPSIS - SHIP:PERIAPSIS),23).
  34.  
  35.  
  36.         IF ETA:APOAPSIS  { BREAK. }
  37.     }.
  38.  
  39.     LOCK THROTTLE TO 0.
  40. }.
  41.  
  42.  
  43.  
  44.  
  45. //hellolaunch
  46.  
  47. //First, we'll clear the terminal screen to make it look nice
  48. CLEARSCREEN.
  49.  
  50.  
  51. //Next, we'll lock our throttle to 100%.
  52. LOCK THROTTLE TO 1.0.   // 1.0 is the max, 0.0 is idle.
  53.  
  54. // //This is our countdown loop, which cycles from 10 to 0
  55. // PRINT "Counting down:".
  56. // FROM {local countdown is 10.} UNTIL countdown = 0 STEP {SET countdown to countdown - 1.} DO {
  57. //     PRINT "..." + countdown.
  58. //     WAIT 1. // pauses the script here for 1 second.
  59. // }
  60.  
  61. //This is a trigger that constantly checks to see if our thrust is zero.
  62. //If it is, it will attempt to stage and then return to where the script
  63. //left off. The PRESERVE keyword keeps the trigger active even after it
  64. //has been triggered.
  65. WHEN MAXTHRUST = 0 THEN {
  66.     PRINT "Staging".
  67.     STAGE.
  68.     PRESERVE.
  69. }.
  70.  
  71. //This will be our main control loop for the ascent. It will
  72. //cycle through continuously until our apoapsis is greater
  73. //than 100km. Each cycle, it will check each of the IF
  74. //statements inside and perform them if their conditions
  75. //are met
  76. SET MYSTEER TO HEADING(90,90).
  77. LOCK STEERING TO MYSTEER. // from now on we'll be able to change steering by just assigning a new value to MYSTEER
  78. UNTIL SHIP:APOAPSIS > 100000 { //Remember, all altitudes will be in meters, not kilometers
  79.  
  80.     //For the initial ascent, we want our steering to be straight
  81.     //up and rolled due east
  82.     IF SHIP:VELOCITY:SURFACE:MAG < 100 {
  83.         //This sets our steering 90 degrees up and yawed to the compass
  84.         //heading of 90 degrees (east)
  85.         SET MYSTEER TO HEADING(90,90).
  86.  
  87.     //Once we pass 100m/s, we want to pitch down ten degrees
  88.     } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 100 AND SHIP:VELOCITY:SURFACE:MAG < 800 {
  89.         SET PITCH_ANG TO (SHIP:ALTITUDE - 24033)/(-282).
  90.         SET MYSTEER TO HEADING(90,ROUND(PITCH_ANG,0)).
  91.         PRINT "Pitching to " + PITCH_ANG + " degrees" AT(0,15).
  92.         PRINT_AT("APOAPSIS",ROUND(SHIP:APOAPSIS,0),16).
  93.  
  94.     //Beyond 800m/s, we can keep facing towards 10 degrees above the horizon and wait
  95.     //for the main loop to recognize that our apoapsis is above 100km
  96.     } ELSE IF SHIP:VELOCITY:SURFACE:MAG >= 800 {
  97.         SET MYSTEER TO HEADING(90,10).
  98.         PRINT "Pitching to 10 degrees" AT(0,15).
  99.         PRINT_AT("APOAPSIS",ROUND(SHIP:APOAPSIS,0),16).
  100.         PRINT_AT("ALTITUDE",ROUND(SHIP:ALTITUDE,0),18).
  101.     }.
  102.  
  103. }.
  104.  
  105. CLEARSCREEN.
  106.  
  107. PRINT "100 km apoapsis reached, cutting throttle".
  108.  
  109. SET MYSTEER TO HEADING(90,0).
  110. PRINT "Pitching to 0 degrees".
  111.  
  112. CIRCLING_FROM_PERIAPSIS()
  113.  
  114.  
  115. //This sets the user's throttle setting to zero to prevent the throttle
  116. //from returning to the position it was at before the script was run.
  117. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement