3 import roslib; roslib.load_manifest(
'flexbe_core')
5 from flexbe_msgs.msg
import BEStatus
13 A proxy for publishing topics. 15 _simulate_delay =
False 21 Initializes the proxy with optionally a given set of topics. 22 Automatically creates a publisher for sending status messages. 24 @type topics: dictionary string - message class 25 @param topics: A dictionay containing a collection of topic - message type pairs. 28 @param: _latch: Defines if messages on the given topics should be latched. 30 for topic, msg_type
in topics.iteritems():
36 Adds a new publisher to the proxy. 39 @param topic: The topic to publish on. 41 @type msg_type: a message class 42 @param msg_type: The type of messages of this topic. 45 @param: _latch: Defines if messages on the given topics should be latched. 47 if topic
not in ProxyPublisher._topics:
48 pub = rospy.Publisher(topic, msg_type, latch = _latch, queue_size=100)
49 ProxyPublisher._topics[topic] = pub
54 Checks if the publisher on the given topic is available. 57 @param topic: The topic of interest. 59 return topic
in ProxyPublisher._topics
64 Publishes a message on the specified topic. 67 @param topic: The topic to publish on. 69 @type msg: message class (defined when created publisher) 70 @param msg: The message to publish. 72 if ProxyPublisher._simulate_delay:
73 time.sleep(max(0, random.gauss(1.5, 1)))
75 if topic
not in ProxyPublisher._topics:
76 rospy.logwarn(
'ProxyPublisher: topic '+ topic +
' not yet registered!')
79 ProxyPublisher._topics[topic].
publish(msg)
80 except Exception
as e:
81 rospy.logwarn(
'Something went wrong when publishing to %s!\n%s', topic, str(e))
86 Blocks until there are any subscribers to the given topic. 89 @param topic: The topic to publish on. 92 @param timeout: How many seconds should be the maximum blocked time. 94 pub = ProxyPublisher._topics[topic]
95 starting_time = rospy.get_rostime()
96 while pub.get_num_connections() < 1:
97 elapsed = rospy.get_rostime() - starting_time
98 if elapsed.to_sec() >= timeout:
def __init__(self, topics={}, _latch=False)
def is_available(self, topic)
def publish(self, topic, msg)
def createPublisher(self, topic, msg_type, _latch=False)
def wait_for_any(self, topic, timeout=5.0)