tf_utils.py
Go to the documentation of this file.
00001 import roslib
00002 roslib.load_manifest('hrl_lib')
00003 
00004 import rospy
00005 import tf.transformations as tr
00006 import numpy as np
00007 
00008 def tf_as_matrix(tup):
00009     return np.matrix(tr.translation_matrix(tup[0])) * np.matrix(tr.quaternion_matrix(tup[1])) 
00010 
00011 def matrix_as_tf(mat):
00012     return (tr.translation_from_matrix(mat), tr.quaternion_from_matrix(mat))
00013 
00014 def transform(to_frame, from_frame, tflistener, t=0):
00015     tflistener.waitForTransform(to_frame, from_frame, rospy.Time(t), rospy.Duration(10))
00016     return tf_as_matrix(tflistener.lookupTransform(to_frame, from_frame, rospy.Time(t)))
00017 
00018 def transform_points(T, points):
00019     return (T * np.row_stack((points, 1+np.zeros((1, points.shape[1])))))[0:3,:]
00020 
00021 def rotate(to_frame, from_frame, tflistener, t=0):
00022     t, q = tflistener.lookupTransform(to_frame, from_frame, rospy.Time(t))
00023     return np.matrix(tr.quaternion_matrix(q)) 
00024 
00025 def quaternion_matrix(quat):
00026     return np.matrix(tr.quaternion_matrix(quat))
00027 
00028 def translation_matrix(trans):
00029     return np.matrix(tr.translation_matrix(trans))
00030 
00031 def pose_as_matrix(p):
00032     t = [p.position.x, p.position.y, p.position.z]
00033     o = [p.orientation.x, p.orientation.y, p.orientation.z, p.orientation.w]
00034     return tf_as_matrix((t, o))
00035 
00036 def posestamped_as_matrix(ps):
00037     p = ps.pose
00038     return pose_as_matrix(p), ps.header.frame_id


hrl_lib
Author(s): Cressel Anderson, Travis Deyle, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:06