ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

log messages to file

asked 2014-09-26 03:22:34 -0600

Mago Nick gravatar image

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:

  1. 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

  2. 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>);
  3. ????

I cannot think anything proper for the purpose, does anyone have any suggestions?

Thank you very much Andrea

edit retag flag offensive close merge delete

Comments

First method looks good, 2nd method output is similar to rostopic echo to text file.

bvbdort gravatar image bvbdort  ( 2014-09-26 03:46:16 -0600 )edit

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

Mago Nick gravatar image Mago Nick  ( 2014-09-26 03:51:35 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-09-26 04:11:28 -0600

gvdhoorn gravatar image

updated 2014-09-26 04:40:08 -0600

3 . ????

.. use rosbag and a suitable bag->X conversion.

From a quick search:

etc


Edit: Another option might be to use the official ROS support released by Mathworks.

edit flag offensive delete link more

Comments

Yes right, that was the third option... do you suggest that one?

Mago Nick gravatar image Mago Nick  ( 2014-09-26 04:25:45 -0600 )edit

Of course. Why create something yourself, that has been done a 1000 times already? I've also added a 4th option.

gvdhoorn gravatar image gvdhoorn  ( 2014-09-26 04:39:03 -0600 )edit

Thank you very much! I will use a rosbag

Mago Nick gravatar image Mago Nick  ( 2014-09-26 04:51:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-09-26 03:22:34 -0600

Seen: 451 times

Last updated: Sep 26 '14