relationship between rospy.init_node and rospy.Publisher?
More specifically, lets say the command
rospy.init_node('topic_publisher')
creates a node with the name topic_publisher
and then I state something like:
pub = rospy.Publisher('/counter', Int32, queue_size=1)
my question is: how does that node topic_publisher
know anything about the pub object? the pub object does not input the node name so how does it know which node is publishing it? Is it because its in the same executable file? THe system somehow knows anything after rospy.init_node
is related to this node?
I was trying to write this as an answer but I don't feel like I have a complete understanding of everything to do so I'll leave this as a comment.
Basically, the node doesn't know about the topics (topics can be registered before node instantiation). When created, topics register themselves with Master and have their names resolved depending on whether they're private or global.
So,
topic_publisher
doesn't know about the/counter
topic because the topic is registered with ROS Master (which in turn keeps track of all nodes, topics, and much more).