diff --git a/arduino/common/lib/CommsControl/CommsCommon.h b/arduino/common/lib/CommsControl/CommsCommon.h index 6ecdb8807af2a72c5ae1fbe5a47625f38991699f..cc5de8da0967d146f822bad3a3836e3358e9ab3e 100644 --- a/arduino/common/lib/CommsControl/CommsCommon.h +++ b/arduino/common/lib/CommsControl/CommsCommon.h @@ -5,7 +5,7 @@ #define CONST_TIMEOUT_ALARM 5 #define CONST_TIMEOUT_DATA 10 -#define CONST_TIMEOUT_CMD 50 +#define CONST_TIMEOUT_CMD 10 #define PAYLOAD_MAX_SIZE_BUFFER 128 diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.cpp b/arduino/hev_prototype_v1/src/BreathingLoop.cpp index 5ad51010f2b4895afc0fbc2c80ab3e99d9b2409b..96738da632463bfba7727c60bfcee92805d6609f 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.cpp +++ b/arduino/hev_prototype_v1/src/BreathingLoop.cpp @@ -575,12 +575,14 @@ void BreathingLoop::FSM_breathCycle() _peak_flow = -100000; // reset peak after inhale _fsm_timeout = _states_durations.exhale_fill; digitalWrite(pin_led_red, LOW); + //measurePEEP(); inhaleTrigger(); break; case BL_STATES::EXHALE: _states_durations.exhale = calculateDurationExhale(); _valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED); _fsm_timeout = _states_durations.exhale; + //measurePEEP(); inhaleTrigger(); break; @@ -607,10 +609,10 @@ void BreathingLoop::FSM_breathCycle() } //logMsg("fsm timeout " + String(_fsm_timeout) + " state "+String(_bl_state));; safetyCheck(); - measure_durations(); + measureDurations(); } -void BreathingLoop::measure_durations( ) { +void BreathingLoop::measureDurations( ) { if (_bl_state != _bl_laststate) { uint32_t tnow = static_cast<uint32_t>(millis()); uint32_t tdiff = tnow - _lasttime; @@ -651,6 +653,10 @@ void BreathingLoop::measure_durations( ) { } } +// void BreathingLoop::measurePEEP() +// { +// } + void BreathingLoop::safetyCheck() { // based on averages or instantaneous values? @@ -788,7 +794,7 @@ void BreathingLoop::updateIE() uint32_t total_cycle = static_cast<uint32_t>(60*1000/_targets_current->respiratory_rate); int32_t exhale_duration; - int32_t inhale_duration = _states_durations.inhale; + int32_t inhale_duration = _targets_current->inhale_time; if (_targets_current->ie_selected == true){ uint32_t tot_inh = total_cycle / (1.0 + (1.0/_targets_current->ie_ratio)); @@ -824,8 +830,7 @@ void BreathingLoop::updateIE() void BreathingLoop::updateFromTargets() { - - _pid.target_final_pressure = _targets_current->inspiratory_pressure; //TODO - should fix this to one variable + _pid.target_final_pressure = _targets_current->inspiratory_pressure ; //TODO - should fix this to one variable updateIE(); //if (_targets.ie_selected == true){ //setIERatio(); @@ -1133,6 +1138,9 @@ void BreathingLoop::runningAvgs() //logMsg("INHALE "+String(_volume_inhale)); } else if ((_bl_state == BL_STATES::EXHALE) || (_bl_state == BL_STATES::EXHALE_FILL)){ _volume_exhale = _volume_inhale - getVolume(); + if(fabs(_flow) < 0.01){ + _peep = _readings_avgs.pressure_patient; + } //logMsg(" EXHALE "+String(_volume_exhale)); } diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.h b/arduino/hev_prototype_v1/src/BreathingLoop.h index 483383adfaaab84001d5d3650401e0baefd570c6..1ce2186cecbf1ea9fbce82f8ca78517162c39648 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.h +++ b/arduino/hev_prototype_v1/src/BreathingLoop.h @@ -114,7 +114,8 @@ private: //durations = {calibration, buff_purge, buff_flush, buff_prefill, buff_fill, buff_loaded, buff_pre_inhale, inhale, pause, exhale_fill, exhale } states_durations _states_durations = {10000, 600, 600, 100, 600, 0, 0, 1200, 10, 1600, 200}; states_durations _measured_durations = {0,0,0,0,0,0,0,0,0,0,0}; - void measure_durations(); + void measureDurations(); + // void measurePEEP(); // targets void initTargets(); target_variables _targets_pcac; @@ -187,6 +188,10 @@ private: float _running_exhale_minute_volume[CYCLE_AVG_READINGS]; float _running_minute_volume[CYCLE_AVG_READINGS]; + // float _running_peep[RUNNING_AVG_READINGS]; + // float _running_avg_peep; + // uint8_t _running_index_peep; + bool _inhale_triggered; float _inhale_trigger_threshold; float _exhale_trigger_threshold; diff --git a/raspberry-dataserver/CommsDebug2.py b/raspberry-dataserver/CommsDebug2.py index a926180586ce93e14f87604c6d6be4d73c5cfc4d..43102cce6f6ae1212c63d7ee08403d5e31413fd6 100755 --- a/raspberry-dataserver/CommsDebug2.py +++ b/raspberry-dataserver/CommsDebug2.py @@ -52,8 +52,8 @@ class Dependant(object): # logging.info(f"payload received: inhale exhale ratio = {payload.inhale_exhale_ratio} ") #if payload.getType() == PAYLOAD_TYPE.CYCLE.value: # logging.info(f"payload received: {payload} ") - if payload.getType() == PAYLOAD_TYPE.READBACK.value: - logging.info(f"payload received: {payload} ") + #if payload.getType() == PAYLOAD_TYPE.READBACK.value: + # logging.info(f"payload received: {payload} ") #if payload.getType() == PAYLOAD_TYPE.DEBUG.value: # logging.info(f" PID {payload.kp:3.6f} {payload.ki:3.6f} {payload.kd:3.6f} {payload.proportional:3.6f} {payload.integral:3.6f} {payload.derivative:3.6f} {payload.valve_duty_cycle:3.6f} {payload.target_pressure:3.6f} {payload.process_pressure:3.6f} fsm {fsm}") if payload.getType() == PAYLOAD_TYPE.LOGMSG.value: