0
$\begingroup$

Rosanswers logo

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.


Originally posted by Duke on ROS Answers with karma: 1 on 2016-02-29

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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 cut.py script from bag_tools (https://github.com/srv/srv_tools/blob/indigo/bag_tools/scripts/cut.py). 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.


Originally posted by vaziri with karma: 46 on 2016-02-29

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Duke on 2016-03-01:
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.

Comment by Augusto Luis Ballardini on 2017-03-16:
did you make it?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.