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 02/24/2015
8 
9 @author: Philipp Schillinger
10 '''
11 
12 class CheckConditionState(EventState):
13  '''
14  Checks if the given condition is true and returns the corresponding outcome.
15  This state can be used if the further control flow of the behavior depends on a simple condition.
16 
17  -- predicate function The condition whose truth value will be evaluated.
18  Has to expect one parameter which will be set to input_value and return a boolean.
19 
20  ># input_value object Input to the predicate function.
21 
22  <= true Returned if the condition evaluates to True
23  <= false Returned if the condition evaluates to False
24 
25  '''
26 
27 
28  def __init__(self, predicate):
29  '''Constructor'''
30  super(CheckConditionState, self).__init__(outcomes=['true', 'false'],
31  input_keys=['input_value'])
32 
33  self._predicate = predicate
34  self._outcome = 'false'
35 
36 
37  def execute(self, userdata):
38  '''Execute this state'''
39 
40  return self._outcome
41 
42 
43  def on_enter(self, userdata):
44  try:
45  self._outcome = 'true' if self._predicate(userdata.input_value) else 'false'
46  except Exception as e:
47  Logger.logwarn('Failed to execute condition function!\n%s' % str(e))


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