Advertisement
UnitedMi

Trubine Control v1.0

Dec 11th, 2019
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. write("Init Turbine ... ")
  2. local turbine
  3. turbine = peripheral.find("BigReactors-Turbine")
  4. print("Done")
  5.  
  6. write("Init Monitor ... ")
  7. local mon
  8. mon = peripheral.wrap("back")
  9. print("Done")
  10.  
  11. write("Init Modem ... ")
  12. rednet.open("bottom")
  13. pripnt("Done")
  14.  
  15. write("Init Values ... ")
  16. TankTimeout = 1
  17.  
  18. NumTanks = 7
  19. Tanks = {"tk01", "tk02", "tk03", "tk04", "tkA1", "tkA2", "tkA3"}
  20. Fluid = {"oil", "oil", "oil", "oil", "stm", "gas", "dsl"}
  21. MxAmt = {6400, 6400, 6400, 6400, 6400, 6400, 6400}
  22. CrStp = {0, 0, 0, 0, 0, 0, 0}
  23. MxStp = {4, 4, 4, 4, 4, 4, 4}
  24.  
  25. MxOil = 0
  26. CrOil = 0
  27. MxStm = 0
  28. CrStm = 0
  29. MxGas = 0
  30. CrGas = 0
  31. MxDsl = 0
  32. CrDsl = 0
  33. print("Done")
  34.  
  35. function UpdateTurbine()
  36. print("Printing Rotor Speed")
  37. mon.setCursorPos(1,1)
  38. mon.write("Rotor Speed")
  39. speed = turbine.getRotorSpeed()
  40. speed = math.floor(speed)
  41. mon.setCursorPos(1,2)
  42. mon.write(tostring(speed).." RPM")
  43.  
  44. print("Printing Fluid Flow Rate")
  45. mon.setCursorPos(1,4)
  46. mon.write("Steam Flow")
  47. flow = turbine.getFluidFlowRate()
  48. mon.setCursorPos(1,5)
  49. mon.write(tostring(flow).." mb/t")
  50.  
  51. print("Printing Power Output")
  52. mon.setCursorPos(1,7)
  53. mon.write("Power Output")
  54. powerOut = turbine.getEnergyProducedLastTick()
  55. mon.setCursorPos(1,8)
  56. mon.write(tostring(math.floor(powerOut)).." RF/t")
  57. end
  58.  
  59. function UpdateFluids()
  60. print("Printing Oil Stat")
  61. mon.setCursorPos(16,1)
  62. mon.write("Oil")
  63. mon.setCursorPos(16,2)
  64. mon.write(tostring(math.floor(CrOil / MxOil * 100)).."% ~"..CrOil.." B")
  65.  
  66. print("Printing Gasoline Stat")
  67. mon.setCursorPos(16,4)
  68. mon.write("Gasoline")
  69. mon.setCursorPos(16,5)
  70. mon.write(tostring(math.floor(CrGas / MxGas * 100)).."% ~"..CrGas.." B")
  71.  
  72. print("Printing Diesel Stat")
  73. mon.setCursorPos(16,7)
  74. mon.write("Diesel")
  75. mon.setCursorPos(16,8)
  76. mon.write(tostring(math.floor(CrDsl / MxDsl * 100)).."% ~"..CrDsl.." B")
  77.  
  78. print("Printing Stem Stat")
  79. mon.setCursorPos(16,10)
  80. mon.write("Steam")
  81. mon.setCursorPos(16,11)
  82. mon.write(tostring(math.floor(CrStm / MxStm * 100)).."% ~"..CrStm.." B")
  83. end
  84.  
  85. write("Init Tank Max Vals ... ")
  86. for i = 1, NumTanks do
  87. if (Fluid[i] == "oil") then
  88. MxOil = MxOil + MxAmt[i]
  89. elseif (Fluid[i] == "stm") then
  90. MxStm = MxStm + MxAmt[i]
  91. elseif (Fluid[i] == "gas") then
  92. MxGas = MxGas + MxAmt[i]
  93. elseif (Fluid[i] == "dsl") then
  94. MxDsl = MxDsl + MxAmt[i]
  95. end
  96. end
  97. print("Done")
  98.  
  99. print("Begining Loop")
  100. while (true) do
  101. print("Clearing Values")
  102. CrOil = 0
  103. CrStm = 0
  104. CrGas = 0
  105. CrDsl = 0
  106.  
  107. for i = 1, NumTanks do
  108. print("Checking Tank "..Tanks[i])
  109. rednet.broadcast(Tanks[i], "tanks")
  110. print("Awaiting Response")
  111. senderID, msg, protocol = rednet.receive("tanks", TankTimeout)
  112. print("Received: "..msg)
  113. CrStp[i] = tonumber(msg) or 0
  114. if (Fluid[i] == "oil") then
  115. fPct = CrStp[i] / MxStp[i]
  116. aCty = fPct * MxAmt[i]
  117. CrOil = CrOil + aCty
  118. -- CrOil = CrOil + (CrStp[i] / MxStp[i] * MxAmt[i])
  119. elseif (Fluid[i] == "stm") then
  120. CrStm = CrStm + (CrStp[i] / MxStp[i] * MxAmt[i])
  121. elseif (Fluid[i] == "gas") then
  122. CrGas = CrGas + (CrStp[i] / MxStp[i] * MxAmt[i])
  123. elseif (Fluid[i] == "dsl") then
  124. CrDsl = CrDsl + (CrStp[i] / MxStp[i] * MxAmt[i])
  125. end
  126. end
  127.  
  128. mon.clear()
  129. UpdateTurbine()
  130. UpdateFluids()
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement