diff --git a/arduino/hev_prototype_v1/src/BreathingLoop.cpp b/arduino/hev_prototype_v1/src/BreathingLoop.cpp index d73a89ca76f5dd8e6c8f28717506f1351046f4d4..bb2178e59cc2fef4533b06eed72cab9d9aaec498 100644 --- a/arduino/hev_prototype_v1/src/BreathingLoop.cpp +++ b/arduino/hev_prototype_v1/src/BreathingLoop.cpp @@ -100,7 +100,7 @@ void BreathingLoop::initTargets() _targets_pcac.buffer_lower_pressure = 285.0; _targets_pcac.buffer_upper_pressure = 300.0; - _targets_pcac.inhale_rise_time = 100; // not yet doing anything + _targets_pcac.pid_gain = 1; // not yet doing anything // copy all from PCAC _targets_pcac_prvc = _targets_pcac; @@ -1001,8 +1001,8 @@ void BreathingLoop::doPID(){ //Calculate the PID error based on the pid set point float error = _pid.target_pressure - _pid.process_pressure; - _pid.proportional = _pid.Kp*error; - _pid.integral += _pid.Ki*error; + _pid.proportional = _targets_current->pid_gain * _pid.Kp*error; + _pid.integral += _targets_current->pid_gain * _pid.Ki*error; //Derivative calculation diff --git a/arduino/hev_prototype_v1/src/UILoop.cpp b/arduino/hev_prototype_v1/src/UILoop.cpp index 05753f76509dcb5199111f37749c82ba661b18b5..7a32c023feefc6bedddf78afe33e0c9ce7eb199e 100644 --- a/arduino/hev_prototype_v1/src/UILoop.cpp +++ b/arduino/hev_prototype_v1/src/UILoop.cpp @@ -314,7 +314,7 @@ void UILoop::reportTargetsNow(target_variables &targets) _target_data.exhale_trigger_threshold = targets.exhale_trigger_threshold; _target_data.buffer_lower_pressure = targets.buffer_lower_pressure; _target_data.buffer_upper_pressure = targets.buffer_upper_pressure; - _target_data.inhale_rise_time = static_cast<uint16_t>(targets.inhale_rise_time); + _target_data.pid_gain = targets.pid_gain; _pl_send.setPayload(PRIORITY::CMD_ADDR, reinterpret_cast<void *>(&_target_data), sizeof(_target_data)); _comms->writePayload(_pl_send); diff --git a/arduino/hev_prototype_v1/src/common.cpp b/arduino/hev_prototype_v1/src/common.cpp index 55dfab85c78923152c8d2f1ea1d597a0f11327c4..6475477675306c34d37b7f9824d6b3b940ada978 100644 --- a/arduino/hev_prototype_v1/src/common.cpp +++ b/arduino/hev_prototype_v1/src/common.cpp @@ -128,8 +128,8 @@ void setTarget(CMD_SET_TARGET cmd, target_variables &targets, float value) case CMD_SET_TARGET::EXHALE_TRIGGER_THRESHOLD : targets.exhale_trigger_threshold = value; break; - case CMD_SET_TARGET::INHALE_RISE_TIME: - targets.inhale_rise_time = static_cast<uint16_t>(value); + case CMD_SET_TARGET::PID_GAIN: + targets.pid_gain = value; break; } } diff --git a/arduino/hev_prototype_v1/src/common.h b/arduino/hev_prototype_v1/src/common.h index 326f6844f476fb0eecd68266fcd50d1f5014e0e6..9d62b9cd138a599e9bc74dfd6de3cd31eff9f6da 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 0xB2 +#define HEV_FORMAT_VERSION 0xB3 // const float MAX_VALVE_FRAC_OPEN = 0.74; @@ -128,7 +128,7 @@ enum CMD_SET_TARGET : uint8_t { INHALE_TIME = 7, INHALE_TRIGGER_THRESHOLD = 8, EXHALE_TRIGGER_THRESHOLD = 9, - INHALE_RISE_TIME = 10, + PID_GAIN = 10, // for debugging only; not for UIs INHALE_TRIGGER_ENABLE = 11, EXHALE_TRIGGER_ENABLE = 12, @@ -394,7 +394,7 @@ struct target_data_format{ float exhale_trigger_threshold ; float buffer_upper_pressure = 0.0; float buffer_lower_pressure = 0.0; - uint16_t inhale_rise_time = 0; //ms + float pid_gain = 0; }; #pragma pack() @@ -630,7 +630,7 @@ struct target_variables { float exhale_trigger_threshold ; float buffer_upper_pressure; float buffer_lower_pressure; - uint16_t inhale_rise_time; //ms + float pid_gain; //ms bool ie_selected; }; diff --git a/raspberry-backend/templates/index.html b/raspberry-backend/templates/index.html index 7db9d0f81a188a7dbd77642505fa635c23e0c641..abc60eec5ff52383cf3b16a75603bb602d9a2375 100644 --- a/raspberry-backend/templates/index.html +++ b/raspberry-backend/templates/index.html @@ -144,7 +144,7 @@ <div class="card-header d-flex align-items-center justify-content-between"> <a class="small text-dark col-center" href="#">Inhale Rise Time <small>[s]</small></a> </div> - <div class="card-body px-1 py-1 tiny"><input class = "setting-main lockable" id = "inhale_rise_time" value=0.0 onclick="show_easy_numpad(this,new input_controller('INHALE_RISE_TIME',this))"></div> + <div class="card-body px-1 py-1 tiny"><input class = "setting-main lockable" id = "pid_gain" value=0.0 onclick="show_easy_numpad(this,new input_controller('PID_GAIN',this))"></div> </div> diff --git a/raspberry-backend/templates/settings.html b/raspberry-backend/templates/settings.html index 2601c06f6bee2215258b0683419999e9f92d2bc4..0600e20c63c19196b267198585a8a6ae4f102ad8 100644 --- a/raspberry-backend/templates/settings.html +++ b/raspberry-backend/templates/settings.html @@ -96,7 +96,7 @@ <tr> <td></td> <td><label class="small">Inhale Rise Time</label></td> - <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="pcac_setting_inhale_rise_time" step = "any" type="number" value="" disabled /> ms</td> + <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="pcac_setting_pid_gain" step = "any" type="number" value="" disabled /> ms</td> </tr> <tr> <td></td> @@ -160,7 +160,7 @@ <tr> <td></td> <td><label class="small">Inhale Rise Time </label></td> - <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="prvc_setting_inhale_rise_time" step = "any" type="number" value="" disabled /> ms</td> + <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="prvc_setting_pid_gain" step = "any" type="number" value="" disabled /> ms</td> </tr> <tr> <td></td> @@ -224,7 +224,7 @@ <tr> <td></td> <td><label class="small">Inhale Rise Time </label></td> - <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="psv_setting_inhale_rise_time" step = "any" type="number" value="" disabled /> ms</td> + <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="psv_setting_pid_gain" step = "any" type="number" value="" disabled /> ms</td> </tr> <tr> <td></td> @@ -287,7 +287,7 @@ <tr> <td></td> <td><label class="small">Inhale Rise Time </label></td> - <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="test_setting_inhale_rise_time" step = "any" type="number" value="" disabled /> ms</td> + <td><input name="Inhale Rise Time" class="form-control py-1 lockable" id="test_setting_pid_gain" step = "any" type="number" value="" disabled /> ms</td> </tr> <tr> <td></td> @@ -559,7 +559,7 @@ function openSetting(el, cityName) { //var settings = ["respiratory_rate", "peep", "ie_ratio", "inhale_time", "inhale_trigger_threshold", "exhale_trigger_threshold","fio2_percent","volume", "inspiratory_pressure"]; -var settings = ["mode", "inspiratory_pressure", "ie_ratio", "volume", "respiratory_rate", "peep", "fiO2_percent", "inhale_time", "inhale_trigger_threshold", "exhale_trigger_threshold", "buffer_upper_pressure", "buffer_lower_pressure", "inhale_rise_time"] +var settings = ["mode", "inspiratory_pressure", "ie_ratio", "volume", "respiratory_rate", "peep", "fiO2_percent", "inhale_time", "inhale_trigger_threshold", "exhale_trigger_threshold", "buffer_upper_pressure", "buffer_lower_pressure", "pid_gain"] $(document).ready(function(){ var tablinks = document.getElementsByClassName("tablinks"); diff --git a/raspberry-dataserver/CommsCommon.py b/raspberry-dataserver/CommsCommon.py index 6b99847f5d17785996341626efa0646a0b1274f6..8dbd15f2d2bc6cb13166c47082e70023cff2c172 100644 --- a/raspberry-dataserver/CommsCommon.py +++ b/raspberry-dataserver/CommsCommon.py @@ -99,7 +99,7 @@ class CMD_SET_TARGET(Enum): INHALE_TIME = 7 INHALE_TRIGGER_THRESHOLD = 8 EXHALE_TRIGGER_THRESHOLD = 9 - INHALE_RISE_TIME = 10 + PID_GAIN = 10 # for debugging only; not for UIs INHALE_TRIGGER_ENABLE = 11 EXHALE_TRIGGER_ENABLE = 12 @@ -206,7 +206,7 @@ class HEVVersionError(Exception): @dataclass class PayloadFormat(): # class variables excluded from init args and output dict - _RPI_VERSION: ClassVar[int] = field(default=0xB2, init=False, repr=False) + _RPI_VERSION: ClassVar[int] = field(default=0xB3, 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) @@ -625,7 +625,7 @@ class IVTFormat(PayloadFormat): # ======================================= @dataclass class TargetFormat(PayloadFormat): - _dataStruct = Struct("<BIBBffffffHBBBffffH") + _dataStruct = Struct("<BIBBffffffHBBBfffff") payload_type: PAYLOAD_TYPE = PAYLOAD_TYPE.TARGET mode : int = 0 @@ -643,7 +643,7 @@ class TargetFormat(PayloadFormat): exhale_trigger_threshold : float = 0.0 buffer_upper_pressure : float = 0.0 buffer_lower_pressure : float = 0.0 - inhale_rise_time : int = 0 + pid_gain : float = 0.0 # for receiving DataFormat from microcontroller # fill the struct from a byteArray, @@ -670,7 +670,7 @@ class TargetFormat(PayloadFormat): self.exhale_trigger_threshold , self.buffer_upper_pressure, self.buffer_lower_pressure, - self.inhale_rise_time ) = self._dataStruct.unpack(byteArray) + self.pid_gain ) = self._dataStruct.unpack(byteArray) self.checkVersion() self.payload_type = PAYLOAD_TYPE(tmp_payload_type) diff --git a/raspberry-dataserver/CommsDebug.py b/raspberry-dataserver/CommsDebug.py index f510e2dd8f1a7a1ceb6a7f08816632fb69e45d6c..d73f9afcb55cc1c2fab46779d28b35e2453f2f9f 100755 --- a/raspberry-dataserver/CommsDebug.py +++ b/raspberry-dataserver/CommsDebug.py @@ -86,6 +86,7 @@ async def commsDebug(): 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_TARGET_CURRENT", cmd_code="PID_GAIN", param=2.5) send_cmd(cmd_type="SET_PID", cmd_code="NSTEPS", param=3) # # # Change TIMEOUT of breathing cycle (BUFF-PRE-INHALE) diff --git a/raspberry-dataserver/CommsDebug2.py b/raspberry-dataserver/CommsDebug2.py index 49a8cf37b1e9e732e8361816b9c1478fc2898ed0..ec2a8a86c3b27f2512e72b3d3c2512fe446e268b 100755 --- a/raspberry-dataserver/CommsDebug2.py +++ b/raspberry-dataserver/CommsDebug2.py @@ -36,7 +36,7 @@ class Dependant(object): while True: payload = await self._lli._payloadrecv.get() global fsm - logging.info(f"payload received: {payload}") + #logging.info(f"payload received: {payload}") #if payload.getType() == PAYLOAD_TYPE.ALARM.value: # logging.info(f"Alarm: {payload.alarm_code} of priority: {payload.alarm_type}") @@ -57,10 +57,10 @@ class Dependant(object): # logging.info(f"payload received: {payload.peep} {fsm}") #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.PERSONAL.value: - logging.info(f"payload received: {payload} ") - if payload.getType() == PAYLOAD_TYPE.LOGMSG.value: - logging.info(f"LOGMSG {payload.timestamp}:{payload.message} {fsm}") + #if payload.getType() == PAYLOAD_TYPE.PERSONAL.value: + # logging.info(f"payload received: {payload} ") + #if payload.getType() == PAYLOAD_TYPE.LOGMSG.value: + # logging.info(f"LOGMSG {payload.timestamp}:{payload.message} {fsm}") if payload.getType() == PAYLOAD_TYPE.TARGET.value: logging.info(f"TARGET {payload} {fsm}") if payload.getType() == PAYLOAD_TYPE.CMD.value: @@ -135,7 +135,7 @@ async def commsDebug(): await asyncio.sleep(1) - send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INHALE_RISE_TIME", param=200.0) + send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="PID_GAIN", param=2.3) #send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INHALE_TIME", param=1.220) #send_cmd(cmd_type="SET_TARGET_CURRENT", cmd_code="INSPIRATORY_PRESSURE", param=25) #await asyncio.sleep(1)