ros2 launch creates two nodes of same type
Hi,
I am experiencing a weird behavior of the ros2 launch
command.
Using following example launch file from the robot_localization packge:
from launch import LaunchDescription
from ament_index_python.packages import get_package_share_directory
import launch_ros.actions
import os
import yaml
from launch.substitutions import EnvironmentVariable
import pathlib
import launch.actions
from launch.actions import DeclareLaunchArgument
def generate_launch_description():
return LaunchDescription([
launch_ros.actions.Node(
package='robot_localization',
node_executable='ekf_node',
node_name='ekf_filter_node',
output='screen',
parameters=[os.path.join(get_package_share_directory("robot_localization"), 'params', 'ekf.yaml')],
),
])
creates following output:
$ ros2 launch robot_localization ekf.launch.py
[INFO] [launch]: All log files can be found below /home/xxx/.ros/log/2020-02-14-12-59-00-118313-xxx-22388
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [ekf_node-1]: process started with pid [22398]
[ekf_node-1] [WARN] [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.
[ekf_node-1] X acceleration is being measured from IMU; X velocity control input is disabled
Listing running nodes with ros2 node list
also shows me two ekf_nodes.
The same happens with ros2 cartographer_ros node.
Any Idea why this is happening? I am able to launch other nodes without any problem.
Asked by potentialdiffer on 2020-02-14 07:11:18 UTC
Answers
Removing the line that names the node fixed it for me, ie. this line:
node_name='ekf_filter_node',
Asked by ddengster on 2020-04-30 01:54:06 UTC
Comments
Thanks! It also fixes it for me.
Asked by DanielRobotics on 2020-04-30 02:41:00 UTC
Though it fixed the problem with the two nodes it seems to cause another error for me. When I remove the naming lines I get a datum error and I receive no information on my /odometry/filtered and /odometry/gps. If I move the naming lines back in I get the duplicate nodes but the datum error is not coming and data is again coming on my /odometry/filtered and /odometry/gps. @Tom Moore do you know why this is happening?
[navsat_transform_node-4] [INFO] [navsat_transform]: Datum (latitude, longitude, altitude) is (-1246152232, -1246031536, -518309968)
[navsat_transform_node-4] [INFO] [navsat_transform]: Datum UTM coordinate is (-124615232, -1246031536)
Asked by DanielRobotics on 2020-05-06 04:45:08 UTC
Check that node naming change did not break your parameter YAML files.
Asked by hidmic on 2020-05-07 08:59:44 UTC
Any idea why adding the node name parameter causes this error?
Asked by nnmm on 2020-11-24 11:07:52 UTC
Thanks for pointing out this solution, I solved the same problem. But if I remove the node name, why doesn't the node become duplicate? We would appreciate it if you could tell us why.
Asked by HyeonJuChoi on 2022-07-05 01:42:09 UTC
Mb it's about too late, but anyway. I believe inside your "node" you have two or more nodes with different names of course. When you set name attr in launch it tells ros2 to force renaming of inside node. That way all nodes you create inside one app will be rename with the single name, that you set in launch
Asked by DrShiki on 2023-07-21 03:23:09 UTC
Comments
I have similar issue.
Asked by kk2105 on 2020-03-19 01:53:38 UTC
I am experiencing the same issue using Dashing version. Any updates on how to fix it and what version do you use of robot_localization?
Asked by DanielRobotics on 2020-04-11 07:40:11 UTC
Can you check if the same node is already running ?
In my case, the launch was happening due to a script which launches ros node automatically after building the code. So when I manually launch the node, it does not run.
After making some modifications to the script, now I am able to run the node manually.
Asked by kk2105 on 2020-04-12 21:35:27 UTC
I just checked and the node is not already running before I run my launch file. Can you show the script where you made the modifications to get it running?
Asked by DanielRobotics on 2020-04-13 03:19:22 UTC
Did you all figure this out? I don't use ROS2, so I don't have a lot to say here, but I'm wondering if this has been solved.
Asked by Tom Moore on 2020-04-20 03:14:48 UTC
Hi, sorry for the late reply. I did not solve this issue. However, I also haven't digged in deeper yet, as I am currently trying out different things in ros.
In reply to @kk2105: I did not use any other script to launch the node. I also checked that there are no nodes running at launch.
Asked by potentialdiffer on 2020-04-20 03:24:47 UTC
@DanielRobotics Apologies for the delay in response. Unfortunately I will not be able to share the script. However that is just a simple script which launches the node by running
ros2 launch launch_file.py
.Asked by kk2105 on 2020-04-20 03:49:50 UTC
@DanielRobotics @Tom Moore Even I did not dig deeper in finding the root cause. However in ROS2 I believe, there is no separate command which actually kills the running node. So if the same node runs in same system, it overrides the already running one. Is this right @gvdhoorn ?
Asked by kk2105 on 2020-04-20 03:54:25 UTC
I have a launch script launching two ekf_nodes + one navsat_transform node. The structure of the script is similar to OPs and similar to this: https://github.com/cra-ros-pkg/robot_localization/blob/dashing-devel/launch/ekf.launch.py The result I get is four eks_nodes + two navsat_transfrom nodes.
Asked by DanielRobotics on 2020-04-23 02:05:35 UTC
Using the same structure for the launch script and launching a turtlesim node does only produce a single running node.
Asked by DanielRobotics on 2020-04-23 02:26:08 UTC
If I launch another node together with the robot_localization nodes ekf_node and navsat_transfrom my own node only gets one instance but the robot_localization nodes gets two instances. Does anyone know the consequences of running two of the same EKF filters might be?
Asked by DanielRobotics on 2020-04-29 04:29:39 UTC
I think this is the same as https://github.com/ros2/geometry2/issues/124.
The issue is that
robot_localization
processes bear two nodes: the node of the filter itself and another, implicit node that is created bytf2_ros::TransformListener
instances that did not receive a reference to an existing node and had to create one of their own. That seems to be about right skimming through robot_localization code. Then, when a node name is specified onlaunch
, that translates into a__node:=...
remapping rule when the process is executed. Since that remapping rule does not specify any node, it applies to all of them (see this design article).Having multiple nodes with the same won't break your application but it comes with a number of nuances that I'd rather avoid (e.g. CLI tools will warn you but pick one of the two).
Asked by hidmic on 2020-05-07 08:59:27 UTC
I still see the similar issue (on
foxy
). Ticketed https://github.com/ros2/launch/issues/704Asked by 130s on 2023-04-14 23:31:51 UTC