Skip to content

Commit

Permalink
#480 updated aux coolant logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaylaFischler committed Feb 25, 2025
1 parent d45f19c commit 2b73196
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions scada-common/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ local rs = {}

rs.IMATRIX_CHARGE_LOW = 0.05 -- activation threshold (less than) for F_MATRIX_LOW
rs.IMATRIX_CHARGE_HIGH = 0.95 -- activation threshold (greater than) for F_MATRIX_HIGH
rs.AUX_COOL_ENABLE = 0.60 -- actiation threshold (less than or equal) for U_AUX_COOL
rs.AUX_COOL_DISABLE = 1.00 -- deactivation threshold (greater than or equal) for U_AUX_COOL

constants.RS_THRESHOLDS = rs

Expand Down
1 change: 1 addition & 0 deletions supervisor/unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function unit.new(reactor_id, num_boilers, num_turbines, ext_idle, aux_coolant)
damage_est_last = 0,
waste_product = WASTE.PLUTONIUM, ---@type WASTE_PRODUCT
status_text = { "UNKNOWN", "awaiting connection..." },
enable_aux_cool = false,
-- logic for alarms
had_reactor = false,
turbine_flow_stable = false,
Expand Down
23 changes: 19 additions & 4 deletions supervisor/unitlogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local FLOW_STABILITY_DELAY_MS = const.FLOW_STABILITY_DELAY_MS

local ANNUNC_LIMS = const.ANNUNCIATOR_LIMITS
local ALARM_LIMS = const.ALARM_LIMITS
local RS_THRESH = const.RS_THRESHOLDS

---@class unit_logic_extension
local logic = {}
Expand All @@ -54,6 +55,10 @@ function logic.update_annunciator(self)
-- variables for boiler, or reactor if no boilers used
local total_boil_rate = 0.0

-- auxiliary coolant control
local need_aux_cool = false
local dis_aux_cool = true

--#region Reactor

annunc.AutoControl = self.auto_engaged
Expand Down Expand Up @@ -148,6 +153,9 @@ function logic.update_annunciator(self)
-- if no boilers, use reactor heating rate to check for boil rate mismatch
if num_boilers == 0 then
total_boil_rate = plc_db.mek_status.heating_rate

need_aux_cool = plc_db.mek_status.ccool_fill <= RS_THRESH.AUX_COOL_ENABLE
dis_aux_cool = plc_db.mek_status.ccool_fill >= RS_THRESH.AUX_COOL_DISABLE
end
else
self.plc_cache.ok = false
Expand Down Expand Up @@ -215,6 +223,9 @@ function logic.update_annunciator(self)

annunc.BoilerOnline[idx] = true
annunc.WaterLevelLow[idx] = boiler.tanks.water_fill < ANNUNC_LIMS.WaterLevelLow

need_aux_cool = need_aux_cool or (boiler.tanks.water_fill <= RS_THRESH.AUX_COOL_ENABLE)
dis_aux_cool = dis_aux_cool and (boiler.tanks.water_fill >= RS_THRESH.AUX_COOL_DISABLE)
end

-- check heating rate low
Expand Down Expand Up @@ -406,6 +417,12 @@ function logic.update_annunciator(self)

-- update auto control ready state for this unit
self.db.control.ready = plc_ready and boilers_ready and turbines_ready

-- update auxiliary coolant command
if plc_ready then
self.enable_aux_cool = self.plc_i.get_db().mek_status.status and
(self.enable_aux_cool or need_aux_cool) and not (dis_aux_cool and self.turbine_flow_stable)
else self.enable_aux_cool = false end
end

-- update an alarm state given conditions
Expand Down Expand Up @@ -953,12 +970,10 @@ function logic.handle_redstone(self)
-----------------------

if self.aux_coolant then
local enable_aux_cool = boiler_water_low or (annunc.CoolantLevelLow and self.num_boilers == 0)

if enable_aux_cool and not self.aux_cool_opened then
if self.enable_aux_cool and (not self.aux_cool_opened) then
log.info(util.c("UNIT ", self.r_id, " auxiliary coolant valve opened"))
self.aux_cool_opened = true
elseif self.aux_cool_opened and self.turbine_flow_stable and not enable_aux_cool then
elseif (not self.enable_aux_cool) and self.aux_cool_opened then
log.info(util.c("UNIT ", self.r_id, " auxiliary coolant valve closed"))
self.aux_cool_opened = false
end
Expand Down

0 comments on commit 2b73196

Please sign in to comment.