From dfc1ee64974ff03d5dfc46eb8c5e4755382376f4 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 10 Apr 2024 22:16:41 -0400 Subject: [PATCH] cleanup and constants --- scada-common/constants.lua | 23 ++++++++++++++++++----- supervisor/facility.lua | 2 +- supervisor/unit.lua | 18 ++++++++++++------ supervisor/unitlogic.lua | 6 +++--- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/scada-common/constants.lua b/scada-common/constants.lua index 8f5d12f..20925bd 100644 --- a/scada-common/constants.lua +++ b/scada-common/constants.lua @@ -75,12 +75,25 @@ constants.FLOW_STABILITY_DELAY_MS = 10000 -- - background radiation 0.0000001 Sv/h (99.99 nSv/h) -- - "green tint" radiation 0.00001 Sv/h (10 uSv/h) -- - damaging radiation 0.00006 Sv/h (60 uSv/h) -constants.LOW_RADIATION = 0.00001 -constants.HAZARD_RADIATION = 0.00006 -constants.HIGH_RADIATION = 0.001 +constants.LOW_RADIATION = 0.00001 +constants.HAZARD_RADIATION = 0.00006 +constants.HIGH_RADIATION = 0.001 constants.VERY_HIGH_RADIATION = 0.1 -constants.SEVERE_RADIATION = 8.0 -constants.EXTREME_RADIATION = 100.0 +constants.SEVERE_RADIATION = 8.0 +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 diff --git a/supervisor/facility.lua b/supervisor/facility.lua index b7900f7..40e8002 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -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)) diff --git a/supervisor/unit.lua b/supervisor/unit.lua index 1472fa7..88fcfb9 100644 --- a/supervisor/unit.lua +++ b/supervisor/unit.lua @@ -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
- -- - 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 diff --git a/supervisor/unitlogic.lua b/supervisor/unitlogic.lua index bc60dfa..4be004b 100644 --- a/supervisor/unitlogic.lua +++ b/supervisor/unitlogic.lua @@ -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)