4 from flexbe_core
import EventState, Logger
11 Gets the latest message on the given topic and stores it to userdata.
13 -- topic string The topic on which should be listened.
14 -- blocking bool Blocks until a message is received.
15 -- clear bool Drops last message on this topic on enter
16 in order to only handle message received since this state is active.
18 #> message object Latest message on the given topic of the respective type.
20 <= received Message has been received and stored in userdata or state is not blocking.
21 <= unavailable The topic is not available when this state becomes actives.
24 def __init__(self, topic, blocking=True, clear=False):
25 super(SubscriberState, self).
__init__(outcomes=[
'received',
'unavailable'],
26 output_keys=[
'message'])
33 Logger.logwarn(
'Topic %s for state %s not yet available.\n'
34 'Will try again when entering the state...' % (self.
_topic, self.name))
38 userdata.message =
None
42 userdata.message = self.
_sub.get_last_msg(self.
_topic)
49 Logger.loginfo(
'Successfully subscribed to previously unavailable topic %s' % self.
_topic)
51 Logger.logwarn(
'Topic %s still not available, giving up.' % self.
_topic)
58 if global_topic[0] !=
'/':
59 global_topic = rospy.get_namespace() + global_topic
60 msg_type, msg_topic, _ = rostopic.get_topic_class(global_topic)
61 if msg_topic == global_topic:
62 self.
_sub = ProxySubscriberCached({self.
_topic: msg_type})