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 datetime
00020 import rospy
00021
00022 def StrTimeStamped():
00023 return datetime.datetime.now().strftime("%Y_%m_%d_%H:%M:%S.%f - ")
00024
00025 class onEntry():
00026
00027 def __init__(self, logs={}, script=None):
00028 self._logs = logs
00029 self._script = script
00030
00031 def execute(self, ud):
00032 if(rospy.get_param("ssm_enable_log", False) == True):
00033 file = open(ud.logfile, "a")
00034 for log in self._logs:
00035 if(log == "outcome"):
00036 rospy.logwarn("[SSM : onEntry] : Log of the outcome expected. This is not possible in <onentry>")
00037 elif(log == ""):
00038 file.write(StrTimeStamped() + self._logs[log] +"\n")
00039 else:
00040 file.write(StrTimeStamped() + self._logs[log] + " " +str(ud[log])+"\n")
00041 file.close()
00042
00043 if(self._script is not None):
00044 try:
00045 exec(self._script)
00046 except RuntimeError as msg:
00047 rospy.logerr("[SSM : onEntry] : %s"%msg)
00048
00049 class onExit():
00050
00051 def __init__(self, logs={}, script=None):
00052 self._logs = logs
00053 self._script = script
00054
00055 def execute(self, ud, outcome_):
00056 outcome = outcome_
00057 if(self._script is not None):
00058 try:
00059 exec(self._script)
00060 except RuntimeError as msg:
00061 rospy.logerr("[SSM : onExit] : %s"%msg)
00062
00063 if(rospy.get_param("ssm_enable_log", False) == True):
00064 file = open(ud.logfile, "a")
00065 for log in self._logs:
00066 if(log == "outcome"):
00067 file.write(StrTimeStamped() + self._logs[log] + " " +str(outcome)+"\n")
00068 elif(log == ""):
00069 file.write(StrTimeStamped() + self._logs[log] +"\n")
00070 else:
00071 file.write(StrTimeStamped() + self._logs[log] + " " +str(ud[log])+"\n")
00072 file.close()
00073 return outcome