From f2629b04c22e8cc50b48bd7127fbbfa0ad80f1a1 Mon Sep 17 00:00:00 2001 From: Martin Shetty <1972005+martukas@users.noreply.github.com> Date: Mon, 4 Jul 2022 01:20:27 -0700 Subject: [PATCH] a bit of cleanup --- software/controller/lib/core/controller.cpp | 35 ++------------------- software/controller/lib/core/controller.h | 12 +++---- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/software/controller/lib/core/controller.cpp b/software/controller/lib/core/controller.cpp index e638ccd9f1..b96188e0f3 100644 --- a/software/controller/lib/core/controller.cpp +++ b/software/controller/lib/core/controller.cpp @@ -15,9 +15,8 @@ limitations under the License. #include "controller.h" -#include - #include +#include #include "system_constants.h" @@ -26,9 +25,7 @@ Duration Controller::GetLoopPeriod() { return MainLoopPeriod; } std::pair Controller::Run(Time now, const VentParams ¶ms, const SensorReadings &sensor_readings) { VolumetricFlow uncorrected_net_flow = - sensor_readings.air_inflow - // + sensor_readings.oxygen_inflow \todo add this once it is well tested - - sensor_readings.outflow; + sensor_readings.air_inflow + sensor_readings.oxygen_inflow - sensor_readings.outflow; flow_integrator_->AddFlow(now, uncorrected_net_flow); uncorrected_flow_integrator_->AddFlow(now, uncorrected_net_flow); @@ -79,17 +76,10 @@ std::pair Controller::Run(Time now, const VentP uncorrected_flow_integrator_.emplace(); } - // At the moment we don't support oxygen mixing -- we deliver either pure - // air or pure oxygen. For any fio2 < 1, deliver air. if (params.fio2 < 0.6) { // Delivering air + oxygen mixes from 21 to 59%. psol_pid_.reset(); - // Calculate blower valve command using calculated gains - /*float blower_valve = - blower_valve_pid_.Compute(now, sensor_readings.patient_pressure.kPa(), - desired_state.pressure_setpoint->kPa());*/ - float flow_cmd = blower_valve_pid_.compute(now, sensor_readings.patient_pressure.kPa(), desired_state.pressure_setpoint->kPa()); float blower_valve = @@ -113,13 +103,6 @@ std::pair Controller::Run(Time now, const VentP // Delivering air + oxygen mixes from 60 to 100% blower_valve_pid_.reset(); - // experimental shit - /* - float blower_valve = - air_flow_pid_.Compute(now, - sensor_readings.inflow.liters_per_sec(), dbg_air_flow_setpoint.Get()); - */ - float psol_valve = psol_pid_.compute(now, sensor_readings.patient_pressure.kPa(), desired_state.pressure_setpoint->kPa()); @@ -130,20 +113,6 @@ std::pair Controller::Run(Time now, const VentP float blower_valve = air_flow_pid_.compute(now, sensor_readings.air_inflow.liters_per_sec(), psol_valve * (1 - fio2_coupling_value)); - // experimental shit - /* - actuators_state = { -// Force psol to stay very slightly open to avoid the discontinuity -// caused by valve hysteresis at very low command. The exhale valve -// compensates for this intentional leakage by staying open when the -// psol valve is closed. -.fio2_valve = 0, -.blower_power = 1, -.blower_valve = blower_valve, -.exhale_valve = 1.0f, // - 0.6f * psol_valve - 0.4f, - }; - */ - actuators_state = { // Force psol to stay very slightly open to avoid the discontinuity // caused by valve hysteresis at very low command. The exhale valve diff --git a/software/controller/lib/core/controller.h b/software/controller/lib/core/controller.h index e3cb440828..71651a0e68 100644 --- a/software/controller/lib/core/controller.h +++ b/software/controller/lib/core/controller.h @@ -89,9 +89,9 @@ class Controller { PID fio2_pid_{"fio2_", " for FIO2 PID", - /*kp=*/0.001f, - /*ki=*/0.1f, - /*kd=*/0.0f, + /*initial_kp=*/0.001f, + /*initial_ki=*/0.1f, + /*initial_kd=*/0.0f, /*p_term=*/PID::TermApplication::OnError, /*d_term=*/PID::TermApplication::OnMeasurement, /*output_min=*/-1.0f, @@ -99,9 +99,9 @@ class Controller { PID air_flow_pid_{"air_flow_", " for air flow PID", - /*kp=*/0.1f, - /*ki=*/20.0f, - /*kd=*/0.0f, + /*initial_kp=*/0.1f, + /*initial_ki=*/20.0f, + /*initial_kd=*/0.0f, /*p_term=*/PID::TermApplication::OnError, /*d_term=*/PID::TermApplication::OnMeasurement, /*output_min=*/0.f,