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

Extract a topic from bag file and save it to another bag file

asked 2016-06-28 02:47:15 -0500

Marcus Barnet gravatar image

Hi to all,

I have a *.bag file which contains different topics and I would like to extract only a specific topic and record it in a new bag file.

Is it possible?

I've read about a solution which enable users to extract a topic and save its content in a CSV file, but the problem is that I need to have another *.bag file and not CSV.

Is there any solution?

Thank you!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-28 03:02:44 -0500

ahendrix gravatar image

This is the first example listed for the rosbag filter command:

rosbag filter my.bag only-tf.bag "topic == '/tf'"

If you want to extract a topic other than /tf, simply change that portion of the command.

Note that the expression topic == '/tf' is surrounded in double quotes so that it isn't interpreted by the shell, and /tf is further enclosed in single quotes because it is a python string literal.

edit flag offensive delete link more


Thank you!!!

Marcus Barnet gravatar image Marcus Barnet  ( 2016-06-28 07:16:28 -0500 )edit

Is there any way to extract more than one topic from a bag file? something like "topic == '/tf1,/tf2'"?

petitchamp gravatar image petitchamp  ( 2019-02-04 05:03:28 -0500 )edit

Yes; you can use any python expression as the filte, so you could do "topic in ['/topic1', '/topic2']" or even use python's string or regex matching!

ahendrix gravatar image ahendrix  ( 2019-02-04 12:15:14 -0500 )edit

Question Tools

1 follower


Asked: 2016-06-28 02:47:15 -0500

Seen: 7,106 times

Last updated: Jun 28 '16