decision_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 from rospy.exceptions import ROSInterruptException
00006 
00007 '''
00008 Created on 11.06.2013
00009 
00010 @author: Philipp Schillinger
00011 '''
00012 
00013 class DecisionState(EventState):
00014         '''
00015         Evaluates a condition function in order to return one of the specified outcomes.
00016         This state can be used if the further control flow of the behavior depends on an advanced condition.
00017 
00018         -- outcomes     string[]        A list containing all possible outcomes of this state
00019         -- conditions   function        Implements the condition check and returns one of the available outcomes.
00020                                                                 Has to expect one parameter which will be set to input_value.
00021 
00022         ># input_value  object          Input to the condition function.
00023 
00024         '''
00025 
00026 
00027         def __init__(self, outcomes, conditions):
00028                 '''
00029                 Constructor
00030                 '''
00031                 super(DecisionState, self).__init__(outcomes=outcomes,
00032                                                                                         input_keys=['input_value'])
00033                 
00034                 self._conditions = conditions
00035                 self._my_outcomes = outcomes
00036                 
00037                 
00038         def execute(self, userdata):
00039                 '''
00040                 Execute this state
00041                 '''
00042                 
00043                 if self._conditions is not None:
00044                         outcome = DecisionState._loopback_name
00045                         try:
00046                                 outcome = str(self._conditions(userdata.input_value))
00047                         except Exception as e:
00048                                 Logger.logwarn('Passed no function as predicate!\n%s' % str(e))
00049                                 outcome = DecisionState._loopback_name
00050                         if outcome is not None:
00051                                 return outcome
00052                         
00053         
00054         def on_enter(self, userdata):
00055                 try:
00056                         rospy.sleep(0.2) # TODO: check why this has been added
00057                 except ROSInterruptException:
00058                         rospy.logwarn('Skipped sleep.')


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