Skip to content
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

Node duplicated when 'name' specified in the .launch.py #704

Open
130s opened this issue Apr 15, 2023 · 6 comments
Open

Node duplicated when 'name' specified in the .launch.py #704

130s opened this issue Apr 15, 2023 · 6 comments

Comments

@130s
Copy link

130s commented Apr 15, 2023

Issue report

Required Info:

  • Operating System:
    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 20.04.3 LTS
    Release:        20.04
    Codename:       focal
    $ uname -a
    Linux 1_xterm 4.15.0-1009-aws #9-Ubuntu SMP Wed May 16 15:22:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    
  • Installation type, Version or commit hash:
    $ apt-cache policy ros-foxy-launch
    Installed: 0.10.10-1focal.20230306.200955
    Candidate: 0.10.10-1focal.20230306.200955
    
  • DDS implementation:
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

t_launch.py (this causes the issue)

import os
import yaml

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
    launchdemo = Node(
        name="pick_place_sample2",
        package="get_pose_client",
        # executable="test_trajectory",
        #executable="test_trajectory2",
        executable="pick_place",
        output="screen",
        parameters=[],
    )
    nodes_to_start = [launchdemo]

    return LaunchDescription(nodes_to_start)
#include <string>
#include "rclcpp/rclcpp.hpp"

class PickPlace : public rclcpp::Node {
public:
  PickPlace(std::shared_ptr<rclcpp::Node> move_group_node)
      : Node("pick_place") {} // end of constructor

}; // End of Class

int main(int argc, char **argv) {
  rclcpp::init(argc, argv);
  rclcpp::NodeOptions node_options;
  node_options.automatically_declare_parameters_from_overrides(true);
  auto move_group_node =
      rclcpp::Node::make_shared("move_group_demo", node_options);

  rclcpp::executors::SingleThreadedExecutor planner_executor;
  std::shared_ptr<PickPlace> planner_node =
      std::make_shared<PickPlace>(move_group_node);
  planner_executor.add_node(planner_node);
  planner_executor.spin();

  rclcpp::shutdown();
  return 0;
}

Expected behavior

[INFO] [pick_place-1]: process started with pid [25768]
:
(No error/warning from this node)

Actual behavior

Stdout

[INFO] [pick_place-1]: process started with pid [25768]
[pick_place-1] [WARN] [1681532371.573175635] [rcl.logging_rosout]: Publisher already registered for provided node name. If this is due to multiple nodes with the same name then all logs for that logger name will go out over the existing publisher. As soon as any node with that name is destructed it will unregister the publisher, preventing any further logs for that name from being published on the rosout topic.
$ ros2 node list
WARNING: Be aware that are nodes in the graph that share an exact name, this can have unintended side effects.
:
/pick_place_sample2
/pick_place_sample2
:

Additional information

Seems related answers.ros.org#344141.

Possible workaround

As mentioned answers.ros.org#344141, removing name in Node instance seems to stop the issue.

@130s

This comment was marked as duplicate.

@christophebedard
Copy link
Member

Since Node is from launch_ros, have you tried updating ros-foxy-launch-ros?

@130s

This comment was marked as off-topic.

@christophebedard
Copy link
Member

Have you tried reproducing with Rolling? I tried to reproduce and I couldn't, so maybe it was fixed after Foxy. I also tried to find potential PRs that fixed this and I couldn't, but I might've just missed them.

@130s
Copy link
Author

130s commented Apr 24, 2023

Sorry I made my post #704 (comment) here but it was actually about another problem.

I don't have a plan to use ROS Humble just yet 🤷‍♂️ so can't tell..

@clalancette
Copy link
Contributor

So this is pretty subtle, but I think what is happening here is that the name that you are specifying in the launch file is being applied to all nodes inside of the executable. That is, both your move_group_node and your planner_node are being renamed to pick_place_sample2. Since we don't really support having two nodes with the same name, you get the behavior you see here.

I have at least two suggestions:

  1. For a quick fix, you can just get rid of the name argument to the Node call in the launch file. That will give the nodes their default names, and avoid the conflict.
  2. The real fix here is to restructure your code so you have one Node per library or executable. You can then compose them together using composable nodes, or something like that.

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

No branches or pull requests

3 participants