Advertisement
KSA_MissionCtrl

droptesthi.ks 4/11

Apr 8th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.27 KB | None | 0 0
  1. //create access to all the parts
  2. set hichute to ship:partstagged("hi")[0].
  3. set lochute to ship:partstagged("lo")[0].
  4. set comms to ship:partstagged("antenna")[0].
  5. set probe to ship:partstagged("core")[0].
  6. set decoupler to ship:partstagged("drop")[0].
  7. set battlist to ship:partsdubbed("z-200 rechargeable battery bank").
  8. set caplist to ship:partsdubbed("cap-101 capacitor").
  9. set goolist to ship:partstagged("goo").
  10.  
  11. // program behavior variables
  12. set deployalt to 25000.
  13. set deployupperheight to 24000.
  14. set loweratmosphere to 18000.
  15. set deploylowerheight to 3000.
  16. set maxdropspeed to 12.
  17. set commtimeout to 30.
  18. set transmissiontimeout to 15.
  19. set lowbattlvl to 25. // for when no data is being transmitted
  20. set lowbattlvltrans to 150. // for when data is being transmitted
  21. set capactive to -1.
  22. set discharged to false.
  23.  
  24. // changed from "set transtime to 0."
  25. // because doing so caused "until time:seconds - transtime > transmissiontimeout" to always be true on first evaluation
  26. // this caused all experiment runs to immediately be skipped once data transmission began
  27. lock transtime to time:seconds.
  28.  
  29. clearscreen.
  30. abort off.
  31. print "[" + time:clock + "] Program running... confirming systems".
  32. log "[" + time:clock + "] Program running... confirming systems" to droplog.
  33. copy droplog to 0.
  34.  
  35. print "[" + time:clock + "] " + battlist:length + " Battery(s) found".
  36. log "[" + time:clock + "] " + battlist:length + " Battery(s) found" to droplog.
  37. copy droplog to 0.
  38. print "[" + time:clock + "] " + caplist:length + " Capacitor(s) found".
  39. log "[" + time:clock + "] " + caplist:length + " Capacitor(s) found" to droplog.
  40. copy droplog to 0.
  41. print "[" + time:clock + "] " + goolist:length + " Goo canister(s) found".
  42. log "[" + time:clock + "] " + goolist:length + " Goo canister(s) found" to droplog.
  43. copy droplog to 0.
  44.  
  45. print "[" + time:clock + "] Operational systems confirmed, awaiting deployment altitude".
  46. log "[" + time:clock + "] Operational systems confirmed, awaiting deployment altitude" to droplog.
  47. copy droplog to 0.
  48.  
  49. // no need to monitor systems as we are conected to power of mothership
  50. until ship:altitude > deployalt { wait 0.001. }.
  51.  
  52. // drop and begin
  53. decoupler:getmodule("moduleanchoreddecoupler"):doevent("decouple").
  54.  
  55. for batt in battlist {
  56. set batt:resources[0]:enabled to true.
  57. }.
  58. print "[" + time:clock + "] All batteries enabled".
  59. log "[" + time:clock + "] All batteries enabled" to droplog.
  60. copy droplog to 0.
  61. print "[" + time:clock + "] Awaiting chute deployment".
  62. log "[" + time:clock + "] Awaiting chute deployment" to droplog.
  63. copy droplog to 0.
  64.  
  65. until hichute:getmodule("realchutemodule"):allevents[0] = "(callable) cut chute, is kspevent" {
  66. if not discharged and ship:resources[0]:amount < lowbattlvl {
  67.  
  68. // when a capacitor discharges, it is logged in "capactive" so we can check to see if it has discharged
  69. // this prevents multiple capacitors from being discharged at once since it could take a few seconds to build up charge past "lowbattlvl" and thus trigger additional capacitor discharges
  70. if capactive > -1 {
  71. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  72. } else {
  73. set capnum to 0.
  74. until capnum = caplist:length {
  75. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  76. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  77. set capactive to capnum.
  78. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  79. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  80. copy droplog to 0.
  81. break.
  82. }.
  83. set capnum to capnum + 1.
  84. }.
  85. if capnum = caplist:length {
  86. set discharged to true.
  87. Print "[" + time:clock + "] All capacitors drained".
  88. log "[" + time:clock + "] All capacitors drained" to droplog.
  89. copy droplog to 0.
  90. }.
  91. }.
  92. }.
  93. wait 0.001.
  94. }.
  95. Print "[" + time:clock + "] Chute deployment confirmed. Awaiting full deployment".
  96. log "[" + time:clock + "] Chute deployment confirmed. Awaiting full deployment" to droplog.
  97. copy droplog to 0.
  98.  
  99. // we don't care how fast we are dropping - air is too thin to rip off antenna at any speed once chute is deployed
  100. until alt:radar < deployupperheight {
  101. if not discharged and ship:resources[0]:amount < lowbattlvl {
  102. // if a capacitor is discharging, check that it is done
  103. if capactive > -1 {
  104. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  105. } else {
  106. set capnum to 0.
  107. until capnum = caplist:length {
  108. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  109. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  110. set capactive to capnum.
  111. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  112. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  113. copy droplog to 0.
  114. break.
  115. }.
  116. set capnum to capnum + 1.
  117. }.
  118. if capnum = caplist:length {
  119. set discharged to true.
  120. Print "[" + time:clock + "] All capacitors drained".
  121. log "[" + time:clock + "] All capacitors drained" to droplog.
  122. copy droplog to 0.
  123. }.
  124. }.
  125. }.
  126. wait 0.001.
  127. }.
  128. Print "[" + time:clock + "] Full chute deployment confirmed".
  129. log "[" + time:clock + "] Full chute deployment confirmed" to droplog.
  130. copy droplog to 0.
  131. comms:getmodule("modulertantenna"):doevent("activate").
  132. Print "[" + time:clock + "] Communications antenna deployed. Awaiting connection".
  133. log "[" + time:clock + "] Communications antenna deployed. Awaiting connection" to droplog.
  134. copy droplog to 0.
  135.  
  136. set timer to time:seconds.
  137. until probe:getmodule("modulespu"):getfield("spu") = "operational." {
  138. if not discharged and ship:resources[0]:amount < lowbattlvl {
  139. // if a capacitor is discharging, check that it is done
  140. if capactive > -1 {
  141. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  142. } else {
  143. set capnum to 0.
  144. until capnum = caplist:length {
  145. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  146. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  147. set capactive to capnum.
  148. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  149. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  150. copy droplog to 0.
  151. break.
  152. }.
  153. set capnum to capnum + 1.
  154. }.
  155. if capnum = caplist:length {
  156. set discharged to true.
  157. Print "[" + time:clock + "] All capacitors drained".
  158. log "[" + time:clock + "] All capacitors drained" to droplog.
  159. copy droplog to 0.
  160. }.
  161. }.
  162. }.
  163. if time:seconds - timer > commtimeout {
  164. Print "[" + time:clock + "] Communications link failed!".
  165. log "[" + time:clock + "] Communications link failed!" to droplog.
  166. copy droplog to 0.
  167. shutdown.
  168. }
  169. wait 0.001.
  170. }.
  171. Print "[" + time:clock + "] Communications link established".
  172. log "[" + time:clock + "] Communications link established" to droplog.
  173. copy droplog to 0.
  174. Print "[" + time:clock + "] First upper atmospheric experiment run commencing".
  175. log "[" + time:clock + "] First upper atmospheric experiment run commencing" to droplog.
  176. copy droplog to 0.
  177.  
  178. toggle AG4.
  179. // goo containers are only run once per atmosphere level (upper/lower)
  180. for goo in goolist {
  181. // we don't care which goo pod is run - if a goo container is unused, it will have an event available
  182. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  183. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  184. break.
  185. }.
  186. }.
  187. Print "[" + time:clock + "] Awaiting data transmission".
  188. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  189. copy droplog to 0.
  190.  
  191. set timer to time:seconds.
  192. set nodata to false.
  193. // until the comms message changes from "idle", nothing is being transmitted
  194. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  195. // keep tabs on our power status - release capcitor charge as necessary
  196. if not discharged and ship:resources[0]:amount < lowbattlvl {
  197. // if a capacitor is discharging, check that it is done
  198. if capactive > -1 {
  199. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  200. } else {
  201. set capnum to 0.
  202. until capnum = caplist:length {
  203. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  204. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  205. set capactive to capnum.
  206. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  207. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  208. copy droplog to 0.
  209. break.
  210. }.
  211. set capnum to capnum + 1.
  212. }.
  213. if capnum = caplist:length {
  214. set discharged to true.
  215. Print "[" + time:clock + "] All capacitors drained".
  216. log "[" + time:clock + "] All capacitors drained" to droplog.
  217. copy droplog to 0.
  218. }.
  219. }.
  220. }.
  221. // keeps tabs on our connection to Mission Control
  222. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  223. Print "[" + time:clock + "] Connection lost".
  224. log "[" + time:clock + "] Connection lost" to droplog.
  225. copy droplog to 0.
  226. shutdown.
  227. }.
  228. // if the user recycles all experiments, no data will be sent
  229. if time:seconds - timer > commtimeout {
  230. set nodata to true.
  231. break.
  232. }
  233. wait 0.001.
  234. }.
  235.  
  236. if nodata {
  237. // aborts the second run as well - no data means no data for this entire biome level
  238. Print "[" + time:clock + "] Aborting upper atmospheric runs due to no data to transmit".
  239. log "[" + time:clock + "] Aborting upper atmospheric runs due to no data to transmit" to droplog.
  240. copy droplog to 0.
  241. } else {
  242. Print "[" + time:clock + "] Data transmission has begun".
  243. log "[" + time:clock + "] Data transmission has begun" to droplog.
  244. copy droplog to 0.
  245.  
  246. until time:seconds - transtime > transmissiontimeout {
  247. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  248. // if a capacitor is discharging, check that it is done
  249. if capactive > -1 {
  250. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  251. } else {
  252. set capnum to 0.
  253. until capnum = caplist:length {
  254. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  255. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  256. set capactive to capnum.
  257. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  258. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  259. copy droplog to 0.
  260. break.
  261. }.
  262. set capnum to capnum + 1.
  263. }.
  264. if capnum = caplist:length {
  265. set discharged to true.
  266. Print "[" + time:clock + "] All capacitors drained".
  267. log "[" + time:clock + "] All capacitors drained" to droplog.
  268. copy droplog to 0.
  269. }.
  270. }.
  271. }.
  272. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  273. Print "[" + time:clock + "] Connection lost".
  274. log "[" + time:clock + "] Connection lost" to droplog.
  275. copy droplog to 0.
  276. shutdown.
  277. }.
  278. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  279. lock transtime to time:seconds.
  280. }.
  281. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  282. set transtime to time:seconds.
  283. }.
  284. wait 0.001.
  285. }.
  286. Print "[" + time:clock + "] Data transmission has ended".
  287. log "[" + time:clock + "] Data transmission has ended" to droplog.
  288. copy droplog to 0.
  289.  
  290. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  291. Print "[" + time:clock + "] Connection lost".
  292. log "[" + time:clock + "] Connection lost" to droplog.
  293. copy droplog to 0.
  294. shutdown.
  295. }.
  296.  
  297. // if we haven't reached the lower atmosphere yet, take a second run for additional data
  298. if alt:radar > loweratmosphere {
  299. Print "[" + time:clock + "] Second upper atmospheric experiment run commencing".
  300. log "[" + time:clock + "] Second upper atmospheric experiment run commencing" to droplog.
  301. copy droplog to 0.
  302. toggle AG4.
  303. for goo in goolist {
  304. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  305. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  306. break.
  307. }.
  308. }.
  309. Print "[" + time:clock + "] Awaiting data transmission".
  310. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  311. copy droplog to 0.
  312.  
  313. set timer to time:seconds.
  314. set nodata to false.
  315. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  316. if not discharged and ship:resources[0]:amount < lowbattlvl {
  317. // if a capacitor is discharging, check that it is done
  318. if capactive > -1 {
  319. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  320. } else {
  321. set capnum to 0.
  322. until capnum = caplist:length {
  323. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  324. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  325. set capactive to capnum.
  326. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  327. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  328. copy droplog to 0.
  329. break.
  330. }.
  331. set capnum to capnum + 1.
  332. }.
  333. if capnum = caplist:length {
  334. set discharged to true.
  335. Print "[" + time:clock + "] All capacitors drained".
  336. log "[" + time:clock + "] All capacitors drained" to droplog.
  337. copy droplog to 0.
  338. }.
  339. }.
  340. }.
  341. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  342. Print "[" + time:clock + "] Connection lost".
  343. log "[" + time:clock + "] Connection lost" to droplog.
  344. copy droplog to 0.
  345. shutdown.
  346. }.
  347. if time:seconds - timer > commtimeout {
  348. set nodata to true.
  349. break.
  350. }
  351. wait 0.001.
  352. }.
  353.  
  354. if nodata {
  355. Print "[" + time:clock + "] Aborting second upper atmospheric run due to no data to transmit".
  356. log "[" + time:clock + "] Aborting second upper atmospheric run due to no data to transmit" to droplog.
  357. copy droplog to 0.
  358. } else {
  359. Print "[" + time:clock + "] Data transmission has begun".
  360. log "[" + time:clock + "] Data transmission has begun" to droplog.
  361. copy droplog to 0.
  362.  
  363. until time:seconds - transtime > transmissiontimeout {
  364. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  365. // if a capacitor is discharging, check that it is done
  366. if capactive > -1 {
  367. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  368. } else {
  369. set capnum to 0.
  370. until capnum = caplist:length {
  371. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  372. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  373. set capactive to capnum.
  374. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  375. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  376. copy droplog to 0.
  377. break.
  378. }.
  379. set capnum to capnum + 1.
  380. }.
  381. if capnum = caplist:length {
  382. set discharged to true.
  383. Print "[" + time:clock + "] All capacitors drained".
  384. log "[" + time:clock + "] All capacitors drained" to droplog.
  385. copy droplog to 0.
  386. }.
  387. }.
  388. }.
  389. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  390. Print "[" + time:clock + "] Connection lost".
  391. log "[" + time:clock + "] Connection lost" to droplog.
  392. copy droplog to 0.
  393. shutdown.
  394. }.
  395. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  396. lock transtime to time:seconds.
  397. }.
  398. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  399. set transtime to time:seconds.
  400. }.
  401. wait 0.01.
  402. }.
  403.  
  404. Print "[" + time:clock + "] Data transmission has ended".
  405. log "[" + time:clock + "] Data transmission has ended" to droplog.
  406. copy droplog to 0.
  407. }.
  408. } else {
  409. Print "[" + time:clock + "] Aborting second upper atmospheric run due to altitude".
  410. log "[" + time:clock + "] Aborting second upper atmospheric run due to altitude" to droplog.
  411. copy droplog to 0.
  412. }.
  413. }.
  414.  
  415. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  416. Print "[" + time:clock + "] Connection lost".
  417. log "[" + time:clock + "] Connection lost" to droplog.
  418. copy droplog to 0.
  419. shutdown.
  420. }.
  421.  
  422. Print "[" + time:clock + "] Advancing to lower atmosphere".
  423. log "[" + time:clock + "] Advancing to lower atmosphere" to droplog.
  424. copy droplog to 0.
  425. comms:getmodule("modulertantenna"):doevent("deactivate").
  426. Print "[" + time:clock + "] Communications antenna retracted".
  427. log "[" + time:clock + "] Communications antenna retracted" to droplog.
  428. copy droplog to 0.
  429. hichute:getmodule("realchutemodule"):doevent("cut chute").
  430. Print "[" + time:clock + "] Chute cut".
  431. log "[" + time:clock + "] Chute cut" to droplog.
  432. copy droplog to 0.
  433. Print "[" + time:clock + "] Awaiting chute deployment".
  434. log "[" + time:clock + "] Awaiting chute deployment" to droplog.
  435. copy droplog to 0.
  436.  
  437. until lochute:getmodule("realchutemodule"):allevents[0] = "(callable) cut chute, is kspevent" {
  438. if not discharged and ship:resources[0]:amount < lowbattlvl {
  439. // if a capacitor is discharging, check that it is done
  440. if capactive > -1 {
  441. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  442. } else {
  443. set capnum to 0.
  444. until capnum = caplist:length {
  445. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  446. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  447. set capactive to capnum.
  448. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  449. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  450. copy droplog to 0.
  451. break.
  452. }.
  453. set capnum to capnum + 1.
  454. }.
  455. if capnum = caplist:length {
  456. set discharged to true.
  457. Print "[" + time:clock + "] All capacitors drained".
  458. log "[" + time:clock + "] All capacitors drained" to droplog.
  459. copy droplog to 0.
  460. }.
  461. }.
  462. }.
  463. wait 0.001.
  464. }.
  465. Print "[" + time:clock + "] Chute deployment confirmed. Awaiting full deployment".
  466. log "[" + time:clock + "] Chute deployment confirmed. Awaiting full deployment" to droplog.
  467. copy droplog to 0.
  468.  
  469. until alt:radar < deploylowerheight and ship:verticalspeed*-1 < maxdropspeed {
  470. if not discharged and ship:resources[0]:amount < lowbattlvl {
  471. // if a capacitor is discharging, check that it is done
  472. if capactive > -1 {
  473. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  474. } else {
  475. set capnum to 0.
  476. until capnum = caplist:length {
  477. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  478. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  479. set capactive to capnum.
  480. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  481. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  482. copy droplog to 0.
  483. break.
  484. }.
  485. set capnum to capnum + 1.
  486. }.
  487. if capnum = caplist:length {
  488. set discharged to true.
  489. Print "[" + time:clock + "] All capacitors drained".
  490. log "[" + time:clock + "] All capacitors drained" to droplog.
  491. copy droplog to 0.
  492. }.
  493. }.
  494. }.
  495. wait 0.001.
  496. }.
  497. Print "[" + time:clock + "] Full chute deployment confirmed".
  498. log "[" + time:clock + "] Full chute deployment confirmed" to droplog.
  499. copy droplog to 0.
  500. comms:getmodule("modulertantenna"):doevent("activate").
  501. Print "[" + time:clock + "] Communications antenna deployed. Awaiting connection".
  502. log "[" + time:clock + "] Communications antenna deployed. Awaiting connection" to droplog.
  503. copy droplog to 0.
  504.  
  505. set timer to time:seconds.
  506. until probe:getmodule("modulespu"):getfield("spu") = "operational." {
  507. if not discharged and ship:resources[0]:amount < lowbattlvl {
  508. // if a capacitor is discharging, check that it is done
  509. if capactive > -1 {
  510. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  511. } else {
  512. set capnum to 0.
  513. until capnum = caplist:length {
  514. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  515. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  516. set capactive to capnum.
  517. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  518. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  519. copy droplog to 0.
  520. break.
  521. }.
  522. set capnum to capnum + 1.
  523. }.
  524. if capnum = caplist:length {
  525. set discharged to true.
  526. Print "[" + time:clock + "] All capacitors drained".
  527. log "[" + time:clock + "] All capacitors drained" to droplog.
  528. copy droplog to 0.
  529. }.
  530. }.
  531. }.
  532. if time:seconds - timer > commtimeout {
  533. Print "[" + time:clock + "] Communications link failed!".
  534. log "[" + time:clock + "] Communications link failed!" to droplog.
  535. copy droplog to 0.
  536. shutdown.
  537. }
  538. wait 0.001.
  539. }.
  540. Print "[" + time:clock + "] Communications link established".
  541. log "[" + time:clock + "] Communications link established" to droplog.
  542. copy droplog to 0.
  543. Print "[" + time:clock + "] First lower atmospheric experiment run commencing".
  544. log "[" + time:clock + "] First lower atmospheric experiment run commencing" to droplog.
  545. copy droplog to 0.
  546.  
  547. toggle AG4.
  548. // goo containers are only run once per atmosphere level (upper/lower)
  549. for goo in goolist {
  550. // we don't care which goo pod is run - if a goo container is unused, it will have an event available
  551. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  552. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  553. break.
  554. }.
  555. }.
  556. Print "[" + time:clock + "] Awaiting data transmission".
  557. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  558. copy droplog to 0.
  559.  
  560. set timer to time:seconds.
  561. set nodata to false.
  562. // until the comms message changes from "idle", nothing is being transmitted
  563. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  564. // keep tabs on our power status - release capcitor charge as necessary
  565. if not discharged and ship:resources[0]:amount < lowbattlvl {
  566. // if a capacitor is discharging, check that it is done
  567. if capactive > -1 {
  568. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  569. } else {
  570. set capnum to 0.
  571. until capnum = caplist:length {
  572. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  573. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  574. set capactive to capnum.
  575. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  576. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  577. copy droplog to 0.
  578. break.
  579. }.
  580. set capnum to capnum + 1.
  581. }.
  582. if capnum = caplist:length {
  583. set discharged to true.
  584. Print "[" + time:clock + "] All capacitors drained".
  585. log "[" + time:clock + "] All capacitors drained" to droplog.
  586. copy droplog to 0.
  587. }.
  588. }.
  589. }.
  590. // keeps tabs on our connection to Mission Control
  591. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  592. Print "[" + time:clock + "] Connection lost".
  593. log "[" + time:clock + "] Connection lost" to droplog.
  594. copy droplog to 0.
  595. shutdown.
  596. }.
  597. // if the user recycles all experiments, no data will be sent
  598. if time:seconds - timer > commtimeout {
  599. set nodata to true.
  600. break.
  601. }
  602. wait 0.001.
  603. }.
  604.  
  605. if nodata {
  606. // aborts the second run as well - no data means no data for this entire biome level
  607. Print "[" + time:clock + "] Aborting lower atmospheric runs due to no data to transmit".
  608. log "[" + time:clock + "] Aborting lower atmospheric runs due to no data to transmit" to droplog.
  609. copy droplog to 0.
  610. } else {
  611. Print "[" + time:clock + "] Data transmission has begun".
  612. log "[" + time:clock + "] Data transmission has begun" to droplog.
  613. copy droplog to 0.
  614.  
  615. until time:seconds - transtime > transmissiontimeout {
  616. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  617. // if a capacitor is discharging, check that it is done
  618. if capactive > -1 {
  619. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  620. } else {
  621. set capnum to 0.
  622. until capnum = caplist:length {
  623. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  624. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  625. set capactive to capnum.
  626. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  627. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  628. copy droplog to 0.
  629. break.
  630. }.
  631. set capnum to capnum + 1.
  632. }.
  633. if capnum = caplist:length {
  634. set discharged to true.
  635. Print "[" + time:clock + "] All capacitors drained".
  636. log "[" + time:clock + "] All capacitors drained" to droplog.
  637. copy droplog to 0.
  638. }.
  639. }.
  640. }.
  641. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  642. Print "[" + time:clock + "] Connection lost".
  643. log "[" + time:clock + "] Connection lost" to droplog.
  644. copy droplog to 0.
  645. shutdown.
  646. }.
  647. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  648. lock transtime to time:seconds.
  649. }.
  650. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  651. set transtime to time:seconds.
  652. }.
  653. wait 0.001.
  654. }.
  655. Print "[" + time:clock + "] Data transmission has ended".
  656. log "[" + time:clock + "] Data transmission has ended" to droplog.
  657. copy droplog to 0.
  658.  
  659. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  660. Print "[" + time:clock + "] Connection lost".
  661. log "[" + time:clock + "] Connection lost" to droplog.
  662. copy droplog to 0.
  663. shutdown.
  664. }.
  665.  
  666. // if we'haven't landed yet, take a second run for additional data
  667. if ship:verticalspeed < 0 {
  668. Print "[" + time:clock + "] Second lower atmospheric experiment run commencing".
  669. log "[" + time:clock + "] Second lower atmospheric experiment run commencing" to droplog.
  670. copy droplog to 0.
  671. toggle AG4.
  672. for goo in goolist {
  673. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  674. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  675. break.
  676. }.
  677. }.
  678. Print "[" + time:clock + "] Awaiting data transmission".
  679. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  680. copy droplog to 0.
  681.  
  682. set timer to time:seconds.
  683. set nodata to false.
  684. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  685. if not discharged and ship:resources[0]:amount < lowbattlvl {
  686. // if a capacitor is discharging, check that it is done
  687. if capactive > -1 {
  688. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  689. } else {
  690. set capnum to 0.
  691. until capnum = caplist:length {
  692. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  693. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  694. set capactive to capnum.
  695. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  696. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  697. copy droplog to 0.
  698. break.
  699. }.
  700. set capnum to capnum + 1.
  701. }.
  702. if capnum = caplist:length {
  703. set discharged to true.
  704. Print "[" + time:clock + "] All capacitors drained".
  705. log "[" + time:clock + "] All capacitors drained" to droplog.
  706. copy droplog to 0.
  707. }.
  708. }.
  709. }.
  710. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  711. Print "[" + time:clock + "] Connection lost".
  712. log "[" + time:clock + "] Connection lost" to droplog.
  713. copy droplog to 0.
  714. shutdown.
  715. }.
  716. if time:seconds - timer > commtimeout {
  717. set nodata to true.
  718. break.
  719. }
  720. wait 0.001.
  721. }.
  722.  
  723. if nodata {
  724. Print "[" + time:clock + "] Aborting second lower atmospheric run due to no data to transmit".
  725. log "[" + time:clock + "] Aborting second lower atmospheric run due to no data to transmit" to droplog.
  726. copy droplog to 0.
  727. } else {
  728. Print "[" + time:clock + "] Data transmission has begun".
  729. log "[" + time:clock + "] Data transmission has begun" to droplog.
  730. copy droplog to 0.
  731.  
  732. until time:seconds - transtime > transmissiontimeout {
  733. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  734. // if a capacitor is discharging, check that it is done
  735. if capactive > -1 {
  736. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  737. } else {
  738. set capnum to 0.
  739. until capnum = caplist:length {
  740. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  741. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  742. set capactive to capnum.
  743. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  744. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  745. copy droplog to 0.
  746. break.
  747. }.
  748. set capnum to capnum + 1.
  749. }.
  750. if capnum = caplist:length {
  751. set discharged to true.
  752. Print "[" + time:clock + "] All capacitors drained".
  753. log "[" + time:clock + "] All capacitors drained" to droplog.
  754. copy droplog to 0.
  755. }.
  756. }.
  757. }.
  758. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  759. Print "[" + time:clock + "] Connection lost".
  760. log "[" + time:clock + "] Connection lost" to droplog.
  761. copy droplog to 0.
  762. shutdown.
  763. }.
  764. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  765. lock transtime to time:seconds.
  766. }.
  767. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  768. set transtime to time:seconds.
  769. }.
  770. wait 0.001.
  771. }.
  772.  
  773. Print "[" + time:clock + "] Data transmission has ended".
  774. log "[" + time:clock + "] Data transmission has ended" to droplog.
  775. copy droplog to 0.
  776. }.
  777. }.
  778. }.
  779.  
  780. // go into a wait state if we haven't landed during the last transmission sequence
  781. if ship:verticalspeed < 0 {
  782. Print "[" + time:clock + "] Awaiting landing".
  783. until ship:verticalspeed >= 0 {
  784. if not discharged and ship:resources[0]:amount < lowbattlvl {
  785. // if a capacitor is discharging, check that it is done
  786. if capactive > -1 {
  787. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  788. } else {
  789. set capnum to 0.
  790. until capnum = caplist:length {
  791. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  792. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  793. set capactive to capnum.
  794. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  795. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  796. copy droplog to 0.
  797. break.
  798. }.
  799. set capnum to capnum + 1.
  800. }.
  801. if capnum = caplist:length {
  802. set discharged to true.
  803. Print "[" + time:clock + "] All capacitors drained".
  804. log "[" + time:clock + "] All capacitors drained" to droplog.
  805. copy droplog to 0.
  806. }.
  807. }.
  808. }.
  809. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  810. Print "[" + time:clock + "] Connection lost".
  811. log "[" + time:clock + "] Connection lost" to droplog.
  812. copy droplog to 0.
  813. shutdown.
  814. }.
  815. wait 0.001.
  816. }.
  817. }.
  818.  
  819. Print "[" + time:clock + "] Landing confirmed. First ground level experiment run commencing".
  820. log "[" + time:clock + "] Landing confirmed. First ground level experiment run commencing" to droplog.
  821. copy droplog to 0.
  822. toggle AG4.
  823. for goo in goolist {
  824. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  825. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  826. break.
  827. }.
  828. }.
  829. Print "[" + time:clock + "] Awaiting data transmission".
  830. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  831. copy droplog to 0.
  832.  
  833. set timer to time:seconds.
  834. set nodata to false.
  835. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  836. if not discharged and ship:resources[0]:amount < lowbattlvl {
  837. // if a capacitor is discharging, check that it is done
  838. if capactive > -1 {
  839. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  840. } else {
  841. set capnum to 0.
  842. until capnum = caplist:length {
  843. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  844. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  845. set capactive to capnum.
  846. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  847. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  848. copy droplog to 0.
  849. break.
  850. }.
  851. set capnum to capnum + 1.
  852. }.
  853. if capnum = caplist:length {
  854. set discharged to true.
  855. Print "[" + time:clock + "] All capacitors drained".
  856. log "[" + time:clock + "] All capacitors drained" to droplog.
  857. copy droplog to 0.
  858. }.
  859. }.
  860. }.
  861. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  862. Print "[" + time:clock + "] Connection lost".
  863. log "[" + time:clock + "] Connection lost" to droplog.
  864. copy droplog to 0.
  865. shutdown.
  866. }.
  867. if time:seconds - timer > commtimeout {
  868. set nodata to true.
  869. break.
  870. }
  871. wait 0.001.
  872. }.
  873.  
  874. if nodata {
  875. Print "[" + time:clock + "] Aborting ground level runs due to no data to transmit".
  876. log "[" + time:clock + "] Aborting ground level runs due to no data to transmit" to droplog.
  877. copy droplog to 0.
  878. } else {
  879. Print "[" + time:clock + "] Data transmission has begun".
  880. log "[" + time:clock + "] Data transmission has begun" to droplog.
  881. copy droplog to 0.
  882.  
  883. until time:seconds - transtime > transmissiontimeout {
  884. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  885. // if a capacitor is discharging, check that it is done
  886. if capactive > -1 {
  887. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  888. } else {
  889. set capnum to 0.
  890. until capnum = caplist:length {
  891. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  892. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  893. set capactive to capnum.
  894. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  895. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  896. copy droplog to 0.
  897. break.
  898. }.
  899. set capnum to capnum + 1.
  900. }.
  901. if capnum = caplist:length {
  902. set discharged to true.
  903. Print "[" + time:clock + "] All capacitors drained".
  904. log "[" + time:clock + "] All capacitors drained" to droplog.
  905. copy droplog to 0.
  906. }.
  907. }.
  908. }.
  909. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  910. Print "[" + time:clock + "] Connection lost".
  911. log "[" + time:clock + "] Connection lost" to droplog.
  912. copy droplog to 0.
  913. shutdown.
  914. }.
  915. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  916. lock transtime to time:seconds.
  917. }.
  918. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  919. set transtime to time:seconds.
  920. }.
  921. wait 0.001.
  922. }.
  923. Print "[" + time:clock + "] Data transmission has ended".
  924. log "[" + time:clock + "] Data transmission has ended" to droplog.
  925. copy droplog to 0.
  926.  
  927. if ship:resources[0]:amount > 0 {
  928. Print "[" + time:clock + "] Second ground level experiment run commencing".
  929. log "[" + time:clock + "] Second ground level experiment run commencing" to droplog.
  930. copy droplog to 0.
  931. toggle AG4.
  932. for goo in goolist {
  933. if goo:getmodule("modulescienceexperiment"):allevents:length > 0 {
  934. goo:getmodule("modulescienceexperiment"):doevent("observe mystery goo").
  935. break.
  936. }.
  937. }.
  938. Print "[" + time:clock + "] Awaiting data transmission".
  939. log "[" + time:clock + "] Awaiting data transmission" to droplog.
  940. copy droplog to 0.
  941.  
  942. set timer to time:seconds.
  943. set nodata to false.
  944. until comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  945. if not discharged and ship:resources[0]:amount < lowbattlvl {
  946. // if a capacitor is discharging, check that it is done
  947. if capactive > -1 {
  948. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  949. } else {
  950. set capnum to 0.
  951. until capnum = caplist:length {
  952. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  953. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  954. set capactive to capnum.
  955. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  956. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  957. copy droplog to 0.
  958. break.
  959. }.
  960. set capnum to capnum + 1.
  961. }.
  962. if capnum = caplist:length {
  963. set discharged to true.
  964. Print "[" + time:clock + "] All capacitors drained".
  965. log "[" + time:clock + "] All capacitors drained" to droplog.
  966. copy droplog to 0.
  967. }.
  968. }.
  969. }.
  970. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  971. Print "[" + time:clock + "] Connection lost".
  972. log "[" + time:clock + "] Connection lost" to droplog.
  973. copy droplog to 0.
  974. shutdown.
  975. }.
  976. if time:seconds - timer > commtimeout {
  977. set nodata to true.
  978. break.
  979. }
  980. wait 0.001.
  981. }.
  982.  
  983. if nodata {
  984. Print "[" + time:clock + "] Aborting second ground level run due to no data to transmit".
  985. log "[" + time:clock + "] Aborting second ground level run due to no data to transmit" to droplog.
  986. copy droplog to 0.
  987. } else {
  988. Print "[" + time:clock + "] Data transmission has begun".
  989. log "[" + time:clock + "] Data transmission has begun" to droplog.
  990. copy droplog to 0.
  991.  
  992. until time:seconds - transtime > transmissiontimeout {
  993. if not discharged and ship:resources[0]:amount < lowbattlvltrans {
  994. // if a capacitor is discharging, check that it is done
  995. if capactive > -1 {
  996. if caplist[capactive]:getmodule("dischargecapacitor"):getfield("status") = "discharged!" { set capactive to -1. }.
  997. } else {
  998. set capnum to 0.
  999. until capnum = caplist:length {
  1000. if caplist[capnum]:getmodule("dischargecapacitor"):getfield("status") = "ready" {
  1001. caplist[capnum]:getmodule("dischargecapacitor"):doevent("discharge capacitor").
  1002. set capactive to capnum.
  1003. Print "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag.
  1004. log "[" + time:clock + "] Power levels low, discharging capacitor " + caplist[capnum]:tag to droplog.
  1005. copy droplog to 0.
  1006. break.
  1007. }.
  1008. set capnum to capnum + 1.
  1009. }.
  1010. if capnum = caplist:length {
  1011. set discharged to true.
  1012. Print "[" + time:clock + "] All capacitors drained".
  1013. log "[" + time:clock + "] All capacitors drained" to droplog.
  1014. copy droplog to 0.
  1015. }.
  1016. }.
  1017. }.
  1018. if probe:getmodule("modulespu"):getfield("spu") <> "operational." {
  1019. Print "[" + time:clock + "] Connection lost".
  1020. log "[" + time:clock + "] Connection lost" to droplog.
  1021. copy droplog to 0.
  1022. shutdown.
  1023. }.
  1024. if transtime < time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "uploading data..." {
  1025. lock transtime to time:seconds.
  1026. }.
  1027. if transtime = time:seconds and comms:getmodule("modulertdatatransmitter"):getfield("comms") = "idle" {
  1028. set transtime to time:seconds.
  1029. }.
  1030. wait 0.001.
  1031. }.
  1032.  
  1033. Print "[" + time:clock + "] Data transmission has ended".
  1034. log "[" + time:clock + "] Data transmission has ended" to droplog.
  1035. copy droplog to 0.
  1036. }.
  1037. }.
  1038. }.
  1039. Print "[" + time:clock + "] All events have executed".
  1040. log "[" + time:clock + "] All events have executed" to droplog.
  1041. copy droplog to 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement