cleanup and constants

This commit is contained in:
Mikayla Fischler 2024-04-10 22:16:41 -04:00
parent a6a1a61954
commit dfc1ee6497
4 changed files with 34 additions and 15 deletions

View File

@ -84,4 +84,17 @@ constants.EXTREME_RADIATION = 100.0
--#endregion
--#region Mekanism Configuration Constants
---@class _mek_constants
local mek = {}
mek.TURBINE_GAS_PER_TANK = 64000 -- mekanism: turbineGasPerTank
mek.TURBINE_DISPERSER_FLOW = 1280 -- mekanism: turbineDisperserGasFlow
mek.TURBINE_VENT_FLOW = 32000 -- mekanism: turbineVentGasFlow
constants.mek = mek
--#endregion
return constants

View File

@ -500,7 +500,7 @@ function facility.new(num_reactors, cooling_conf)
self.saturated = output ~= out_c
-- stop idling early if the output is zero, we are at or above the setpoint, and are not losing charge
_set_idling(not ((out_c == 0) and (error <= 0) and (avg_outflow < avg_inflow)))
_set_idling(not ((out_c == 0) and (error <= 0) and (avg_outflow <= 0)))
-- log.debug(util.sprintf("CHARGE[%f] { CHRG[%f] ERR[%f] INT[%f] => OUT[%f] OUT_C[%f] <= P[%f] I[%f] D[%f] }",
-- runtime, avg_charge, error, integral, output, out_c, P, I, D))

View File

@ -255,14 +255,13 @@ function unit.new(reactor_id, num_boilers, num_turbines)
end
-- init turbine table fields
for t = 1, num_turbines do
for _ = 1, num_turbines do
table.insert(self.db.annunciator.TurbineOnline, false)
table.insert(self.db.annunciator.SteamDumpOpen, TRI_FAIL.OK)
table.insert(self.db.annunciator.TurbineOverSpeed, false)
table.insert(self.db.annunciator.GeneratorTrip, false)
table.insert(self.db.annunciator.TurbineTrip, false)
self.turbine_stability_data[t] = { time_state = 0, time_tanks = 0, rotation = 1 }
table.insert(self.turbine_stability_data, { time_state = 0, time_tanks = 0, rotation = 1 })
end
-- PRIVATE FUNCTIONS --
@ -542,6 +541,13 @@ function unit.new(reactor_id, num_boilers, num_turbines)
-- re-engage auto lock if it reconnected without it
if self.auto_engaged and not self.plc_i.is_auto_locked() then self.plc_i.auto_lock(true) end
-- stop idling when completed
if self.auto_idling and ((util.time_ms() - self.auto_idle_start) > IDLE_TIME) then
log.info(util.c("UNIT ", self.r_id, ": completed idling period"))
self.auto_idling = false
self.plc_i.auto_set_burn(0, false)
end
end
-- update deltas
@ -591,9 +597,9 @@ function unit.new(reactor_id, num_boilers, num_turbines)
end
-- set automatic control idling mode to change behavior when given a burn rate command of zero<br>
-- - enabling will hold the reactor at 0.01 mB/t for a period before disabling when commanded zero
-- - disabling will stop the reactor when commanded zero
---@param idle boolean true to enable, false to disable and stop right away
-- - enabling it will hold the reactor at 0.01 mB/t for a period when commanded zero before disabling
-- - disabling it will stop the reactor when commanded zero
---@param idle boolean true to enable, false to disable (and stop)
function public.auto_set_idle(idle)
if not (idle and self.auto_idle) then
self.auto_idling = false

View File

@ -44,9 +44,9 @@ local logic = {}
local function turbine_rotation(turbine)
local build = turbine.build
local inner_vol = build.steam_cap / 64000
local disp_rate = (build.dispersers * 1280) * inner_vol
local vent_rate = build.vents * 32000
local inner_vol = build.steam_cap / const.mek.TURBINE_GAS_PER_TANK
local disp_rate = (build.dispersers * const.mek.TURBINE_DISPERSER_FLOW) * inner_vol
local vent_rate = build.vents * const.mek.TURBINE_VENT_FLOW
local max_rate = math.min(disp_rate, vent_rate)
local flow = math.min(max_rate, turbine.tanks.steam.amount)