Ask Your Question

How can i read messages from a ROSbag file ?

asked 2018-04-11 10:20:22 -0500

aks gravatar image

I have a bag file in which some are custom messages whereas others are string messages. How can i display the contents of the topics which have message of type strings (without converting it to a .csv file) ?image description

for example, From the attached image, how can i read the messages of the topic /pnc/relative_carstatus

edit retag flag offensive close merge delete


I do have a question for you, how do you convert a rosbag file into a csv file? Anyway, why don't you use the rosbag play to play your bag file, and then in another terminal you just see the messages passing into the topic with rostopic echo /pnc/relative_carstatus?

kharkad gravatar imagekharkad ( 2018-04-11 10:31:51 -0500 )edit

Hi to convert a bag file to .csv format, use rostopic echo /topicname -b bagFileName.bag -p > file.csv And to the second part, I only have a bag file and when i play it, unfortunately no new nodes are created and no topics as well. That is why i cannot echo any topic.

aks gravatar imageaks ( 2018-04-11 10:39:00 -0500 )edit

Personally, whenever I use rosbag I start all nodes manually, and then play the bad file to publish on the wanted topics. I don't think rosbag starts nodes.

kharkad gravatar imagekharkad ( 2018-04-11 14:48:45 -0500 )edit

@aakash_sehgal please don't use an image to display text. Images are not searchable and people cannot copy and paste the text from the image. See

jayess gravatar imagejayess ( 2018-04-12 01:10:42 -0500 )edit

@kharkad how do you start all the nodes manually when you receive a bag file from someone else ?

aks gravatar imageaks ( 2018-04-12 06:16:41 -0500 )edit

I am confused: @aakash_sehgal: which nodes are you talking about? rosbag publishes msgs as if the original nodes were running. rosbag does not need the original nodes. If you're referring to "the rest" of the application (ie: consumers of msgs), that would be something else.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-12 06:20:17 -0500 )edit

@gvdhoorn yes, that is correct. I wanted to reply to @kharkad 's previous comment and then realised that rosbag do not requires original nodes. Question : that means just by playing a bagfile i cannot access the messages. am i right ?

aks gravatar imageaks ( 2018-04-12 06:25:26 -0500 )edit

You can, as long as the system on which you are playing the bag has the necessary msgs. rostopic echo should be able to show msg content though, just as it would with 'normal' publications.

gvdhoorn gravatar imagegvdhoorn ( 2018-04-12 06:26:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-04-11 22:47:00 -0500

ZainMehdi gravatar image

You can use Rosbag API to access messages using a simple script

edit flag offensive delete link more



Can you please update your question with a minimum working example?

jayess gravatar imagejayess ( 2018-04-12 01:11:17 -0500 )edit

@ZainMehdi is it possible that i can execute this script in the terminal or do i need to specifically put this in the bagfiles directory and then execute it ?

aks gravatar imageaks ( 2018-04-12 06:19:27 -0500 )edit

@jayess ill try and do that and next time will take care about the image with text.

aks gravatar imageaks ( 2018-04-12 06:19:49 -0500 )edit

Sorry for the late response. I hope your problem has been resolved. and to answer your question yes you can execute it like a normal script

ZainMehdi gravatar imageZainMehdi ( 2018-04-29 19:59:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-04-11 10:20:22 -0500

Seen: 6,661 times

Last updated: Apr 11 '18