#20 process target charge level

This commit is contained in:
Mikayla Fischler 2023-02-11 00:21:00 -05:00
parent da9eead2d5
commit ff1bd02739
4 changed files with 26 additions and 40 deletions

View File

@ -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.5"
local COORDINATOR_VERSION = "beta-v0.9.6"
local print = util.print
local println = util.println

View File

@ -64,7 +64,7 @@ local function new_view(root, x, y)
local auto_ready = IndicatorLight{parent=main,label="Configured Units Ready",colors=cpair(colors.green,colors.red)}
local auto_act = IndicatorLight{parent=main,label="Process Active",colors=cpair(colors.green,colors.gray)}
local auto_ramp = IndicatorLight{parent=main,label="Process Ramping",colors=cpair(colors.white,colors.gray),flash=true,period=period.BLINK_250_MS}
local auto_sat = IndicatorLight{parent=main,label="Max Burn Rate",colors=cpair(colors.yellow,colors.gray)}
local auto_sat = IndicatorLight{parent=main,label="Min/Max Burn Rate",colors=cpair(colors.yellow,colors.gray)}
local auto_scram = IndicatorLight{parent=main,label="Automatic SCRAM",colors=cpair(colors.red,colors.gray),flash=true,period=period.BLINK_250_MS}
facility.ps.subscribe("auto_ready", auto_ready.update)
@ -109,11 +109,11 @@ local function new_view(root, x, y)
local chg_target = Div{parent=targets,x=9,y=6,width=23,height=3,fg_bg=cpair(colors.gray,colors.white)}
local c_target = SpinboxNumeric{parent=chg_target,x=2,y=1,whole_num_precision=15,fractional_precision=0,min=0,arrow_fg_bg=cpair(colors.gray,colors.white),fg_bg=bw_fg_bg}
TextBox{parent=chg_target,x=18,y=2,text="kFE"}
local cur_charge = DataIndicator{parent=targets,x=9,y=9,label="",format="%19d",value=0,unit="kFE",commas=true,lu_colors=cpair(colors.black,colors.black),width=23,fg_bg=cpair(colors.black,colors.brown)}
TextBox{parent=chg_target,x=18,y=2,text="MFE"}
local cur_charge = DataIndicator{parent=targets,x=9,y=9,label="",format="%19d",value=0,unit="MFE",commas=true,lu_colors=cpair(colors.black,colors.black),width=23,fg_bg=cpair(colors.black,colors.brown)}
facility.ps.subscribe("process_charge_target", c_target.set_value)
facility.induction_ps_tbl[1].subscribe("energy", function (j) cur_charge.update(util.joules_to_fe(j) / 1000) end)
facility.induction_ps_tbl[1].subscribe("energy", function (j) cur_charge.update(util.joules_to_fe(j) / 1000000) end)
local gen_tag = Div{parent=targets,x=1,y=11,width=8,height=4,fg_bg=cpair(colors.black,colors.purple)}
TextBox{parent=gen_tag,x=2,y=2,text="Gen. Target",width=7,height=2}

View File

