Advertisement
KSA_MissionCtrl

sndRocket.ks 8/22

Aug 22nd, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. // manual abort procedure
  2. on abort {
  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. // this line below was missing!! Copy and past fail :(
  13. // Runtime error thrown when the variable could not be found by the following line
  14. set minDeployAlt to chute:getmodule("moduleparachute"):getfield("altitude").
  15. until ship:altitude < minDeployAlt and chute:getmodule("moduleparachute"):getfield("safe to deploy?") = "safe" {}.
  16.  
  17. // pop the chute
  18. LogData("Deploying chute").
  19. chute:getmodule("ModuleParachute"):doevent("deploy chute").
  20.  
  21. // confirm chute is open and run science experiments
  22. until chute:getmodule("ModuleParachute"):hasevent("cut parachute") {}.
  23. LogData("Chute deployment successful, running experiments...").
  24. toggle AG1.
  25. until avionics:hasevent("review telemetry") and science: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 <> 46.5 {
  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 <> 48 {
  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("ModuleEngines"):getfield("status") = "flame-out!" {
  113. if abort { return false. }.
  114. }.
  115. wait 0.5.
  116. sre2:getmodule("ModuleEngines"):doevent("activate engine").
  117. LogData("Stage 1 flame out detected. Stage 2 activated").
  118.  
  119. // wait until engine expires then stage
  120. until sre2:getmodule("ModuleEngines"):getfield("status") = "flame-out!" {
  121. if abort { return false. }.
  122. }.
  123. LogData("Stage 2 flame out detected").
  124.  
  125. // wait until apokee (with a litte fudge)
  126. until ship:altitude >= (ship:obt:apoapsis - 5) {}.
  127. LogData("Apokee achieved - releasing payload fairings").
  128. for fairing in fairings {
  129. fairing:getmodule("ModuleDecouple"):doevent("decouple").
  130. }
  131. toggle AG1.
  132. LogData("Experiments running...").
  133. until avionics:hasevent("review telemetry") and science:hasevent("Reset meteorological data") {}.
  134.  
  135. LogData("Experiment run complete! Awaiting safe conditions for chute deployment").
  136. set minDeployAlt to chute:getmodule("moduleparachute"):getfield("altitude").
  137. until ship:altitude < minDeployAlt and chute:getmodule("moduleparachute"):getfield("safe to deploy?") = "safe" {}.
  138.  
  139. // pop the chute
  140. LogData("Deploying chute").
  141. chute:getmodule("ModuleParachute"):doevent("deploy chute").
  142.  
  143. // confirm chute is open and run science experiments
  144. until chute:getmodule("ModuleParachute"):hasevent("cut parachute") {}.
  145. LogData("Chute deployment successful").
  146.  
  147. return true.
  148. }
  149.  
  150. // done! All data will be stored for retrieval, as battery power may not last until landing
  151. if Launch() {
  152. LogData("All events have executed. Awaiting landing & retrieval").
  153. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement