mirror_state.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import roslib; roslib.load_manifest('flexbe_mirror')
4 import rospy
5 from rospy.exceptions import ROSInterruptException
6 from flexbe_core import EventState, JumpableStateMachine
7 
8 from flexbe_core.proxy import ProxyPublisher, ProxySubscriberCached
9 from std_msgs.msg import String, UInt8
10 
11 '''
12 Created on 07.05.2013
13 
14 @author: Philipp Schillinger
15 '''
16 
17 class MirrorState(EventState):
18  '''
19  This state will display its possible outcomes as buttons in the GUI and is designed in a way to be created dynamically.
20  '''
21 
22 
23  def __init__(self, target_name, target_path, given_outcomes, outcome_autonomy):
24  '''
25  Constructor
26  '''
27  super(MirrorState, self).__init__(outcomes=given_outcomes)
28  self._rate = rospy.Rate(100)
29  self._given_outcomes = given_outcomes
30  self._outcome_autonomy = outcome_autonomy
31  self._target_name = target_name
32  self._target_path = target_path
33 
34  self._outcome_topic = 'flexbe/mirror/outcome'
35 
36  self._pub = ProxyPublisher() #{'flexbe/behavior_update': String}
37  self._sub = ProxySubscriberCached({self._outcome_topic: UInt8})
38 
39 
40  def execute(self, userdata):
41  '''
42  Execute this state
43  '''
44  if JumpableStateMachine.refresh:
45  JumpableStateMachine.refresh = False
46  self.on_enter(userdata)
47 
48  if self._sub.has_buffered(self._outcome_topic):
49  msg = self._sub.get_from_buffer(self._outcome_topic)
50  if msg.data < len(self._given_outcomes):
51  rospy.loginfo("State update: %s > %s", self._target_name, self._given_outcomes[msg.data])
52  return self._given_outcomes[msg.data]
53 
54  try:
55  self._rate.sleep()
56  except ROSInterruptException:
57  print 'Interrupted mirror sleep.'
58 
59 
60  def on_enter(self, userdata):
61  #rospy.loginfo("Mirror entering %s", self._target_path)
62  self._pub.publish('flexbe/behavior_update', String("/" + "/".join(self._target_path.split("/")[1:])))
63 
64 
65 
66 
67 
68 
69 
def __init__(self, target_name, target_path, given_outcomes, outcome_autonomy)
Definition: mirror_state.py:23


flexbe_mirror
Author(s): Philipp Schillinger
autogenerated on Wed Jun 5 2019 21:52:12