Commit ffbf1e36 authored by Your Name's avatar Your Name

initial work on o2 mixing

parent 09022cb3
...@@ -79,9 +79,10 @@ BreathingLoop::BreathingLoop() ...@@ -79,9 +79,10 @@ BreathingLoop::BreathingLoop()
_cycle_index = 0; _cycle_index = 0;
_min_inhale_time = 150; _min_inhale_time = 150;
_min_exhale_time = 300; _min_exhale_time = 800;
_max_exhale_time = 10000; // for mandatory cycle - changed to 30s for the sponteneous breath testing _max_exhale_time = 10000; // for mandatory cycle - changed to 30s for the sponteneous breath testing
initTargets(); initTargets();
setVentilationMode(_ventilation_mode); setVentilationMode(_ventilation_mode);
...@@ -99,7 +100,7 @@ void BreathingLoop::initTargets() ...@@ -99,7 +100,7 @@ void BreathingLoop::initTargets()
_targets_pcac.peep = 5; _targets_pcac.peep = 5;
_targets_pcac.fiO2_percent = 21; _targets_pcac.fiO2_percent = 21;
_targets_pcac.inhale_trigger_threshold = 1; // abs flow ? unit / _targets_pcac.inhale_trigger_threshold = 5; // abs flow ? unit /
_targets_pcac.exhale_trigger_threshold = 0.25; // 25% of the peak flow _targets_pcac.exhale_trigger_threshold = 0.25; // 25% of the peak flow
_targets_pcac.buffer_lower_pressure = 285.0; _targets_pcac.buffer_lower_pressure = 285.0;
...@@ -445,7 +446,7 @@ void BreathingLoop::FSM_assignment() { ...@@ -445,7 +446,7 @@ void BreathingLoop::FSM_assignment() {
next_state = BL_STATES::PAUSE; next_state = BL_STATES::PAUSE;
break; break;
case BL_STATES::PAUSE: case BL_STATES::PAUSE:
next_state = BL_STATES::EXHALE; next_state = BL_STATES::EXHALE;
break; break;
case BL_STATES::EXHALE: case BL_STATES::EXHALE:
if (_running == false) { if (_running == false) {
...@@ -610,9 +611,11 @@ void BreathingLoop::FSM_breathCycle() ...@@ -610,9 +611,11 @@ void BreathingLoop::FSM_breathCycle()
_peak_flow = -100000; // reset peak after inhale _peak_flow = -100000; // reset peak after inhale
_peak_flow_time = millis(); _peak_flow_time = millis();
_fsm_timeout = _states_durations.exhale; _fsm_timeout = _states_durations.exhale;
// uint32_t tnow = millis();
if(doExhalePurge()){
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::OPEN);
// fill buffer to required pressure or timeout ; close valves 10ms before timeout. // fill buffer to required pressure or timeout ; close valves 10ms before timeout.
if((_readings_avgs.pressure_buffer >= _targets_current->buffer_upper_pressure) || (millis() - _fsm_time >= (_fsm_timeout - 10))){ } else if((_readings_avgs.pressure_buffer >= _targets_current->buffer_upper_pressure) || (millis() - _fsm_time >= (_fsm_timeout - 10))){
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED); _valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
} else if(_readings_avgs.pressure_buffer < _targets_current->buffer_lower_pressure){ } else if(_readings_avgs.pressure_buffer < _targets_current->buffer_lower_pressure){
_valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED); _valves_controller.setValves(VALVE_STATE::OPEN, VALVE_STATE::OPEN, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
...@@ -1259,3 +1262,25 @@ void BreathingLoop::tsigReset() ...@@ -1259,3 +1262,25 @@ void BreathingLoop::tsigReset()
} }
} }
float BreathingLoop::o2ValveFrac(float desired_fiO2)
{
// airValveFrac = 1.0 - O2ValveFrac
return (desired_fiO2-0.21)/0.79;
}
bool BreathingLoop::doExhalePurge()
{
// do nothing for now
return false;
uint32_t tnow = millis();
// purge-to-fill ratio = 0.66 => spend 66% time purging 33% filling buffer
if (tnow - _fsm_time >= static_cast<uint32_t>(0.66*_min_exhale_time) ) {
if (fabs(_targets_current->fiO2_percent - _readings_avgs.o2_percent) < 1){
return true;
}
}
return false;
}
...@@ -120,6 +120,9 @@ private: ...@@ -120,6 +120,9 @@ private:
states_durations _measured_durations = {0,0,0,0,0,0,0,0,0}; states_durations _measured_durations = {0,0,0,0,0,0,0,0,0};
void measureDurations(); void measureDurations();
void measurePEEP(); void measurePEEP();
float o2ValveFrac(float desired_fiO2);
bool doExhalePurge();
// targets // targets
void initTargets(); void initTargets();
target_variables _targets_pcac; target_variables _targets_pcac;
......
...@@ -49,7 +49,7 @@ ValvesController::ValvesController() ...@@ -49,7 +49,7 @@ ValvesController::ValvesController()
_valve_params.inhale_duty_cycle = 0; _valve_params.inhale_duty_cycle = 0;
_valve_params.inhale_open_max = MAX_VALVE_FRAC_OPEN; _valve_params.inhale_open_max = MAX_VALVE_FRAC_OPEN;
_valve_params.inhale_open_min = 0.53; _valve_params.inhale_open_min = 0.51;
_valve_params.valve_air_in_enable = 1; _valve_params.valve_air_in_enable = 1;
_valve_params.valve_o2_in_enable = 1; _valve_params.valve_o2_in_enable = 1;
_valve_params.valve_purge_enable = 1; _valve_params.valve_purge_enable = 1;
......
...@@ -41,7 +41,8 @@ class Dependant(object): ...@@ -41,7 +41,8 @@ class Dependant(object):
# logging.info(f"Alarm: {payload.alarm_code} of priority: {payload.alarm_type}") # logging.info(f"Alarm: {payload.alarm_code} of priority: {payload.alarm_type}")
if payload.getType() == PAYLOAD_TYPE.DATA.value: if payload.getType() == PAYLOAD_TYPE.DATA.value:
logging.info(f"payload received: {payload}") #logging.info(f"payload received: {payload}")
logging.info(f"payload received: {payload.timestamp} pc {payload.flow:3.6f} dc {payload.flow_calc:3.6f} fsm {payload.fsm_state}")
# #logging.info(f"payload received: {payload.timestamp} pc {payload.flow:3.6f} dc {payload.volume:3.6f} fsm {payload.fsm_state}") # #logging.info(f"payload received: {payload.timestamp} pc {payload.flow:3.6f} dc {payload.volume:3.6f} fsm {payload.fsm_state}")
# #logging.info(f"payload received: {payload.pressure_buffer:3.6f} fsm {payload.fsm_state}") # #logging.info(f"payload received: {payload.pressure_buffer:3.6f} fsm {payload.fsm_state}")
# #logging.info(f"Fsm state: {payload.fsm_state}") # #logging.info(f"Fsm state: {payload.fsm_state}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment