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 PKG = 'qualification'
00040
00041 import roslib
00042 roslib.load_manifest(PKG)
00043
00044 from pr2_self_test_msgs.srv import ScriptDone, ScriptDoneRequest
00045
00046 import rospy
00047 import traceback
00048 import socket
00049 import subprocess
00050
00051
00052 class ProjectorChecker:
00053 def __init__(self):
00054 self._dmm_address = rospy.get_param("~dmm_address")
00055
00056 @property
00057 def dmm_address(self): return self._dmm_address
00058
00059 def check_projector(self):
00060 retcode = subprocess.call('ping -c1 -W1 %s > /dev/null' % self._dmm_address, shell=True)
00061 if retcode != 0:
00062 return False
00063
00064 try :
00065 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00066 lxi_port = 5025
00067 sock.settimeout(15)
00068 sock.connect((self._dmm_address, 5025))
00069 sock.close()
00070 return True
00071 except socket.error:
00072 return False
00073 except Exception, e:
00074 rospy.logerr('Caught unknown exception checking projector:\n%s' % traceback.format_exc())
00075 return False
00076 return True
00077
00078
00079 def main():
00080 r = ScriptDoneRequest()
00081 r.result = ScriptDoneRequest.RESULT_ERROR
00082 r.failure_msg = 'Unable to contact projector'
00083
00084 try:
00085 rospy.init_node('projector_monitor')
00086 done_srv = rospy.ServiceProxy('prestartup_done', ScriptDone)
00087
00088 monitor = ProjectorChecker()
00089 if not monitor.check_projector():
00090 r.failure_msg = 'Unable to contact projector at %s' % monitor.dmm_address
00091 done_srv.call(r)
00092 rospy.spin()
00093 else:
00094 r.result = ScriptDoneRequest.RESULT_OK
00095 r.failure_msg = 'Projector OK'
00096 done_srv.call(r)
00097
00098 except Exception, e:
00099 import traceback
00100 r.failure_msg = 'Error contacting projector. Exception:\n%s' % traceback.format_exc()
00101 done_srv.call(r)
00102
00103 rospy.spin()
00104
00105 if __name__ == '__main__':
00106 main()