rosbag2 icon indicating copy to clipboard operation
rosbag2 copied to clipboard

Support topic remaps in `ros2 bag convert` YAML

Open asymingt opened this issue 2 years ago • 3 comments

Description

It would be useful to be able to specify topic remaps in the ros2 bag converter YAML syntax. So, for example if we recorded some topics /input and /output in our experimental run, when we ros2 bag convert ... the bag we can remap /output -> /original/output. In replay we might have some algorithm that consumes /input to produce a new /output, which we could then compare to /original/output in a metrics pipeline. I realize we can do this in a launch context when ros2 bag play ... is called. However, this mixes data preparation steps with launch files.

Related Issues

No. But this is connected more broadly to bag migration, in the sense that bag migration updates structure, while topic remapping updates location. Both are required steps to prepare recorded data for re-use in replay. Bag migration appears to not yet be available in rosbag2.

Completion Criteria

Supporting YAML syntax for declaring topic remaps to be done before the topic filter is applied when converting a bag using the ros2 bag convert tool, and specifying a output filter YAML. The remaps should work exactly like --remap in ros2 play and hopefully support wildcards.

Implementation Notes / Suggestions

The YAML syntax for an output filter might support the remap keyword. The example below is equivalent for ros2 bag play --remap /output:=/old/output into a new bag, and then running the converter. Now the converter does this for you.

output_bags:
- uri: /tmp/recorded.bag
  storage_id: sqlite3
  topics: ["/input", "/output"]
  remappings: [               # applied after the topic filter before writing to the bag
    "/output:=/old/output"    # same syntax as '--ros-args -r /output:=/old/output'
  ]

Testing Notes / Suggestions

It should be trivial to setup an example where some arbitrary test message is remapped from some old to some new topic, and verify that the converted bag contains the original message on the new topic. A more advanced test might also include wildcard mapping.

asymingt avatar Jun 20 '22 17:06 asymingt

@asymingt Thank your for new feature request. As usual PRs are welcome for consideration. Form my side as a help with design and implementation I created draft https://github.com/ros2/rosbag2/pull/1028

MichaelOrlov avatar Jun 22 '22 06:06 MichaelOrlov

Thanks @MichaelOrlov -- I see you've added the mechanics of rewriting, and it appears as if new key in YAML parsing needs to be added, along with some unit tests. I'll see if I can find some cycles to fill in the missing blanks.

asymingt avatar Jun 22 '22 18:06 asymingt

@MichaelOrlov can you maybe take a look at my PR (https://github.com/ros2/rosbag2/pull/1030) to try and help me understand how I'm using rcl_remap_topic_name incorrectly?

asymingt avatar Jun 22 '22 23:06 asymingt