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

C++ Equivalent of ROSBag Code

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

Ankush gravatar image

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

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
4

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

Lorenz gravatar image

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

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

Comments

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 -0600 )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 -0600 )edit

Just tried it out, it works. Thanks.

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

Question Tools

Stats

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

Seen: 1,310 times

Last updated: Jul 20 '12