calibrate.py
Go to the documentation of this file.
00001 #!/usr/bin/env python  
00002 #
00003 # Copyright (c) 2009, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 #Author: Marc Killpack
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     ############################################ I really need to verify the order of sys.arg[4] and sys.arg[1], this could be wrong!!! best way to check 
00081     ############################################ is to transform something from argv[4] frame to argv[1] frame and check
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 #run this to calibrate playpen, I should include it in a launch file with arguments and launching pr2_launch/ar_kinect and launch/ar_kinect
00087 #./calibrate.py  /torso_lift_link /calibration_pattern /calibration_pattern2 /openni_camera2


pr2_playpen
Author(s): Marc Killpack / mkillpack3@gatech.edu, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 12:18:32