check_condition_state.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from flexbe_core import EventState, Logger
3 
4 
5 class CheckConditionState(EventState):
6  '''
7  Checks if the given condition is true and returns the corresponding outcome.
8  This state can be used if the further control flow of the behavior depends on a simple condition.
9 
10  -- predicate function The condition whose truth value will be evaluated.
11  Has to expect one parameter which will be set to input_value and return a boolean.
12 
13  ># input_value object Input to the predicate function.
14 
15  <= true Returned if the condition evaluates to True
16  <= false Returned if the condition evaluates to False
17  '''
18 
19  def __init__(self, predicate):
20  super(CheckConditionState, self).__init__(outcomes=['true', 'false'],
21  input_keys=['input_value'])
22  self._predicate = predicate
23  self._outcome = 'false'
24 
25  def execute(self, userdata):
26  return self._outcome
27 
28  def on_enter(self, userdata):
29  try:
30  self._outcome = 'true' if self._predicate(userdata.input_value) else 'false'
31  except Exception as e:
32  Logger.logwarn('Failed to execute condition function!\n%s' % str(e))


flexbe_states
Author(s): Philipp Schillinger
autogenerated on Sun Dec 13 2020 04:01:46