I would like for one node to wait for a subscriber to a topic to exist before publishing to it. Is there a straightforward way to do that in rclcpp?
I'm developing on rolling if that matters.
Originally posted by tyler-picknik on ROS Answers with karma: 241 on 2021-11-24
Post score: 0
Original comments
Comment by aprotyas on 2021-11-25:
I think @Geoff's answer suffices for your purpose, but FYI there are wait_for_[publishers/subscribers]
methods in the RCL layer (refer to https://github.com/ros2/rcl/pull/907/). It would be nice if there were client library (rclcpp/rclpy) wrappers because that fits your use case exactly!
Comment by Mike Scheutzow on 2021-11-25:
Some advice: in a robust distributed design, there are almost no good reasons a publishing node needs to know the number of subscribers. Remember you don't control who connects, and message delivery is unreliable. How does your node use this information?
Comment by tyler-picknik on 2022-03-02:
The original reason for this was to recreate the behavior of latched topics. I've found another way to do that though.