Advertisement
KSA_MissionCtrl

sndRocket.ks 9/12

Sep 7th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. // manual abort procedure
  2. function FlightAbort {
  3. LogData("ABORT ABORT ABORT!!").
  4.  
  5. // we can't kill engine thrust
  6. // detach the payload, fairings and deploy the chute when able
  7. sep:getmodule("ModuleDecouple"):doevent("decouple").
  8. for fairing in fairings {
  9. fairing:getmodule("ModuleDecouple"):doevent("decouple").
  10. }
  11. LogData("Payload free, awaiting safe chute deployment").
  12. set minDeployAlt to chute:getmodule("moduleparachute"):getfield("altitude").
  13. until ship:altitude < minDeployAlt and chute:getmodule("moduleparachute"):getfield("safe to deploy?") = "safe" {}.
  14.  
  15. // pop the chute
  16. LogData("Deploying chute").
  17. chute:getmodule("ModuleParachute"):doevent("deploy chute").
  18.  
  19. // confirm chute is open and run science experiments
  20. until chute:getmodule("ModuleParachute"):hasevent("cut parachute") {}.
  21. LogData("Chute deployment successful, running experiments...").
  22. toggle AG1.
  23. until avionics:hasevent("review telemetry") and science:hasevent("reset meteorological data") {}.
  24.  
  25. LogData("Experiment run complete!").
  26. }.
  27.  
  28. function LogData {
  29. parameter text.
  30.  
  31. // print to both the console and log
  32. print "[" + time:clock + "] " + text.
  33. log "[" + time:clock + "] " + text to missionlog.
  34. copy missionlog to 0.
  35. }.
  36.  
  37. function Launch {
  38. clearscreen.
  39. LogData("Sounding Rocket Flight Program initiating...").
  40.  
  41. // find all our parts
  42. set sre1 to ship:partstagged("sre1")[0].
  43. set sre2 to ship:partstagged("sre2")[0].
  44. set chute to ship:partstagged("chute")[0].
  45. set clamp to ship:partstagged("clamp")[0].
  46. set sep to ship:partstagged("sep")[0].
  47. set avionics to ship:partstagged("avionics")[0].
  48. set science to ship:partstagged("science")[0].
  49. set fairings to ship:partstagged("fairing").
  50.  
  51. // perform pre-launch checks
  52. if fairings:length < 2 {
  53. LogData("ERR: Fairing parts missing, only found " + fairings:length).
  54. return false.
  55. }.
  56. wait 1.
  57. LogData("All systems nominal").
  58.  
  59. // check engine thrust
  60. list engines in englist.
  61. for eng in englist {
  62. if eng:tag = "sre1" {
  63. if eng:thrustlimit <> 50.5 {
  64. LogData("ERR: Improper thrust limiter set for SRE1. Thrust set to " + eng:thrustlimit + "%").
  65. return false.
  66. }
  67. }
  68. if eng:tag = "sre2" {
  69. if eng:thrustlimit <> 48 {
  70. LogData("ERR: Improper thrust limiter set for SRE2. Thrust set to " + eng:thrustlimit + "%").
  71. return false.
  72. }
  73. }
  74. }
  75. wait 1.
  76. LogData("All engines nominal").
  77.  
  78. // all good, begin the countdown
  79. LogData("GO for launch!").
  80. wait 1.
  81. LogData("T-10").
  82. wait 1.
  83. LogData("T-9").
  84. wait 1.
  85. LogData("T-8").
  86. wait 1.
  87. LogData("T-7").
  88. wait 1.
  89. LogData("T-6").
  90. wait 1.
  91. LogData("T-5").
  92. wait 1.
  93. LogData("T-4").
  94. wait 1.
  95. LogData("T-3").
  96. wait 1.
  97. LogData("T-2").
  98. wait 1.
  99. LogData("T-1").
  100. wait 1.
  101.  
  102. // fire the engine and detach from the launch stick
  103. // direct commands replaced by stage command to trigger data loggers
  104. // sre1:getmodule("ModuleEngines"):doevent("activate engine").
  105. // clamp:getmodule("ModuleAnchoredDecoupler"):doevent("decouple").
  106. stage.
  107. LogData("Liftoff!!").
  108.  
  109. // wait until engine expires then stage
  110. until sre1:getmodule("ModuleEnginesFX"):getfield("status") = "flame-out!" {
  111. if abort {
  112. FlightAbort().
  113. return false.
  114. }.
  115. }.
  116. wait 0.5.
  117. sre2:getmodule("ModuleEnginesFX"):doevent("activate engine").
  118. LogData("Stage 1 flame out detected. Stage 2 activated").
  119.  
  120. // wait until engine expires then stage
  121. until sre2:getmodule("ModuleEnginesFX"):getfield("status") = "flame-out!" {
  122. if abort {
  123. FlightAbort().
  124. return false.
  125. }.
  126. }.
  127. LogData("Stage 2 flame out detected").
  128.  
  129. // wait until apokee (with a litte fudge)
  130. until ship:altitude >= (ship:obt:apoapsis - 5) {}.
  131. LogData("Apokee achieved - releasing payload fairings").
  132. for fairing in fairings {
  133. fairing:getmodule("ModuleDecouple"):doevent("decouple").
  134. }
  135. toggle AG1.
  136. LogData("Experiments running...").
  137. until avionics:hasevent("review telemetry") and science:hasevent("Reset meteorological data") {}.
  138.  
  139. LogData("Experiment run complete! Awaiting safe conditions for chute deployment").
  140. set minDeployAlt to chute:getmodule("moduleparachute"):getfield("altitude").
  141. until ship:altitude < minDeployAlt and chute:getmodule("moduleparachute"):getfield("safe to deploy?") = "safe" {}.
  142.  
  143. // pop the chute
  144. LogData("Deploying chute").
  145. chute:getmodule("ModuleParachute"):doevent("deploy chute").
  146.  
  147. // confirm chute is open
  148. until chute:getmodule("ModuleParachute"):hasevent("cut parachute") {}.
  149. LogData("Chute deployment successful").
  150.  
  151. return true.
  152. }
  153.  
  154. // done! All data will be stored for retrieval, as battery power may not last until landing
  155. if Launch() {
  156. LogData("All events have executed. Awaiting landing & retrieval").
  157. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement