log messages to file
Hello everybody. I am trying to write a package for storing some information in a file in order to plot them later (usually in matlab). I need it in order to check if the things will work properly. Follows a more detailed description of the problem. What I would like to do is a simple logger class that would be initialized using the full path to the desired "log" file. A part from standard constructor and destructor i would like to have a function, lets say something like
void logMsg(<generic_msg> m);
That takes any ros msg as parameter and writes it to a file in matlab friendly format. Now I can think of multiple ways of doing it for example:
Use overloading. I will define multiple versions of logMsg with different parameters and code. Example:
void logMsg(nav_msg::Odometry o); void logMsg(geometry_msg::Point p);
PROS: easy to implement CONS: huge file, code repetition, poor flexibility
Taking a string as input. I will handle the messages as a string and print them to file as a string. However this requires the user to convert the string himself/herself, and this is not what I have in mind. Providing a function that formats the message in a string would end up in the problems above. Example:
void logMsg(std::string s); std::string toString(<various_types_of_msgs>);
????
I cannot think anything proper for the purpose, does anyone have any suggestions?
Thank you very much Andrea
First method looks good, 2nd method output is similar to rostopic echo to text file.
I know, but the first method requires implementing each function for each file. I am trying to understand if there is a better way of doing it