ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

It's safe to Publish and Subscribe on same Topic?

asked 2014-05-10 01:33:29 -0600

merosss gravatar image

Hi everybody, I am developing a framework where multiple identical nodes are running concurrently and each of them controls the movements of a different robot (3 robots for now). They all have a matrix describing the environment in which they are moving to plan the movements.

Each of them also has another matrix containing the number of times a certain position has been visited. What I want is that every node updates its map when one of the robots moves to a new position and to do this I was thinking of making them publishing and subscribing to the same topic their position, and in the callback function modify the "visitCountMatrix" accordingly.

Is this safe? If not, can you think of a different solution? Keep in mind that I want the controllers to be independent one from another, i.e. they cannot share a common matrix. Thanks! :)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-05-10 01:46:52 -0600

Hansg91 gravatar image


This is perfectly safe, in fact it is often done with the /tf topic. As long as you keep in mind that when you publish something, that node will also receive that message again. If you then in that callback publish a new message on the same topic again, you get an endless 'loop' ;).

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-05-10 01:33:29 -0600

Seen: 3,623 times

Last updated: May 10 '14