Skip to content

Commit

Permalink
a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
martukas committed Jul 6, 2022
1 parent fbbe201 commit 1b75acb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
35 changes: 2 additions & 33 deletions software/controller/lib/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ limitations under the License.

#include "controller.h"

#include <math.h>

#include <algorithm>
#include <cmath>

#include "system_constants.h"

Expand All @@ -26,9 +25,7 @@ Duration Controller::GetLoopPeriod() { return MainLoopPeriod; }
std::pair<ActuatorsState, ControllerState> Controller::Run(Time now, const VentParams &params,
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);

Expand Down Expand Up @@ -79,17 +76,10 @@ std::pair<ActuatorsState, ControllerState> 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 =
Expand All @@ -113,13 +103,6 @@ std::pair<ActuatorsState, ControllerState> 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());

Expand All @@ -130,20 +113,6 @@ std::pair<ActuatorsState, ControllerState> 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
Expand Down
12 changes: 6 additions & 6 deletions software/controller/lib/core/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ 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,
/*output_max=*/1.0f};

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,
Expand Down

0 comments on commit 1b75acb

Please sign in to comment.