When is it safe to publish after declaring a rospy.Publisher?
I recently had a problem on Hydro with publishing a message to a topic I had recently declared. The logic looked like:
self.pub = rospy.Publisher(self.pub_topic, SchedulerRequests)
self.pub.publish(msg)
The message does not appear. But, if I wait a tenth of a second, it works:
self.pub = rospy.Publisher(self.pub_topic, SchedulerRequests)
rospy.sleep(0.1)
self.pub.publish(msg)
The Tutorial has a call to rospy.ros_init()
between the Publisher()
and publish()
calls. That does not work for the class I am writing, because ros_init()
was called earlier in the main program.
Is there a safe way to check that self.pub
is ready to send messages?
Clarification: the subscriber(s) are already up and running. My problem is that unless I wait a while, no message gets sent.
How do I determine that my own Publish object is ready to use?