Commit 76721259 authored by pkda001's avatar pkda001

updated config to use periods instead of rates.

parent 19b83884
......@@ -4,15 +4,15 @@
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
monitor = {
input_rate = 0.02; ## MUST be multiple of 50.0
output_rate = 0.01; ## Must be less than monitor.rate and also multiple of 50.0
input_period = 30.0; # in secs MUST be multiple of 0.02
output_period = 60.0; # in secs MUST be >= monitor.input_period
# and be multiple of 0.02
};
controller = {
rate = 0.01;
period = 60.0; # in secs MUST be >= monitor.output_period
# and be multiple of 0.02
patientData = {
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
}
......@@ -24,22 +24,19 @@ controller = {
pump = {
rate = 1.0; # Intercommand delay -> to be used later
delay = 15.0;
period = 60.0; # Intercommand delay -> to be used later
delay = 15.0; # in secs
};
simulation = {
patients = {
names = ["Hassan", "Gus", "ExtremeFemale"];
}
time = {
time = {
run = 3600.0; # Time -> Seconds # How long should simulation run
injury_start = 15.0; # When should injury be introduced to patient
injury_start = 50.0; # When should injury be introduced to patient
injury_stop = 700.0; # When should injury be stopped
}
path = "results"; # folder to store out sim output files -> to be used later
};
#include "Controller.h"
//Default constructor
Controller::Controller(): MAX_RATE_Hz(50.0) {
Controller::Controller(): MIN_PERIOD_SECS(0.02) {
}
// Overloard Constructor
Controller::Controller(CMD::Environment* env, PhysiologyData* data, std::map<string, Pump*>& pumps ) : m_env(env),
m_data(data), m_pumps(pumps), MAX_RATE_Hz(50.0) {
m_data(data), m_pumps(pumps), MIN_PERIOD_SECS(0.02) {
// Initalize algorithm configuration variables
currentNorepiInfusionRate = 0;
......@@ -58,7 +58,7 @@ void Controller::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std
// Extract the rate and assign it to m_rate_Hz
controller_rate_Hz = cf->lookup("controller.rate");
controller_period_secs = cf->lookup("controller.period");
Setting& root = cf->getRoot();
......@@ -94,12 +94,13 @@ void Controller::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std
WAIT_5_MIN = (60 * WAIT_5_MIN)/time_step; // 5 min
// integer input rate for controller
input_period = (1/controller_rate_Hz) / time_step;
input_period = controller_period_secs / time_step;
//is_input_multiple = fmod(MAX_RATE_Hz, controller_rate_Hz) == 0.0;
is_input_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(controller_rate_Hz*1000)) == 0;
is_input_multiple = ((int)(controller_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000)) == 0;
if(controller_rate_Hz > MAX_RATE_Hz) {
if(controller_period_secs < MIN_PERIOD_SECS) {
cout <<"\nController rate is greater than MAX: 50.0\n\n";
Stop();
......
......@@ -2,8 +2,8 @@
// Constructor
MedicalDevice::MedicalDevice() :
m_rate_Hz(50.0), MAX_RATE_Hz(50.0) // Initialize member variables
MedicalDevice::MedicalDevice() :
m_input_period_secs(0.02), MIN_PERIOD_SECS(0.02) // Initialize member variables
{
};
......
......@@ -68,27 +68,29 @@ void Monitor::update(std::unique_ptr<PhysiologyEngine>& engine) {
void Monitor::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::shared_ptr<Config>& cf) {
m_rate_Hz = cf->lookup("monitor.input_rate");
output_rate_Hz = cf->lookup("monitor.output_rate");
m_input_period_secs = cf->lookup("monitor.input_period");
m_output_period_secs = cf->lookup("monitor.output_period");
// Get engine time step/period
time_step = engine->GetTimeStep(TimeUnit::s);
/*Had issues with fmod*/
// Check if rate provided in config file is multiple of MAX_RATE_Hz
//is_input_multiple = fmod(MAX_RATE_Hz, m_rate_Hz) == 0.0;
//is_output_multiple = fmod(MAX_RATE_Hz, output_rate_Hz) == 0.0;
// Check if rate provided in config file is multiple of MIN_PERIOD_SECS
//is_input_multiple = fmod(MIN_PERIOD_SECS, m_input_period_secs) == 0.0;
//is_output_multiple = fmod(MIN_PERIOD_SECS, m_output_period_secs) == 0.0;
is_input_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(m_rate_Hz*1000)) == 0;
is_output_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(output_rate_Hz*1000)) == 0;
is_input_multiple = ((int)(m_input_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000))== 0;
is_output_multiple = ((int)(m_output_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000))== 0;
// Convert frequence to integer period
//i.e. freq:25Hz period:0.04 int_period: (0.04/time_step) = 2
input_period= (1/m_rate_Hz) / time_step;
output_period = (1/output_rate_Hz) / time_step;
input_period = m_input_period_secs / time_step;
output_period = m_output_period_secs / time_step;
if(m_rate_Hz > MAX_RATE_Hz || output_rate_Hz > MAX_RATE_Hz ) {
if(m_input_period_secs < MIN_PERIOD_SECS || m_output_period_secs < MIN_PERIOD_SECS ) {
cout <<"\nOne of the monitor rate values is greater than MAX: 50.0\n\n";
Stop();
......
......@@ -66,7 +66,7 @@ std::shared_ptr<Config>& cf) {
// Grab pump settings from config file
pump_rate_Hz = cf->lookup("pump.rate");
pump_period_sec = cf->lookup("pump.period");
pump_delay = cf->lookup("pump.delay");
......@@ -77,14 +77,15 @@ std::shared_ptr<Config>& cf) {
// integer input rate for controller
input_period = (1/pump_rate_Hz) / time_step;
input_period = pump_period_sec / time_step;
delay_period = (pump_delay/ time_step);
period = input_period + delay_period;
is_input_multiple = fmod(MAX_RATE_Hz, pump_rate_Hz) == 0.0;
is_input_multiple = ((int)(1000*pump_period_sec))
% ((int)(1000*MIN_PERIOD_SECS)) == 0.0;
if(pump_rate_Hz > MAX_RATE_Hz) {
if(pump_period_sec < MIN_PERIOD_SECS) {
cout <<"\nPump rate is greater than MAX: 50.0\n\n";
Stop();
......
#include "Controller.h"
//Default constructor
Controller::Controller(): MAX_RATE_Hz(50.0) {
Controller::Controller(): MIN_PERIOD_SECS(0.02) {
}
// Overloard Constructor
Controller::Controller(CMD::Environment* env, PhysiologyData* data, std::map<string, Pump*>& pumps ) : m_env(env),
m_data(data), m_pumps(pumps), MAX_RATE_Hz(50.0) {
m_data(data), m_pumps(pumps), MIN_PERIOD_SECS(0.02) {
// Initalize algorithm configuration variables
currentNorepiInfusionRate = 0;
......@@ -58,7 +58,7 @@ void Controller::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std
// Extract the rate and assign it to m_rate_Hz
controller_rate_Hz = cf->lookup("controller.rate");
controller_period_secs = cf->lookup("controller.period");
Setting& root = cf->getRoot();
......@@ -94,12 +94,13 @@ void Controller::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std
WAIT_5_MIN = (60 * WAIT_5_MIN)/time_step; // 5 min
// integer input rate for controller
input_period = (1/controller_rate_Hz) / time_step;
input_period = controller_period_secs / time_step;
//is_input_multiple = fmod(MAX_RATE_Hz, controller_rate_Hz) == 0.0;
is_input_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(controller_rate_Hz*1000)) == 0;
is_input_multiple = ((int)(controller_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000)) == 0;
if(controller_rate_Hz > MAX_RATE_Hz) {
if(controller_period_secs < MIN_PERIOD_SECS) {
cout <<"\nController rate is greater than MAX: 50.0\n\n";
Stop();
......
......@@ -3,7 +3,7 @@
// Constructor
MedicalDevice::MedicalDevice() :
m_rate_Hz(50.0), MAX_RATE_Hz(50.0) // Initialize member variables
m_input_period_secs(0.02), MIN_PERIOD_SECS(0.02) // Initialize member variables
{
};
......
......@@ -68,27 +68,29 @@ void Monitor::update(std::unique_ptr<PhysiologyEngine>& engine) {
void Monitor::LoadConfig(std::unique_ptr<PhysiologyEngine>& engine, const std::shared_ptr<Config>& cf) {
m_rate_Hz = cf->lookup("monitor.input_rate");
output_rate_Hz = cf->lookup("monitor.output_rate");
m_input_period_secs = cf->lookup("monitor.input_period");
m_output_period_secs = cf->lookup("monitor.output_period");
// Get engine time step/period
time_step = engine->GetTimeStep(TimeUnit::s);
/*Had issues with fmod*/
// Check if rate provided in config file is multiple of MAX_RATE_Hz
//is_input_multiple = fmod(MAX_RATE_Hz, m_rate_Hz) == 0.0;
//is_output_multiple = fmod(MAX_RATE_Hz, output_rate_Hz) == 0.0;
// Check if rate provided in config file is multiple of MIN_PERIOD_SECS
//is_input_multiple = fmod(MIN_PERIOD_SECS, m_input_period_secs) == 0.0;
//is_output_multiple = fmod(MIN_PERIOD_SECS, m_output_period_secs) == 0.0;
is_input_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(m_rate_Hz*1000)) == 0;
is_output_multiple = ((int)(MAX_RATE_Hz*1000)) % ((int)(output_rate_Hz*1000)) == 0;
is_input_multiple = ((int)(m_input_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000))== 0;
is_output_multiple = ((int)(m_output_period_secs*1000))
% ((int)(MIN_PERIOD_SECS*1000))== 0;
// Convert frequence to integer period
//i.e. freq:25Hz period:0.04 int_period: (0.04/time_step) = 2
input_period= (1/m_rate_Hz) / time_step;
output_period = (1/output_rate_Hz) / time_step;
input_period = m_input_period_secs / time_step;
output_period = m_output_period_secs / time_step;
if(m_rate_Hz > MAX_RATE_Hz || output_rate_Hz > MAX_RATE_Hz ) {
if(m_input_period_secs < MIN_PERIOD_SECS || m_output_period_secs < MIN_PERIOD_SECS ) {
cout <<"\nOne of the monitor rate values is greater than MAX: 50.0\n\n";
Stop();
......
......@@ -32,11 +32,11 @@ class Pump;
class Controller {
private:
double controller_rate_Hz; // The rate at which device receives or sends data
double controller_period_secs; // The rate at which device receives or sends data
double time_step;
int new_rate;
Config cfg; // API for accessing configuration files
const double MAX_RATE_Hz;
const double MIN_PERIOD_SECS;
bool is_input_multiple;
//static const int array_sz;
......
......@@ -19,11 +19,11 @@ using namespace libconfig;
class MedicalDevice {
protected:
double m_rate_Hz; // The rate at which device receives or sends data
const double MAX_RATE_Hz; // Maximum rate in Hz at which data can be transfered
double m_input_period_secs; // The rate at which device receives or sends data
const double MIN_PERIOD_SECS; // Maximum rate in Hz at which data can be transfered
Config m_cfg; // API for accessing configuration files
public:
MedicalDevice();
......@@ -34,12 +34,10 @@ class MedicalDevice {
// Load the configuration file to capture device rate
virtual void
LoadConfig(std::unique_ptr<PhysiologyEngine>&, const std::shared_ptr<Config>& cf);
LoadConfig(std::unique_ptr<PhysiologyEngine>&, const std::shared_ptr<Config>& cf);
// Destructor
~MedicalDevice();
};
#endif
......@@ -34,8 +34,8 @@ class Monitor : public MedicalDevice {
bool HeartRate;
bool BloodPressure;
double output_rate_Hz;
double m_rate_Hz;
double m_output_period_secs;
double m_input_period_secs;
double time_step;
double heart_rate;
......
......@@ -32,7 +32,7 @@ class Pump : public MedicalDevice {
bool is_input_multiple;
double pump_rate_Hz;
double pump_period_sec;
double pump_delay;
double time_step;
double delay_period;
......
# Configuration file for Heart Rate Scenario
## rate : Number of samples per second ## MAX: 50.0 Hz ## Type: double
monitor = {
input_period = 30.0; # in secs MUST be multiple of 0.02
output_period = 60.0; # in secs MUST be >= monitor.input_period
# and be multiple of 0.02
};
controller = {
period = 60.0; # in secs MUST be >= monitor.output_period
# and be multiple of 0.02
patientData = {
enabled = ["HeartRate", "BloodPressure", "BloodVolume"];
}
algorithm= {
wait_10 = 10.0; # Wait for 10 minutes
wait_5 = 5.0; # Wait for 5 minutes
}
};
pump = {
period = 60.0; # Intercommand delay -> to be used later
delay = 15.0; # in secs
};
simulation = {
patients = {
names = ["Hassan"];
}
time = {
run = 3600.0; # Time -> Seconds # How long should simulation run
injury_start = 50.0; # When should injury be introduced to patient
injury_stop = 700.0; # When should injury be stopped
}
path = "results"; # folder to store out sim output files -> to be used later
};
Markdown is supported
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