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

Using python for automatically writing data in bag to csv file

asked 2011-04-12 03:32:59 -0600

Tinne De Laet gravatar image

updated 2014-01-28 17:09:31 -0600

ngrennan gravatar image

Hi all,

I want to write python code to automatically analyse a bag file and write the contents to a csv file (to allow for easy plotting afterwards). So far I can analyse the topics in the bag file, ... but I still looking for a tool that can automatically tell me how a message looks like (for instance PoseStamped consist of a header and a pose). I know that this information is in the message definition but I did not find an efficient way yet to get it into python. Of course I also had a look at rxbag, but I did not immediately found what I need. Can someone give me a hint?

Thanks,

Tinne

edit retag flag offensive close merge delete

5 Answers

Sort by ยป oldest newest most voted
3

answered 2011-04-12 03:54:17 -0600

rostopic echo -p may do what you want with no code required.

edit flag offensive delete link more
1

answered 2012-06-17 02:07:06 -0600

Thomas gravatar image

updated 2012-06-17 02:09:09 -0600

A non generic approach is rosbag_analysis (see http://www.ros.org/wiki/rosbag_analysis). I just check for some attribute names and I "guess" the type from the attribute name for a very narrow set of message types.

This is bad, but it works... :)

edit: rostopic -p does not do what I want as it works on topics "live" so it may drop messages... rosbag_analysis processes bag files offline using the bag Python API.

edit flag offensive delete link more
1

answered 2012-06-15 07:07:44 -0600

punching gravatar image

updated 2015-03-09 20:38:03 -0600

tfoote gravatar image

I was trying to figure out the same thing. Last few commands on this page worked perfectly for converting .bag to .csv.

http://wiki.fieldrobot.dk/index.php/FroboMind:Cheat_Sheet

edit flag offensive delete link more

Comments

I've ticketed the broken link here: https://code.ros.org/trac/ros/ticket/3988 , as it looks fine in preview but is broken here.

Eric Perko gravatar image Eric Perko  ( 2012-06-15 12:48:43 -0600 )edit
1

answered 2011-04-12 04:17:07 -0600

kwc gravatar image

You can introspect on a message using _slots and _slot_types. Here are their values for Header.

  __slots__ = ['seq','stamp','frame_id']
  _slot_types = ['uint32','time','string']

They have different underscores because __slots__ is a Python builtin and has special meaning.

from std_msgs.msg import Header
for name, type_ in zip(Header.__slots__, Header._slot_types):
     print name, type_

prints:

seq uint32
stamp time
frame_id string
edit flag offensive delete link more
1

answered 2011-04-12 04:23:47 -0600

You might find the info on the Interoperability wiki page helpful (even if not, please consider adding to it if you find something later on that isn't there). In particular it mentions the BagLoader class from starmac_tools, which was written mainly for the plotting use case you have in mind. Good Luck!

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2011-04-12 03:32:59 -0600

Seen: 2,598 times

Last updated: Mar 09 '15