3 from subprocess
import call
7 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
8 from force_torque_sensor.srv
import CalculateAverageMasurement
9 from geometry_msgs.msg
import Vector3
14 rospy.init_node(
'calibrate_tool')
16 tool_name = rospy.get_param(
'~tool_name')
17 robot_name = rospy.get_param(
'~robot_name')
18 store_to_file = rospy.get_param(
'~store_to_file')
19 robot = rospy.get_param(
'~robot')
22 joint_names = rospy.get_param(
'/controller_joint_names')
23 controller_topic =
'/position_trajectory_controller/command' 24 calcOffset_service =
'/CalculateAverageMasurement' 26 joint_names = rospy.get_param('/hardware_interface/joints')
27 controller_topic =
'/pos_based_pos_traj_controller/command' 28 calcOffset_service =
'/CalculateAverageMasurement' 30 joint_names = rospy.get_param(
'/arm/joint_names')
31 controller_topic =
'/arm/joint_trajectory_controller/command' 32 calcOffset_service =
'/arm/CalculateAverageMasurement' 34 trajectory_pub = rospy.Publisher(controller_topic, JointTrajectory, latch=
True, queue_size=1)
35 average_measurements_srv = rospy.ServiceProxy(calcOffset_service, CalculateAverageMasurement)
38 poses = [[0.0, 0.0, 1.5707963, 0.0, -1.5707963, 0.0],
39 [0.0, 0.0, 1.5707963, 0.0, 1.5707963, 0.0],
40 [0.0, 0.0, 0.0, 0.0, 1.5707963, 0.0]]
42 poses_kuka = [[0.0, -1.5707963, 1.5707963, 0.0, -1.5707963, 0.0],
43 [0.0, -1.5707963, 1.5707963, 0.0, 1.5707963, 0.0],
44 [0.0, -1.5707963, 1.5707963, 0.0, 0.0, 0.0]]
46 poses_ur = [[1.5707963, -1.5707963, 1.5707963, -1.5707963, 1.5707963, 0.0],
47 [1.5707963, -1.5707963, 1.5707963, -1.5707963, -1.5707963, 0.0],
48 [1.5707963, -1.5707963, 1.5707963, -1.5707963, 0.0, 0.0]]
52 for i
in range(0,len(poses)):
53 trajectory = JointTrajectory()
54 point = JointTrajectoryPoint()
55 trajectory.header.stamp = rospy.Time.now()
56 trajectory.joint_names = joint_names
58 point.time_from_start = rospy.Duration(5.0)
60 point.positions = poses_kuka[i]
62 point.positions = poses_ur[i] 64 point.positions = poses[i]
66 trajectory.points.append(point)
67 trajectory_pub.publish(trajectory)
68 rospy.loginfo(
"Going to position: " + str(point.positions))
72 rospy.loginfo(
"Calculating tool force.")
74 ret = average_measurements_srv(500, 0.01,
"fts_base_link")
76 measurement.append(ret.measurement)
80 Fg = (abs(measurement[0].force.z) + abs(measurement[1].force.z))/2.0
81 CoG.z = (sqrt(measurement[2].torque.x*measurement[2].torque.x + measurement[2].torque.y*measurement[2].torque.y)) / Fg
84 rospy.loginfo(
"Setting parametes for tool: " + tool_name)
86 rospy.set_param(
'/temp/tool/CoG_x', CoG.x)
87 rospy.set_param(
'/temp/tool/CoG_y', CoG.y)
88 rospy.set_param(
'/temp/tool/CoG_z', CoG.z)
89 rospy.set_param(
'/temp/tool/force', Fg)
93 call("rosparam dump -v `rospack find ipr_ur_bringup`/urdf/tools" + tool_name +
"/" + robot_name +
"_gravity.yaml /temp/tool", shell=
True)
95 call(
"rosparam dump -v `rospack find iirob_description`/tools/urdf/" + tool_name +
"/" + robot_name +
"_gravity.yaml /temp/tool", shell=
True)
98 if __name__ ==
"__main__":
102 except rospy.ROSInterruptException: