Advertisement
KSA_MissionCtrl

sndRocket.ks 10/5

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