3 from flexbe_core
import EventState, Logger
10 Gets the latest message on the given topic and stores it to userdata. 12 -- topic string The topic on which should be listened. 13 -- blocking bool Blocks until a message is received. 14 -- clear bool Drops last message on this topic on enter 15 in order to only handle message received since this state is active. 17 #> message object Latest message on the given topic of the respective type. 19 <= received Message has been received and stored in userdata or state is not blocking. 20 <= unavailable The topic is not available when this state becomes actives. 23 def __init__(self, topic, blocking=True, clear=False):
24 super(SubscriberState, self).
__init__(outcomes=[
'received',
'unavailable'],
25 output_keys=[
'message'])
32 Logger.logwarn(
'Topic %s for state %s not yet available.\n' 33 'Will try again when entering the state...' % (self.
_topic, self.name))
37 userdata.message =
None 41 userdata.message = self._sub.get_last_msg(self.
_topic)
42 self._sub.remove_last_msg(self.
_topic)
48 Logger.loginfo(
'Successfully subscribed to previously unavailable topic %s' % self.
_topic)
50 Logger.logwarn(
'Topic %s still not available, giving up.' % self.
_topic)
53 self._sub.remove_last_msg(self.
_topic)
56 msg_type, msg_topic, _ = rostopic.get_topic_class(self.
_topic)
57 if msg_topic == self.
_topic:
58 self.
_sub = ProxySubscriberCached({self.
_topic: msg_type})
def execute(self, userdata)
def on_enter(self, userdata)
def __init__(self, topic, blocking=True, clear=False)