Helper class providing logging capabilities. Useful in control loops for logging data and easily parsing to Matlab.
More...
|
| Logger () |
| Empty constructor. Calling this constructor will not open the file. After this you need to call Logger::open(). More...
|
|
| Logger (const std::string &file_name, const std::string &log_path="/home/user/autharl_logfiles/") |
| The default constructor which directly opens and initialize the file for logging. More...
|
|
| ~Logger () |
|
void | open (const std::string &file_name, const std::string &log_path="/home/user/autharl_logfiles/") |
| Opens the file in the given destination. More...
|
|
void | close () |
| Closes the file. More...
|
|
template<class V > |
void | logVector (const V &data, const std::string &name) |
| Function for logging vectors containing data. More...
|
|
template<class T > |
void | log (const T &data, const std::string &name) |
| The main function for logging. More...
|
|
Helper class providing logging capabilities. Useful in control loops for logging data and easily parsing to Matlab.
The logger saves the data in the provided path with a time stamp of the current time and the provided file name. Within a loop you can use the Logger::log() function providing the data and the name of the variable. The logger will log in the first line the name of the variables logged in this loop and then in each row of the file the corresponding data. The comma dilimiter is used by this class.
Example of use in a control loop:
Logger logger(
"my_file",
"/home/user/my_logfiles");
double t;
double dt = 0.001;
while (true)
{
t += dt;
logger.log(t, "time");
arma::vec joint_positions = getJointPositionsFromRobot();
logger.log(joint_positions, "joint_positions");
double a = 5;
logger.log(a, "a");
}
If you have a robot with 3 joints the log file will located in /home/user/my_logfiles/20-09-2017_09:34:52_my_file.log and it will look like this:
time,joint_positions_0,joint_positions_1,joint_positions_2
0,1,1,1,5
0.001,1.1,1.1,1.1,5
0.002,1.2,1.2,1.2,5
...etc