diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.cpp b/arduino/hev_prototype_v1/src/BreathingLoop.cpp index a75e9b0b6b27cf91818301b360ec363a72c2df5d..83f705c34e09f4d84801a898db3b27e8b74d79b8 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.cpp +++ b/arduino/hev_prototype_v1/src/BreathingLoop.cpp @@ -74,12 +74,6 @@ BreathingLoop::BreathingLoop() _cycle_index = 0; - _inhale_trigger_threshold = 0.005; // abs flow ?unit - _exhale_trigger_threshold = 0.2; // 30% of peak - - _inhale_trigger_threshold = _valves_controller.getValveParams().inhale_trigger_threshold; - _exhale_trigger_threshold = _valves_controller.getValveParams().exhale_trigger_threshold; - _min_inhale_time = 150; _min_exhale_time = 300; _max_exhale_time = 30000; // for mandatory cycle - changed to 30s for the sponteneous breath testing @@ -100,7 +94,11 @@ void BreathingLoop::initTargets() _targets_pcac.inhale_time= 1000; _targets_pcac.peep = 5; _targets_pcac.fiO2_percent = 21; - _targets_pcac.buffer_lower_pressure = 0.0; + + _targets_pcac.inhale_trigger_threshold = 0.0005; // abs flow ? unit / + _targets_pcac.exhale_trigger_threshold = 0.25; // 25% of the peak flow + + _targets_pcac.buffer_lower_pressure = 285.0; _targets_pcac.buffer_upper_pressure = 300.0; // copy all from PCAC @@ -109,6 +107,21 @@ void BreathingLoop::initTargets() _targets_cpap = _targets_pcac; _targets_test = _targets_pcac; + _targets_pcac.inhale_trigger_enable = true; + _targets_pcac.exhale_trigger_enable = false; + _targets_pcac.volume_trigger_enable = false; + _targets_pcac_prvc.inhale_trigger_enable = true; + _targets_pcac_prvc.exhale_trigger_enable = false; + _targets_pcac_prvc.volume_trigger_enable = true; + _targets_pc_psv.inhale_trigger_enable = true; + _targets_pc_psv.exhale_trigger_enable = true; + _targets_pc_psv.volume_trigger_enable = false; + _targets_cpap.inhale_trigger_enable = true; + _targets_cpap.exhale_trigger_enable = true; + _targets_cpap.volume_trigger_enable = false; + _targets_test.inhale_trigger_enable = true; + _targets_test.exhale_trigger_enable = true; + _targets_test.volume_trigger_enable = false; // "current" mode is set by ventilation mode // set modes for readback @@ -301,37 +314,34 @@ void BreathingLoop::updateCycleReadings() void BreathingLoop::setVentilationMode(VENTILATION_MODE mode) { _ventilation_mode = mode; - valve_params &vp = _valves_controller.getValveParams(); switch(_ventilation_mode){ case VENTILATION_MODE::PC_AC : - vp.inhale_trigger_enable = true; - vp.exhale_trigger_enable = false; - vp.volume_trigger_enable = false; + _targets_pcac.inhale_trigger_enable = true; + _targets_pcac.exhale_trigger_enable = false; + _targets_pcac.volume_trigger_enable = false; _targets_current = &_targets_pcac; break; case VENTILATION_MODE::PC_AC_PRVC : - vp.inhale_trigger_enable = true; - vp.exhale_trigger_enable = false; - vp.volume_trigger_enable = true; + _targets_pcac_prvc.inhale_trigger_enable = true; + _targets_pcac_prvc.exhale_trigger_enable = false; + _targets_pcac_prvc.volume_trigger_enable = true; _targets_current = &_targets_pcac_prvc; break; case VENTILATION_MODE::PC_PSV : - vp.inhale_trigger_enable = true; - vp.exhale_trigger_enable = true; - vp.volume_trigger_enable = false; + _targets_pc_psv.inhale_trigger_enable = true; + _targets_pc_psv.exhale_trigger_enable = true; + _targets_pc_psv.volume_trigger_enable = false; _targets_current = &_targets_pc_psv; break; case VENTILATION_MODE::CPAP : - vp.inhale_trigger_enable = true; - vp.exhale_trigger_enable = true; - vp.volume_trigger_enable = false; + _targets_cpap.inhale_trigger_enable = true; + _targets_cpap.exhale_trigger_enable = true; + _targets_cpap.volume_trigger_enable = false; _targets_current = &_targets_cpap; break; case VENTILATION_MODE::TEST: - vp.inhale_trigger_enable = true; - vp.exhale_trigger_enable = true; - vp.volume_trigger_enable = false; + // in test mode you can set the triggers on / off _targets_current = &_targets_test; break; default : @@ -567,7 +577,7 @@ void BreathingLoop::FSM_breathCycle() // 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))){ _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_upper_pressure - 15){ + } 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); } measurePEEP(); @@ -1029,7 +1039,7 @@ target_variables& BreathingLoop::getTargetVariablesCurrent(){ return (*_targets_ bool BreathingLoop::inhaleTrigger() { - bool en = _valves_controller.getValveParams().inhale_trigger_enable; + bool en = _targets_current->inhale_trigger_enable; //logMsg("inhale trig- " + String(_readings_avgs.pressure_diff_patient,6) + " " + String(_valves_controller.getValveParams().inhale_trigger_threshold,6)); String result = ""; @@ -1042,7 +1052,7 @@ bool BreathingLoop::inhaleTrigger() } //_fsm_timeout = _max_exhale_time; uint32_t tnow = static_cast<uint32_t>(millis()); - if((_readings_avgs.pressure_diff_patient > _valves_controller.getValveParams().inhale_trigger_threshold) + if((_readings_avgs.pressure_diff_patient > _targets_current->inhale_trigger_threshold) && (tnow - _valley_flow_time >= 100)){ // wait 100ms after the valley if (tnow - _fsm_time >= _min_exhale_time ) { // TRIGGER @@ -1070,7 +1080,7 @@ bool BreathingLoop::inhaleTrigger() bool BreathingLoop::exhaleTrigger() { - bool en = _valves_controller.getValveParams().exhale_trigger_enable; + bool en = _targets_current->exhale_trigger_enable; //logMsg("EXhale trig- " + String(_flow) + " " + String(_running_avg_flow) +" "+ String(_valves_controller.getValveParams().exhale_trigger_threshold)+" "+String(_peak_flow)); @@ -1078,7 +1088,7 @@ bool BreathingLoop::exhaleTrigger() //logMsg("exhale trigger"); uint32_t tnow = static_cast<uint32_t>(millis()); valve_params vp = _valves_controller.getValveParams(); - if((_running_avg_flow < (vp.exhale_trigger_threshold * _peak_flow)) + if((_running_avg_flow < (_targets_current->exhale_trigger_threshold * _peak_flow)) && (tnow - _peak_flow_time >= 100)){ // wait 10ms after peak //TODO - check we're past 'peak' //logMsg(" EXhale trig- " + String(_running_avg_flow) +" "+ String(vp.exhale_trigger_threshold)+" "+String(_peak_flow)); @@ -1095,15 +1105,14 @@ bool BreathingLoop::exhaleTrigger() bool BreathingLoop::volumeTrigger() { - bool en = _valves_controller.getValveParams().volume_trigger_enable; + bool en = _targets_current->volume_trigger_enable; //logMsg("volume trig- " + String(_flow) + " " + String(_running_avg_flow) +" "+ String(_valves_controller.getValveParams().exhale_trigger_threshold)+" "+String(_peak_flow)); if(en == true){ //logMsg("volume trigger"); uint32_t tnow = static_cast<uint32_t>(millis()); - valve_params vp = _valves_controller.getValveParams(); - if(_volume < vp.volume_trigger_threshold ){ + if(_volume < _targets_current->volume){ if (tnow - _fsm_time >= _min_inhale_time ) { // TRIGGER _fsm_timeout = 0; // go to next state immediately diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.h b/arduino/hev_prototype_v1/src/BreathingLoop.h index 17f2e002c737cc46fdf2ba4d612025f3498fe671..fc3ae604355b17adb973f4c7173b63755a94ab05 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.h +++ b/arduino/hev_prototype_v1/src/BreathingLoop.h @@ -192,8 +192,6 @@ private: uint8_t _running_index_peep; bool _inhale_triggered; - float _inhale_trigger_threshold; - float _exhale_trigger_threshold; float _peak_flow; float _valley_flow; uint32_t _peak_flow_time; diff --git a/arduino/hev_prototype_v1/src/UILoop.cpp b/arduino/hev_prototype_v1/src/UILoop.cpp index dbdb9de6d6f3e17bbff87a906ea4680309e0700a..e364a3d3036bd5e3bf9990584793b78b61aece73 100644 --- a/arduino/hev_prototype_v1/src/UILoop.cpp +++ b/arduino/hev_prototype_v1/src/UILoop.cpp @@ -151,8 +151,8 @@ void UILoop::reportReadbackValues() _readback_data.valve_air_in_enable = vparams.valve_air_in_enable; _readback_data.valve_o2_in_enable = vparams.valve_o2_in_enable; _readback_data.valve_purge_enable = vparams.valve_purge_enable; - _readback_data.inhale_trigger_enable = vparams.inhale_trigger_enable; - _readback_data.exhale_trigger_enable = vparams.exhale_trigger_enable; + _readback_data.inhale_trigger_enable = _breathing_loop->getTargetVariablesCurrent().inhale_trigger_enable; + _readback_data.exhale_trigger_enable = _breathing_loop->getTargetVariablesCurrent().exhale_trigger_enable; _readback_data.peep = _breathing_loop->getPEEP(); _readback_data.inhale_exhale_ratio = _breathing_loop->getIERatio(); @@ -448,28 +448,6 @@ void UILoop::cmdSetTarget(cmd_format &cf, int8_t mode){ } } -// void UILoop::cmdSetPersonal(cmd_format &cf){ -// switch(cf.cmd_code){ - -// case CMD_SET_PERSONAL::NAME: -// _personal.name = static_cast<char*>(cf.param); -// break; -// case CMD_SET_PERSONAL::AGE: -// _personal.age = static_cast<uint8_t>(cf.param); -// break; -// case CMD_SET_PERSONAL::SEX: -// _personal.sex = static_cast<char>(cf.param); -// break; -// case CMD_SET_PERSONAL::HEIGHT: -// _personal.height = static_cast<uint8_t>(cf.param); -// break; -// case CMD_SET_PERSONAL::WEIGHT: -// _personal.weight = static_cast<uint8_t>(cf.param); -// break; -// default: -// break; -// } -// } void UILoop::cmdGetTarget(cmd_format &cf){ diff --git a/arduino/hev_prototype_v1/src/ValvesController.cpp b/arduino/hev_prototype_v1/src/ValvesController.cpp index 8ba77603f4930a78b46cb0cb31ef0ca3a40aa38b..91299260f7a2634edc1ffc0e127cee6215331498 100644 --- a/arduino/hev_prototype_v1/src/ValvesController.cpp +++ b/arduino/hev_prototype_v1/src/ValvesController.cpp @@ -53,14 +53,6 @@ ValvesController::ValvesController() _valve_params.valve_air_in_enable = 1; _valve_params.valve_o2_in_enable = 1; _valve_params.valve_purge_enable = 1; - _valve_params.inhale_trigger_enable = 0; // params - associated val of peak flow - _valve_params.exhale_trigger_enable = 0; - _valve_params.volume_trigger_enable = 0; - - _valve_params.inhale_trigger_threshold = 0.0025; // abs flow ? unit / - _valve_params.exhale_trigger_threshold = 0.3; // 30% of the peak flow - _valve_params.volume_trigger_threshold = 400; // ml - _PID_output = 0; _INA_found = false; diff --git a/arduino/hev_prototype_v1/src/common.cpp b/arduino/hev_prototype_v1/src/common.cpp index 7abb8dace7dc7c686dece26a7a797f136b7a9847..1a1ac018093cbc3db3b00612745f3e2097b235c5 100644 --- a/arduino/hev_prototype_v1/src/common.cpp +++ b/arduino/hev_prototype_v1/src/common.cpp @@ -49,12 +49,6 @@ void setValveParam(CMD_SET_VALVE cmd, valve_params &vparams, float value) case CMD_SET_VALVE::PURGE_ENABLE : vparams.valve_purge_enable = (value > 0.9); break; - case CMD_SET_VALVE::INHALE_TRIGGER_ENABLE : - vparams.inhale_trigger_enable = (value > 0.9); - break; - case CMD_SET_VALVE::EXHALE_TRIGGER_ENABLE : - vparams.exhale_trigger_enable = (value > 0.9); - break; case CMD_SET_VALVE::INHALE_DUTY_CYCLE : vparams.inhale_duty_cycle = (value < 0) ? 0.0 : (value > MAX_VALVE_FRAC_OPEN) ? MAX_VALVE_FRAC_OPEN : value; break; @@ -64,12 +58,6 @@ void setValveParam(CMD_SET_VALVE cmd, valve_params &vparams, float value) case CMD_SET_VALVE::INHALE_OPEN_MAX : vparams.inhale_open_max = (value < 0) ? 0.0 : (value > MAX_VALVE_FRAC_OPEN) ? MAX_VALVE_FRAC_OPEN : value; break; - case CMD_SET_VALVE::INHALE_TRIGGER_THRESHOLD : - vparams.inhale_trigger_threshold = value; - break; - case CMD_SET_VALVE::EXHALE_TRIGGER_THRESHOLD : - vparams.exhale_trigger_threshold = value; - break; default: break; } @@ -125,6 +113,21 @@ void setTarget(CMD_SET_TARGET cmd, target_variables &targets, float value) targets.inhale_time = value; targets.ie_selected = false; break; + case CMD_SET_TARGET::INHALE_TRIGGER_ENABLE : + targets.inhale_trigger_enable = (value > 0.9); + break; + case CMD_SET_TARGET::EXHALE_TRIGGER_ENABLE : + targets.exhale_trigger_enable = (value > 0.9); + break; + case CMD_SET_TARGET::VOLUME_TRIGGER_ENABLE : + targets.volume_trigger_enable = (value > 0.9); + break; + case CMD_SET_TARGET::INHALE_TRIGGER_THRESHOLD : + targets.inhale_trigger_threshold = value; + break; + case CMD_SET_TARGET::EXHALE_TRIGGER_THRESHOLD : + targets.exhale_trigger_threshold = value; + break; } } diff --git a/arduino/hev_prototype_v1/src/common.h b/arduino/hev_prototype_v1/src/common.h index 4688beb22b32f4d46fbd0012fd1b6cc9fdf0caf3..7776bab889456ce2433b5504c95fdabd4f17625e 100644 --- a/arduino/hev_prototype_v1/src/common.h +++ b/arduino/hev_prototype_v1/src/common.h @@ -21,7 +21,7 @@ #include <Arduino_Due_pinout.h> #endif -#define HEV_FORMAT_VERSION 0xB0 +#define HEV_FORMAT_VERSION 0xB1 // const float MAX_VALVE_FRAC_OPEN = 0.74; @@ -106,10 +106,6 @@ enum CMD_SET_VALVE: uint8_t { INHALE_DUTY_CYCLE = 4, INHALE_OPEN_MIN = 5, INHALE_OPEN_MAX = 6, - INHALE_TRIGGER_ENABLE = 7, - EXHALE_TRIGGER_ENABLE = 8, - INHALE_TRIGGER_THRESHOLD = 9, - EXHALE_TRIGGER_THRESHOLD = 10 }; enum CMD_SET_PID : uint8_t { @@ -121,13 +117,20 @@ enum CMD_SET_PID : uint8_t { }; enum CMD_SET_TARGET : uint8_t { - INSPIRATORY_PRESSURE = 1, - RESPIRATORY_RATE = 2, - IE_RATIO = 3, - VOLUME = 4, - PEEP = 5, - FIO2 = 6, - INHALE_TIME = 7 + INSPIRATORY_PRESSURE = 1, + RESPIRATORY_RATE = 2, + IE_RATIO = 3, + VOLUME = 4, + PEEP = 5, + FIO2 = 6, + INHALE_TIME = 7, + INHALE_TRIGGER_THRESHOLD = 8, + EXHALE_TRIGGER_THRESHOLD = 9, + // for debugging only; not for UIs + INHALE_TRIGGER_ENABLE = 10, + EXHALE_TRIGGER_ENABLE = 11, + VOLUME_TRIGGER_ENABLE = 12 + }; enum CMD_SET_PERSONAL : uint8_t { @@ -381,6 +384,11 @@ struct target_data_format{ float peep = 0.0; float fiO2_percent = 0.0; uint16_t inhale_time = 0 ; + uint8_t inhale_trigger_enable = 0; // params - associated val of peak flow + uint8_t exhale_trigger_enable = 0; + uint8_t volume_trigger_enable = 0; + float inhale_trigger_threshold ; // params - associated val of peak flow + float exhale_trigger_threshold ; float buffer_upper_pressure = 0.0; float buffer_lower_pressure = 0.0; }; @@ -611,6 +619,11 @@ struct target_variables { float peep; float fiO2_percent; uint16_t inhale_time; + bool inhale_trigger_enable ; // params - associated val of peak flow + bool exhale_trigger_enable ; + bool volume_trigger_enable ; + float inhale_trigger_threshold ; // params - associated val of peak flow + float exhale_trigger_threshold ; float buffer_upper_pressure; float buffer_lower_pressure; bool ie_selected; @@ -659,15 +672,9 @@ struct valve_params{ bool valve_air_in_enable ; bool valve_o2_in_enable ; bool valve_purge_enable ; - bool inhale_trigger_enable ; // params - associated val of peak flow - bool exhale_trigger_enable ; - bool volume_trigger_enable ; float inhale_duty_cycle; float inhale_open_min; float inhale_open_max; - float inhale_trigger_threshold ; // params - associated val of peak flow - float exhale_trigger_threshold ; - float volume_trigger_threshold ; }; diff --git a/raspberry-dataserver/CommsCommon.py b/raspberry-dataserver/CommsCommon.py index 79afd44a3323205bbdcee67f22f4d32ecc89b86c..3634547b6f5e4ce4410807a6064fe0adaa2b8516 100644 --- a/raspberry-dataserver/CommsCommon.py +++ b/raspberry-dataserver/CommsCommon.py @@ -76,8 +76,6 @@ class CMD_SET_VALVE(Enum): INHALE_OPEN_MAX = 6 INHALE_TRIGGER_ENABLE = 7 EXHALE_TRIGGER_ENABLE = 8 - INHALE_TRIGGER_THRESHOLD = 9 - EXHALE_TRIGGER_THRESHOLD = 10 @unique class CMD_SET_PID(Enum): @@ -89,13 +87,19 @@ class CMD_SET_PID(Enum): @unique class CMD_SET_TARGET(Enum): - INSPIRATORY_PRESSURE = 1 - RESPIRATORY_RATE = 2 - IE_RATIO = 3 - VOLUME = 4 - PEEP = 5 - FIO2 = 6 - INHALE_TIME = 7 + INSPIRATORY_PRESSURE = 1 + RESPIRATORY_RATE = 2 + IE_RATIO = 3 + VOLUME = 4 + PEEP = 5 + FIO2 = 6 + INHALE_TIME = 7 + INHALE_TRIGGER_THRESHOLD = 8 + EXHALE_TRIGGER_THRESHOLD = 9 + # for debugging only; not for UIs + INHALE_TRIGGER_ENABLE = 10 + EXHALE_TRIGGER_ENABLE = 11 + VOLUME_TRIGGER_ENABLE = 12 @unique # class CMD_SET_PERSONAL(Enum): @@ -196,7 +200,7 @@ class HEVVersionError(Exception): @dataclass class PayloadFormat(): # class variables excluded from init args and output dict - _RPI_VERSION: ClassVar[int] = field(default=0xB0, init=False, repr=False) + _RPI_VERSION: ClassVar[int] = field(default=0xB1, init=False, repr=False) _dataStruct: ClassVar[Any] = field(default=Struct("<BIB"), init=False, repr=False) _byteArray: ClassVar[bytearray] = field(default=None, init=False, repr=False) @@ -615,19 +619,24 @@ class IVTFormat(PayloadFormat): # ======================================= @dataclass class TargetFormat(PayloadFormat): - _dataStruct = Struct("<BIBBffffffHff") + _dataStruct = Struct("<BIBBffffffHBBBffff") payload_type: PAYLOAD_TYPE = PAYLOAD_TYPE.TARGET - mode : int = 0 - inspiratory_pressure : float = 0.0 - ie_ratio : float = 0.0 - volume : float = 0.0 - respiratory_rate : float = 0.0 - peep : float = 0.0 - fiO2_percent : float = 0.0 - inhale_time : int = 0 - buffer_upper_pressure : float = 0.0 - buffer_lower_pressure : float = 0.0 + mode : int = 0 + inspiratory_pressure : float = 0.0 + ie_ratio : float = 0.0 + volume : float = 0.0 + respiratory_rate : float = 0.0 + peep : float = 0.0 + fiO2_percent : float = 0.0 + inhale_time : int = 0 + inhale_trigger_enable : int = 0 + exhale_trigger_enable : int = 0 + volume_trigger_enable : int = 0 + inhale_trigger_threshold : float = 0.0 + exhale_trigger_threshold : float = 0.0 + buffer_upper_pressure : float = 0.0 + buffer_lower_pressure : float = 0.0 # for receiving DataFormat from microcontroller # fill the struct from a byteArray, @@ -647,6 +656,11 @@ class TargetFormat(PayloadFormat): self.peep , self.fiO2_percent , self.inhale_time , + self.inhale_trigger_enable , + self.exhale_trigger_enable , + self.volume_trigger_enable , + self.inhale_trigger_threshold , + self.exhale_trigger_threshold , self.buffer_upper_pressure, self.buffer_lower_pressure ) = self._dataStruct.unpack(byteArray) diff --git a/raspberry-dataserver/CommsDebug.py b/raspberry-dataserver/CommsDebug.py index 7eed10a401206ab55e36e602a01f34fe0606544c..25e046d714b282800b1d2fb4d2ab51e7b81e9794 100755 --- a/raspberry-dataserver/CommsDebug.py +++ b/raspberry-dataserver/CommsDebug.py @@ -80,47 +80,43 @@ def send_cmd(cmd_type, cmd_code, param=0.0): # initialise as start command, automatically executes toByteArray() async def commsDebug(): await asyncio.sleep(1) - cmd = send_cmd(cmd_type="SET_PID", cmd_code="KP", param=1.0*0.001)# - cmd = send_cmd(cmd_type="SET_PID", cmd_code="KI", param=1.0*0.0005)# 0.0005 - cmd = send_cmd(cmd_type="SET_PID", cmd_code="KD", param=1.0*0.001)# 0.001 - cmd = send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INSPIRATORY_PRESSURE", param=17.5)# - #cmd = send_cmd(cmd_type="SET_PID", cmd_code="TARGET_FINAL_PRESSURE", param=20.0)# - cmd = send_cmd(cmd_type="SET_PID", cmd_code="NSTEPS", param=3) # + send_cmd(cmd_type="SET_MODE", cmd_code="TEST", param=0) + + send_cmd(cmd_type="SET_PID", cmd_code="KP", param=1.0*0.001)# + send_cmd(cmd_type="SET_PID", cmd_code="KI", param=1.0*0.0005)# 0.0005 + send_cmd(cmd_type="SET_PID", cmd_code="KD", param=1.0*0.001)# 0.001 + send_cmd(cmd_type="SET_PID", cmd_code="NSTEPS", param=3) # + # # Change TIMEOUT of breathing cycle (BUFF-PRE-INHALE) - cmd = send_cmd(cmd_type="SET_DURATION", cmd_code="BUFF_PRE_INHALE", param=10.) # - # Change TIMEOUT of breathing cycle (INHALE) - cmd = send_cmd(cmd_type="SET_DURATION", cmd_code="PAUSE", param=10.) # - # Start the cycles - cmd = send_cmd(cmd_type="SET_VALVE", cmd_code="INHALE_TRIGGER_THRESHOLD", param=0.0005) # - # Enable exhale trigger threshold - cmd = send_cmd(cmd_type="SET_VALVE", cmd_code="EXHALE_TRIGGER_THRESHOLD", param=0.25) # - # Start the cycles - cmd = CommandFormat(cmd_type="SET_MODE", cmd_code="TEST", param=0) + send_cmd(cmd_type="SET_DURATION", cmd_code="BUFF_PRE_INHALE", param=10.) # + send_cmd(cmd_type="SET_DURATION", cmd_code="PAUSE", param=10.) # - send_cmd(cmd_type="SET_VALVE", cmd_code="INHALE_OPEN_MIN", param=0.53) - #comms.writePayload(cmd) - print('sent cmd start') - await asyncio.sleep(1) - send_cmd(cmd_type="SET_VALVE", cmd_code="INHALE_TRIGGER_ENABLE", param=0) - send_cmd(cmd_type="SET_VALVE", cmd_code="EXHALE_TRIGGER_ENABLE", param=0) send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="RESPIRATORY_RATE", param=10.0) send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INHALE_TIME", param=1000) + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INSPIRATORY_PRESSURE", param=17.5)# + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INHALE_TRIGGER_THRESHOLD", param=0.0005) # + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="EXHALE_TRIGGER_THRESHOLD", param=0.25) # + + send_cmd(cmd_type="SET_VALVE", cmd_code="INHALE_OPEN_MIN", param=0.53) + + ### NOTE : THESE ARE FOR TESTING ONLY, AS THEY OVERRIDE THE VALUES SET BY THE VENTILATION MODE + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INHALE_TRIGGER_ENABLE", param=0) + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="EXHALE_TRIGGER_ENABLE", param=0) + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="VOLUME_TRIGGER_ENABLE", param=0) + + print('sent cmd start') send_cmd(cmd_type="GENERAL", cmd_code="START", param=1000) - #print('sent inhale + exhale trigger -> 1') + toggle = "STOP" while True: await asyncio.sleep(300) - #cmd = send_cmd(cmd_type="SET_PID", cmd_code="KP", param=5) # - #comms.writePayload(cmd) - #print('sent cmd set Kp = 0.2') await asyncio.sleep(300) - cmd = send_cmd(cmd_type="GENERAL", cmd_code=toggle, param=0) + send_cmd(cmd_type="GENERAL", cmd_code=toggle, param=0) if toggle == "STOP" : toggle = "START" else : toggle = "STOP" - comms.writePayload(cmd) print('sent cmd stop') try: