#366 idling and charge level PD gain changes

This commit is contained in:
Mikayla Fischler
2024-04-09 22:23:43 -04:00
parent 4fcd375ee2
commit 65d43d55c7
3 changed files with 85 additions and 16 deletions

View File

@@ -8,9 +8,6 @@ local logic = require("supervisor.unitlogic")
local plc = require("supervisor.session.plc")
local rsctl = require("supervisor.session.rsctl")
---@class reactor_control_unit
local unit = {}
local WASTE_MODE = types.WASTE_MODE
local WASTE = types.WASTE_PRODUCT
local ALARM = types.ALARM
@@ -55,6 +52,14 @@ local AISTATE = {
---@field id ALARM alarm ID
---@field tier integer alarm urgency tier (0 = highest)
-- burn rate to idle at
local IDLE_RATE = 0.01
-- time (ms) to idle
local IDLE_TIME = 15000
---@class reactor_control_unit
local unit = {}
-- create a new reactor unit
---@nodiscard
---@param reactor_id integer reactor unit number
@@ -83,6 +88,9 @@ function unit.new(reactor_id, num_boilers, num_turbines)
emcool_opened = false,
-- auto control
auto_engaged = false,
auto_idle = false,
auto_idling = false,
auto_idle_start = 0,
auto_was_alarmed = false,
ramp_target_br100 = 0,
-- state tracking
@@ -578,6 +586,23 @@ function unit.new(reactor_id, num_boilers, num_turbines)
end
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
function public.auto_set_idle(idle)
if not (idle and self.auto_idle) then
self.auto_idling = false
self.auto_idle_start = 0
end
if idle ~= self.auto_idle then
log.debug(util.c("UNIT ", self.r_id, ": idling mode changed to ", idle))
end
self.auto_idle = idle
end
-- get the actual limit of this unit<br>
-- if it is degraded or not ready, the limit will be 0
---@nodiscard
@@ -597,7 +622,35 @@ function unit.new(reactor_id, num_boilers, num_turbines)
if self.auto_engaged then
if self.plc_i ~= nil then
log.debug(util.c("UNIT ", self.r_id, ": commit br100 of ", self.db.control.br100, " with ramp set to ", ramp))
self.plc_i.auto_set_burn(self.db.control.br100 / 100, ramp)
local rate = self.db.control.br100 / 100
if self.auto_idle then
if rate <= IDLE_RATE then
if self.auto_idle_start == 0 then
self.auto_idling = true
self.auto_idle_start = util.time_ms()
log.info(util.c("UNIT ", self.r_id, ": started idling at ", IDLE_RATE, " mB/t"))
rate = IDLE_RATE
elseif (util.time_ms() - self.auto_idle_start) > IDLE_TIME then
if self.auto_idling then
self.auto_idling = false
log.info(util.c("UNIT ", self.r_id, ": completed idling period"))
end
else
log.debug(util.c("UNIT ", self.r_id, ": continuing idle at ", IDLE_RATE, " mB/t"))
rate = IDLE_RATE
end
else
self.auto_idling = false
self.auto_idle_start = 0
end
end
self.plc_i.auto_set_burn(rate, ramp)
if ramp then self.ramp_target_br100 = self.db.control.br100 end
end
end