Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------
- -- BR_Mgr - a high efficiency Big Reactors control program for
- -- OpenComputers v5.2.3
- -- by RBooks (PoopLooskey)
- -- version: 0.1a
- --
- -- This program optimizes a *Passive Only* Big Reactors reactor.
- -- It relies on settings you have to calculate externally and
- -- congifure in the settings (specifically oCRI)
- --
- -- To find your omptimal insertion level goto br.sidoh.org
- -- and create an exact simulation of your reactor.
- -- Then goto the controls tab and click the Optimize button to see
- -- what the optimal Control Rod Insertion level is for your build.
- --
- -- Tested in TPPI2 server at tppi.devcoftb.net
- -- Big thanks to all those who contribute to:
- -- TPPI, Big Reactors, OpenComputers and DeVcoFTB
- --
- -- Special thanks to Kai Kikuchi for providing the framework on
- -- which this script was developed (functions are mostly his)
- -- Kai's SafeReactor.lua script is at http://pastebin.com/k40ktpxK
- ----------------------
- -- Config settings
- -- The two main settings oCRI or optimal Control Rod Insertion level and
- -- mCRI your insertion level for high energy usage periods (when you need a lot of power)
- -- for oCRI goto br.sidoh.org and simulate your reactor design to see what the optimal level is
- -- for mCRI you should just figure out what insertion level you need to produce 80-90% of the maximum
- -- energy production for you design. This value should be around halfway between 0 and the oCRI
- local oCRI = 85 -- Optimal Control Rod Insertion level from br.sidoh.org
- local mCRI = oCRI*.58 -- Insertion level for max production (what insertion level)
- local maxPrdLmt = 10 -- battery level needed to kick into high production mode
- local avgPrdLmt = 20 -- Normal battery level for the reactor to start charging
- local offPrdLmt = 98 -- Battery level that will cause it to stop charging
- ----------------------
- local event = require "event"
- local comp=require("component")
- local term=require("term")
- local r=comp.getPrimary("br_reactor")
- -- Initialize reactor to idle state
- r.setAllControlRodLevels(100)
- chargeStatus = "Idle."
- -- global variables
- energyStored=0
- energyProduced=0
- energyProducedMax=0
- totalEnergyStored=0
- brEfficiency=0
- running=true
- -- functions
- local function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- local function rfkrf(rf)
- if rf >= 1000 then
- return round(rf/1000, 2).." kRF"
- else
- return rf.." RF"
- end
- end
- function unknownEvent()
- end
- local events = setmetatable({}, { __index = function() return unknownEvent end })
- function events.key_up(adress, char, code, playerName)
- if (char == 3) then
- running = false
- end
- end
- function handleEvent(eventID, ...)
- if (eventID) then
- events[eventID](...)
- end
- end
- -- main
- term.clear()
- term.write("Initialization...")
- local intTick=18;
- event.listen("key_up", handleEvent)
- casingTemp=round(r.getCasingTemperature(), 0)
- while running do
- lastEnergyStored=energyStored
- energyStored=r.getEnergyStored()
- bufferPercent=round(energyStored/100000, 2)
- energyProduced=r.getEnergyProducedLastTick()
- energyOutput=(lastEnergyStored-energyStored+energyProduced)
- brEfficiency = r.getEnergyProducedLastTick() / r.getFuelConsumedLastTick()
- if bufferPercent < maxPrdLmt then
- r.setAllControlRodLevels(mCRI)
- chargeStatus = "Charging - MAX"
- elseif bufferPercent < avgPrdLmt then
- r.setAllControlRodLevels(oCRI)
- chargeStatus = "Charging"
- elseif bufferPercent < offPrdLmt then
- if chargeStatus == "Charging" then
- r.setAllControlRodLevels(oCRI)
- end
- elseif bufferPercent >= offPrdLmt then
- r.setAllControlRodLevels(100)
- chargeStatus = "Idle.."
- end
- -- if energyProduced > energyProducedMax then
- energyProducedMax = energyProduced
- -- end
- if intTick>=20 then
- -- comp.getPrimary("gpu").setResolution(30, 10)
- term.clear()
- term.write("Heat (int|ext):\t"..round(r.getFuelTemperature()).."C|"..round(r.getCasingTemperature()).."C\n")
- term.write("Buffer:\t\t".. round(bufferPercent,2).. " %\n")
- term.write("Power Usage:\t".. rfkrf(energyOutput).. "\n")
- -- term.write("Max Output:\t".. rfkrf(energyProducedMax).. "\n")
- term.write("Fuel Used:\t".. round(r.getFuelConsumedLastTick(), 3).. " mB\n")
- term.write("Energy Made:\t".. round(r.getEnergyProducedLastTick(), 0).. " RF\n")
- term.write("\n")
- term.write("Insertion: \t".. r.getControlRodLevel(1) .. "%\n")
- if r.getFuelConsumedLastTick() > 0 then
- term.write("Efficiency:\t".. round(brEfficiency,0).." RF/mB\n")
- else
- term.write("Efficiency:\t0 RF/mB\n")
- end
- term.write("Status:\t\t".. chargeStatus .."\n")
- term.write("\n[Press Ctrl+C to exit program]\n")
- intTick=0
- else
- if intTick==20 then
- term.clear()
- term.write("not connected")
- end
- end
- intTick=intTick+1;
- os.sleep(.05)
- end -- do while
- term.clear()
- print("BR_Mgr closed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement