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 import roslib
00036 roslib.load_manifest('qualification')
00037
00038 import sys
00039 import rospy
00040 from std_srvs.srv import *
00041 import std_msgs
00042 import subprocess
00043 import os
00044 import os.path
00045 import traceback
00046 import time
00047 from wg_invent_client import Invent
00048 from pr2_self_test_msgs.srv import ScriptDone, ScriptDoneRequest
00049
00050 rospy.init_node("wge100_camera_set_name")
00051
00052 def getparam(name):
00053 val = rospy.get_param(name, None)
00054 if val == None:
00055 failed("Parameter %s not set"%name)
00056 return val
00057
00058 def failed(message):
00059 send_response("Error setting camera name", message, 1)
00060
00061 def passed(message):
00062 send_response("Camera successfully set to %s at %s "%(cameraname, cameraip),
00063 message, 0)
00064
00065 def send_response(summary, message, retval):
00066 print summary
00067 print message.replace('<b>','').replace('</b>','')
00068 r=ScriptDoneRequest()
00069 r.failure_msg = message.replace('<b>','').replace('</b>','')
00070
00071 if retval != 0:
00072 r.result = ScriptDoneRequest.RESULT_FAIL
00073 else:
00074 r.result = ScriptDoneRequest.RESULT_OK
00075
00076 rospy.wait_for_service('prestartup_done', 2)
00077 result_service = rospy.ServiceProxy('prestartup_done', ScriptDone)
00078 result_service.call(r)
00079 exit(retval)
00080
00081 try:
00082
00083 username = getparam('/invent/username')
00084 password = getparam('/invent/password')
00085 barcode = getparam('qual_item/serial')
00086 cameraname = getparam('~camera_name')
00087 cameraip = getparam('~camera_ip')
00088 progip = getparam('~programming_ip')
00089
00090
00091 i = Invent(username, password)
00092 if not i.login():
00093 failed("Could not connect to invent.")
00094
00095
00096 try:
00097 camera_url = i.get_item_references(barcode)["camera_url"]
00098 if camera_url == '':
00099 raise KeyError
00100 except KeyError:
00101 failed("Could not get camera url from invent. Try setting the serial and MAC")
00102
00103
00104 msg = ""
00105 reps = 0
00106 while True:
00107 p = subprocess.Popen(["rosrun", "wge100_camera", "set_name",
00108 camera_url+"@"+progip, cameraname, cameraip ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00109 setnameout = p.communicate()
00110
00111 msg = msg+"Output from setname tool...\n<b>Standard output:</b>\n"+setnameout[0]+"\n\n<b>Standard error:</b>\n"+setnameout[1]
00112
00113 if "Success" in msg:
00114 i.setKV(barcode, "Configured name", cameraname)
00115 i.setKV(barcode, "Configured ip", cameraip)
00116 passed(msg)
00117 else:
00118 if reps < 8:
00119 reps = reps + 1
00120 time.sleep(5)
00121 continue
00122 i.setKV(barcode, "Configured name", "<configure failed>")
00123 i.setKV(barcode, "Configured ip", "<configure failed>")
00124 failed(msg)
00125 except:
00126 failed('<b>Exception:</b>\n%s'%traceback.format_exc())