check_condition_state.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from flexbe_core import EventState, Logger
00005 
00006 '''
00007 Created on 02/24/2015
00008 
00009 @author: Philipp Schillinger
00010 '''
00011 
00012 class CheckConditionState(EventState):
00013         '''
00014         Checks if the given condition is true and returns the corresponding outcome.
00015         This state can be used if the further control flow of the behavior depends on a simple condition.
00016         
00017         -- predicate    function        The condition whose truth value will be evaluated.
00018                                                                 Has to expect one parameter which will be set to input_value and return a boolean.
00019 
00020         ># input_value  object          Input to the predicate function.
00021 
00022         <= true                                         Returned if the condition evaluates to True
00023         <= false                                        Returned if the condition evaluates to False
00024         
00025         '''
00026 
00027 
00028         def __init__(self, predicate):
00029                 '''Constructor'''
00030                 super(CheckConditionState, self).__init__(outcomes=['true', 'false'],
00031                                                                                                         input_keys=['input_value'])
00032                 
00033                 self._predicate = predicate
00034                 self._outcome = 'false'
00035                 
00036                 
00037         def execute(self, userdata):
00038                 '''Execute this state'''
00039 
00040                 return self._outcome
00041                 
00042         
00043         def on_enter(self, userdata):
00044                 try:
00045                         self._outcome = 'true' if self._predicate(userdata.input_value) else 'false'
00046                 except Exception as e:
00047                         Logger.logwarn('Failed to execute condition function!\n%s' % str(e))


flexbe_states
Author(s): Philipp Schillinger
autogenerated on Thu Jun 6 2019 19:32:33