software:firmware
MakAir Firmware
main_controller.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 // INCLUDES ===================================================================
11 
12 // Internal
13 
14 #include "../includes/alarm_controller.h"
15 #include "../includes/battery.h"
16 #include "../includes/blower.h"
17 #include "../includes/config.h"
18 #include "../includes/cycle.h"
19 #include "../includes/debug.h"
20 #include "../includes/parameters.h"
21 #include "../includes/pc_ac_controller.h"
22 #include "../includes/pc_cmv_controller.h"
23 #include "../includes/pc_vsai_controller.h"
24 #include "../includes/pressure_valve.h"
25 #include "../includes/telemetry.h"
26 #include "../includes/vc_ac_controller.h"
27 #include "../includes/vc_cmv_controller.h"
28 
30 #define MAX_PRESSURE_SAMPLES 10u
31 
32 // CLASS ======================================================================
33 
35 // cppcheck-suppress misra-c2012-5.2 ; false positive
37  public:
40 
42  void setup();
43 
45  void initRespiratoryCycle();
46 
48  void endRespiratoryCycle(uint32_t p_currentMillis);
49 
55  void updateTick(uint32_t p_tick);
56 
62  void updatePressure(int16_t p_currentPressure);
63 
69  void updateInspiratoryFlow(int32_t p_currentInspiratoryFlow);
70 
76  void updateExpiratoryFlow(int32_t p_currentExpiratoryFlow);
77 
80 
86  void compute();
87 
89  void onVentilationModeSet(uint16_t p_ventilationControllerMode);
90 
92  void onInspiratoryTriggerFlowSet(uint16_t p_inspiratoryTriggerFlow);
93 
95  void onExpiratoryTriggerFlowSet(uint16_t p_expiratoryTriggerFlow);
96 
98  void onTiMinSet(uint16_t p_tiMin);
99 
101  void onTiMaxSet(uint16_t p_tiMax);
102 
105  uint16_t p_lowInspiratoryMinuteVolumeAlarmThreshold);
106 
109  uint16_t p_highInspiratoryMinuteVolumeAlarmThreshold);
110 
113  uint16_t p_lowExpiratoryMinuteVolumeAlarmThreshold);
114 
117  uint16_t p_highExpiratoryMinuteVolumeAlarmThreshold);
118 
120  void onlowRespiratoryRateAlarmThresholdSet(uint16_t p_lowRespiratoryRateAlarmThreshold);
121 
123  void onhighRespiratoryRateAlarmThresholdSet(uint16_t p_highRespiratoryRateAlarmThreshold);
124 
126  void onTargetTidalVolumeSet(uint16_t p_targetTidalVolume);
127 
129  void onLowTidalVolumeAlarmThresholdSet(uint16_t p_lowTidalVolumeAlarmThreshold);
130 
132  void onHighTidalVolumeAlarmThresholdSet(uint16_t p_highTidalVolumeAlarmThreshold);
133 
135  void onPlateauDurationSet(uint16_t p_plateauDuration);
136 
138  void onLeakAlarmThresholdSet(uint16_t p_leakAlarmThreshold);
139 
141  void onTargetInspiratoryFlow(uint16_t p_targetInspiratoryFlow);
142 
144  void onInspiratoryDuration(uint16_t p_inspiratoryDuration);
145 
147  void onCycleDecrease();
148 
150  void onCycleIncrease();
151 
157  void onCycleSet(uint16_t p_cpm);
158 
160  void onPeepPressureDecrease();
161 
163  void onPeepPressureIncrease();
164 
170  void onPeepSet(int16_t p_peep);
171 
174 
177 
183  void onPlateauPressureSet(int16_t p_plateauPressure);
184 
190  void onPeakPressureDecrease();
191 
197  void onPeakPressureIncrease();
198 
205  void onExpiratoryTermSet(uint16_t p_expiratoryTerm);
206 
212  void onTriggerModeEnabledSet(uint16_t p_triggerEnabled);
213 
219  void onTriggerOffsetSet(uint16_t p_triggerOffset);
220 
226  void onPatientHeight(int16_t p_patientHeight);
227 
233  void onPeakPressureAlarmThreshold(int16_t p_peakPressureAlarmThreshold);
234 
240  void onPatientGender(int16_t p_patientGender);
241 
246  void onPatientComputePreset();
247 
248  // Get the patient Height in cm
249  inline int32_t patientHeight() const { return m_patientHeight; }
250  // Get the desired tidalVolue
251  inline int16_t tidalVolumeCommand() const { return m_tidalVolumeCommand; }
252  // Get the desired plateau duration (in VC modes)
253  inline int16_t plateauDurationCommand() const { return m_plateauDurationCommand; }
255  inline int16_t peakPressureCommand() const { return m_peakPressureCommand; }
257  inline int16_t plateauPressureCommand() const { return m_plateauPressureCommand; }
259  inline int16_t peepCommand() const { return m_peepNextCommand; }
261  inline uint16_t cyclesPerMinuteCommand() const { return m_cyclesPerMinuteCommand; }
263  inline const int16_t pressureTriggerOffsetCommand() const {
265  }
269  inline const int16_t inspiratoryTriggerFlowCommand() const {
271  }
273  inline const int16_t expiratoryTriggerFlowCommand() const {
275  }
277  inline const int16_t tiMinCommand() const { return m_tiMinCommand; }
279  inline const int16_t tiMaxCommand() const { return m_tiMaxCommand; }
281  inline const int32_t targetInspiratoryFlowCommand() const {
283  }
285  inline const int16_t inspiratoryDurationCommand() const { return m_inspiratoryDurationCommand; }
286 
288  inline int16_t tidalVolumeNextCommand() const { return m_tidalVolumeNextCommand; }
289  // Get the desired plateau duration for the next cycle (used in VC modes)
290  inline int16_t plateauDurationNextCommand() const { return m_plateauDurationNextCommand; }
292  inline int16_t peakPressureNextCommand() const { return m_peakPressureNextCommand; }
294  inline int16_t plateauPressureNextCommand() const { return m_plateauPressureNextCommand; }
296  inline int16_t peepNextCommand() const { return m_peepNextCommand; }
298  inline uint16_t cyclesPerMinuteNextCommand() const { return m_cyclesPerMinuteNextCommand; }
300  inline const int16_t pressureTriggerOffsetNextCommand() const {
302  }
306  inline const int16_t inspiratoryTriggerFlowNextCommand() const {
308  }
310  inline const int16_t expiratoryTriggerFlowNextCommand() const {
312  }
314  inline const int16_t tiMinNextCommand() const { return m_tiMinNextCommand; }
316  inline const int16_t tiMaxNextCommand() const { return m_tiMaxNextCommand; }
318  inline const int32_t targetInspiratoryFlowNextCommand() const {
320  }
322  inline const int16_t inspiratoryDurationNextCommand() const {
324  }
328  }
329 
331  inline int16_t peakPressureMeasure() const { return m_peakPressureMeasure; }
335  inline int16_t plateauPressureMeasure() const { return m_plateauPressureMeasure; }
337  inline int16_t peepMeasure() const { return m_peepMeasure; }
339  inline uint16_t cyclesPerMinuteMeasure() const { return m_cyclesPerMinuteMeasure; }
341  inline uint16_t tidalVolumeMeasure() const { return m_tidalVolumeMeasure; }
343  inline int32_t currentDeliveredVolume() const { return m_currentDeliveredVolume; }
344 
346  inline uint32_t cycleNumber() const { return m_cycleNb; }
347 
349  inline uint16_t ticksPerCycle() const { return m_ticksPerCycle; }
350 
352  inline uint32_t ticksPerInhalation() const { return m_ticksPerInhalation; }
353 
355  inline void ticksPerInhalationSet(uint32_t p_ticksPerInhalation) {
356  m_ticksPerInhalation = p_ticksPerInhalation;
357  }
358 
360  inline int16_t pressure() const { return m_pressure; }
361 
363  inline int32_t inspiratoryFlow() const { return m_inspiratoryFlow; }
364 
366  inline int32_t expiratoryFlow() const { return m_expiratoryFlow; }
367 
369  inline int32_t dt() const { return m_dt; }
370 
372  inline uint32_t tick() const { return m_tick; }
373 
375  inline int32_t pressureCommand() const { return m_pressureCommand; }
376 
378  inline CyclePhases phase() const { return m_phase; }
379 
381  inline const bool triggered() const { return m_triggered; }
382 
384  inline const void setTrigger(bool triggerValue) { m_triggered = triggerValue; }
385 
387  inline const bool isPeepDetected() { return m_isPeepDetected; }
388 
390  inline int16_t* lastPressureValues() { return m_lastPressureValues; }
391 
394 
400  void updateDt(int32_t p_dt);
401 
408  void updateCurrentDeliveredVolume(int32_t p_currentDeliveredVolume);
409 
410  // current expiratory Volume
411  void updateCurrentExpiratoryVolume(int32_t p_expiratoryVolume);
412 
414  void reachSafetyPosition();
415 
417  void stop(uint32_t p_currentMillis);
418 
420  void sendStopMessageToUi();
421 
423  void sendMachineState();
424 
425  private:
431  void updatePhase();
432 
435  void inhale();
436 
439  void exhale();
440 
449  void computeTickParameters();
450 
452  void executeCommands();
453 
455  void checkCycleAlarm();
456 
458 
460  void printDebugValues();
461 
462  private:
464  uint32_t m_tick;
465 
482 
491 
518 
520  int16_t m_peepCommand;
524  int16_t m_peepMeasure;
527 
534 
539 
542 
550 
555 
560 
562  int16_t m_tiMinCommand;
564  int16_t m_tiMaxCommand;
569 
574 
577 
579 
583 
588 
593 
602 
606  // cppcheck-suppress misra-c2012-5.2
608 
612  // cppcheck-suppress misra-c2012-5.2
614 
618  // cppcheck-suppress misra-c2012-5.2
620 
624  // cppcheck-suppress misra-c2012-5.2
626 
630  // cppcheck-suppress misra-c2012-5.2
632 
636  // cppcheck-suppress misra-c2012-5.2
638 
643 
647  // cppcheck-suppress misra-c2012-5.2
649 
654 
659 
662 
664  uint16_t m_ticksPerCycle;
665 
668 
670  int16_t m_pressure;
671 
674 
677 
680 
683 
686 
693 
696 
699 
702 
704  uint32_t m_cycleNb;
705 
707  int32_t m_dt;
708 
711 
714 
717 
720 
723 
724  // Height of the patient in cm
726 
727  // Gender of patient 0 = male, 1 = female
729 };
730 
Controls breathing cycle.
void onTargetInspiratoryFlow(uint16_t p_targetInspiratoryFlow)
Set the inspiratory flow target.
void sendStopMessageToUi()
Send a "stopped" telemetry message.
int16_t m_pressure
Measured pressure.
int32_t dt() const
Get the delta of time since the last cycle (in ms)
void onTriggerOffsetSet(uint16_t p_triggerOffset)
Set the desired offset for expiratory trigger.
void onInspiratoryDuration(uint16_t p_inspiratoryDuration)
Set the inspiration duration.
const bool triggered() const
Get the state of the inspiratory trigger.
void executeCommands()
Send the computed commands to actuators.
void updatePhase()
Update the cycle phase.
uint16_t m_PlateauMeasureCount
Count for calulating plateau value.
void onPeakPressureIncrease()
Increase the desired peak pressure.
int16_t m_tiMaxNextCommand
Max duration of inspiration in ms for next cycle.
uint32_t m_cycleNb
Number of elapsed cycles since beginning.
void updateFakeExpiratoryFlow()
Calculate expiratory flow from pressure and valve angle.
uint16_t m_expiratoryTermCommand
Actual expiratory term.
int16_t m_plateauPressureCommand
Actual desired plateau pressure.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
uint16_t tidalVolumeMeasure() const
Get the measured Tidal Volume. Updated only at the end of inspiration.
int16_t m_expiratoryTriggerFlowNextCommand
Desired expiratory trigger flow for next cycle (in percent of max flow)
int16_t m_peakPressureNextCommand
Peak pressure desired by the operator for the next cycle.
int16_t peepNextCommand() const
Get the desired PEEP for the next cycle.
void onCycleSet(uint16_t p_cpm)
Set the desired number of cycles per minute.
int16_t m_inspiratoryDurationNextCommand
Duration of inspiration.
VentilationController * m_ventilationControllerNextCommand
Ventilation controller for the next cycle.
uint32_t m_tick
Actual tick number (given by the main state machine)
int16_t m_tiMinCommand
Minimum duration of inspiration in ms.
void checkCycleAlarm()
At the end of a respiratory cycle, check if some alarms are triggered.
void onLowTidalVolumeAlarmThresholdSet(uint16_t p_lowTidalVolumeAlarmThreshold)
Set threshold on tidal volume below which an alarm is raised.
void onlowRespiratoryRateAlarmThresholdSet(uint16_t p_lowRespiratoryRateAlarmThreshold)
Set alarm threshold for low respiratory rate.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
void onPeakPressureDecrease()
Decrease the desired peak pressure.
const int16_t tiMinCommand() const
Get the value of the minimum duration of inspiration in ms.
void onLeakAlarmThresholdSet(uint16_t p_leakAlarmThreshold)
Set the threshold for leak that raise the alarm.
void onCycleIncrease()
Increase the desired number of cycles per minute.
uint16_t m_cyclesPerMinuteNextCommand
Number of cycles per minute desired by the operator for the next cycle.
int16_t plateauPressureNextCommand() const
Get the desired plateau pressure for the next cycle.
const VentilationController * ventilationControllerNextCommand() const
Ventilation controller pointer for the next cycle.
int16_t * lastPressureValues()
Get last pressure values.
uint16_t cyclesPerMinuteMeasure() const
Get the desired number of cycles per minute.
void onExpiratoryTermSet(uint16_t p_expiratoryTerm)
Set the desired expiratory term.
uint16_t m_cyclesPerMinuteCommand
Actual desired number of cycles per minute.
int16_t m_lastPressureValues[MAX_PRESSURE_SAMPLES]
Last pressure values.
int16_t m_plateauDurationCommand
Plateau duration command (used in VC modes)
const int16_t tiMaxCommand() const
Get the value of the max duration of inspiration in ms.
const int16_t inspiratoryTriggerFlowCommand() const
Get the value of the inspiratory trigger flow command.
int32_t m_highRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
void onhighRespiratoryRateAlarmThresholdSet(uint16_t p_highRespiratoryRateAlarmThreshold)
Set alarm threshold for high respiratory rate.
int16_t m_tidalVolumeMeasure
Measured value of the Tidal volume (volume of air pushed in patient lungs in last inspiration)
int32_t patientHeight() const
int16_t peakPressureNextCommand() const
Get the desired max peak for the next cycle.
void onPatientComputePreset()
Updates patient computed params.
int16_t m_rebouncePeakPressureMeasure
Measured value of rebounce peak pressure.
int32_t m_leakAlarmThresholdCommand
Threshold for leak alarm.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
void endRespiratoryCycle(uint32_t p_currentMillis)
End a respiratory cycle.
void onTiMinSet(uint16_t p_tiMin)
Set min inspiratory time.
int32_t m_highTidalVolumeAlarmThresholdCommand
Threshold for high tidal Volume Alarm.
CyclePhases phase() const
Get the current cycle phase.
int32_t m_lowExpiratoryMinuteVolumeAlarmThresholdCommand
Threshold for low inspiratory minute volume alarm.
int16_t tidalVolumeNextCommand() const
Get the desired tidal Volume for the next cycle (used in VC modes)
uint32_t tick() const
Get the tick number of the current cycle.
uint16_t ticksPerCycle() const
Get the duration of a cycle in ticks.
const bool isPeepDetected()
Get if the PEEP has been detected during this cycle.
int32_t m_maxExpiratoryFlow
Measured max inspiratory flow.
int16_t m_plateauPressureMeasure
Measured value of the plateau pressure.
int16_t tidalVolumeCommand() const
uint16_t cyclesPerMinuteNextCommand() const
Get the desired number of cycles per minute for the next cycle.
int32_t m_highTidalVolumeAlarmThresholdNextCommand
Threshold for high tidal Volume Alarm next cycle.
int16_t pressure() const
Get the current measured pressure.
void onInspiratoryTriggerFlowSet(uint16_t p_inspiratoryTriggerFlow)
Set inspiratory trigger flow.
void onPlateauPressureIncrease()
Increase the desired plateau pressure.
int32_t m_patientHeight
void updateDt(int32_t p_dt)
Input the real duration since the last pressure controller computation.
void updateExpiratoryFlow(int32_t p_currentExpiratoryFlow)
Input an expiratory flow reading.
VentilationController * m_ventilationController
Ventilation controller in use (for everything related to breathing control)
void updateCurrentExpiratoryVolume(int32_t p_expiratoryVolume)
int16_t rebouncePeakPressureMeasure() const
Get the measured rebounce peak pressure.
int32_t expiratoryFlow() const
Get the current expiratoryFlow.
int32_t m_pressureCommand
Requested pressure at a given point in time.
uint16_t m_numberOfPressures
Number of the current cycle's pressures.
uint32_t m_plateauDurationMs
Duration of the plateau.
bool m_isPeepDetected
Is PEEP pressure detected in the cycle?
uint16_t m_ticksPerCycle
Number of hundredth of second per cycle.
void onCycleDecrease()
Decrease the desired number of cycles per minute.
const int32_t targetInspiratoryFlowCommand() const
get target inspiratory flow in mL/min (used in VC modes)
int16_t m_tidalVolumeCommand
Tidal volume command (used in VC modes)
void onTiMaxSet(uint16_t p_tiMax)
Set max inspiratory time.
int16_t m_tiMinNextCommand
Minimum duration of inspiration in ms for next cycle.
int16_t m_peakPressureAlarmThresholdNextCommand
Threshold for peak pressure alarmfor next cycle.
void onPeepPressureIncrease()
Increase the minimal PEEP desired.
const int16_t expiratoryTriggerFlowCommand() const
Get the value of the expiratory trigger flow command.
void updateCurrentDeliveredVolume(int32_t p_currentDeliveredVolume)
Input the current delivered volume in inspiratory branch since beginning of the respiratory cycle.
int16_t peakPressureMeasure() const
Get the measured peak pressure.
void onPeepSet(int16_t p_peep)
Set the desired PEEP.
const int16_t pressureTriggerOffsetCommand() const
Get the value of the inspiratory trigger pressure command.
int32_t currentDeliveredVolume() const
Get the measured Tidal Volume. Updated in real time.
void onPeepPressureDecrease()
Decrease the minimal PEEP desired.
uint32_t m_inspiratoryValveAngle
Blower valve angle at peak.
const int16_t pressureTriggerOffsetNextCommand() const
Get the value of the inspiratory trigger pressure command for the next cycle.
int16_t m_pressureTriggerOffsetNextCommand
Desired pressure trigger offset for the next cycle.
int16_t peepCommand() const
Get the desired PEEP.
uint32_t m_lastBreathPeriodsMsIndex
Index for the m_lastBreathPeriodsMs array.
void onPeakPressureAlarmThreshold(int16_t p_peakPressureAlarmThreshold)
Set the desired threshold for max peak pressure.
int32_t m_highExpiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for high inspiratory minute volume alarm for next cycle.
int16_t m_tiMaxCommand
Max duration of inspiration in ms.
uint32_t m_sumOfPressures
Sum of the current cycle's pressures.
void onLowExpiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_lowExpiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for low expiratory minute volume.
int32_t m_lowRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_inspiratoryTriggerFlowNextCommand
Desired inspiratory trigger flow for next cycle.
int32_t m_lowTidalVolumeAlarmThresholdCommand
Threshold for low tidal Volume Alarm.
void sendMachineState()
Send a "machine state snapshot" telemetry message.
int32_t m_highInspiratoryMinuteVolumeAlarmThresholdCommand
Threshold for high inspiratory minute volume alarm.
void updatePressure(int16_t p_currentPressure)
Input a pressure reading.
int16_t m_inhalationLastPressure
Last pressure of inhalation.
int32_t m_patientGender
void computeTickParameters()
Compute various cycle durations given the desired number of cycles per minute.
void exhale()
Perform the pressure control and compute the actuators commands during the exhalation phase.
bool m_tidalVolumeAlreadyRead
True if Tidal volume has already been read during cycle.
const int16_t inspiratoryTriggerFlowNextCommand() const
Get the value of the inspiratory trigger flow command for the next cycle.
uint32_t m_ticksPerInhalation
Number of hundredth of second per inhalation.
int16_t peepMeasure() const
Get the measured PEEP.
int32_t m_expiratoryVolume
Volume expired by the patient during the exhalation phase.
int16_t m_peepMeasure
Measured value of the PEEP.
const int16_t tiMaxNextCommand() const
Get the value of the max duration of inspiration in ms for the next cycle.
void printDebugValues()
Print debug values, used to tweak PID, and triggers.
int32_t m_dt
Time since the last computation (in microsecond)
uint32_t m_cyclesPerMinuteMeasure
Measured number of cycles per minute.
bool m_triggered
Is inspiratory triggered or not?
void setup()
Initialize actuators.
void onPlateauPressureSet(int16_t p_plateauPressure)
Set the desired plateau pressure.
int16_t plateauPressureCommand() const
Get the desired plateau pressure.
int32_t m_currentDeliveredVolume
Current delivered volume by the blower.
const int16_t inspiratoryDurationCommand() const
Get duration of inspiration command.
CyclePhases m_phase
Current respiratory cycle phase.
int32_t m_leakAlarmThresholdNextCommand
Threshold for leak alarm for next cycle.
int16_t m_inspiratoryTriggerFlowCommand
Desired inspiratory trigger flow.
int16_t m_peakPressureMeasure
Measured value of peak pressure.
void calculateBlowerIncrement()
void initRespiratoryCycle()
Begin a respiratory cycle.
const int16_t inspiratoryDurationNextCommand() const
Get duration of inspiration command fo next cycle.
int32_t m_lowTidalVolumeAlarmThresholdNextCommand
Threshold for low tidal Volume Alarm next cycle.
int16_t m_pressureTriggerOffsetCommand
Actual pressure trigger offset.
int32_t m_targetInspiratoryFlowNextCommand
inspiratory flow required (used in VC modes) for next cycle
void onPatientHeight(int16_t p_patientHeight)
Set the desired patient height.
void onPatientGender(int16_t p_patientGender)
Set the desired patient gender.
int16_t m_plateauPressureNextCommand
Plateau pressure desired by the operator for the next cycle.
void onLowInspiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_lowInspiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for low inspiratory minute volume.
int64_t m_PlateauMeasureSum
Sum for calulating plateau value.
const bool triggerModeEnabledCommand()
Get the enabling state of trigger mode.
void stop(uint32_t p_currentMillis)
Stop the breathing.
int32_t m_targetInspiratoryFlowCommand
inspiratory flow required (used in VC modes)
int16_t m_plateauPressureToDisplay
Measured value of the plateau pressure for display.
int32_t inspiratoryFlow() const
Get the current inspiratoryFlow.
void onPlateauPressureDecrease()
Decrease the desired plateau pressure.
const int16_t tiMinNextCommand() const
Get the value of the minimum duration of inspiration in ms for the next cycle.
VentilationController * m_ventilationControllersTable[NUMBER_OF_VENTILATION_MODES+1u]
Array containing pointers to different ventilation controllers.
uint16_t cyclesPerMinuteCommand() const
Get the desired number of cycles per minute.
int16_t m_peakPressureCommand
Actual desired peak pressure.
void onHighInspiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_highInspiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for high inspiratory minute volume.
int16_t plateauDurationCommand() const
void onVentilationModeSet(uint16_t p_ventilationControllerMode)
Set ventilation mode.
void reachSafetyPosition()
Put actuators in safety position.
void onTargetTidalVolumeSet(uint16_t p_targetTidalVolume)
Set target tidal volume (used in VC modes)
void ticksPerInhalationSet(uint32_t p_ticksPerInhalation)
Get the duration of an inhalation in ticks.
void onHighExpiratoryMinuteVolumeAlarmThresholdSet(uint16_t p_highExpiratoryMinuteVolumeAlarmThreshold)
Set alarm threshold for high expiratory minute volume.
void compute()
Perform the pressure control.
int16_t m_expiratoryTriggerFlowCommand
Desired expiratory trigger flow (in percent of max flow)
const bool triggerModeEnabledNextCommand()
Get the enabling state of trigger mode for the next cycle.
int16_t plateauDurationNextCommand() const
uint32_t ticksPerInhalation() const
Get the duration of an inhalation in ticks.
void inhale()
Perform the pressure control and compute the actuators commands during the inhalation phase.
int32_t m_highRespiratoryRateAlarmThresholdCommand
Threshold for low respiratory rate.
int16_t m_peepCommand
Actual desired PEEP.
int16_t m_inspiratoryDurationCommand
Duration of inspiration.
uint32_t m_lastBreathPeriodsMs[NUMBER_OF_BREATH_PERIOD]
Period durations of last beathings.
int32_t pressureCommand() const
Get the pressure command.
int16_t m_plateauDurationNextCommand
Plateau duration command for next cycle.
uint32_t m_lastEndOfRespirationDateMs
Date of the last ending of a respiration.
int32_t m_lowInspiratoryMinuteVolumeAlarmThresholdNextCommand
Threshold for low inspiratory minute volume alarm for next cycle.
void onPlateauDurationSet(uint16_t p_plateauDuration)
Set the duration of Pause at the end of expiration in VC modes.
uint16_t lastPressureValuesIndex()
Get last pressure values index.
uint16_t m_lastPressureValuesIndex
Last pressure index.
const int16_t expiratoryTriggerFlowNextCommand() const
Get the value of the expiratory trigger flow command for the next cycle.
int16_t plateauPressureMeasure() const
Get the measured plateau pressure.
int16_t m_tidalVolumeNextCommand
Tidal volume command for next cycle.
int32_t m_expiratoryFlow
Measured inspiratory flow.
int16_t m_peepNextCommand
Desired PEEP for the next cycle.
const void setTrigger(bool triggerValue)
Reset the trigger to false.
int16_t peakPressureCommand() const
Get the desired max peak.
void updateTick(uint32_t p_tick)
Input a tick number.
int32_t m_maxInspiratoryFlow
Measured max inspiratory flow.
void updateInspiratoryFlow(int32_t p_currentInspiratoryFlow)
Input an inspiratory flow reading.
int32_t m_inspiratoryFlow
Measured inspiratory flow.
bool m_triggerModeEnabledNextCommand
Desired state of enabling of trigger mode for the next cycle.
VentilationModes m_ventilationControllerMode
uint16_t m_expiratoryTermNextCommand
Desired expiratory term for the next cycle.
void onExpiratoryTriggerFlowSet(uint16_t p_expiratoryTriggerFlow)
Set expiratory trigger flow.
bool m_triggerModeEnabledCommand
Actual state of enabling of trigger mode.
const int32_t targetInspiratoryFlowNextCommand() const
get target inspiratory flow in mL/min (used in VC modes) for next cycle
void onTriggerModeEnabledSet(uint16_t p_triggerEnabled)
Enable or disable expiratory trigger mode.
void onHighTidalVolumeAlarmThresholdSet(uint16_t p_highTidalVolumeAlarmThreshold)
Set threshold on tidal volume for which an alarm is raised.
MainController()
Default constructor.
int32_t m_lowRespiratoryRateAlarmThresholdNextCommand
Threshold for low respiratory rate for next cycle.
uint32_t cycleNumber() const
Get the number of past cycles since the beginning.
int16_t m_peakPressureAlarmThresholdCommand
Threshold for peak pressure alarm.
int32_t m_lastMaxExpiratoryFlow
Measured max inspiratory flow.
Abstract class for ventilation controllers.
VentilationModes
Supported ventilation modes.
Definition: cycle.h:22
#define NUMBER_OF_VENTILATION_MODES
Definition: cycle.h:9
CyclePhases
Defines the 2 main phases of the respiratory cycle.
Definition: cycle.h:14
#define MAX_PRESSURE_SAMPLES
Number of values to aggregate when computing plateau pressure.
MainController mainController
#define NUMBER_OF_BREATH_PERIOD
Number of periods used for calculating the respiratory rate.
Definition: parameters.h:157