Robotics StackExchange | Archived questions

ros2 bag topic remapping from launch file

Hi,

I'm trying to run the following command from a launch file:

some_remap = '/namespace/rgb/camera_info:=/namespace_test/rgb/camera_info'
remap = f'--remap {some_remap}'
ld = LaunchDescription(
    [
        ExecuteProcess(
            cmd=['ros2', 'bag', 'play', str(rosbag_file), remap],
            output='screen'
        ),
        ReadyToTest(),
    ]

This results in the following command:

ros2 bag play /.../rosbag.db3 --remap /namespace/rgb/camera_info:=/namespace_test/rgb/camera_info

For some reason Ros2 complains about unrecognized arguments:

ros2: error: unrecognized arguments: --remap /namespace/rgb/camera_info:=/namespace_test/rgb/camera_info

But according to this answer and ros2 bag play -h the above command should work. Without the remapping things work fine. So what's wrong here?

And if I copy-paste the resulting command directly into the terminal it works fine...

Thanks in advance!

(Ros2 Humble on Ubuntu 22.04)

Asked by oddbotwl on 2023-08-08 09:20:11 UTC

Comments

It works for my case. maybe you try to update your rosbag2 version?

sudo apt-get install ros-humble-rosbag2

Asked by BCJ on 2023-08-08 09:34:35 UTC

Sorry updating makes no difference.

Asked by oddbotwl on 2023-08-08 09:42:17 UTC

Answers

Ok so it should be:

remap = '<old_topic>:=<new_topic>'
LaunchDescription(
    [
        ExecuteProcess(
            cmd=['ros2', 'bag', 'play', rosbag_file, '--remap', remap],
            output='screen'
        ),
        ReadyToTest(),
    ]

And for multiple remaps:

remap1 = '<old_topic>:=<new_topic>'
remap2 = '<old_topic>:=<new_topic>'
LaunchDescription(
    [
        ExecuteProcess(
            cmd=['ros2', 'bag', 'play', rosbag_file, '--remap', remap1, remap2],
            output='screen'
        ),
        ReadyToTest(),
    ]

Asked by oddbotwl on 2023-08-08 13:52:24 UTC

Comments