Go to the documentation of this file.00001
00002
00003 from subprocess import call
00004 from math import sqrt
00005
00006 import rospy
00007 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
00008 from ati_force_torque.srv import CalculateAverageMasurement
00009 from geometry_msgs.msg import Vector3
00010
00011
00012 def calibrate_tool():
00013
00014 rospy.init_node('calibrate_tool')
00015 trajectory_pub = rospy.Publisher('/arm/joint_trajectory_controller/command', JointTrajectory, latch=True, queue_size=1)
00016 average_measurements_srv = rospy.ServiceProxy('/arm/CalculateAverageMasurement', CalculateAverageMasurement)
00017
00018 joint_names = rospy.get_param('/arm/joint_names')
00019
00020 tool_name = rospy.get_param('~tool_name')
00021 store_to_file = rospy.get_param('~store_to_file')
00022
00023
00024 poses = [[0.0, 0.0, 1.5707963, 0.0, -1.5707963, 0.0],
00025 [0.0, 0.0, 1.5707963, 0.0, 1.5707963, 0.0],
00026 [0.0, 0.0, 0.0, 0.0, 1.5707963, 0.0]]
00027
00028 measurement = []
00029
00030 for i in range(0,len(poses)):
00031 trajectory = JointTrajectory()
00032 point = JointTrajectoryPoint()
00033 trajectory.header.stamp = rospy.Time.now()
00034 trajectory.joint_names = joint_names
00035
00036 point.time_from_start = rospy.Duration(5.0)
00037 point.positions = poses[i]
00038
00039 trajectory.points.append(point)
00040 trajectory_pub.publish(trajectory)
00041 rospy.loginfo("Going to position: " + str(poses[i]))
00042
00043 rospy.sleep(10.0)
00044
00045 rospy.loginfo("Calculating tool force.")
00046
00047 ret = average_measurements_srv(500, 0.01, "fts_base_link")
00048
00049 measurement.append(ret.measurement)
00050
00051 CoG = Vector3()
00052
00053 Fg = (abs(measurement[0].force.z) + abs(measurement[1].force.z))/2.0;
00054
00055 CoG.z = (measurement[2].torque.y) / Fg;
00056
00057 rospy.loginfo("Setting parametes for tool: " + tool_name)
00058
00059 rospy.set_param('/temp/tool/CoG/x', CoG.x)
00060 rospy.set_param('/temp/tool/CoG/y', CoG.y)
00061 rospy.set_param('/temp/tool/CoG/z', CoG.z)
00062 rospy.set_param('/temp/tool/force', Fg)
00063
00064 if store_to_file:
00065 call("rosparam dump -v `rospack find iirob_description`/tools/urdf/" + tool_name + "/gravity.yaml /temp/tool", shell=True)
00066
00067
00068 if __name__ == "__main__":
00069
00070 try:
00071 calibrate_tool()
00072 except rospy.ROSInterruptException:
00073 pass