ros2 / launch_ros

Tools for launching ROS nodes and for writing tests involving ROS nodes.
Apache License 2.0
56 stars 70 forks source link

Setting name parameter leads to duplicate nodes with same name #342

Open g-argyropoulos opened 1 year ago

g-argyropoulos commented 1 year ago

Bug report

Required Info:

Steps to reproduce issue

ros2 launch moveit2_tutorials moveit_cpp_tutorial.launch.py

Expected behavior

A single /moveit_cpp_tutorial node and a single /rviz2 node will be created.

Actual behavior

Two /moveit_cpp_tutorial and /rviz2 nodes were created.

~$ ros2 node list
WARNING: Be aware that are nodes in the graph that share an exact name, this can have unintended side effects.
/controller_manager
/joint_state_broadcaster
/moveit_cpp_tutorial
/moveit_cpp_tutorial
/moveit_cpp_tutorial_private_94809022977232
/panda_arm_controller
/panda_hand_controller
/robot_state_publisher
/rviz2
/rviz2
/rviz2_private_140513882059600
/static_transform_publisher
/transform_listener_impl_5605b0dc2500
/transform_listener_impl_563a722cba70
/transform_listener_impl_7fcbf0098ea0

Additional information

Everything is from their respective official repositories. If I remove (or comment out), like below, the name parameter of the Nodes in the launch file, the problem goes away. Why is that? Is this an expected behavior? Should I ignore the warning or stop naming Nodes through the launch file?

Thank you in advance.

def generate_launch_description():
    moveit_config = (
        MoveItConfigsBuilder("moveit_resources_panda")
        .robot_description(file_path="config/panda.urdf.xacro")
        .trajectory_execution(file_path="config/gripper_moveit_controllers.yaml")
        .moveit_cpp(
            file_path=get_package_share_directory("moveit2_tutorials")
            + "/config/moveit_cpp.yaml"
        )
        .to_moveit_configs()
    )
    # MoveItCpp demo executable
    moveit_cpp_node = Node(
        #name="moveit_cpp_tutorial",
        package="moveit2_tutorials",
        executable="moveit_cpp_tutorial",
        output="screen",
        parameters=[moveit_config.to_dict()],
    )

    # RViz
    rviz_config_file = (
        get_package_share_directory("moveit2_tutorials")
        + "/launch/moveit_cpp_tutorial.rviz"
    )
    rviz_node = Node(
        package="rviz2",
        executable="rviz2",
        #name="rviz2",
        output="log",
        arguments=["-d", rviz_config_file],
        parameters=[
            moveit_config.robot_description,
            moveit_config.robot_description_semantic,
        ],
    )
dhood commented 1 year ago

Hi @g-argyropoulos , not a maintainer here, but passed by your question and figure others might too:

This can happen when two nodes exist in a single executable, they will all get the same name remapping, which might explain the behaviour you're seeing. The launch_ros Node concept is a wrapper around an executable and doesn't know how many times rclcpp nodes are created inside, and it'll pass the name remapping to any and all that are inside. HTH