decision_state.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from flexbe_core import EventState, Logger
5 from rospy.exceptions import ROSInterruptException
6 
7 '''
8 Created on 11.06.2013
9 
10 @author: Philipp Schillinger
11 '''
12 
13 class DecisionState(EventState):
14  '''
15  Evaluates a condition function in order to return one of the specified outcomes.
16  This state can be used if the further control flow of the behavior depends on an advanced condition.
17 
18  -- outcomes string[] A list containing all possible outcomes of this state
19  -- conditions function Implements the condition check and returns one of the available outcomes.
20  Has to expect one parameter which will be set to input_value.
21 
22  ># input_value object Input to the condition function.
23 
24  '''
25 
26 
27  def __init__(self, outcomes, conditions):
28  '''
29  Constructor
30  '''
31  super(DecisionState, self).__init__(outcomes=outcomes,
32  input_keys=['input_value'])
33 
34  self._conditions = conditions
35  self._my_outcomes = outcomes
36 
37 
38  def execute(self, userdata):
39  '''
40  Execute this state
41  '''
42 
43  if self._conditions is not None:
44  outcome = DecisionState._loopback_name
45  try:
46  outcome = str(self._conditions(userdata.input_value))
47  except Exception as e:
48  Logger.logwarn('Passed no function as predicate!\n%s' % str(e))
49  outcome = DecisionState._loopback_name
50  if outcome is not None:
51  return outcome
52 
53 
54  def on_enter(self, userdata):
55  try:
56  rospy.sleep(0.2) # TODO: check why this has been added
57  except ROSInterruptException:
58  rospy.logwarn('Skipped sleep.')
def __init__(self, outcomes, conditions)


flexbe_states
Author(s): Philipp Schillinger
autogenerated on Wed Jun 5 2019 21:52:08