calibrate_tool.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from subprocess import call
4 from math import sqrt
5 
6 import rospy
7 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
8 from force_torque_sensor.srv import CalculateAverageMasurement
9 from geometry_msgs.msg import Vector3
10 
11 
13 
14  rospy.init_node('calibrate_tool')
15 
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')
20 
21  if robot == "kuka":
22  joint_names = rospy.get_param('/controller_joint_names')
23  controller_topic = '/position_trajectory_controller/command'
24  calcOffset_service = '/CalculateAverageMasurement'
25  elif robot == "ur":
26  joint_names = rospy.get_param('/hardware_interface/joints')
27  controller_topic = '/pos_based_pos_traj_controller/command'
28  calcOffset_service = '/CalculateAverageMasurement'
29  else:
30  joint_names = rospy.get_param('/arm/joint_names')
31  controller_topic = '/arm/joint_trajectory_controller/command'
32  calcOffset_service = '/arm/CalculateAverageMasurement'
33 
34  trajectory_pub = rospy.Publisher(controller_topic, JointTrajectory, latch=True, queue_size=1)
35  average_measurements_srv = rospy.ServiceProxy(calcOffset_service, CalculateAverageMasurement)
36 
37  # Posees
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]]
41 
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]]
45 
46  poses_ur = [[1.5707963, -1.5707963, 1.5707963, -1.5707963, 1.5707963, 0.0], # top
47  [1.5707963, -1.5707963, 1.5707963, -1.5707963, -1.5707963, 0.0], # home
48  [1.5707963, -1.5707963, 1.5707963, -1.5707963, 0.0, 0.0]] # right
49 
50  measurement = []
51 
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
57 
58  point.time_from_start = rospy.Duration(5.0)
59  if robot == "kuka":
60  point.positions = poses_kuka[i]
61  elif robot == "ur":
62  point.positions = poses_ur[i]
63  else:
64  point.positions = poses[i]
65 
66  trajectory.points.append(point)
67  trajectory_pub.publish(trajectory)
68  rospy.loginfo("Going to position: " + str(point.positions))
69 
70  rospy.sleep(10.0)
71 
72  rospy.loginfo("Calculating tool force.")
73  #ret = average_measurements_srv(500, 0.01)
74  ret = average_measurements_srv(500, 0.01, "fts_base_link")
75 
76  measurement.append(ret.measurement)
77 
78  CoG = Vector3()
79 
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
82  #CoG.z = (measurement[2].torque.x) / Fg;
83 
84  rospy.loginfo("Setting parametes for tool: " + tool_name)
85 
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)
90 
91  if store_to_file:
92  if robot == "ur":
93  call("rosparam dump -v `rospack find ipr_ur_bringup`/urdf/tools" + tool_name + "/" + robot_name + "_gravity.yaml /temp/tool", shell=True)
94  else:
95  call("rosparam dump -v `rospack find iirob_description`/tools/urdf/" + tool_name + "/" + robot_name + "_gravity.yaml /temp/tool", shell=True)
96 
97 
98 if __name__ == "__main__":
99 
100  try:
102  except rospy.ROSInterruptException:
103  pass


force_torque_sensor
Author(s):
autogenerated on Fri Sep 18 2020 03:06:30