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 import argparse
00032 import os
00033 import sys
00034
00035 import rospy
00036
00037 import baxter_interface
00038
00039 from baxter_interface import CHECK_VERSION
00040 from baxter_maintenance_msgs.msg import (
00041 CalibrateArmEnable,
00042 )
00043
00044
00045 class CalibrateArm(baxter_interface.RobustController):
00046 def __init__(self, limb):
00047 """
00048 Wrapper to run the CalibrateArm RobustController.
00049
00050 @param limb: Limb to run CalibrateArm on [left/right]
00051 """
00052 enable_msg = CalibrateArmEnable(isEnabled=True, uid='sdk')
00053
00054 disable_msg = CalibrateArmEnable(isEnabled=False, uid='sdk')
00055
00056
00057
00058 super(CalibrateArm, self).__init__(
00059 'robustcontroller/%s/CalibrateArm' % (limb,),
00060 enable_msg,
00061 disable_msg,
00062 10 * 60)
00063
00064
00065 def gripper_removed(side):
00066 """
00067 Verify grippers are removed for calibration/tare.
00068 """
00069 gripper = baxter_interface.Gripper(side)
00070 if gripper.type() != 'custom':
00071 rospy.logerr("Cannot calibrate with grippers attached."
00072 " Remove grippers before calibration!")
00073 return False
00074 return True
00075
00076
00077 def main():
00078 parser = argparse.ArgumentParser()
00079 required = parser.add_argument_group('required arguments')
00080 required.add_argument('-l', '--limb', required=True,
00081 choices=['left', 'right'],
00082 help="Calibrate the specified arm")
00083 args = parser.parse_args(rospy.myargv()[1:])
00084 arm = args.limb
00085
00086 print("Initializing node...")
00087 rospy.init_node('rsdk_calibrate_arm_%s' % (arm,))
00088
00089 print("Preparing to calibrate...")
00090 gripper_warn = ("\nIMPORTANT: Make sure to remove grippers and other"
00091 " attachments before running calibrate.\n")
00092 print(gripper_warn)
00093 if not gripper_removed(args.limb):
00094 return 1
00095
00096 rs = baxter_interface.RobotEnable(CHECK_VERSION)
00097 rs.enable()
00098 cat = CalibrateArm(arm)
00099 rospy.loginfo("Running calibrate on %s arm" % (arm,))
00100
00101 error = None
00102 try:
00103 cat.run()
00104 except Exception, e:
00105 error = e.strerror
00106 finally:
00107 try:
00108 rs.disable()
00109 except Exception:
00110 pass
00111
00112 if error == None:
00113 rospy.loginfo("Calibrate arm finished")
00114 else:
00115 rospy.logerr("Calibrate arm failed: %s" % (error,))
00116
00117 return 0 if error == None else 1
00118
00119 if __name__ == '__main__':
00120 sys.exit(main())