ssm_on.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
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


airbus_ssm_core
Author(s): Ludovic Delval
autogenerated on Thu Jun 6 2019 17:59:28