Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cla_prosim_driver
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fmg005
cla_prosim_driver
Commits
2f74b654
Commit
2f74b654
authored
Jun 24, 2018
by
fmg005
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simulated monitor
parent
9ecfb1c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
147 additions
and
0 deletions
+147
-0
SimMonitor.cpp
SimMonitor.cpp
+78
-0
include/SimMonitor.h
include/SimMonitor.h
+69
-0
No files found.
SimMonitor.cpp
0 → 100644
View file @
2f74b654
#include "SimMonitor.h"
SimMonitor
::
SimMonitor
(
std
::
shared_ptr
<
CLA
::
LOGGER
>&
logger
,
\
CLA
::
Environment
&
env
,
std
::
map
<
std
::
string
,
CLA
::
Pump
*>&
pumps
)
:
\
m_logger
(
logger
),
m_env
(
env
),
m_pumps
(
pumps
),
PatientOut
(
logger
,
env
,
pumps
)
{
m_monitor
=
new
CLA
::
Monitor
(
logger
,
"/dummy_monitor"
,
"std_msgs/String"
);
m_logger
->
info
(
"Patient data will be published to /dummy_monitor topic"
);
}
void
SimMonitor
::
update
(
std
::
unique_ptr
<
PhysiologyEngine
>&
engine
)
{
/*
* synchronize pulse with real-time clock
*/
m_start
=
system_clock
::
now
();
// start
engine
->
AdvanceModelTime
(
advance_time
,
TimeUnit
::
s
);
m_engine_advance_end
=
system_clock
::
now
();
m_command_start
=
system_clock
::
now
();
systolic_pressure
=
engine
->
GetCardiovascularSystem
()
->
GetSystolicArterialPressure
(
PressureUnit
::
mmHg
);
diastolic_pressure
=
engine
->
GetCardiovascularSystem
()
->
GetDiastolicArterialPressure
(
PressureUnit
::
mmHg
);
heart_rate
=
engine
->
GetCardiovascularSystem
()
->
GetHeartRate
(
FrequencyUnit
::
Per_min
);
resp_rate
=
engine
->
GetRespiratorySystem
()
->
GetRespirationRate
(
FrequencyUnit
::
Per_min
);
oxygen_sat
=
engine
->
GetBloodChemistrySystem
()
->
GetOxygenSaturation
();
/* publish data to dummy monitor topic for algorithm to capture
* i.e. systolic/diastolic
*/
m_monitor
->
publish_patient_data
(
to_string
(
systolic_pressure
)
+
"/"
\
+
to_string
(
diastolic_pressure
));
m_command_end
=
system_clock
::
now
();
/* perform infusions whenever the pump rate changes */
m_infusion_start
=
system_clock
::
now
();
m_action
.
infuse_drug
(
engine
);
m_infusion_end
=
system_clock
::
now
();
// end
/* start time for the next execution */
m_next_update_time
=
system_clock
::
to_time_t
(
m_start
)
+
m_next_start_in
.
count
();
/* compute durations */
m_engine_duration_ms
=
duration_cast
<
milliseconds
>
(
m_engine_advance_end
-
\
m_start
).
count
();
m_command_duration_ms
=
duration_cast
<
milliseconds
>
(
m_command_end
-
\
m_command_start
).
count
();
m_infusion_duration_ms
=
duration_cast
<
milliseconds
>
(
m_infusion_end
-
\
m_infusion_start
).
count
();
m_next_update_time_duration_ms
=
duration_cast
<
milliseconds
>
(
m_next_start_in
).
count
();
/* total duration */
m_total_duration_ms
=
duration_cast
<
milliseconds
>
(
m_infusion_end
-
m_start
).
count
();
/* log data */
m_logger
->
log_data
(
engine
->
GetSimulationTime
(
TimeUnit
::
s
),
\
m_action
.
get_bpdrug_rate
(),
m_action
.
get_saline_rate
());
/* log durations */
m_logger
->
log_duration
(
m_start
,
m_engine_duration_ms
,
m_infusion_duration_ms
,
\
m_total_duration_ms
,
m_next_update_time
);
/* checking if simulation will take longer than allotted 'time' */
if
(
m_total_duration_ms
>
m_next_update_time_duration_ms
)
m_logger
->
error
(
"Simulation too slow"
);
/* wait out the remaining time before starting the next execution */
while
(
true
)
{
m_delta
=
m_next_update_time
-
system_clock
::
to_time_t
(
system_clock
::
now
());
if
(
m_delta
<=
0
)
break
;
std
::
this_thread
::
sleep_for
(
milliseconds
(
m_delta
));
}
/* track data */
engine
->
GetEngineTracker
()
->
TrackData
(
engine
->
GetSimulationTime
(
TimeUnit
::
s
));
}
void
SimMonitor
::
Clear
()
{
m_monitor
=
nullptr
;
m_pumps
.
clear
();
}
SimMonitor
::~
SimMonitor
()
{
Clear
();
delete
m_monitor
;
}
include/SimMonitor.h
0 → 100644
View file @
2f74b654
#ifndef SimMonitor_H
#define SimMonitor_H
#include <string>
#include <iostream>
#include <cstdio>
#include <chrono>
#include <thread>
#include <map>
#include <libconfig.h++>
#include "serial/serial.h"
#include "CLA_Logger.h"
#include "Environment.h"
#include "Action.h"
#include "Pump.h"
#include "Monitor.h"
#include "PatientOut.h"
/* Pulse header files */
#include "PulsePhysiologyEngine.h"
#include "properties/SEScalarTime.h"
#include "properties/SEScalarPressure.h"
#include "properties/SEScalarFrequency.h"
#include "engine/SEEngineTracker.h"
#include "system/physiology/SECardiovascularSystem.h"
#include "system/physiology/SEBloodChemistrySystem.h"
#include "system/physiology/SERespiratorySystem.h"
using
namespace
std
;
using
namespace
libconfig
;
using
namespace
std
::
chrono
;
class
SimMonitor
:
public
PatientOut
{
private:
CLA
::
Environment
m_env
;
CLA
::
Monitor
*
m_monitor
;
double
systolic_pressure
;
double
diastolic_pressure
;
double
heart_rate
;
double
resp_rate
;
double
oxygen_sat
;
std
::
shared_ptr
<
CLA
::
LOGGER
>
m_logger
;
std
::
map
<
std
::
string
,
CLA
::
Pump
*>
m_pumps
;
void
Clear
();
/* chrono */
system_clock
::
time_point
m_start
;
system_clock
::
time_point
m_engine_advance_end
;
system_clock
::
time_point
m_command_start
;
system_clock
::
time_point
m_command_end
;
system_clock
::
time_point
m_infusion_start
;
system_clock
::
time_point
m_infusion_end
;
time_t
m_delta
;
time_t
m_next_update_time
;
time_t
m_engine_duration_ms
;
time_t
m_command_duration_ms
;
time_t
m_infusion_duration_ms
;
time_t
m_next_update_time_duration_ms
;
time_t
m_total_duration_ms
;
public:
SimMonitor
(
std
::
shared_ptr
<
CLA
::
LOGGER
>&
,
CLA
::
Environment
&
,
\
std
::
map
<
std
::
string
,
CLA
::
Pump
*>&
);
~
SimMonitor
();
void
update
(
std
::
unique_ptr
<
PhysiologyEngine
>&
);
};
#endif
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