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 PKG = 'qualification'
00039 import roslib
00040 roslib.load_manifest(PKG)
00041 import wx
00042 import sys
00043
00044 from pr2_self_test_msgs.srv import ScriptDone, ScriptDoneRequest
00045
00046 import rospy
00047
00048 def _report_invalid_id():
00049 dlg = wx.MessageDialog(None, "Invalid ID. Tip ID should be four digits, numeric. Press Cancel to abort or OK to retry.", "Invalid ID", wx.OK|wx.CANCEL)
00050 return dlg.ShowModal() == wx.ID_OK
00051
00052 def _report_id_mismatch():
00053 dlg = wx.MessageBox("Tip ID entries don't match.", "ID Mismatch", wx.OK|wx.ICON_ERROR, None)
00054 return
00055
00056 def get_code_from_user():
00057 code1 = None
00058 while not rospy.is_shutdown():
00059 code1 = wx.GetTextFromUser("Enter the four digit ID on the back of the gripper tip.", "Gripper Tip ID")
00060 if not unicode(code1).isnumeric() or not len(code1) == 4:
00061 if _report_invalid_id():
00062 continue
00063 else:
00064 return None
00065
00066 code2 = wx.GetTextFromUser("Re-enter the four digit ID on the back of the gripper tip.", "Gripper Tip ID")
00067 if code1 == code2:
00068 break
00069 _report_id_mismatch()
00070
00071 if not code1 or code1 != code2:
00072 return None
00073
00074 code = str(code1)
00075 return code
00076
00077
00078 def add_reference(reference):
00079 from wg_invent_client import Invent
00080 username = rospy.get_param('/invent/username', '')
00081 password = rospy.get_param('/invent/password', '')
00082 serial = rospy.get_param('/qual_item/serial', None)
00083
00084 iv = Invent(username, password)
00085 if not iv.login() or serial == None:
00086 return False
00087
00088 return iv.addItemReference(serial, 'PPS', 'pps' + reference)
00089
00090
00091 if __name__ == '__main__':
00092 rospy.init_node('tip_sensor_id_recovery')
00093 done_srv = rospy.ServiceProxy('prestartup_done', ScriptDone)
00094 rospy.wait_for_service('prestartup_done')
00095
00096 app = wx.PySimpleApp()
00097
00098 code = get_code_from_user()
00099 if code is None:
00100 done_srv.call(result = ScriptDoneRequest.RESULT_FAIL, failure_msg = "User was unable to get correct PPS ID code from tip sensor")
00101 rospy.spin()
00102 sys.exit()
00103
00104 if not add_reference(code):
00105 done_srv.call(result = ScriptDoneRequest.RESULT_ERROR, failure_msg = "Unable to load PPS code pps%s into inventory system. May have incorrect serial number." % code)
00106 rospy.spin()
00107 sys.exit()
00108
00109 done_srv.call(result = ScriptDoneRequest.RESULT_OK, failure_msg = "Loaded PPS code pps%s into invent" % code)
00110
00111 rospy.spin()
00112
00113 sys.exit(0)