ROS2 launch IncludeLaunchDescription with launch arguments, remapped topics, and namespace

asked 2023-04-26 06:10:25 -0600

aserbremen gravatar image

I am trying to to control two rovers in simulation using two joysticks on the same computer. I want to use two teleop_twist_joy instances by including the launch description with different namespaces and remapped topics. However, using a different namespace in the launch file, causes the launch_arguments of IncludeLaunchDescription not to be evaluated. Here is a minimal example:

from ament_index_python import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import SetRemap, PushRosNamespace
from launch.actions import IncludeLaunchDescription, GroupAction
from launch.launch_description_sources import PythonLaunchDescriptionSource


def generate_launch_description():

    # Create teleop node using remappings in a GroupAction
    teleop_1 = GroupAction(
        actions=[
            # PushRosNamespace("rover1"),
            SetRemap(src='/cmd_vel', dst='/rover1/cmd_vel'),
            SetRemap(src='/joy', dst='/rover1/joy'),
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource([get_package_share_directory('teleop_twist_joy') + '/launch/teleop-launch.py']),
                # launch arguments will be evaluated, namespace is NOT set above
                launch_arguments={'joy_config': 'xbox', 'joy_dev': '/dev/input/js0'}.items(),)
        ]
    )

    # Create teleop node using a different namespace and remappings in a GroupAction
    teleop_2 = GroupAction(
        actions=[
            PushRosNamespace("rover2"),
            SetRemap(src='/cmd_vel', dst='/rover2/cmd_vel'),
            SetRemap(src='/joy', dst='/rover2/joy'),
            IncludeLaunchDescription(
                PythonLaunchDescriptionSource([get_package_share_directory('teleop_twist_joy') + '/launch/teleop-launch.py']),
                # launch arguments will NOT be evaluated, namespace is set above
                launch_arguments={'joy_config': 'xbox', 'joy_dev': '/dev/input/js1'}.items(),),
        ]
    )

    return LaunchDescription([
        teleop_1,
        teleop_2,
    ])

Is it possible to create the node with a namespace and the launch arguments?

Platform: Ubuntu 22.04, ROS humble

edit retag flag offensive close merge delete