Skip to content

Add --remap argument to launch command #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: rolling
Choose a base branch
from

Conversation

JoLichtenfeld
Copy link

This adds the option to specify remapping rules for launch files in the launch command.

Example: ros2 launch <launch_file> --remap topic1:=new1 --remap topic2:=new2

@JoLichtenfeld JoLichtenfeld force-pushed the rolling branch 2 times, most recently from b2404b3 to 59ff19b Compare January 28, 2025 16:41
Copy link
Contributor

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe that would be really nice to have the ros2launch test aligns with this enhancement.

@fujitatomoya
Copy link
Contributor

@JoLichtenfeld could you consider if we can add the test case for this?

@JoLichtenfeld
Copy link
Author

I will come up with a test case as soon as I find the time for it.

@kramer-sim
Copy link

@fujitatomoya Hi, in which directory should the test be placed? Do you want that we write the test cases in /ros2launch/test?
Should it be similar to the test cases in https://github.com/ros2/ros2cli/blob/f5e5a798d57c437410452f2b106f115d3a42c7a2/ros2cli/test/test_ros2cli_direct.py#L45C1-L48C34 or do you want to actually start a launch file on the command line and check whether the remapping works?
You can find an example of that below:

    def test_remap_argument(self):
        """Test that the --remap argument correctly remaps topics."""

        try:
            # Start the talker_listener launch file with remapping
            launch_proc_remapped = subprocess.Popen(
                ['ros2', 'launch', 'demo_nodes_cpp', 'talker_listener_launch.py', 
                 '--remap', '/chatter:=/chatter_remapped'],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )

            # Run ros2 topic list to get the remapped topics
            result = subprocess.run(['ros2', 'topic', 'list'], 
                                  stdout=subprocess.PIPE, 
                                  stderr=subprocess.PIPE, 
                                  text=True, 
                                  check=True)
            remapped_topics = result.stdout.strip().split('\n')

            # Verify /chatter is NOT in the list
            self.assertNotIn('/chatter', remapped_topics, 
                           f"Did not expect to find /chatter after remapping. Topics: {remapped_topics}")

            # Verify /chatter_remapped IS in the list
            self.assertIn('/chatter_remapped', remapped_topics, 
                        f"Expected to find /chatter_remapped after remapping. Topics: {remapped_topics}")

        finally:
            # Clean up
            if 'launch_proc_remapped' in locals():
                launch_proc_remapped.terminate()
                try:
                    launch_proc_remapped.wait(timeout=5)
                except subprocess.TimeoutExpired:
                    launch_proc_remapped.kill()
                    launch_proc_remapped.wait()


if __name__ == '__main__':
    unittest.main()

@fujitatomoya
Copy link
Contributor

do you want to actually start a launch file on the command line and check whether the remapping works?

probably this one? because it actually verifies that this arguments work with launch.
https://github.com/ros2/launch_ros/tree/rolling/ros2launch/test is suitable place to put the test codes for ros2launch.

@kramer-sim
Copy link

@fujitatomoya It appears that the test environment is missing the ROS 2 CLI extensions that provide the topic command. Only a limited set of commands are available, see this error message:

test/test_cli_remap.py:55: in test_remap_argument
    self.fail(f"'ros2 topic list' command failed with error: {result.stderr}")
E   AssertionError: 'ros2 topic list' command failed with error: usage: ros2 [-h] [--use-python-default-buffering]
E               Call `ros2 <command> -h` for more detailed usage. ...
E   ros2: error: argument Call `ros2 <command> -h` for more detailed usage.: invalid choice: 'topic' (choose from 'daemon', 'extension_points', 'extensions', 'pkg')

Do you have any recommendations how to proceed?

@fujitatomoya
Copy link
Contributor

@Mergifyio rebase

JoLichtenfeld and others added 11 commits April 26, 2025 02:12
Signed-off-by: Jonathan <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Signed-off-by: Jonathan <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Signed-off-by: Jonathan <[email protected]>
Signed-off-by: Jonathan <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Signed-off-by: Markus Kramer <[email protected]>
Copy link

mergify bot commented Apr 26, 2025

rebase

✅ Branch has been successfully rebased

@fujitatomoya
Copy link
Contributor

@ros-pull-request-builder retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants