ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

relationship between rospy.init_node and rospy.Publisher?

asked 2017-08-25 17:19:45 -0600

badrobot91 gravatar image

updated 2017-08-26 12:58:20 -0600

jayess gravatar image

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?

edit retag flag offensive close merge delete

Comments

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.

jayess gravatar image jayess  ( 2017-08-26 14:01:40 -0600 )edit

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.

jayess gravatar image jayess  ( 2017-08-26 14:03:11 -0600 )edit

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).

jayess gravatar image jayess  ( 2017-08-26 14:04:12 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-28 06:36:25 -0600

updated 2017-10-09 06:55:47 -0600

Although on the tutorial Writing a Simple Publisher and Subscriber (Python) doesn't answer your question, we can see that our executable only can publish after call rospy.init_node, as you can see:

  • The next line, rospy.init_node(NAME, ...), is very important as it tells rospy the name of your node -- until rospy has this information, it cannot start communicating with the ROS Master.

When we try to publish without calling rospy.init_node, the following exception is raised:

  • rospy.exceptions.ROSInitException: time is not initialized. Have you called init_node()?
edit flag offensive delete link more

Comments

Do you mean "publish" instead of "public?"

jayess gravatar image jayess  ( 2017-08-28 13:25:55 -0600 )edit

Yes ;) Fixed. Thanks!

Ruben Alves gravatar image Ruben Alves  ( 2017-08-29 17:10:36 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-08-25 17:19:45 -0600

Seen: 787 times

Last updated: Oct 09 '17