Ask Your Question
0

Select topics with search pattern (regex) in rosbag2

asked 2020-10-20 02:08:45 -0500

Phgo gravatar image

updated 2021-01-08 08:38:54 -0500

Is there a simple way to select multiple topics (e.g. all topics from a node or (sub)namespace) with some sort of search pattern in rosbag2? The previous ROS(1) rosbag implementation did allow to use regular expressions of the form

$ rosbag record -e "/(.*)_foo/bar"

I can not find anything like that in rosbag2 CLI or documentation. However, this looks like a pretty common use case. Am I missing something or is there a more generic way of doing just this in ROS2.

edit retag flag offensive close merge delete

Comments

Wondering the same thing. There is no issue in rosbag2 repo for regex. I thought that ros2 targets to have feature parity with ros(1). Is it not so?

timok gravatar image timok  ( 2020-11-11 04:44:03 -0500 )edit
1

I added issues for -e and -x options for rosbag2

timok gravatar image timok  ( 2020-11-11 05:15:16 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-01-08 08:37:24 -0500

Phgo gravatar image

updated 2021-12-01 02:17:01 -0500

To sum this up, it looks like this feature is simply not yet implemented and there is at least no obvious generic way in ROS2 of achieving this.

You can follow up the corresponding issue on the rosbag2 repo.

If you find a suitable workaround feel free to add another answer.


UPDATE:
In the meantime the feature was added and is available for galactic with rosbag -e and -x option. For older distributions you might want to consider the workaround provided by @gilaadb

-e REGEX, --regex REGEX  
                  recording only topics matching provided regularexpression  
-x EXCLUDE, --exclude EXCLUDE  
                      exclude topics matching provided regular expression.  
                      Works with -a and -e, subtracting excluded topics
edit flag offensive delete link more
2

answered 2021-11-30 02:43:01 -0500

gilaadb gravatar image

This is how I would go about doing it in ROS2:

ros2 bag record `ros2 topic list | grep --regexp="/.*_foo/bar"`

Of course you can add more topics manually if you want:

ros2 bag record `ros2 topic list | grep --regexp="/.*_foo/bar"` /kuku /muku
edit flag offensive delete link more

Comments

The workaround works only if the topics exist at the start of recording.

timok gravatar image timok  ( 2021-12-01 04:40:56 -0500 )edit

To get this to work in a python launch file for ROS2 Foxy use the following:

    launch.actions.ExecuteProcess(
        cmd=['sleep 5; ros2 bag record `ros2 topic list'
             ' | grep --regexp="/depth_camera/*" -v`'],
        output='screen',
        shell=True

the sleep 5 is to ensure that the system has time to startup all nodes, since the command for recording will not find any new topics that do not show up at startup

bvaningen gravatar image bvaningen  ( 2022-02-16 09:37:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2020-10-20 02:08:45 -0500

Seen: 402 times

Last updated: Dec 01 '21