From 846f9685ad7815286b06d59855da233d58d2a1c5 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Thu, 2 Feb 2023 20:17:23 -0500 Subject: [PATCH] #148 fixed burn rate ramping, adjusted auto burn rate ramping --- reactor-plc/plc.lua | 17 ++++++++++++++--- reactor-plc/startup.lua | 2 +- reactor-plc/threads.lua | 8 ++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index 468d190..7381c00 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -824,9 +824,12 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co 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 else -- too soon to disable @@ -838,24 +841,32 @@ function plc.comms(id, version, modem, local_port, server_port, reactor, rps, co elseif burn_rate <= self.max_burn_rate then if not rps.is_active() then -- activate the reactor - if not rps.auto_activate() then - log.debug("automatic reactor activation failed") + 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 + else + log.debug("AUTO: automatic reactor activation failed") end end -- if active, set/ramp burn rate if rps.is_active() then if ramp then + log.debug(util.c("AUTO: setting burn rate ramp to ", burn_rate)) setpoints.burn_rate_en = true setpoints.burn_rate = burn_rate ack = AUTO_ACK.RAMP_SET_OK else + log.debug(util.c("AUTO: setting burn rate directly to ", burn_rate)) self.reactor.setBurnRate(burn_rate) ack = util.trinary(self.reactor.__p_is_faulted(), AUTO_ACK.FAIL, AUTO_ACK.DIRECT_SET_OK) end end else - log.debug(burn_rate .. " rate outside of 0 < x <= " .. self.max_burn_rate) + log.debug(util.c(burn_rate, " rate outside of 0 < x <= ", self.max_burn_rate)) end end diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 427f8f7..cc7dbba 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.0" +local R_PLC_VERSION = "beta-v0.10.1" local print = util.print local println = util.println diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index b1f35d0..d503bcf 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -601,7 +601,7 @@ function threads.thread__setpoint_control(smem) ---@diagnostic disable-next-line: need-check-nil reactor.setBurnRate(setpoints.burn_rate) else - log.debug("starting burn rate ramp from " .. last_sp_burn .. "mB/t to " .. setpoints.burn_rate .. "mB/t") + log.debug("starting burn rate ramp from " .. last_sp_burn .. " mB/t to " .. setpoints.burn_rate .. " mB/t") running = true end @@ -623,19 +623,19 @@ function threads.thread__setpoint_control(smem) local current_burn_rate = reactor.getBurnRate() -- we yielded, check enable again - if setpoints.burn_rate_en and (current_burn_rate ~= ppm.ACCESS_FAULT) and (current_burn_rate ~= setpoints.burn_rate) then + if setpoints.burn_rate_en and (type(current_burn_rate) == "number") and (current_burn_rate ~= setpoints.burn_rate) then -- calculate new burn rate local new_burn_rate = current_burn_rate if setpoints.burn_rate > current_burn_rate then -- need to ramp up - local new_burn_rate = current_burn_rate + (BURN_RATE_RAMP_mB_s * min_elapsed_s) + new_burn_rate = current_burn_rate + (BURN_RATE_RAMP_mB_s * min_elapsed_s) if new_burn_rate > setpoints.burn_rate then new_burn_rate = setpoints.burn_rate end else -- need to ramp down - local new_burn_rate = current_burn_rate - (BURN_RATE_RAMP_mB_s * min_elapsed_s) + new_burn_rate = current_burn_rate - (BURN_RATE_RAMP_mB_s * min_elapsed_s) if new_burn_rate < setpoints.burn_rate then new_burn_rate = setpoints.burn_rate end