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 os
00032 import roslib
00033 roslib.load_manifest('pr2_playpen')
00034 roslib.load_manifest('tf_conversions')
00035 import rospy
00036 import math
00037 import tf
00038 import sys
00039 import tf_conversions.posemath as pm
00040 import numpy as np
00041 from geometry_msgs.msg import Pose
00042
00043 if __name__ == '__main__':
00044 rospy.init_node('playpen_calibration')
00045
00046 listener = tf.TransformListener()
00047 trans_list = []
00048 rot_list = []
00049
00050 rate = rospy.Rate(10.0)
00051 while not rospy.is_shutdown():
00052 try:
00053 (trans, rot) = listener.lookupTransform(sys.argv[1], sys.argv[2], rospy.Time(0))
00054 (trans2, rot2) = listener.lookupTransform(sys.argv[3], sys.argv[4], rospy.Time(0))
00055 msg1 = Pose()
00056 msg2 = Pose()
00057 msg1.position.x, msg1.position.y, msg1.position.z = trans[0], trans[1], trans[2]
00058 msg2.position.x, msg2.position.y, msg2.position.z = trans2[0], trans2[1], trans2[2]
00059 msg1.orientation.x, msg1.orientation.y, msg1.orientation.z, msg1.orientation.w = rot[0], rot[1], rot[2], rot[3]
00060 msg2.orientation.x, msg2.orientation.y, msg2.orientation.z, msg2.orientation.w = rot2[0], rot2[1], rot2[2], rot2[3]
00061 (trans_tot, rot_tot) = pm.toTf(pm.fromMsg(msg1)*pm.fromMsg(msg2))
00062 print "translation: ", trans_tot, ", rotation :", rot_tot
00063 trans_list.append(trans_tot)
00064 rot_list.append(rot_tot)
00065
00066 except (tf.LookupException, tf.ConnectivityException):
00067 continue
00068 rate.sleep()
00069 trans_str = str(np.median(np.array(trans_list), axis = 0))
00070 rot_str = str(np.median(np.array(rot_list), axis = 0))
00071 print "median of translation :", trans_str
00072 print "median of rotation :", rot_str
00073
00074 try:
00075 os.remove('../../launch/kinect_playpen_to_torso_lift_link.launch')
00076 except:
00077 print 'no file to be removed, creating new file'
00078 f = open('../../launch/kinect_playpen_to_torso_lift_link.launch', 'w')
00079 f.write('<launch>\n')
00080
00081
00082 f.write('<node pkg="tf" type="static_transform_publisher" name="kinect_playpen_to_pr2_lift_link" args=" '+trans_str[1:-1]+' '+rot_str[1:-1]+' '+sys.argv[1]+' '+sys.argv[4]+' 30" />\n')
00083 f.write('</launch>')
00084 f.close()
00085
00086
00087