Advertisement
Guest User

Dark KoS

a guest
Aug 14th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. // This program launches a ship from the KSC and flies it into equatorial orbit at 100km
  2. //Set the ship to a known configuration
  3. // SET SASMODE TO "STABILITYASSIST".
  4.  
  5. // declare parameter targetAltitude.
  6.  
  7. SAS on.
  8. RCS off.
  9. lights off.
  10. lock throttle to 0. //Throttle is a decimal from 0.0 to 1.0
  11. gear off.
  12. clearscreen.
  13. set mth to SHIP:MAXTHRUST.
  14. set targetAltitude to 100000. // Convert Target altitude in meter for a circular orbit
  15.  
  16. set runmode to 2. //Safety in case we start mid-flight
  17.  
  18.  
  19. if ALT:RADAR < 50 { //Guess if we are waiting for take off
  20. set runmode to 1.
  21. print "Launchpad. Check.".
  22. }
  23.  
  24. until runmode = 0 {
  25.  
  26. if runmode = 1 { // Ship on launchpad
  27. lock steering to heading (90,90). //Point the rocket straight up
  28. set TVAL to 1. //Throttle up to 100%
  29. stage.
  30. wait 1.
  31. stage.
  32. set mth to SHIP:MAXTHRUST.
  33. set runmode to 2. //Go to the next runmode
  34. print "Ignition !".
  35. }
  36.  
  37. else if runmode = 2 { // Fly up to 12k
  38. lock steering to heading (90,90). //Straight up.
  39.  
  40. if SHIP:ALTITUDE < 800 {
  41. set TVAL to 1.
  42. }
  43. if SHIP:ALTITUDE > 800 {
  44. SET cTWR to SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG).
  45. if cTWR > 1.5 {
  46. SET TVAL to 1.5*(SHIP:MASS * SHIP:SENSORS:GRAV:MAG)/SHIP:MAXTHRUST.
  47. }
  48. if cTWR < 1.5 {
  49. SET TVAL to 1.
  50. }
  51. }
  52. if SHIP:ALTITUDE > 12000 {
  53. set runmode to 3.
  54. print "Initiate gravity turn...".
  55. }
  56. }
  57.  
  58. else if runmode = 3 { // Gravity turn and burd until AP is 90k
  59. set targetPitch to max( 3, 90 * (1 - (SHIP:ALTITUDE-12000) / (50000-12000) )).
  60. //Pitch over gradually until levelling out to 1 degrees at 50km
  61. lock steering to heading ( 90, targetPitch). //Heading 90' (East), then target pitch
  62. if SHIP:ALTITUDE < 45000 {
  63. SET cTWR to SHIP:MAXTHRUST / (SHIP:MASS * SHIP:SENSORS:GRAV:MAG).
  64. if cTWR > 1.5 {
  65. SET TVAL to 1.5*(SHIP:MASS * SHIP:SENSORS:GRAV:MAG)/SHIP:MAXTHRUST.
  66. }
  67. if cTWR < 1.5 {
  68. SET TVAL to 1.
  69. }
  70. }
  71. else {
  72. set TVAL to 1.
  73. }
  74. if SHIP:APOAPSIS > 100000 {
  75. set runmode to 4.
  76. print "Stabilize...".
  77. }
  78. }
  79.  
  80. else if runmode = 4 { // Warp just after AP
  81. lock steering to heading ( 90, 0). //Stay pointing 1 degrees above horizon
  82. set TVAL to 0.
  83. if (ETA:APOAPSIS > 60) and (VERTICALSPEED > 0) {
  84. if WARP = 0 AND SHIP:ALTITUDE > 70000 { // If we are not time warping
  85. wait 1. //Wait to make sure the ship is stable
  86. SET WARP TO 3. //Be really careful about warping
  87. }
  88. }.
  89. else if ETA:APOAPSIS < 20 {
  90. SET WARP to 0.
  91. set runmode to 5.
  92. print "Circulize...".
  93. }
  94. }
  95.  
  96. else if runmode = 5 { // Burn until AP/PER is targetAltitude
  97. set TVAL to 1.
  98. if (SHIP:PERIAPSIS > targetAltitude*0.90) {
  99. set TVAL to 0.5.
  100. }
  101. if (SHIP:PERIAPSIS > targetAltitude-500) {
  102. set TVAL to 0.
  103. set runmode to 10.
  104. print "Circulized.".
  105. }
  106. }
  107.  
  108. else if runmode =10 {
  109. set TVAL to 0.
  110. unlock steering.
  111. print "Launch sucessfull.".
  112. print "Orbit is " + SHIP:PERIAPSIS/1000 + "km / " + SHIP:APOAPSIS/1000 + "km.".
  113. set runmode to 0.
  114. }
  115.  
  116. lock throttle to TVAL. //Write our planned throttle to the physical throttle
  117.  
  118. // Staging
  119. if mth>SHIP:MAXTHRUST or SHIP:MAXTHRUST=0 {
  120. stage.
  121. wait 0.1.
  122. set mth to SHIP:MAXTHRUST.
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement