Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require "component"
- --component wrapping
- local gpu = com.gpu
- local capacitorBank = com.capacitor_bank
- local R = com.br_reactor
- local insertionHigh = 95 -- high control rod level
- local insertionLow = 64 -- low control rod level
- local hotPoint 400 -- point where reactor gets forced shut down from over heating
- R.setAllControlRodLevels(insertionLow)
- --used varriables
- local addList = {} --Stores list of turbine address
- --Populates addList tabel with turbine address
- local a = 1
- for k, v in com.list("br_turbine") do
- addList[a] = k
- a = a + 1
- end
- local allData = {}
- allData["turbine"] = {}
- allData["reactor"] = {}
- allData["capacitor"] = {}
- local function rpm(num)
- allData["turbine"][num]={}
- local turbineRPM = com.invoke(addList[num], "getRotorSpeed")
- if turbineRPM < 1798 then --keeps the turbines spinning at 1800 rpm even if steam flow rate is very low
- com.invoke(addList[num], "setInductorEngaged", false)
- allData["turbine"][num]["state"] = "Inactive"
- else
- com.invoke(addList[num], "setInductorEngaged", true)
- allData["turbine"][num]["state"] = "Active"
- end
- allData["turbine"][num]["RPM"] = turbineRPM
- end
- local function steam(num)
- allData["turbine"][num]["FluidRate"] = com.invoke(addList[num], "getFluidFlowRate")
- end
- local function reactorHeat()
- local heat = R.getCasingTemperature()
- local capEnergy = capacitorBank.getEnergyStored()
- --simple control if the energy level of my capacitors reaches below 80% it adjusts the rector control rods to be less inserted
- --if the stored power is above 93% then it adjusts the control rods to be more inserted
- allData["capacitor"] = capEnergy
- capEnergy = capEnergy/1000000000
- if capEnergy <.8 then
- R.setActive(true)
- R.setAllControlRodLevels(insertionLow)
- elseif capEnergy > 0.93 then
- R.setAllControlRodLevels(insertionHigh)
- end
- --keeps reactor from getting to hot if the steam is backed up
- if heat > hotPoint then
- R.setActive(false)
- end
- allData["reactor"]["temp"] = heat
- if R.getActive() == true then
- allData["reactor"]["state"] = "Active"
- else
- allData["reactor"]["state"] = "Inactive"
- end
- allData["reactor"]["FluidRate"] = R.getHotFluidProducedLastTick()
- allData["reactor"]["controlRodLevel"] = R.getControlRodLevel(1)
- end
- local function turbine()
- for i = 1, (a-1) do
- rpm(i)
- steam(i)
- end
- end
- -- prints all contents of a passed tabel
- function print_r ( t )
- local print_r_cache={}
- local function sub_print_r(t,indent)
- if (print_r_cache[tostring(t)]) then
- print(indent.."*"..tostring(t))
- else
- print_r_cache[tostring(t)]=true
- if (type(t)=="table") then
- for pos,val in pairs(t) do
- if (type(val)=="table") then
- print(indent.."["..pos.."] => "..tostring(t).." {")
- sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
- print(indent..string.rep(" ",string.len(pos)+6).."}")
- elseif (type(val)=="string") then
- print(indent.."["..pos..'] => "'..val..'"')
- else
- print(indent.."["..pos.."] => "..tostring(val))
- end
- end
- else
- print(indent..tostring(t))
- end
- end
- end
- if (type(t)=="table") then
- print(tostring(t).." {")
- sub_print_r(t," ")
- print("}")
- else
- sub_print_r(t," ")
- end
- print()
- end
- local function Data()
- print_r(allData)
- allData = {}
- allData["turbine"] = {}
- allData["reactor"] = {}
- allData["capacitor"] = {}
- end
- while true do
- turbine()
- reactorHeat()
- Data()
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement