Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 import traceback
00020 import rospy
00021 import smach
00022
00023 __all__ = ['State','CBState']
00024
00025 class ssmState(smach.State):
00026
00027 def __init__(self, outcomes=[], io_keys=[]):
00028 io_keys.append("logfile")
00029 io_keys.append("skill")
00030 smach.State.__init__(self, outcomes, io_keys=io_keys)
00031 self.register_outcomes(["preempt"])
00032 self._datamodel = {}
00033 self._onEntry = None
00034 self._onExit = None
00035
00036 def execute(self, ud):
00037
00038 if self.preempt_requested():
00039 self.service_preempt()
00040 return "preempt"
00041
00042
00043 for data in self._datamodel:
00044 if(self._datamodel[data] != ""):
00045 ud[data] = self._datamodel[data]
00046
00047
00048 if(self._onEntry is not None):
00049 try:
00050 self._onEntry.execute(ud)
00051 except Exception as ex:
00052 rospy.logerr('%s::onEntry::execute() raised | %s'
00053 %(self.__class__.__name__,str(ex)))
00054 return "preempt"
00055
00056
00057 try:
00058 outcome = self.execution(ud)
00059 except Exception as ex:
00060 rospy.logerr('%s::execute() raised | %s'
00061 %(self.__class__.__name__,str(ex)))
00062 return "preempt"
00063 finally:
00064 if self.preempt_requested():
00065 self.service_preempt()
00066 return "preempt"
00067
00068
00069 if(self._onExit is not None):
00070 try:
00071 outcome = self._onExit.execute(ud, outcome)
00072 except Exception as ex:
00073 rospy.logerr('%s::onExit::execute() raised | %s'
00074 %(self.__class__.__name__,str(ex)))
00075 return "preempt"
00076
00077 return outcome
00078
00079 def execution(self, ud):
00080 """Called when executing a state.
00081 In the base class this raises a NotImplementedError.
00082
00083 @type ud: L{UserData} structure
00084 @param ud: Userdata for the scope in which this state is executing
00085 """
00086 raise NotImplementedError()
00087
00088 class EmptyState(ssmState):
00089 def __init__(self):
00090 ssmState.__init__(self,outcomes=["next"])
00091
00092 def execution(self, ud):
00093 rospy.sleep(2)
00094 ud.skill = "Empty"
00095 return "next"