00001 # 00002 # Copyright (c) 2009, Georgia Tech Research Corporation 00003 # All rights reserved. 00004 # 00005 # Redistribution and use in source and binary forms, with or without 00006 # modification, are permitted provided that the following conditions are met: 00007 # * Redistributions of source code must retain the above copyright 00008 # notice, this list of conditions and the following disclaimer. 00009 # * Redistributions in binary form must reproduce the above copyright 00010 # notice, this list of conditions and the following disclaimer in the 00011 # documentation and/or other materials provided with the distribution. 00012 # * Neither the name of the Georgia Tech Research Corporation nor the 00013 # names of its contributors may be used to endorse or promote products 00014 # derived from this software without specific prior written permission. 00015 # 00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND 00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT, 00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 # 00027 00028 # \author Advait Jain (Healthcare Robotics Lab, Georgia Tech.) 00029 00030 00031 import numpy as np, math 00032 00033 import roslib 00034 roslib.load_manifest('hrl_lib') 00035 00036 import PyKDL as kdl 00037 00038 00039 ## kdl vector -> 3x1 np matrix. 00040 def kdl_vec_to_np(kdl_vec): 00041 v = np.matrix([kdl_vec[0],kdl_vec[1],kdl_vec[2]]).T 00042 return v 00043 00044 ## kdl rotation matrix -> 3x3 numpy matrix. 00045 def kdl_rot_to_np(kdl_rotation): 00046 m = kdl_rotation 00047 rot = np.matrix([[m[0,0],m[0,1],m[0,2]], 00048 [m[1,0],m[1,1],m[1,2]], 00049 [m[2,0],m[2,1],m[2,2]]]) 00050 return rot 00051 00052 ## 3x1 np vector -> KDL Vector 00053 def np_vec_to_kdl(p): 00054 return kdl.Vector(p[0,0],p[1,0],p[2,0]) 00055 00056 ## 3x3 np rotation matrix -> KDL Rotation. 00057 def np_rot_to_kdl(rot): 00058 return kdl.Rotation(rot[0,0],rot[0,1],rot[0,2],rot[1,0],rot[1,1],rot[1,2],rot[2,0],rot[2,1],rot[2,2]) 00059 00060 00061