0
$\begingroup$

Rosanswers logo

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.


Originally posted by i_ on ROS Answers with karma: 3 on 2022-05-24

Post score: 0

$\endgroup$

3 Answers 3

1
$\begingroup$

Rosanswers logo

Yes, remapping works with rosbags too:

ros2 bag play [bag name] --remap <old name>:=<new name>

Originally posted by Joe28965 with karma: 1124 on 2022-05-25

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by i_ on 2022-05-25:
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 ?

Comment by Joe28965 on 2022-05-25:
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.

$\endgroup$
1
$\begingroup$

I made a simple bash script for excluding specific topics.

--remap is not good enough for me because the remapped topic will still consume resources. Currently, the only way is to use the --topic option to specify the topics to be included.


A quick explanation of the script is as follows.

We can use ros2 bag info to list all topics recorded in the bag. The script extracts and compiles the output into a string. Then, it searches for topics to be excluded and removes them from the string.

$\endgroup$
0
$\begingroup$

Currently we have '-x' or '--exclude' option for ros2 bag play command.

Which is a regular expressions to exclude topics from replay, separated by space.

$\endgroup$
1
  • $\begingroup$ This option is not available in humble $\endgroup$
    – Anthony
    Commented Jan 29 at 15:08

Your Answer

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