Skip to content
Snippets Groups Projects
Commit 82183e1f authored by Karol Hennessy's avatar Karol Hennessy
Browse files

added peep calc, inhale_time

parent ede4d99b
No related merge requests found
......@@ -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
......
......@@ -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));
}
......
......@@ -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;
......
......@@ -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:
......
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