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

read single message from bag-file (c++)

asked 2016-02-29 07:30:00 -0600

Duke gravatar image

updated 2016-02-29 07:31:20 -0600

Hi,I'm new to this whole ROS stuff and have a problem which I can't solve on my own.

I want to read a single message from a given bag-file using c++11. To do this I read the short tutorial and cookbook for rosbag. I get the message with iterating over all messages in the bag. But I want to know if there is a way to direct get the specified message (data)? The topic (m.getTopic()), timestamp (m.getTime()) and the structure of the message (m.MessageDefinition()) is known.

Thanks for your help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-29 10:26:58 -0600

vaziri gravatar image

I dont know for sure what the best solution to your problem is. But just to brainstorm things you might try (I have not tried these myself): Perhaps you could use the filter functionality to make a new bag file containing only the messages you care about. Another option would be to use script from bag_tools ( ). Those would be more "direct" in that you would write fewer lines of codes, but I am not sure that it would be any faster than what you are doing now.

If you need a faster solution the bag file format supports random access. Assuming the bag file is in chronological order you could make a function that does a binary search to find the message you care about.

edit flag offensive delete link more


thanks for your answer. I think the filter functionality also iterates over the whole bag and looking for one element is already a kind of filter. its working but it feels not right to search the whole file just to get one special element.

Duke gravatar image Duke  ( 2016-03-01 03:04:45 -0600 )edit

did you make it?

Augusto Luis Ballardini gravatar image Augusto Luis Ballardini  ( 2017-03-16 14:35:40 -0600 )edit

Question Tools

1 follower


Asked: 2016-02-29 07:30:00 -0600

Seen: 1,216 times

Last updated: Feb 29 '16