When launching a program from a launch file, which is the node that is initialised? is it the node mentioned in the python script using rospy.init_node("Node_created_from_python_script")
or is it the one mentioned in the launch file as
<node pkg="package_name" type="name_of_python_script.py" name="Name_of_initialising_node" output="screen">
Example:
The python script python_script.py is launched by the package “my_package”, as below:
#! /usr/bin/env python
import rospy
rospy.init_node("Node_created_from_python_script")
print("Node Created")
rospy.spin()
The launch file of package my_package is launch_file.launch is as below:
<launch>
<node pkg="my_package" type="python_script.py" name="Node_created_from_launch_node" output="screen">
</node>
</launch>
Upon running the launch file launch_file.launch , we get successful file output as:
SUMMARY
========
PARAMETERS
* /rosdistro: noetic
* /rosversion: 1.15.9
NODES
/
Node_created_from_launch_node (my_package/python_script.py)
ROS_MASTER_URI=http://1_simulation:11311
process[Node_created_from_launch_node-1]: started with pid [12186]
Node Created
Upon running the command rosnode list
, the following output is received:
rosnode list
/Node_created_from_launch_node
/gazebo/rosout
/rostopic_2656_1632028662905
From above we see that the Node created has the node name mentioned in the launch file (/Node_created_from_launch_node)
and not the node name mentioned in the python script (/Node_created_from_python_script)
.
***1. Where did the (/Node_created_from_python_script)
disappear to? ***
2. Why is the launch node name given priority over the python script node name?