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

Can I filter out or rename topics from a bag file?

asked 2022-05-24 10:59:12 -0500

i_ gravatar image

updated 2022-05-25 02:29:06 -0500

ljaniec gravatar image

I have a bag file with several topics (a lot of them, actually), and I'm trying to launch it from a launch file.

However, in my test case that I want to run, I want to exclude a topic and insert my module to publish it instead. I was looking into either renaming the culprit topic, or just filter out a topic.

These features seemed to be available in rosbag, which from my understanding is from ROS1. I have googled and searched this site a lot, but all answers seem to be related to rosbag. Is there a way to do this in ROS2, or can I use rosbag somehow with ROS2?

In rosbag there seemed to be both a --filter flag, and you could do /topic:=/dummy/topic to make the whole system ignore it.

The closest solution I have found is to, in the launch file run:

ExecuteProcess(
            cmd=['ros2', 'bag', 'play', os.path.expanduser(
                #'~') + '/PATH/TO/BAGFILE/', '--loop', '--topics', 'TOPIC_1', ... ,'TOPIC_N']

But having a lot of topics already, this isn't really feasible with all the copy and paste that would be required, especially since I need to do this for multiple bag files with different topics on them.

Any way to solve this reasonably?

Using ROS2, Foxy.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-05-25 02:03:52 -0500

Joe28965 gravatar image

Yes, remapping works with rosbags too:

ros2 bag play [bag name] --remap <old name>:=<new name>
edit flag offensive delete link more

Comments

Ohh! I've been looking around, and I even checked the --help, and I swear I didn't see it before, and googling didn't give me a good answer, this does solve the specific problem at least neatly, at the cost of memory. Thanks, I even saw it in ros2 bag play --help

Do you know if it is possible to filter out topics? Basically the inverse of --topics ?

i_ gravatar image i_  ( 2022-05-25 03:49:07 -0500 )edit

ros2 bag play -h gives you the options.

I don't see a filter option, so my guess would be that it's not possible. However, it's important to note why you want to filter them out.

Did you record just too much and don't want it all clogging up your connection, in that case, I don't think there is an easy solution (you could hypothetically record a new bag while playing the old bag to filter it out that way, but that seems like a pain).

If you want to use (for example) your real camera data, and your bag also includes /camera/image_raw and that would mean you've got 2 publishers on that topic, you could simply do:

ros2 bag play [bag name] --remap camera/image_raw:=garbagetopic <another topic>:=<new name>

It's not the cleanest solution by a long shot, however it should work.

Joe28965 gravatar image Joe28965  ( 2022-05-25 03:55:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-05-24 10:59:12 -0500

Seen: 1,860 times

Last updated: May 25 '22