@ -30,9 +30,9 @@ local START_STATUS = {
BLADE_MISMATCH = 2
}
local charge_Kp = 1.0
local charge_Kp = 0.275
local charge_Ki = 0.0
local charge_Kd = 0.0
local charge_Kd = 4.5
local rate_Kp = 2.45
local rate_Ki = 0.4825
@ -80,9 +80,9 @@ function facility.new(num_reactors, cooling_conf)
last_time = 0.0,
-- statistics
im_stat_init = false,
avg_charge = util.mov_avg(10, 0.0),
avg_inflow = util.mov_avg(10, 0.0),
avg_outflow = util.mov_avg(10, 0.0)
avg_charge = util.mov_avg(3, 0.0),
avg_inflow = util.mov_avg(6, 0.0),
avg_outflow = util.mov_avg(6, 0.0)
}
-- create units
@ -290,8 +290,6 @@ function facility.new(num_reactors, cooling_conf)
self.start_fail = START_STATUS.NO_UNITS
else
self.charge_conversion = blade_count * POWER_PER_BLADE
log.debug(util.c("FAC: starting auto control: chg_conv = ", self.charge_conversion, ", blade_count = ", blade_count, ", max_burn = ", self.max_burn_combined))
end
elseif self.mode == PROCESS.INACTIVE then
for i = 1, #self.prio_defs do
@ -357,29 +355,20 @@ function facility.new(num_reactors, cooling_conf)
self.saturated = self.burn_target == self.max_burn_combined or unallocated > 0
elseif self.mode == PROCESS.CHARGE then
-- target a level of charge
-- convert to kFE to make constants not microscopic
local error = (self.charge_setpoint - avg_charge) / 1000000
if state_changed then
self.time_start = now
self.last_time = now
log.debug(util.c("FAC: CHARGE mode first call completed"))
elseif self.waiting_on_ramp then
if _all_units_ramped() then
self.waiting_on_ramp = false
self.last_error = 0
self.accumulator = 0
self.time_start = now
self.last_time = now
self.last_error = 0
self.accumulator = 0
self.status_text = { "CHARGE MODE", "running control loop" }
log.info(util.c("FAC: CHARGE mode starting PID control"))
elseif self.last_update ~= charge_update then
-- convert to kFE to make constants not microscopic
local error = util.round((self.charge_setpoint - avg_charge) / 1000) / 1000
self.status_text = { "CHARGE MODE", "running control loop" }
log.info(util.c("FAC: CHARGE mode initial ramp completed"))
end
end
if not self.waiting_on_ramp and self.last_update ~= rate_update then
-- stop accumulator when saturated to avoid windup, deadband accumulator at 1kFE to avoid windup
if (not self.saturated) and (math.abs(error) >= 0.001) then
-- stop accumulator when saturated to avoid windup
if not self.saturated then
self.accumulator = self.accumulator + (error * (now - self.last_time))
end
@ -398,16 +387,13 @@ function facility.new(num_reactors, cooling_conf)
self.saturated = output ~= out_c
log.debug(util.sprintf("PROC_CHRG[%f] { CHRG[%f] ERR[%f] INT[%f] => OUT[%f] OUT_C[%f] <= P[%f] I[%f] D[%d] }",
log.debug(util.sprintf("CHARGE[%f] { CHRG[%f] ERR[%f] INT[%f] => OUT[%f] OUT_C[%f] <= P[%f] I[%f] D[%d] }",
runtime, avg_charge, error, integral, output, out_c, P, I, D))
_allocate_burn_rate(out_c, self.initial_ramp)
_allocate_burn_rate(out_c, true)
self.last_time = now
if self.initial_ramp then
self.waiting_on_ramp = true
end
self.last_error = error
end
self.last_update = charge_update
@ -450,7 +436,7 @@ function facility.new(num_reactors, cooling_conf)
-- convert to MFE (in rounded kFE) to make constants not microscopic
local error = util.round((self.gen_rate_setpoint - avg_inflow) / 1000) / 1000
-- stop accumulator when saturated to avoid windup, deadband accumulator at 1kFE to avoid windup
-- stop accumulator when saturated to avoid windup
if not self.saturated then
self.accumulator = self.accumulator + (error * (now - self.last_time))
end
@ -656,7 +642,7 @@ function facility.new(num_reactors, cooling_conf)
end
if (type(config.charge_target) == "number") and config.charge_target >= 0 then
self.charge_setpoint = config.charge_target
self.charge_setpoint = config.charge_target * 1000000 -- convert MFE to FE
end
if (type(config.gen_target) == "number") and config.gen_target >= 0 then

View File

@ -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.6"
local SUPERVISOR_VERSION = "beta-v0.10.7"
local print = util.print
local println = util.println