diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 4d71b67..5a160c4 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol") local renderer = require("coordinator.renderer") local sounder = require("coordinator.sounder") -local COORDINATOR_VERSION = "beta-v0.9.3" +local COORDINATOR_VERSION = "beta-v0.9.4" local print = util.print local println = util.println diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index 99990e8..17d064f 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -85,7 +85,7 @@ local function init(parent, id) u_ps.subscribe("heating_rate", heating_r.update) TextBox{parent=main,x=12,y=25,text="Commanded Burn Rate",height=1,width=19,fg_bg=style.label} - local burn_r = DataIndicator{parent=main,x=12,label="",format="%14.1f",value=0,unit="mB/t",lu_colors=lu_cpair,width=19,fg_bg=bw_fg_bg} + local burn_r = DataIndicator{parent=main,x=12,label="",format="%14.2f",value=0,unit="mB/t",lu_colors=lu_cpair,width=19,fg_bg=bw_fg_bg} u_ps.subscribe("burn_rate", burn_r.update) TextBox{parent=main,text="F",x=2,y=22,width=1,height=1,fg_bg=style.label} @@ -126,7 +126,7 @@ local function init(parent, id) u_ps.subscribe("temp", core_temp.update) TextBox{parent=main,x=32,y=25,text="Burn Rate",height=1,width=9,fg_bg=style.label} - local act_burn_r = DataIndicator{parent=main,x=32,label="",format="%8.1f",value=0,unit="mB/t",lu_colors=lu_cpair,width=13,fg_bg=bw_fg_bg} + local act_burn_r = DataIndicator{parent=main,x=32,label="",format="%8.2f",value=0,unit="mB/t",lu_colors=lu_cpair,width=13,fg_bg=bw_fg_bg} u_ps.subscribe("act_burn_rate", act_burn_r.update) TextBox{parent=main,x=32,y=28,text="Damage",height=1,width=6,fg_bg=style.label} diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index 71f17e4..6be0a84 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -25,8 +25,6 @@ local println_ts = util.println_ts local PCALL_SCRAM_MSG = "pcall: Scram requires the reactor to be active." local PCALL_START_MSG = "pcall: Reactor is already active." -local AUTO_TOGGLE_DELAY_MS = 5000 - -- RPS SAFETY CONSTANTS local MAX_DAMAGE_PERCENT = 90 @@ -832,7 +830,7 @@ function plc.comms(id, version, modem, local_port, server_port, range, reactor, -- automatic control requested a new burn rate if (packet.length == 3) and (type(packet.data[1]) == "number") and (type(packet.data[3]) == "number") then local ack = AUTO_ACK.FAIL - local burn_rate = math.floor(packet.data[1] * 10) / 10 + local burn_rate = math.floor(packet.data[1] * 100) / 100 local ramp = packet.data[2] self.auto_ack_token = packet.data[3] @@ -843,20 +841,15 @@ function plc.comms(id, version, modem, local_port, server_port, range, reactor, -- if we know our max burn rate, update current burn rate setpoint if in range if self.max_burn_rate ~= ppm.ACCESS_FAULT then - if burn_rate < 0.1 then + if burn_rate < 0.01 then if rps.is_active() then - if rps.get_runtime() > AUTO_TOGGLE_DELAY_MS then - -- auto scram to disable - log.debug("AUTO: stopping the reactor to meet 0.0 burn rate") - if rps.scram() then - ack = AUTO_ACK.ZERO_DIS_OK - self.auto_last_disable = util.time_ms() - else - log.debug("AUTO: automatic reactor stop failed") - end + -- auto scram to disable + log.debug("AUTO: stopping the reactor to meet 0.0 burn rate") + if rps.scram() then + ack = AUTO_ACK.ZERO_DIS_OK + self.auto_last_disable = util.time_ms() else - -- too soon to disable - ack = AUTO_ACK.ZERO_DIS_WAIT + log.debug("AUTO: automatic reactor stop failed") end else ack = AUTO_ACK.ZERO_DIS_OK @@ -865,13 +858,14 @@ function plc.comms(id, version, modem, local_port, server_port, range, reactor, if not rps.is_active() then -- activate the reactor log.debug("AUTO: activating the reactor") - if rps.auto_activate() then - self.reactor.setBurnRate(0.1) - if self.reactor.__p_is_faulted() then - log.debug("AUTO: failed to reset burn rate on auto activation") - end + + self.reactor.setBurnRate(0.01) + if self.reactor.__p_is_faulted() then + log.debug("AUTO: failed to reset burn rate for auto activation") else - log.debug("AUTO: automatic reactor activation failed") + if not rps.auto_activate() then + log.debug("AUTO: automatic reactor activation failed") + end end end diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index c8f8b23..b0374c9 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -14,7 +14,7 @@ local config = require("reactor-plc.config") local plc = require("reactor-plc.plc") local threads = require("reactor-plc.threads") -local R_PLC_VERSION = "beta-v0.10.7" +local R_PLC_VERSION = "beta-v0.10.8" local print = util.print local println = util.println diff --git a/rtu/startup.lua b/rtu/startup.lua index 557bf28..19c201b 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -25,7 +25,7 @@ local sna_rtu = require("rtu.dev.sna_rtu") local sps_rtu = require("rtu.dev.sps_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "beta-v0.10.1" +local RTU_VERSION = "beta-v0.10.2" local rtu_t = types.rtu_t diff --git a/scada-common/comms.lua b/scada-common/comms.lua index 94bfd15..6b1918a 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -14,7 +14,7 @@ local insert = table.insert local max_distance = nil -comms.version = "1.3.1" +comms.version = "1.3.2" ---@alias PROTOCOLS integer local PROTOCOLS = { @@ -95,8 +95,7 @@ local PLC_AUTO_ACK = { FAIL = 0, -- failed to set burn rate/burn rate invalid DIRECT_SET_OK = 1, -- successfully set burn rate RAMP_SET_OK = 2, -- successfully started burn rate ramping - ZERO_DIS_OK = 3, -- successfully disabled reactor with < 0.1 burn rate - ZERO_DIS_WAIT = 4 -- too soon to disable reactor with < 0.1 burn rate + ZERO_DIS_OK = 3 -- successfully disabled reactor with < 0.01 burn rate } ---@alias FAC_COMMANDS integer diff --git a/supervisor/session/facility.lua b/supervisor/session/facility.lua index b9db2b2..498652f 100644 --- a/supervisor/session/facility.lua +++ b/supervisor/session/facility.lua @@ -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 diff --git a/supervisor/session/plc.lua b/supervisor/session/plc.lua index 45e8bae..7947526 100644 --- a/supervisor/session/plc.lua +++ b/supervisor/session/plc.lua @@ -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 diff --git a/supervisor/session/unit.lua b/supervisor/session/unit.lua index 32debf9..5c220a4 100644 --- a/supervisor/session/unit.lua +++ b/supervisor/session/unit.lua @@ -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 diff --git a/supervisor/session/unitlogic.lua b/supervisor/session/unitlogic.lua index 369f761..84f7c58 100644 --- a/supervisor/session/unitlogic.lua +++ b/supervisor/session/unitlogic.lua @@ -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 diff --git a/supervisor/startup.lua b/supervisor/startup.lua index 1025f8a..29963ec 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -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