Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HEV - High Energy Ventilator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
HEV - High Energy Ventilator
Commits
7560bc0d
Commit
7560bc0d
authored
Apr 06, 2020
by
Antonio Fernández Prieto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Timeout added to FSM and new FSM structure for test HW.
parent
253fc28d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
348 additions
and
0 deletions
+348
-0
common.cpp
arduino/breathing_loop_only/src/common.cpp
+10
-0
common.h
arduino/breathing_loop_only/src/common.h
+43
-0
main_afp.cpp
arduino/breathing_loop_only/src/main_afp.cpp
+101
-0
test_hw_loop.cpp
arduino/breathing_loop_only/src/test_hw_loop.cpp
+163
-0
test_hw_loop.h
arduino/breathing_loop_only/src/test_hw_loop.h
+31
-0
No files found.
arduino/breathing_loop_only/src/common.cpp
0 → 100644
View file @
7560bc0d
#include "common.h"
void
setValves
(
bool
vin
,
bool
vout
,
bool
vscav
,
bool
vpurge
)
{
digitalWrite
(
pin_valve_in
,
vin
);
digitalWrite
(
pin_valve_out
,
vout
);
digitalWrite
(
pin_valve_scavenge
,
vscav
);
digitalWrite
(
pin_valve_purge
,
vpurge
);
}
arduino/breathing_loop_only/src/common.h
0 → 100644
View file @
7560bc0d
#include <Arduino.h>
#if defined(ARDUINO_FEATHER_ESP32)
#define BOARD "HUZZAH32"
#include <huzzah32_pinout.h>
#elif defined(ARDUINO_NodeMCU_32S)
#define BOARD "ESP32"
#include <nodemcu_32s_pinout.h>
#elif defined(ARDUINO_AVR_UNO)
#define BOARD "UNO"
#include <Arduino_uno_pinout.h>
#elif defined(ARDUINO_SAMD_MKRVIDOR4000)
#define BOARD "VIDOR"
#include <Arduino_MKR_4000_Vidor_pinout.h>
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
#define BOARD "MKR1010"
#include <Arduino_MKR_1010_WIFI_pinout.h>
#elif defined(ARDUINO_SAM_DUE)
#define BOARD "MKR1010"
#include <Arduino_Due_pinout.h>
#elif defined(ARDUINO_AVR_YUN)
#define BOARD "MKR1010"
#include <Arduino_Yun_pinout.h>
#endif
// input params
enum
hev_modes
:
byte
{
HEV_MODE_PS
,
HEV_MODE_CPAP
,
HEV_MODE_PRVC
,
HEV_MODE_TEST
};
enum
valve_states
:
bool
{
V_OPEN
=
LOW
,
V_CLOSED
=
HIGH
};
void
setValves
(
bool
vin
,
bool
vout
,
bool
vscav
,
bool
vpurge
);
arduino/breathing_loop_only/src/main_afp.cpp
0 → 100644
View file @
7560bc0d
#include <Arduino.h>
#include "test_hw_loop.h"
#include "common.h"
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(pin_lcd_rs, pin_lcd_en, pin_lcd_d4, pin_lcd_d5, pin_lcd_d6, pin_lcd_d7);
int
ventilation_mode
=
HEV_MODE_PS
;
float
working_pressure
=
1
;
//?
float
inspiratory_minute_volume
=
6000
;
// ml/min
float
respiratory_rate
=
15
;
// 10-40 +-1 ;aka breaths_per_min
float
inspiratory_pressure
=
10
;
// 10-80 cmH2O +-1
//float tidal_volume = 200; // calc 200-1500ml +- 100
float
inspiratory_time
=
1.0
;
// 0.4-1.5s +-0.1
float
pause_time
=
1.0
;
// range?
//float expiratory_time ; // calc
float
expiratory_minute_volume
;
// calc?? same as inspiratory_minute_volume?
float
trigger_sensitivity
;
// calculations
float
calc_tidal_volume
()
{
return
inspiratory_minute_volume
/
respiratory_rate
;
}
float
calc_expiration_time
()
{
float
total_respiratory_time
=
60.0
/
respiratory_rate
;
// total = expire + inspire + pause
return
(
total_respiratory_time
-
inspiratory_time
-
pause_time
);
}
float
calc_expiratory_minute_volume
()
{
// probably need to calculate this from readings
return
0
;
}
// FROM OVERLEAF DOC
// Working pressure, corresponding to the manually set and monitored input pressure to the unit
// Inspiratory Minute Volume setting
// Breaths per minute setting
// Tidal volume display, based on previous two parameters
// Inspiration time setting
// Pause time setting
// expiration time display based on previous two parameters
// expired minute volume
// Airway pressure display based on the reading of $P_2$ ??? not a setting
// PEEP setting ??? external
// Trigger sensitivity to patient initiated breath
void
setup
()
{
pinMode
(
pin_valve_in
,
OUTPUT
);
pinMode
(
pin_valve_out
,
OUTPUT
);
pinMode
(
pin_valve_scavenge
,
OUTPUT
);
pinMode
(
pin_valve_purge
,
OUTPUT
);
pinMode
(
pin_p_supply
,
INPUT
);
pinMode
(
pin_p_regulated
,
INPUT
);
pinMode
(
pin_p_buffer
,
INPUT
);
pinMode
(
pin_p_inhale
,
INPUT
);
pinMode
(
pin_p_patient
,
INPUT
);
pinMode
(
pin_temp
,
INPUT
);
pinMode
(
pin_led_0
,
OUTPUT
);
pinMode
(
pin_led_1
,
OUTPUT
);
pinMode
(
pin_led_2
,
OUTPUT
);
pinMode
(
pin_buzzer
,
OUTPUT
);
pinMode
(
pin_button_0
,
INPUT
);
Serial
.
begin
(
9600
);
// lcd.begin(16, 2); // Declare number of columns and rows
}
void
loop
()
{
// put your main code here, to run repeatedly:
//Serial.println(BOARD);
// delay(1000);
// buzzer
// tone(pin, freq (Hz), duration);
//breath_cycle();
FSM_assignment
();
FSM_breath_cycle
();
delay
(
10
);
}
arduino/breathing_loop_only/src/test_hw_loop.cpp
0 → 100644
View file @
7560bc0d
#include "test_hw_loop.h"
#include "common.h"
/*
The Idea of this code is to unfold the FSM in two: one to assign the transitions and the second one to program the states.
*/
uint64_t
FSM_time
;
int
timeout
;
byte
lab_cycle_mode
=
0
;
int
bs_state
=
BS_IDLE
;
bool
start
=
LOW
;
int
next_state
;
//This is used to assign the transitions of the fsm
void
FSM_assignment
(
)
{
if
(
millis
()
>
FSM_time
+
timeout
)
{
switch
(
bs_state
)
{
case
BS_IDLE
:
if
(
start
==
LOW
)
{
next_state
=
BS_BUFF_PREFILL
;
FSM_time
=
millis
();
Serial
.
println
(
"Exit IDLE"
)
;
}
else
{
next_state
=
BS_IDLE
;
}
break
;
case
BS_BUFF_PREFILL
:
next_state
=
BS_BUFF_FILL
;
break
;
case
BS_BUFF_FILL
:
next_state
=
BS_BUFF_LOADED
;
break
;
case
BS_BUFF_LOADED
:
switch
(
lab_cycle_mode
)
{
case
LAB_MODE_FLUSH
:
next_state
=
BS_BUFF_FLUSH
;
break
;
case
LAB_MODE_PURGE
:
next_state
=
BS_BUFF_PURGE
;
break
;
default:
next_state
=
BS_BUFF_PRE_INHALE
;
}
break
;
case
BS_BUFF_PRE_INHALE
:
next_state
=
BS_INHALE
;
break
;
case
BS_INHALE
:
next_state
=
BS_WAIT
;
break
;
case
BS_WAIT
:
next_state
=
BS_EXHALE_FILL
;
break
;
case
BS_EXHALE_FILL
:
next_state
=
BS_EXHALE
;
break
;
case
BS_EXHALE
:
next_state
=
BS_BUFF_LOADED
;
break
;
case
BS_BUFF_PURGE
:
next_state
=
BS_BUFF_PREFILL
;
break
;
case
BS_BUFF_FLUSH
:
next_state
=
BS_IDLE
;
break
;
default:
next_state
=
bs_state
;
}
bs_state
=
next_state
;
FSM_time
=
millis
();
}
}
void
FSM_breath_cycle
()
{
// basic cycle for testing hardware
start
=
digitalRead
(
pin_button_0
);
switch
(
bs_state
)
{
case
BS_IDLE
:
if
(
start
==
LOW
)
{
FSM_time
=
millis
();
}
else
{
timeout
=
1000
;
}
setValves
(
V_CLOSED
,
V_OPEN
,
V_OPEN
,
V_CLOSED
);
break
;
case
BS_BUFF_PREFILL
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_OPEN
,
V_CLOSED
);
timeout
=
1000
;
break
;
case
BS_BUFF_FILL
:
setValves
(
V_OPEN
,
V_CLOSED
,
V_OPEN
,
V_CLOSED
);
timeout
=
500
;
break
;
case
BS_BUFF_LOADED
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_OPEN
,
V_CLOSED
);
switch
(
lab_cycle_mode
)
{
case
LAB_MODE_FLUSH
:
timeout
=
500
;
break
;
case
LAB_MODE_PURGE
:
timeout
=
500
;
break
;
default:
timeout
=
1500
;
}
break
;
case
BS_BUFF_PRE_INHALE
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_CLOSED
,
V_CLOSED
);
timeout
=
100
;
break
;
case
BS_INHALE
:
setValves
(
V_CLOSED
,
V_OPEN
,
V_CLOSED
,
V_CLOSED
);
timeout
=
100
;
break
;
case
BS_WAIT
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_CLOSED
,
V_CLOSED
);
timeout
=
1000
;
break
;
case
BS_EXHALE_FILL
:
setValves
(
V_OPEN
,
V_CLOSED
,
V_OPEN
,
V_CLOSED
);
timeout
=
1000
;
break
;
case
BS_EXHALE
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_OPEN
,
V_CLOSED
);
timeout
=
10
;
break
;
case
BS_BUFF_PURGE
:
setValves
(
V_CLOSED
,
V_CLOSED
,
V_OPEN
,
V_OPEN
);
timeout
=
1000
;
break
;
case
BS_BUFF_FLUSH
:
setValves
(
V_CLOSED
,
V_OPEN
,
V_OPEN
,
V_CLOSED
);
timeout
=
1000
;
break
;
}
Serial
.
println
(
"state FSM_breath_cycle: "
+
String
(
bs_state
));
Serial
.
println
(
"start: "
+
String
(
start
));
}
arduino/breathing_loop_only/src/test_hw_loop.h
0 → 100644
View file @
7560bc0d
#include <Arduino.h>
void
FSM_assignment
();
void
FSM_breath_cycle
();
// states
enum
BS_STATES
:
byte
{
BS_IDLE
,
BS_BUFF_PREFILL
,
BS_BUFF_FILL
,
BS_BUFF_LOADED
,
BS_BUFF_PRE_INHALE
,
BS_INHALE
,
BS_WAIT
,
BS_EXHALE_FILL
,
BS_EXHALE
,
BS_BUFF_PURGE
,
BS_BUFF_FLUSH
};
enum
lab_cycle_modes
:
byte
{
LAB_MODE_BREATHE
=
0
,
LAB_MODE_PURGE
=
1
,
LAB_MODE_FLUSH
=
2
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment