flexible_check_condition_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 
6 '''
7 Created on 08.11.2016
8 
9 @author: Alberto Romay
10 '''
11 
12 class FlexibleCheckConditionState(EventState):
13  '''
14  Implements a state that checks if the given condition is true based on multiple userdata inputs provided as a list to the calculation function
15  and returns the corresponding outcome.
16  This state can be used if the further control flow of the behavior depends on a simple condition.
17 
18  -- predicate function The condition whose truth value will be evaluated.
19  It could be a private function (self.foo) manually defined in a behavior's source code
20  or a lambda function (e.g., lambda x: x[0]^2 + x[1]^2).
21  -- input_keys string[] List of available input keys.
22 
23  ># input_keys object[] Input(s) to the calculation function as a list of userdata.
24  The individual inputs can be accessed as list elements (see lambda expression example).
25 
26  <= true Returned if the condition evaluates to True
27  <= false Returned if the condition evaluates to False
28 
29  '''
30 
31 
32  def __init__(self, predicate, input_keys):
33  '''Constructor'''
34  super(FlexibleCheckConditionState, self).__init__(outcomes=['true', 'false'],
35  input_keys=input_keys)
36 
37  self._input_keys = input_keys
38  self._predicate = predicate
39  self._outcome = 'false'
40 
41 
42  def execute(self, userdata):
43  '''Execute this state'''
44 
45  return self._outcome
46 
47 
48  def on_enter(self, userdata):
49 
50  if self._predicate is not None:
51  try:
52  self._outcome = "true" if self._predicate(map(lambda key: userdata[key], self._input_keys)) else 'false'
53  except Exception as e:
54  Logger.logwarn('Failed to execute condition function!\n%s' % str(e))
55  else:
56  Logger.logwarn('Passed no predicate!')


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