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

C++ Equivalent of ROSBag Code

asked 2012-07-20 15:36:14 -0500

Ankush gravatar image

updated 2014-01-28 17:13:06 -0500

ngrennan gravatar image

What is the C++ equivalent of "rewriting bag", given in the cookbook?

I want to process a particular topic from a rosbag file and write the others unchanged to a new bagfile. Any help would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-20 22:49:00 -0500

Lorenz gravatar image

updated 2012-07-20 22:49:29 -0500

This code should work:

rosbag::Bag input("input.bag");
rosbag::Bag output("output.bag", rosbag::bagmode::Write);
rosbag::View topic_view(input, rosbag::TopicQuery("topic_to_reqrite"));

BOOST_FOREACH(rosbag::MessageInstance const message, topic_view) {
  output.write(message.getTopic(), message.getTime(), message, message.getConnectionHeader()); 

For more information on the API functions, have a look at the API docs.

edit flag offensive delete link more


Thank you, again! It is not very clear from the APIs that rosbag::write takes a MessageInstance as an argument.

Ankush gravatar image Ankush  ( 2012-07-21 00:58:30 -0500 )edit

Well, I didn't try it out but I expect it to work because the MessageInstance has all the required traits defined to be serializable.

Lorenz gravatar image Lorenz  ( 2012-07-21 02:41:28 -0500 )edit

Just tried it out, it works. Thanks.

Ankush gravatar image Ankush  ( 2012-07-22 12:46:43 -0500 )edit

Question Tools


Asked: 2012-07-20 15:36:14 -0500

Seen: 1,283 times

Last updated: Jul 20 '12