#24 coordinator/supervisor setting process groups and unit burn rate limits
This commit is contained in:
@@ -3,17 +3,102 @@ local rsio = require("scada-common.rsio")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local rsctl = require("supervisor.session.rsctl")
|
||||
local unit = require("supervisor.session.unit")
|
||||
|
||||
local HEATING_WATER = 20000
|
||||
local HEATING_SODIUM = 200000
|
||||
|
||||
-- 7.14 kJ per blade for 1 mB of fissile fuel
|
||||
local POWER_PER_BLADE = util.joules_to_fe(7140)
|
||||
|
||||
local function m_avg(length, default)
|
||||
local data = {}
|
||||
local index = 1
|
||||
local last_t = 0 ---@type number|nil
|
||||
|
||||
---@class moving_average
|
||||
local public = {}
|
||||
|
||||
-- reset all to a given value
|
||||
---@param x number value
|
||||
function public.reset(x)
|
||||
data = {}
|
||||
for _ = 1, length do table.insert(data, x) end
|
||||
end
|
||||
|
||||
-- record a new value
|
||||
---@param x number new value
|
||||
---@param t number? optional last update time to prevent duplicated entries
|
||||
function public.record(x, t)
|
||||
if type(t) == "number" and last_t == t then
|
||||
return
|
||||
end
|
||||
|
||||
data[index] = x
|
||||
last_t = t
|
||||
|
||||
index = index + 1
|
||||
if index > length then index = 1 end
|
||||
end
|
||||
|
||||
-- compute the moving average
|
||||
---@return number average
|
||||
function public.compute()
|
||||
local sum = 0
|
||||
for i = 1, length do sum = sum + data[i] end
|
||||
return sum
|
||||
end
|
||||
|
||||
public.reset(default)
|
||||
|
||||
return public
|
||||
end
|
||||
|
||||
---@alias PROCESS integer
|
||||
local PROCESS = {
|
||||
INACTIVE = 1,
|
||||
SIMPLE = 2,
|
||||
CHARGE = 3,
|
||||
GEN_RATE = 4,
|
||||
BURN_RATE = 5
|
||||
}
|
||||
|
||||
---@class facility_management
|
||||
local facility = {}
|
||||
|
||||
facility.PROCESS_MODES = PROCESS
|
||||
|
||||
-- create a new facility management object
|
||||
function facility.new()
|
||||
---@param num_reactors integer number of reactor units
|
||||
---@param cooling_conf table cooling configurations of reactor units
|
||||
function facility.new(num_reactors, cooling_conf)
|
||||
local self = {
|
||||
-- components
|
||||
units = {},
|
||||
induction = {},
|
||||
redstone = {}
|
||||
redstone = {},
|
||||
-- process control
|
||||
mode = PROCESS.INACTIVE,
|
||||
charge_target = 0, -- FE
|
||||
charge_rate = 0, -- FE/t
|
||||
charge_limit = 0.99, -- percentage
|
||||
burn_rate_set = 0,
|
||||
unit_limits = {},
|
||||
-- statistics
|
||||
im_stat_init = false,
|
||||
avg_charge = m_avg(10, 0.0),
|
||||
avg_inflow = m_avg(10, 0.0),
|
||||
avg_outflow = m_avg(10, 0.0)
|
||||
}
|
||||
|
||||
-- create units
|
||||
for i = 1, num_reactors do
|
||||
table.insert(self.units, unit.new(i, cooling_conf[i].BOILERS, cooling_conf[i].TURBINES))
|
||||
|
||||
local u_lim = { burn_rate = -1.0, temp = 1100 } ---@class unit_limit
|
||||
table.insert(self.unit_limits, u_lim)
|
||||
end
|
||||
|
||||
-- init redstone RTU I/O controller
|
||||
local rs_rtu_io_ctl = rsctl.new(self.redstone)
|
||||
|
||||
@@ -58,6 +143,13 @@ function facility.new()
|
||||
_unlink_disconnected_units(self.redstone)
|
||||
end
|
||||
|
||||
function public.update_units()
|
||||
for i = 1, #self.units do
|
||||
local u = self.units[i] ---@type reactor_unit
|
||||
u.update()
|
||||
end
|
||||
end
|
||||
|
||||
-- READ STATES/PROPERTIES --
|
||||
|
||||
-- get build properties of all machines
|
||||
@@ -94,6 +186,10 @@ function facility.new()
|
||||
return status
|
||||
end
|
||||
|
||||
function public.get_units()
|
||||
return self.units
|
||||
end
|
||||
|
||||
return public
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user