Advertisement
KSA_MissionCtrl

droptestlo.ks 5/6

May 5th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. // we need this for mutliple drop pods on the aircraft
  2. declare parameter podnum.
  3.  
  4. function LogData {
  5. parameter text.
  6.  
  7. // print to both the console and log
  8. print "[" + time:clock + "] " + text.
  9. log "[" + time:clock + "] " + text to droplog.
  10.  
  11. // make a copy on the local KSC archive in case we lose connection
  12. // be sure we don't try to do this while not in contact with KSC!
  13. if addons:rt:haskscconnection(ship) { copy droplog to 0. }.
  14. }.
  15.  
  16. function BattStatusCheck {
  17. parameter lowbattlvl.
  18.  
  19. // only bother if all capacitors are not discharged and electric charge has fallen below danger levels
  20. if not discharged and ship:resources[0]:amount < lowbattlvl {
  21. // if a capacitor is discharging, check that it is done
  22. if capactive > -1 {
  23. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  24. } else {
  25. set capnum to 0.
  26. until capnum = caplist:length {
  27. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  28. // tweak the discharge rate down so batteries do not fill up before capacitor finishes discharging, wasting energy
  29. caplist[capnum]:getmodule("dischargecapacitor"):setfield("percent power", 50).
  30. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  31.  
  32. // remember which capacitor is actively discharging
  33. set capactive to capnum.
  34.  
  35. LogData("Power levels low, discharging capacitor " + caplist[capnum]:tag).
  36. break.
  37. }.
  38. set capnum to capnum + 1.
  39. }.
  40. // was that all of them?
  41. if capnum = caplist:length {
  42. set discharged to true.
  43. LogData("All capacitors drained").
  44. }.
  45. }.
  46. }.
  47. }.
  48.  
  49. function BeginTransmission {
  50. LogData("Awaiting data transmission").
  51.  
  52. local timer is time:seconds.
  53. // until the comms message changes from "idle", nothing is being transmitted
  54. until comms:getmodule("modulertdatatransmitter"):getfield("comms") <> "idle" {
  55. // keep tabs on our power status - release capcitor charge as necessary
  56. BattStatusCheck(lowbattlvlnorm).
  57.  
  58. // keeps tabs on our connection to Mission Control
  59. if not addons:rt:haskscconnection(ship) {
  60. LogData("Connection lost").
  61. return false.
  62. }.
  63.  
  64. // if the user recycles all experiments, no data will be sent
  65. if time:seconds - timer > commtimeout {
  66. return false.
  67. }
  68. wait 0.001.
  69. }.
  70.  
  71. // we are transmitting!
  72. return true.
  73. }.
  74.  
  75. function MonitorTransmission {
  76. LogData("Data transmission has begun").
  77.  
  78. // keep an eye on the comm status and if it stays idle for too long we're done transmitting
  79. until time:seconds - transtime > transmissiontimeout {
  80. BattStatusCheck(lowbattlvltrans).
  81. if not addons:rt:haskscconnection(ship) {
  82. LogData("Connection lost").
  83. return false.
  84. }.
  85.  
  86. // if there was a period of idleness broken by a new transmission, reset the time-out counter
  87. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  88. lock transtime to time:seconds.
  89. }.
  90.  
  91. // comms have fallen silent, start the time-out counter
  92. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  93. set transtime to time:seconds.
  94. }.
  95. wait 0.001.
  96. }.
  97. // re-lock the time-out timer to the current time so it's always 0
  98. lock transtime to time:seconds.
  99. LogData("Data transmission has ended").
  100.  
  101. // do a check of comm status as we exit
  102. return addons:rt:haskscconnection(ship).
  103. }.
  104.  
  105. function DoExperimentRun {
  106. parameter name.
  107.  
  108. LogData("First " + name + " experiment run commencing").
  109.  
  110. toggle AG4.
  111. // goo containers are only used once per run
  112. for goo in goolist {
  113. // we don't care which goo pod is run - if a goo container is unused, it will have an event available
  114. if goo:getmodule("modulescienceexperiment"):hasevent("observe mystery goo") {
  115. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  116. break.
  117. }.
  118. }.
  119.  
  120. if not BeginTransmission() {
  121. // aborts the second run as well - no data means no data for this entire biome level
  122. LogData("Aborting " + name + " runs due to no data to transmit").
  123. return false.
  124. } else {
  125. if not MonitorTransmission() {
  126. return false.
  127. }.
  128.  
  129. // take a second run for any additional data
  130. LogData("Second " + name + " experiment run commencing").
  131.  
  132. toggle AG4.
  133.  
  134. if not BeginTransmission() {
  135. LogData("Aborting second " + name + " run due to no data to transmit").
  136. return false.
  137. } else {
  138. if not MonitorTransmission() {
  139. return false.
  140. }.
  141. }.
  142. }.
  143.  
  144. // a good run!
  145. return true.
  146. }.
  147.  
  148. function Main {
  149. // let user know what is available for program use
  150. LogData("Program running... confirming systems").
  151.  
  152. LogData(battlist:length + " Battery(s) found").
  153. LogData(caplist:length + " Capacitor(s) found").
  154. LogData(goolist:length + " Goo canister(s) found").
  155.  
  156. LogData("Operational systems confirmed, awaiting deployment").
  157.  
  158. // no need to monitor systems as we are connected to power of mothership
  159. until not decoupler:getmodule("moduleanchoreddecoupler"):hasevent("decouple") { wait 1.}.
  160. LogData("Pod deployed, awaiting chute deployment").
  161.  
  162. // wait for chute to open
  163. until lochute:getmodule("realchutemodule"):hasevent("cut chute") {
  164. wait 0.001.
  165. }.
  166. LogData("Chute deployment confirmed. Awaiting full deployment").
  167.  
  168. // turn on all batteries
  169. for batt in battlist {
  170. set batt:resources[0]:enabled to true.
  171. }.
  172. LogData("All batteries enabled").
  173.  
  174. // wait for full deployment and reduced vertical speed
  175. until alt:radar < deploylowerheight and ship:verticalspeed*-1 < maxdropspeed {
  176. BattStatusCheck(lowbattlvlnorm).
  177. wait 0.001.
  178. }.
  179. LogData("Full chute deployment confirmed").
  180. comms:getmodule("modulertantenna"):doevent("activate").
  181. LogData("Communications antenna deployed. Awaiting connection").
  182.  
  183. // can we connect to KSC?
  184. set timer to time:seconds.
  185. until addons:rt:haskscconnection(ship) {
  186. BattStatusCheck(lowbattlvlnorm).
  187. if time:seconds - timer > commtimeout {
  188. LogData("Communications link failed to connect to KSC!").
  189. return.
  190. }
  191. wait 0.001.
  192. }.
  193. LogData("Communications link established").
  194.  
  195. // begin run, check for connection if something went wrong
  196. if not DoExperimentRun("lower atmospheric") {
  197. if not addons:rt:haskscconnection(ship) {
  198. return false.
  199. }.
  200. }.
  201.  
  202. // wait for landing
  203. LogData("Awaiting landing").
  204. until ship:verticalspeed >= 0 {
  205. BattStatusCheck(lowbattlvlnorm).
  206. if not addons:rt:haskscconnection(ship) {
  207. LogData("Connection lost").
  208. return false.
  209. }.
  210. wait 0.001.
  211. }.
  212. LogData("Landing confirmed").
  213.  
  214. // one last run
  215. if not DoExperimentRun("ground level") {
  216. if not addons:rt:haskscconnection(ship) {
  217. return false.
  218. }.
  219. }.
  220.  
  221. return true.
  222. }.
  223.  
  224. //create access to all the parts
  225. set hichute to ship:partstagged("hi" + podnum)[0].
  226. set lochute to ship:partstagged("lo" + podnum)[0].
  227. set comms to ship:partstagged("antenna" + podnum)[0].
  228. set probe to ship:partstagged("core" + podnum)[0].
  229. set decoupler to ship:partstagged("drop" + podnum)[0].
  230. set battlist to ship:partsdubbed("z-200 rechargeable battery bank" + podnum).
  231. set caplist to ship:partsdubbed("cap-101 capacitor" + podnum).
  232. set goolist to ship:partstagged("goo" + podnum).
  233.  
  234. // program behavior variables
  235. set deploylowerheight to 3000.
  236. set maxdropspeed to 12.
  237. set commtimeout to 30.
  238. set transmissiontimeout to 15.
  239. set lowbattlvlnorm to 25. // for when no data is being transmitted
  240. set lowbattlvltrans to 150. // for when data is being transmitted
  241. set capactive to -1.
  242. set discharged to false.
  243. lock transtime to time:seconds.
  244.  
  245. clearscreen.
  246. abort off.
  247. if Main() {
  248. LogData("All events have executed").
  249. }.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement