Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Includes
- local component = require("component")
- local term = require("term")
- --Capacitor Variables
- local capacitor = component.capacitor_bank
- local cap_store, cap_max, cap_avg
- local low_trigger = 0.2
- --Reactor Variables
- local reactor = component.br_reactor
- local rea_steam, rea_fuel, rea_rea
- --Turbine Variables
- local turbines = {}
- for temp, _ in pairs(component.list("br_turbine")) do
- table.insert (turbines, component.proxy(temp))
- end
- local tur_high_trig = 1900
- local tur_target = 1840
- local tur_low_trig = 1600
- --Init the turbines
- for t, turbine in pairs(turbines) do
- turbine.setActive (true)
- turbine.setInductorEngaged (false)
- end
- --General Variables
- local gpu = component.gpu
- local w, h = gpu.getResolution ()
- local run = true
- local total_power
- local charging = true
- function updateData ()
- cap_store = capacitor.getEnergyStored ()
- cap_max = capacitor.getMaxEnergyStored ()
- cap_avg = capacitor.getAverageChangePerTick ()
- rea_steam = reactor.getHotFluidProducedLastTick ()
- rea_fuel = reactor.getFuelAmount ()
- rea_fuel_max = reactor.getFuelAmountMax ()
- rea_waste = reactor.getWasteAmount ()
- rea_consum = reactor.getFuelConsumedLastTick ()
- rea_reac = reactor.getFuelReactivity ()
- total_power = 0;
- for t, turbine in pairs(turbines) do
- total_power = total_power + turbine.getEnergyProducedLastTick()
- end
- end
- function reactorControl ()
- --Charge until full
- if (reactor.getActive ()) then
- if (cap_store == cap_max) then
- charging = false
- end
- end
- --If power low start charging again
- if (cap_store < (cap_max * low_trigger)) then
- charging = true
- reactor.setActive (true)
- end
- --setActive
- --setAllControlRodLevel
- end
- function turbineControl ()
- local highest_rpm = 0
- local lowest_rpm = 10000
- for t, turbine in pairs(turbines) do
- if (charging) then
- --If we are charging, spin up the rotors to the target speed and engage coils
- if ((turbine.getRotorSpeed() >= tur_target) and (turbine.getInductorEngaged (false))) then
- turbine.setInductorEngaged (true)
- elseif ((turbine.getRotorSpeed() < tur_low_trig) and (turbine.getInductorEngaged (true))) then
- turbine.setInductorEngaged (false)
- reactor.setActive (false)
- end
- else
- --Otherwise get the highest and lowest rpm
- if (turbine.getRotorSpeed () > highest_rpm) then
- highest_rpm = turbine.getRotorSpeed ()
- end
- if (turbine.getRotorSpeed () < lowest_rpm) then
- lowest_rpm = turbine.getRotorSpeed ()
- end
- end
- end
- --If not charging control the reactor to keep the turbine spun up
- if (charging == false) then
- if (highest_rpm > tur_high_trig) then
- reactor.setActive (true)
- elseif (lowest_rpm < tur_low_trig) then
- reactor.setActive (false)
- end
- end
- --setActive
- --setInductorEngaged
- end
- function renderGUI ()
- --gpu.fill (1, 1, w, h, " ")
- term.clear()
- print ("Capacitor")
- print ("---------")
- print ("Stored: " .. cap_store .. " / " .. cap_max)
- print ("Power Change: " .. cap_avg)
- print ("")
- print ("Reactor")
- print ("-------")
- print ("Steam: " .. rea_steam .. " / 10000")
- print ("Fuel Use: " .. rea_consum)
- print ("Reactivity: " .. rea_reac)
- print ("")
- --for x,t in pairs(turbines) do
- for t, turbine in pairs(turbines) do
- --local turbine = component.proxy(x)
- print ("Turbine " .. t)
- print ("---------")
- print ("Speed: " .. turbine.getRotorSpeed())
- print ("Steam: " .. turbine.getFluidFlowRate())
- print ("Power: " .. turbine.getEnergyProducedLastTick())
- print ("Stored: " .. turbine.getEnergyStored())
- print ("")
- end
- end
- while (run) do
- updateData ()
- renderGUI ()
- os.sleep (1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement