NTRT Simulator
Version: Master
|
#include <tgDataLogger2.h>
Public Member Functions | |
tgDataLogger2 (std::string fileNamePrefix, double timeInterval=0.0) | |
tgDataLogger2 () | |
~tgDataLogger2 () | |
virtual void | setup () |
virtual void | teardown () |
virtual void | step (double dt) |
virtual std::string | toString () const |
virtual void | addSenseable (tgSenseable *pSenseable) |
virtual void | addSensorInfo (tgSensorInfo *pSensorInfo) |
Protected Member Functions | |
bool | invariant () const |
Protected Attributes | |
std::string | m_fileName |
std::string | m_fileNamePrefix |
std::ofstream | tgOutput |
double | m_totalTime |
double | m_timeInterval |
double | m_updateTime |
std::vector< tgSensor * > | m_sensors |
std::vector< tgSensorInfo * > | m_sensorInfos |
std::vector< tgSenseable * > | m_senseables |
tgDataLogger2 is a tgDataManager. It records data from sensors and outputs that data to a log file, in comma-separated-value (CSV) format.
Definition at line 38 of file tgDataLogger2.h.
tgDataLogger2::tgDataLogger2 | ( | std::string | fileNamePrefix, |
double | timeInterval = 0.0 |
||
) |
The constructor for tgDataLogger2 takes in a string that specifies the location of the log file to create, as well as an optional variable that controls frequency of sensor readings.
[in] | fileNamePrefix | a string that specifies the path to the log file that will be written. The current time will be appended to this prefix. |
[in] | timeInterval | the time interval for querying sensors. Note that an updateTime of 0 means that sensors will be queried at each call of step(). |
The constructor for this class only assigns the filename prefix. The actual filename is created in setup. This makes it so that, upon reset, a new log file is opened (instead of appending to the same one.) Call the constructor of the parent class anyway, though it does nothing.
Definition at line 46 of file tgDataLogger2.cpp.
tgDataLogger2::tgDataLogger2 | ( | ) |
Since folks will probably forget that a file name is needed, create a constructor with no arguments, and have it complain at them!
The "BAD" constructor. Since people who use NTRT are apt to be new to C++, the errors that they'd get when trying to create a tgDataLogger2 may be confusing. So, this constructor lets the simulator compile, but then complains when it's called. DO NOT USE THIS ONE: use the one with the string passed in!
Definition at line 87 of file tgDataLogger2.cpp.
tgDataLogger2::~tgDataLogger2 | ( | ) |
The base class handles destruction of the sensors and sensorInfos, so nothing to do here.
The destructor should not have to do anything. Closing the log file is handled by teardown(), and the parent class handles deletion of the sensors and sensor infos.
Definition at line 97 of file tgDataLogger2.cpp.
|
virtualinherited |
Add a tgSenseable object to this data manager. These objects will be checked via the sensor infos, and sensors will be assigned to them if appropriate.
[in] | pSenseable | a pointer to a tgSenseable object that will be added to this data manager's list of senseable objects. |
This method adds sense-able objects to this data manager. It takes in a pointer to a sense-able object and pushes it to the current list of tgSenseables.
Definition at line 224 of file tgDataManager.cpp.
|
virtualinherited |
Add a sensor info object to the current list of sensor infos.
[in] | pSensorInfo | a pointer to a tgSensorInfo. |
This method adds sensor info objects to this data manager. It takes in a pointer to a sensor info and pushes it to the current list of sensor infos.
Definition at line 198 of file tgDataManager.cpp.
|
virtual |
The setup function for tgDataLogger2 will: (1) create all the sensors, (2) create a heading from the sensors, and (3) ouput the heading to a file. Declared virtual here just in case any classes inherit from this.
Setup will do three things: (1) create the full filename, based on the current time from the operating system, (2) create the sensors based on the sensor infos that have been added and the senseable objects that have also been added, (3) opens the log file and writes a heading line (then closes the file.)
Reimplemented from tgDataManager.
Definition at line 109 of file tgDataLogger2.cpp.
|
virtual |
The step function for tgDataLogger2 will open the log file for output, write a line of sensor data, then close the log file. Declared virtual here just in case any classes inherit from this.
[in] | dt | a double, the amount of time since the last step. |
The step method is where data is actually collected! This data logger will do two things here: (1) iterate through all the sensors, collect their data, (2) write that line of data to the log file (then close the log again.)
Reimplemented from tgDataManager.
Definition at line 196 of file tgDataLogger2.cpp.
|
virtual |
The teardown function closes the log file. TO-DO: should this class also teardown the sensors, or should we let the superclass handle it??
The parent's teardown method handles the sensors and sensor infos.
Reimplemented from tgDataManager.
Definition at line 180 of file tgDataLogger2.cpp.
|
virtual |
Overwrite toString for the superclass to specify that this data manager is a tgDataLogger2.
The toString method for tgDataLogger2 should have some specific information about (for example) the log file...
Reimplemented from tgDataManager.
Definition at line 240 of file tgDataLogger2.cpp.
|
protected |
Store the full name of the file for writing data. note that this is NOT what is passed into the constructor: that string is modified to create m_fileName.
Definition at line 103 of file tgDataLogger2.h.
|
protected |
In order to have the filename for the log file be created in the setup function, instead of in the constructor, we need to hold the filename prefix too. This allows for running setup and teardown and having different log files - e.g., when the space bar is pressed, a new log file will be opened.
Definition at line 112 of file tgDataLogger2.h.
|
protectedinherited |
A data manager will also have a list of tgSenseable objects (really, just tgModels most of the time) that it will collect data from.
Definition at line 137 of file tgDataManager.h.
|
protectedinherited |
Data managers also have a list of the sensor infos that have been passed in to it. These are used to create the sensors
Definition at line 131 of file tgDataManager.h.
|
protectedinherited |
A data manager has a list of sensors that it has created (during setup.)
Definition at line 124 of file tgDataManager.h.
|
protected |
The time interval for sensor readings. Taking sensor data at each call of step() can result in very very large files, so this parameter allows querying at a slower interval.
Definition at line 130 of file tgDataLogger2.h.
|
protected |
Keep track of the total time that the simulation has run. This is for adding a timestamp into the log file.
Definition at line 123 of file tgDataLogger2.h.
|
protected |
A variable to keep track of time between sensor readings. This is used to check m_timeInterval.
Definition at line 136 of file tgDataLogger2.h.
|
protected |
A file stream, based on m_fileName.
Definition at line 117 of file tgDataLogger2.h.