Skip to content
Snippets Groups Projects
Commit 356463fd authored by Stephen Farry's avatar Stephen Farry
Browse files

settings merged

parents 21e1a12a 3b43482b
Branches
No related merge requests found
......@@ -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;
......@@ -599,7 +599,7 @@ void BreathingLoop::FSM_breathCycle()
break;
case BL_STATES::STOP:
// TODO : require a reset command to go back to idle
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::CLOSED);
_valves_controller.setValves(VALVE_STATE::CLOSED, VALVE_STATE::CLOSED, VALVE_STATE::FULLY_CLOSED, VALVE_STATE::OPEN, VALVE_STATE::CLOSED);
_fsm_timeout = 1000;
break;
default:
......@@ -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
......
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -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;
};
......
......@@ -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>
......
This diff is collapsed.
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
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