Advertisement
KSA_MissionCtrl

sndRocket.ks 9/29

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