Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SELF-REGULATING BIG REACTOR: ITERATION FOUR
- -- Determines the most efficient control rod setting for actively-cooled reactor to produce 2000 mB/t of steam
- -- Brings a Big Reactor / Turbine pair up to running speed of 1830 RPM from cold
- -- When reactor is at running speed, will produce power until your power storage is full
- -- When batteries are full, keeps the turbine spinning at or above 1830 RPM until power is needed again
- -- Utilizes redstone signal to bottom of computer to signify low / high energy in batteries (I use a Power Monitor from EnderIO)
- -- No monitor necessary, as there are no controls or displays - it simply detects your setup and keeps it running smoothly.
- -- This program will function with any reactor / turbine pair capable of steady operation at 1800-1830 RPM. No other requirements.
- -- Create optional display which only appears if a monitor is wrapped. A monitor will never be necessary for this program.
- reactor = peripheral.find("BigReactors-Reactor")
- turbine = peripheral.find("BigReactors-Turbine")
- local function round(someNumber) -- simple rounding function to obtain integers.
- result = math.floor(someNumber + 0.5)
- return result
- end
- local function passiveMaintain()
- print("Engaging Passive Maintain Mode.")
- reactor.setActive(true)
- while true do
- sleep(1)
- local i = round(reactor.getEnergyStored() / 100000) -- converts the reactor's stored energy buffer to an integer between 1-100.
- local energyProd = reactor.getEnergyProducedLastTick()
- reactor.setAllControlRodLevels(i)
- term.clear()
- term.setCursorPos(1,1)
- print("Passively Cooled Reactor Detected. Rod Insertion Control Engaged.")
- term.setCursorPos(1,2)
- print("Control Rods set at " ..i.. "%.")
- term.setCursorPos(1,3)
- print("Output: " ..energyProd.. " RF/t.")
- end
- end
- local roughGuess = 0 -- floating variable for rough guesses of the optimal rod insertion. (via the adjustRods() function)
- local nextGuess = 0 -- floating variable for more accurate guesses of optimal control rod insertion.
- local function tooLow() -- runs when the roughGuess variable ends up sending too little steam to the turbine.
- while reactor.getHotFluidProducedLastTick() <= 2000 do
- nextGuess = roughGuess - 1
- print("Low Output. Trying " ..nextGuess.. "%.")
- reactor.setActive(false)
- sleep(2) -- small sleep with the reactor off to let its steam tank empty
- reactor.setAllControlRodLevels(nextGuess)
- reactor.setActive(true)
- sleep(4) -- small sleep to let the reactor build up to full steam production
- local finalProd = reactor.getHotFluidProducedLastTick()
- print("Steam Production: " ..finalProd.. " mB/t.")
- roughGuess = roughGuess - 1
- end
- end
- local function tooHigh() -- runs when the roughGuess variable ends up sending too much steam to the turbine.
- while reactor.getHotFluidProducedLastTick() >= 2000 do
- nextGuess = roughGuess + 1
- print("High Output. Trying " ..nextGuess.. "%.")
- reactor.setActive(false)
- sleep(2) -- small sleep with the reactor off to let its steam tank empty
- reactor.setAllControlRodLevels(nextGuess)
- reactor.setActive(true)
- sleep(4) -- small sleep to let the reactor build up to full steam production
- local finalProd = reactor.getHotFluidProducedLastTick()
- print("Steam Production: " ..finalProd.. " mB/t.")
- roughGuess = roughGuess + 1
- end
- end
- local function adjustRods() --main function for determining optimal control rod insertion level
- turbine.setActive(true) -- makes sure the turbine is draining steam from the reactor
- turbine.setInductorEngaged(true) -- makes sure the turbine does not spin too quickly while active
- reactor.setActive(false)
- if reactor.getFuelTemperature() >= 100 then -- brings reactor under boiling temp to increase reading accuracy
- print("Please wait while reactor cools down...")
- while reactor.getFuelTemperature() >= 100 do
- sleep(1)
- end
- end
- reactor.setAllControlRodLevels(99) -- sets rods to 99% in order to better predict steam output incrementally
- reactor.setActive(true)
- print("Reactor below 100C. Control Rods set to 99%.")
- print("Waiting for measurement...")
- while reactor.getFuelTemperature() <= 100 do
- sleep(1) -- sleeps to make sure the reactor is fully powered up before measuring steam output
- end
- sleep(5)
- local steamProd = reactor.getHotFluidProducedLastTick() -- first measurement of steam production, at 99% rod insertion
- print("Steam Production: " ..steamProd.. " mB/t.")
- local middleman = 2000 / steamProd -- to determine roughly how much steam is produced per % insertion
- local inverseLevel = round(middleman) -- gets the inverse integer for the roughGuess variable
- print("Rounding to " ..inverseLevel)
- if inverseLevel < 1 then
- inverseLevel = 1
- print("Steam output too low! Setting inverseLevel to 1.")
- roughGuess = 100 - inverseLevel -- first guess of what the optimal control rod insertion level might be
- print("First guess for optimal control rod level is " ..roughGuess.. "%.")
- reactor.setAllControlRodLevels(roughGuess)
- print("Setting all control rods to " ..roughGuess.. "%.")
- sleep(3) -- once again, a sleep to make sure the steam production reading is stable and accurate
- local finalProd = reactor.getHotFluidProducedLastTick()
- print("Steam Production: " ..finalProd.. " mB/t.")
- tooLow() -- this order of functions (low, high, low) ensures that the final result is just over 2000 mB/t of steam.
- tooHigh()
- tooLow()
- print("Optimum Rod Insertion: " ..nextGuess.. "%.")
- end
- local function charge() -- spins turbine up to full-speed and then produces power until redstone signal to computer turns off
- reactor.setActive(true)
- turbine.setInductorEngaged(false)
- while turbine.getRotorSpeed() < 1830 do
- local rotorSpeed = round(turbine.getRotorSpeed())
- term.clear()
- term.setCursorPos(1,1)
- print("Spinning Up Turbine: " ..rotorSpeed.. " RPM")
- sleep(1)
- end
- turbine.setInductorEngaged(true)
- while rs.getInput("bottom") do
- local rotorSpeed = round(turbine.getRotorSpeed())
- local energyRate = round(turbine.getEnergyProducedLastTick())
- term.clear()
- term.setCursorPos(1,1)
- print("Inductors Engaged!")
- term.setCursorPos(1,2)
- print("Turbine Speed: " ..rotorSpeed.. " RPM")
- term.setCursorPos(1,3)
- print("Output: " ..energyRate.. " RF/t")
- sleep(1)
- end
- end
- local function activeMaintain() -- no power produced, but keeps the turbine spinning full-speed at a negligible expense of yellorium
- while not rs.getInput("bottom") do
- sleep(1)
- while turbine.getRotorSpeed() <= 1830 do
- if turbine.getInductorEngaged() == true then
- turbine.setInductorEngaged(false)
- end
- if reactor.getActive() == false then
- reactor.setActive(true)
- end
- local rotorSpeed = round(turbine.getRotorSpeed())
- term.clear()
- term.setCursorPos(1,1)
- print("Turbine Velocity Low.")
- term.setCursorPos(1,2)
- print("Spooling: " ..rotorSpeed.. " RPM")
- sleep(1)
- end
- if turbine.getRotorSpeed() >= 1830 and reactor.getActive() == true then
- reactor.setActive(false)
- end
- local rotorSpeed = round(turbine.getRotorSpeed())
- term.clear()
- term.setCursorPos(1,1)
- print("Turbine Velocity Stable.")
- term.setCursorPos(1,2)
- print("Sleeping at " ..rotorSpeed.. " RPM")
- end
- end
- end
- -- EXECUTION --
- print("Detecting reactor: " ..tostring(reactor.getConnected()))
- print("Reactor Passively Cooled: " ..tostring(reactor.isActivelyCooled()))
- if reactor.isActivelyCooled() == false then
- passiveMaintain()
- end
- adjustRods()
- while true do
- sleep(1)
- if rs.getInput("bottom") then
- charge()
- end
- if not rs.getInput("bottom") then
- activeMaintain()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement