gripper_tip_sn.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Software License Agreement (BSD License)
00003 #
00004 # Copyright (c) 2010, Willow Garage, Inc.
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of the Willow Garage nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 #
00034 
00035 ##\author Kevin Watts
00036 ##\brief Gets the 4 digit gripper tip code from users and puts it in invent
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)


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34