I recently had the following warning when loading a node inside an rclcpp_component manager.
[rcl.logging_rosout]: Publisher already registered for node name: ‘my_manager’. If this is due to multiple nodes with the same name then all logs for the logger named ‘my_manager’ 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.
It also showed two nodes named “my_manager” in the node list, with each their own parameter’s related services.
After digging, it appears that MoveIt’s RobotModelLoader calls moveit::getLogger, which itself creates a new node. However, because the component manager was started with -r __node:=foobar, all subsequent nodes created inside the same process would inherit the same name.
The same problem can appears without rclcpp_component, with this example:
#include <moveit/robot_model_loader/robot_model_loader.hpp>
#include <rclcpp/rclcpp.hpp>
// Try to run it with and without --ros-args -r __node:=foobar
int main(int argc, char** argv)
{
rclcpp::init(argc, argv);
rclcpp::Node::SharedPtr myNode = rclcpp::Node::make_shared("my_node");
myNode->declare_parameter("my_param", 42.0);
robot_model_loader::RobotModelLoader rml {myNode, "robot_description", false};
rclcpp::spin(myNode);
rclcpp::shutdown();
}
Now, this didn’t cause any problem as far as I could tell, but I don’t like warnings and I really don’t like multiple nodes sharing the same name.
I see multiple solutions:
- Rename the node using its orignal name, e.g.
-r my_node:__node:=foobar. This requires knowing the original node name, and it doesn’t work with launch_ros, namelyComposableNodeContainerwhich crafts the renaming argument itself and needs to know the manager’s name to load the components inside. Maybe modify launch_ros in consequence. - Ask MoveIt not to create a new node, or at least accept a custom logger argument for the RobotModelLoader
- Modify rcl to only apply the
__noderenaming to the first created node. - Ignore the warning, maybe disable the parameters services from the node created by
moveit::getLogger.
What do you think? Is there a guideline on how to use __node:= and creating multiple nodes in the same process?