#154 increased auto burn rate precision
This commit is contained in:
@@ -111,7 +111,7 @@ function facility.new(num_reactors, cooling_conf)
|
||||
---@param ramp boolean true to ramp, false to set right away
|
||||
---@return integer unallocated
|
||||
local function _allocate_burn_rate(burn_rate, ramp)
|
||||
local unallocated = math.floor(burn_rate * 10)
|
||||
local unallocated = math.floor(burn_rate * 100)
|
||||
|
||||
-- go through alll priority groups
|
||||
for i = 1, #self.prio_defs do
|
||||
@@ -129,14 +129,14 @@ function facility.new(num_reactors, cooling_conf)
|
||||
local u = units[id] ---@type reactor_unit
|
||||
|
||||
local ctl = u.get_control_inf()
|
||||
local lim_br10 = u.a_get_effective_limit()
|
||||
local lim_br100 = u.a_get_effective_limit()
|
||||
|
||||
local last = ctl.br10
|
||||
local last = ctl.br100
|
||||
|
||||
if splits[id] <= lim_br10 then
|
||||
ctl.br10 = splits[id]
|
||||
if splits[id] <= lim_br100 then
|
||||
ctl.br100 = splits[id]
|
||||
else
|
||||
ctl.br10 = lim_br10
|
||||
ctl.br100 = lim_br100
|
||||
|
||||
if id < #units then
|
||||
local remaining = #units - id
|
||||
@@ -146,11 +146,11 @@ function facility.new(num_reactors, cooling_conf)
|
||||
end
|
||||
end
|
||||
|
||||
unallocated = math.max(0, unallocated - ctl.br10)
|
||||
unallocated = math.max(0, unallocated - ctl.br100)
|
||||
|
||||
if last ~= ctl.br10 then
|
||||
log.debug("unit " .. id .. ": set to " .. ctl.br10 .. " (was " .. last .. ")")
|
||||
u.a_commit_br10(ramp)
|
||||
if last ~= ctl.br100 then
|
||||
log.debug("unit " .. id .. ": set to " .. ctl.br100 .. " (was " .. last .. ")")
|
||||
u.a_commit_br100(ramp)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -253,13 +253,13 @@ function facility.new(num_reactors, cooling_conf)
|
||||
table.sort(self.prio_defs[i],
|
||||
---@param a reactor_unit
|
||||
---@param b reactor_unit
|
||||
function (a, b) return a.get_control_inf().lim_br10 < b.get_control_inf().lim_br10 end
|
||||
function (a, b) return a.get_control_inf().lim_br100 < b.get_control_inf().lim_br100 end
|
||||
)
|
||||
|
||||
for _, u in pairs(self.prio_defs[i]) do
|
||||
blade_count = blade_count + u.get_control_inf().blade_count
|
||||
u.a_engage()
|
||||
self.max_burn_combined = self.max_burn_combined + (u.get_control_inf().lim_br10 / 10.0)
|
||||
self.max_burn_combined = self.max_burn_combined + (u.get_control_inf().lim_br100 / 100.0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -366,13 +366,10 @@ function facility.new(num_reactors, cooling_conf)
|
||||
|
||||
local setpoint = P + I + D
|
||||
|
||||
-- round setpoint -> setpoint rounded (sp_r)
|
||||
local sp_r = util.round(setpoint * 10.0) / 10.0
|
||||
|
||||
-- clamp at range -> setpoint clamped (sp_c)
|
||||
local sp_c = math.max(0, math.min(sp_r, self.max_burn_combined))
|
||||
local sp_c = math.max(0, math.min(setpoint, self.max_burn_combined))
|
||||
|
||||
self.saturated = sp_r ~= sp_c
|
||||
self.saturated = setpoint ~= sp_c
|
||||
|
||||
log.debug(util.sprintf("PROC_CHRG[%f] { CHRG[%f] ERR[%f] INT[%f] => SP[%f] SP_C[%f] <= P[%f] I[%f] D[%d] }",
|
||||
runtime, avg_charge, error, integral, setpoint, sp_c, P, I, D))
|
||||
@@ -395,11 +392,9 @@ function facility.new(num_reactors, cooling_conf)
|
||||
-- estimate an initial setpoint
|
||||
output = (error * 1000000) / self.charge_conversion
|
||||
|
||||
local out_r = util.round(output * 10.0) / 10.0
|
||||
log.debug(util.c("FAC: initial burn rate for gen rate is " .. output))
|
||||
|
||||
log.debug(util.c("FAC: initial burn rate for gen rate setpoint is " .. out_r))
|
||||
|
||||
_allocate_burn_rate(out_r, true)
|
||||
_allocate_burn_rate(output, true)
|
||||
|
||||
self.waiting_on_ramp = true
|
||||
|
||||
@@ -444,13 +439,10 @@ function facility.new(num_reactors, cooling_conf)
|
||||
|
||||
output = P + I + D + FF
|
||||
|
||||
-- round output -> output rounded (sp_r)
|
||||
local out_r = util.round(output * 10.0) / 10.0
|
||||
|
||||
-- clamp at range -> output clamped (sp_c)
|
||||
local out_c = math.max(0, math.min(out_r, self.max_burn_combined))
|
||||
local out_c = math.max(0, math.min(output, self.max_burn_combined))
|
||||
|
||||
self.saturated = out_r ~= out_c
|
||||
self.saturated = output ~= out_c
|
||||
|
||||
log.debug(util.sprintf("GEN_RATE[%f] { RATE[%f] ERR[%f] INT[%f] => OUT[%f] OUT_C[%f] <= P[%f] I[%f] D[%f] }",
|
||||
runtime, avg_inflow, error, integral, output, out_c, P, I, D))
|
||||
@@ -621,7 +613,7 @@ function facility.new(num_reactors, cooling_conf)
|
||||
local limits = {}
|
||||
for i = 1, num_reactors do
|
||||
local u = self.units[i] ---@type reactor_unit
|
||||
limits[i] = u.get_control_inf().lim_br10 * 10
|
||||
limits[i] = u.get_control_inf().lim_br100 * 100
|
||||
end
|
||||
|
||||
-- only allow changes if not running
|
||||
|
||||
@@ -463,9 +463,6 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
|
||||
log.debug(log_header .. "RPLC automatic burn rate set fail")
|
||||
elseif ack == PLC_AUTO_ACK.DIRECT_SET_OK or ack == PLC_AUTO_ACK.RAMP_SET_OK or ack == PLC_AUTO_ACK.ZERO_DIS_OK then
|
||||
self.acks.burn_rate = true
|
||||
elseif ack == PLC_AUTO_ACK.ZERO_DIS_WAIT then
|
||||
self.acks.burn_rate = false
|
||||
log.debug(log_header .. "RPLC automatic burn rate too soon to disable at 0 mB/t")
|
||||
else
|
||||
self.acks.burn_rate = false
|
||||
log.debug(log_header .. "RPLC automatic burn rate ack unknown")
|
||||
@@ -665,7 +662,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
|
||||
elseif cmd.key == PLC_S_DATA.AUTO_BURN_RATE then
|
||||
-- set automatic burn rate
|
||||
if self.auto_lock then
|
||||
cmd.val = math.floor(cmd.val * 10) / 10 -- round to 10ths place
|
||||
cmd.val = math.floor(cmd.val * 100) / 100 -- round to 100ths place
|
||||
if cmd.val >= 0 and cmd.val <= self.sDB.mek_struct.max_burn then
|
||||
self.auto_cmd_token = util.time_ms()
|
||||
self.commanded_burn_rate = cmd.val
|
||||
|
||||
@@ -77,7 +77,7 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
boilers = {},
|
||||
redstone = {},
|
||||
-- auto control
|
||||
ramp_target_br10 = 0,
|
||||
ramp_target_br100 = 0,
|
||||
-- state tracking
|
||||
deltas = {},
|
||||
last_heartbeat = 0,
|
||||
@@ -208,8 +208,8 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
ready = false,
|
||||
degraded = false,
|
||||
blade_count = 0,
|
||||
br10 = 0,
|
||||
lim_br10 = 0
|
||||
br100 = 0,
|
||||
lim_br100 = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,8 +413,8 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
if self.plc_s ~= nil and not self.plc_s.open then
|
||||
self.plc_s = nil
|
||||
self.plc_i = nil
|
||||
self.db.control.br10 = 0
|
||||
self.db.control.lim_br10 = 0
|
||||
self.db.control.br100 = 0
|
||||
self.db.control.lim_br100 = 0
|
||||
end
|
||||
|
||||
-- unlink RTU unit sessions if they are closed
|
||||
@@ -480,31 +480,31 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
self.db.annunciator.AutoControl = false
|
||||
if self.plc_i ~= nil then
|
||||
self.plc_i.auto_lock(false)
|
||||
self.db.control.br10 = 0
|
||||
self.db.control.br100 = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- get the actual limit of this unit
|
||||
--
|
||||
-- if it is degraded or not ready, the limit will be 0
|
||||
---@return integer lim_br10
|
||||
---@return integer lim_br100
|
||||
function public.a_get_effective_limit()
|
||||
if not self.db.control.ready or self.db.control.degraded or self.plc_cache.rps_trip then
|
||||
self.db.control.br10 = 0
|
||||
self.db.control.br100 = 0
|
||||
return 0
|
||||
else
|
||||
return self.db.control.lim_br10
|
||||
return self.db.control.lim_br100
|
||||
end
|
||||
end
|
||||
|
||||
-- set the automatic burn rate based on the last set br10
|
||||
-- set the automatic burn rate based on the last set burn rate in 100ths
|
||||
---@param ramp boolean true to ramp to rate, false to set right away
|
||||
function public.a_commit_br10(ramp)
|
||||
function public.a_commit_br100(ramp)
|
||||
if self.db.annunciator.AutoControl then
|
||||
if self.plc_i ~= nil then
|
||||
self.plc_i.auto_set_burn(self.db.control.br10 / 10, ramp)
|
||||
self.plc_i.auto_set_burn(self.db.control.br100 / 100, ramp)
|
||||
|
||||
if ramp then self.ramp_target_br10 = self.db.control.br10 end
|
||||
if ramp then self.ramp_target_br100 = self.db.control.br100 end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -514,7 +514,7 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
function public.a_ramp_complete()
|
||||
if self.plc_i ~= nil then
|
||||
return self.plc_i.is_ramp_complete() or
|
||||
(self.plc_i.get_status().act_burn_rate == 0 and self.db.control.br10 == 0) or
|
||||
(self.plc_i.get_status().act_burn_rate == 0 and self.db.control.br100 == 0) or
|
||||
public.a_get_effective_limit() == 0
|
||||
else return true end
|
||||
end
|
||||
@@ -609,11 +609,11 @@ function unit.new(for_reactor, num_boilers, num_turbines)
|
||||
---@param limit number burn rate limit for auto control
|
||||
function public.set_burn_limit(limit)
|
||||
if limit > 0 then
|
||||
self.db.control.lim_br10 = math.floor(limit * 10)
|
||||
self.db.control.lim_br100 = math.floor(limit * 100)
|
||||
|
||||
if self.plc_i ~= nil then
|
||||
if limit > self.plc_i.get_struct().max_burn then
|
||||
self.db.control.lim_br10 = math.floor(self.plc_i.get_struct().max_burn * 10)
|
||||
self.db.control.lim_br100 = math.floor(self.plc_i.get_struct().max_burn * 100)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,8 +50,8 @@ function logic.update_annunciator(self)
|
||||
plc_ready = (not plc_db.rps_tripped) and (plc_db.last_status_update > 0) and (plc_db.mek_struct.length > 0)
|
||||
|
||||
-- update auto control limit
|
||||
if (self.db.control.lim_br10 == 0) or ((self.db.control.lim_br10 / 10) > plc_db.mek_struct.max_burn) then
|
||||
self.db.control.lim_br10 = math.floor(plc_db.mek_struct.max_burn * 10)
|
||||
if (self.db.control.lim_br100 == 0) or ((self.db.control.lim_br100 / 100) > plc_db.mek_struct.max_burn) then
|
||||
self.db.control.lim_br100 = math.floor(plc_db.mek_struct.max_burn * 100)
|
||||
end
|
||||
|
||||
-- some alarms wait until the burn rate has stabilized, so keep track of that
|
||||
|
||||
@@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions")
|
||||
local config = require("supervisor.config")
|
||||
local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local SUPERVISOR_VERSION = "beta-v0.10.3"
|
||||
local SUPERVISOR_VERSION = "beta-v0.10.4"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
||||
Reference in New Issue
Block a user