Advertisement
rbooks

OpenComputers Big Reactor Manager

Jul 27th, 2015
3,576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. ----------------------
  2. -- BR_Mgr - a high efficiency Big Reactors control program for
  3. -- OpenComputers v5.2.3
  4. -- by RBooks (PoopLooskey)
  5. -- version: 0.1a
  6. --
  7. -- This program optimizes a *Passive Only* Big Reactors reactor.
  8. -- It relies on settings you have to calculate externally and
  9. -- congifure in the settings (specifically oCRI)
  10. --
  11. -- To find your omptimal insertion level goto br.sidoh.org
  12. -- and create an exact simulation of your reactor.
  13. -- Then goto the controls tab and click the Optimize button to see
  14. -- what the optimal Control Rod Insertion level is for your build.
  15. --
  16. -- Tested in TPPI2 server at tppi.devcoftb.net
  17. -- Big thanks to all those who contribute to:
  18. -- TPPI, Big Reactors, OpenComputers and DeVcoFTB
  19. --
  20. -- Special thanks to Kai Kikuchi for providing the framework on
  21. -- which this script was developed (functions are mostly his)
  22. -- Kai's SafeReactor.lua script is at http://pastebin.com/k40ktpxK
  23. ----------------------
  24.  
  25. -- Config settings
  26. -- The two main settings oCRI or optimal Control Rod Insertion level and
  27. -- mCRI your insertion level for high energy usage periods (when you need a lot of power)
  28. -- for oCRI goto br.sidoh.org and simulate your reactor design to see what the optimal level is
  29. -- for mCRI you should just figure out what insertion level you need to produce 80-90% of the maximum
  30. -- energy production for you design. This value should be around halfway between 0 and the oCRI
  31. local oCRI = 85 -- Optimal Control Rod Insertion level from br.sidoh.org
  32. local mCRI = oCRI*.58 -- Insertion level for max production (what insertion level)
  33. local maxPrdLmt = 10 -- battery level needed to kick into high production mode
  34. local avgPrdLmt = 20 -- Normal battery level for the reactor to start charging
  35. local offPrdLmt = 98 -- Battery level that will cause it to stop charging
  36.  
  37. ----------------------
  38. local event = require "event"
  39. local comp=require("component")
  40. local term=require("term")
  41. local r=comp.getPrimary("br_reactor")
  42.  
  43. -- Initialize reactor to idle state
  44. r.setAllControlRodLevels(100)
  45. chargeStatus = "Idle."
  46.  
  47. -- global variables
  48. energyStored=0
  49. energyProduced=0
  50. energyProducedMax=0
  51. totalEnergyStored=0
  52. brEfficiency=0
  53.  
  54. running=true
  55.  
  56. -- functions
  57. local function round(num, idp)
  58. local mult = 10^(idp or 0)
  59. return math.floor(num * mult + 0.5) / mult
  60. end
  61.  
  62. local function rfkrf(rf)
  63. if rf >= 1000 then
  64. return round(rf/1000, 2).." kRF"
  65. else
  66. return rf.." RF"
  67. end
  68. end
  69.  
  70. function unknownEvent()
  71. end
  72.  
  73. local events = setmetatable({}, { __index = function() return unknownEvent end })
  74.  
  75.  
  76. function events.key_up(adress, char, code, playerName)
  77. if (char == 3) then
  78. running = false
  79. end
  80. end
  81.  
  82. function handleEvent(eventID, ...)
  83. if (eventID) then
  84. events[eventID](...)
  85. end
  86. end
  87.  
  88. -- main
  89. term.clear()
  90. term.write("Initialization...")
  91.  
  92. local intTick=18;
  93. event.listen("key_up", handleEvent)
  94.  
  95. casingTemp=round(r.getCasingTemperature(), 0)
  96.  
  97. while running do
  98. lastEnergyStored=energyStored
  99. energyStored=r.getEnergyStored()
  100.  
  101. bufferPercent=round(energyStored/100000, 2)
  102.  
  103. energyProduced=r.getEnergyProducedLastTick()
  104. energyOutput=(lastEnergyStored-energyStored+energyProduced)
  105. brEfficiency = r.getEnergyProducedLastTick() / r.getFuelConsumedLastTick()
  106.  
  107. if bufferPercent < maxPrdLmt then
  108. r.setAllControlRodLevels(mCRI)
  109. chargeStatus = "Charging - MAX"
  110. elseif bufferPercent < avgPrdLmt then
  111. r.setAllControlRodLevels(oCRI)
  112. chargeStatus = "Charging"
  113. elseif bufferPercent < offPrdLmt then
  114. if chargeStatus == "Charging" then
  115. r.setAllControlRodLevels(oCRI)
  116. end
  117. elseif bufferPercent >= offPrdLmt then
  118. r.setAllControlRodLevels(100)
  119. chargeStatus = "Idle.."
  120. end
  121.  
  122. -- if energyProduced > energyProducedMax then
  123. energyProducedMax = energyProduced
  124. -- end
  125.  
  126. if intTick>=20 then
  127. -- comp.getPrimary("gpu").setResolution(30, 10)
  128. term.clear()
  129. term.write("Heat (int|ext):\t"..round(r.getFuelTemperature()).."C|"..round(r.getCasingTemperature()).."C\n")
  130. term.write("Buffer:\t\t".. round(bufferPercent,2).. " %\n")
  131. term.write("Power Usage:\t".. rfkrf(energyOutput).. "\n")
  132. -- term.write("Max Output:\t".. rfkrf(energyProducedMax).. "\n")
  133. term.write("Fuel Used:\t".. round(r.getFuelConsumedLastTick(), 3).. " mB\n")
  134. term.write("Energy Made:\t".. round(r.getEnergyProducedLastTick(), 0).. " RF\n")
  135. term.write("\n")
  136. term.write("Insertion: \t".. r.getControlRodLevel(1) .. "%\n")
  137. if r.getFuelConsumedLastTick() > 0 then
  138. term.write("Efficiency:\t".. round(brEfficiency,0).." RF/mB\n")
  139. else
  140. term.write("Efficiency:\t0 RF/mB\n")
  141. end
  142. term.write("Status:\t\t".. chargeStatus .."\n")
  143. term.write("\n[Press Ctrl+C to exit program]\n")
  144. intTick=0
  145. else
  146. if intTick==20 then
  147. term.clear()
  148. term.write("not connected")
  149. end
  150. end
  151.  
  152. intTick=intTick+1;
  153. os.sleep(.05)
  154. end -- do while
  155.  
  156. term.clear()
  157. print("BR_Mgr closed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement