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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 from __future__ import with_statement
00041
00042 PKG = 'pr2_hardware_test_monitor'
00043 import roslib; roslib.load_manifest(PKG)
00044
00045 from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus, KeyValue
00046 from std_srvs.srv import *
00047
00048 import rospy
00049
00050 import threading
00051
00052 from pr2_hw_listener import PR2HWListenerBase
00053
00054 STALE_TIMEOUT = 8.0
00055 ERROR_TIMEOUT = 8.0
00056 ERROR_MAX = 3
00057
00058 class CameraListener(PR2HWListenerBase):
00059 def __init__(self):
00060 self._diag_sub = rospy.Subscriber('/diagnostics', DiagnosticArray, self._diag_callback)
00061 self._mutex = threading.Lock()
00062
00063 self._lvl = 3
00064 self._update_time = 0
00065
00066
00067 self._last_ok_time = rospy.get_time()
00068 self._error_cnt = 0
00069 self._last_msg_ok = False
00070
00071 self._was_stale = True
00072 self._reported_vals = False
00073
00074 def _diag_callback(self, msg):
00075 with self._mutex:
00076 has_wge100 = False
00077 this_lvl = 0
00078 this_msg = ''
00079 for stat in msg.status:
00080 if stat.name.find('wge100') >= 0:
00081 this_lvl = max(stat.level, this_lvl)
00082 self._update_time = rospy.get_time()
00083 has_wge100 = True
00084
00085 if stat.level == this_lvl:
00086 this_msg = stat.message
00087
00088 if has_wge100:
00089 if this_lvl == 0:
00090 self._last_ok_time = rospy.get_time()
00091 self._error_cnt = 0
00092
00093
00094 if self._reported_vals:
00095 self._last_msg_ok = True
00096 else:
00097 self._last_msg_ok = False
00098
00099 if this_lvl > 1:
00100 rospy.logwarn('Camera error from wge100 camera. Message: %s' % this_msg)
00101 self._error_cnt += 1
00102
00103 self._was_stale = False
00104 self._reported_vals = False
00105
00106
00107 def check_ok(self):
00108 with self._mutex:
00109 msg = 'OK'
00110 lvl = 0
00111
00112
00113 if not self._last_msg_ok:
00114 lvl = 1
00115 msg = 'Camera Warning'
00116
00117
00118 if self._error_cnt > ERROR_MAX or rospy.get_time() - self._last_ok_time > ERROR_TIMEOUT:
00119 lvl = 2
00120 msg = 'Camera Error'
00121 if rospy.get_time() - self._last_ok_time > ERROR_TIMEOUT:
00122 rospy.logwarn('Too long since last OK message received. Camera error')
00123
00124 if rospy.get_time() - self._update_time > STALE_TIMEOUT:
00125 if not self._was_stale:
00126 rospy.logerr('wge100 camera is stale. No updates from camera')
00127 self._was_stale = True
00128
00129 lvl = 3
00130 msg = 'Camera Stale'
00131 if self._update_time == 0:
00132 msg = 'No Camera Data'
00133
00134
00135 self._reported_vals = True
00136
00137 return lvl, msg, None
00138