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

synchronize between publisher and subscriber

asked 2018-08-29 18:23:40 -0600

debonair gravatar image

I am working on test program which subscribes to one topic published by main program. There is only single message on this topic published by main program. Now it might happen that my subscriber is not alive when publisher is publishing a message and it will get lost. One way to avoid it is put while inside main program till numsubcribers are not zero. but I cannot put while inside my main program. How do i achieve it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-30 01:32:30 -0600

luk.mitka gravatar image

You could latch the topic in publisher. For latched topics, last message published is sent to any new subscriber. You create topic as below:

ros::Publisher chatter_pub = n.advertise<std_msgs::String>("topic_name", 1, true);

Third parameter defines if topic should be latched. You can find more info in documentation.

edit flag offensive delete link more


This is a good suggestion, but note that technically this is not the same as only publishing when you're sure that there is a subscriber.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-30 05:04:52 -0600 )edit

Question Tools



Asked: 2018-08-29 18:23:40 -0600

Seen: 571 times

Last updated: Aug 30 '18