3 from subprocess
import call
6 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
7 from force_torque_sensor.srv
import CalculateSensorOffset
8 from force_torque_sensor.srv
import SetSensorOffset
9 from geometry_msgs.msg
import Wrench
11 import dynamic_reconfigure.client
15 rospy.init_node(
'calculate_offsets')
17 package_to_store = rospy.get_param(
'~package_to_store')
18 store_to_file = rospy.get_param(
'~store_to_file')
19 scenario = rospy.get_param(
'~scenario')
20 robot = rospy.get_param(
'~robot')
21 set_calculated_offset = rospy.get_param(
'~set_calculated_offset')
22 offset_params_ns = rospy.get_param(
'~offset_params_ns',
"/temp")
23 recalibrate_srv_ns = rospy.get_param(
'~recalibrate_srv_ns',
"")
25 joint_names = rospy.get_param(
'/controller_joint_names')
26 controller_topic =
'/position_trajectory_controller/command' 27 calcOffset_service =
'/CalculateOffsets' 28 setOffset_service =
'/SetSensorOffset' 30 joint_names = rospy.get_param("/hardware_interface/joints")
31 controller_topic =
"/pos_based_pos_traj_controller/command" 32 calcOffset_service =
'/CalculateOffsets' 33 setOffset_service =
'/SetSensorOffset' 35 joint_names = rospy.get_param(
'/arm/joint_names')
36 controller_topic =
'/arm/joint_trajectory_controller/command' 37 calcOffset_service =
'/arm/CalculateOffsets' 38 setOffset_service =
'/arm/SetSensorOffset' 40 trajectory_pub = rospy.Publisher(controller_topic, JointTrajectory, latch=
True, queue_size=1)
41 calculate_offsets_srv = rospy.ServiceProxy(calcOffset_service, CalculateSensorOffset)
42 set_offsets_srv = rospy.ServiceProxy(setOffset_service, SetSensorOffset)
48 poses = [[0.0, 0.0, 1.5707963, 0.0, -1.5707963, 0.0],
49 [0.0, 0.0, 1.5707963, 0.0, 1.5707963, 0.0]]
51 poses_kuka = [[0.0, -1.5707963, 1.5707963, 0.0, -1.5707963, 0.0],
52 [0.0, -1.5707963, 1.5707963, 0.0, 1.5707963, 0.0]]
54 poses_ur = [[1.5707963, -1.5707963, 1.5707963, -1.5707963, 1.5707963, 0.0],
55 [1.5707963, -1.5707963, 1.5707963, -1.5707963, -1.5707963, 0.0]]
57 measurement = Wrench()
59 for i
in range(0,len(poses)):
60 trajectory = JointTrajectory()
61 point = JointTrajectoryPoint()
62 trajectory.header.stamp = rospy.Time.now()
63 trajectory.joint_names = joint_names
65 point.time_from_start = rospy.Duration(2.5)
67 point.positions = poses_kuka[i]
69 point.positions = poses_ur[i] 71 point.positions = poses[i]
73 trajectory.points.append(point)
74 trajectory_pub.publish(trajectory)
75 rospy.loginfo(
"Going to position: " + str(point.positions))
79 rospy.loginfo(
"Calculating offsets.")
80 ret = calculate_offsets_srv(
False)
82 measurement.force.x += ret.offset.force.x
83 measurement.force.y += ret.offset.force.y
84 measurement.force.z += ret.offset.force.z
85 measurement.torque.x += ret.offset.torque.x
86 measurement.torque.y += ret.offset.torque.y
87 measurement.torque.z += ret.offset.torque.z
90 measurement.force.x /= len(poses)
91 measurement.force.y /= len(poses)
92 measurement.force.z /= len(poses)
93 measurement.torque.x /= len(poses)
94 measurement.torque.y /= len(poses)
95 measurement.torque.z /= len(poses)
98 rospy.set_param(offset_params_ns +
'/Offset/force/x', measurement.force.x)
99 rospy.set_param(offset_params_ns +
'/Offset/force/y', measurement.force.y)
100 rospy.set_param(offset_params_ns +
'/Offset/force/z', measurement.force.z)
101 rospy.set_param(offset_params_ns +
'/Offset/torque/x', measurement.torque.x)
102 rospy.set_param(offset_params_ns +
'/Offset/torque/y', measurement.torque.y)
103 rospy.set_param(offset_params_ns +
'/Offset/torque/z', measurement.torque.z)
105 if set_calculated_offset:
106 ret = set_offsets_srv(measurement)
107 rospy.loginfo(ret.message)
113 call(
'rosparam dump -v `rospack find ' + package_to_store +
' `/config/sensor_offset.yaml ' + offset_params_ns +
'/Offset', shell=
True)
115 call(
'rosparam dump -v `rospack find ' + package_to_store +
' `/config/robot_with_' + scenario +
'_offset.yaml ' + offset_params_ns +
'/Offset', shell=
True)
119 if __name__ ==
"__main__":
123 except rospy.ROSInterruptException:
def calculate_sensor_offsets()