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

About Subscriber Structure and “latch” on Publisher

asked 2014-10-20 04:23:43 -0600

pcler gravatar image

Hi everyone. Recently I met a question when I read something about "latch" in Publisher. On the Publisher wiki page, "latch" is described as:(

    "Enable 'latching' on the connection. When a connection is latched, the last message published is saved and sent to any future subscribers that connect. This is useful for slow-changing or static data like a map."

Now I am so confused that [when a node subscribes a message from a topic, will this message disappears? If not, than what is "latch" for? Anyhow the last message will NOT disappear.]

PS. I have done some experiments. When several nodes subscribe a same topic, they always get the same messages content from that topic. And this can also explain how qrt_plot works.(It always subscribe messages from some topics but it never affects other nodes working)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-10-20 07:51:39 -0600

dornhege gravatar image

I don't know what you mean with "disappear". The documentation doesn't use this word and it doesn't make any sense to have messages disappear on purpose.

The feature of latching makes sure that a new subscriber always gets the last message that was published even if the message was published before the subscriber was connected. Text in bold is the difference to an unlatched connection.

edit flag offensive delete link more


Thanks!!! Your answer helps a lot! Actually, I am thinking about the data structure of "topic". At first I think it is a STACK. "Subscribe" is like POP and "publish" is like PUSH. That's why I said "disappear". But now I think it is more complicated. Would you mind telling me how "topic" works?

pcler gravatar image pcler  ( 2014-10-22 11:36:45 -0600 )edit

This explains the misunderstanding. Topic is not a data structure at all. A topic doesn't exist anywhere on its own. As a concept it is a common name for two nodes to connect to each other. The data is only in the nodes. Therefore if a node isn't running yet it cannot send or receive data.

dornhege gravatar image dornhege  ( 2014-10-23 05:24:13 -0600 )edit

Thanks again! It helps! Best Wishes!

pcler gravatar image pcler  ( 2014-10-26 11:31:14 -0600 )edit

so , if we set latching to particular period of time , say 10 seconds , does it mean that if a new subscriber connects to this node within 10 seconds , it receives the last message from the last connection of the publisher ?

sam26 gravatar image sam26  ( 2017-02-08 01:13:42 -0600 )edit

There is no time limit.

dornhege gravatar image dornhege  ( 2017-02-15 06:11:24 -0600 )edit

I have an additional question: if you start a node and publish to a latched topic but then kill the node which did the original publishing, will the data still be available for future subscribers? Thanks!

buckley.toby gravatar image buckley.toby  ( 2018-09-11 12:38:47 -0600 )edit

Question Tools

1 follower


Asked: 2014-10-20 04:16:23 -0600

Seen: 10,804 times

Last updated: Oct 20 '14