conversions.py
Go to the documentation of this file.
00001 from __future__ import print_function
00002 
00003 import numbers
00004 
00005 from tf.transformations import *
00006 from geometry_msgs.msg import Pose
00007 
00008 
00009 
00010 def rounded(val):
00011   if isinstance(val, numbers.Number):
00012     return int(round(val,6) * 1e5) / 1.0e5
00013   else:
00014     return numpy.array([rounded(v) for v in val])
00015 
00016 
00017 def homogeneous2translation_quaternion(homogeneous):
00018   """
00019   Translation: [x, y, z]
00020   Quaternion: [x, y, z, w]
00021   """
00022   translation = translation_from_matrix(homogeneous)
00023   quaternion = quaternion_from_matrix(homogeneous)
00024   return translation, quaternion
00025 
00026 
00027 def homogeneous2translation_rpy(homogeneous):
00028   """
00029   Translation: [x, y, z]
00030   RPY: [sx, sy, sz]
00031   """
00032   translation = translation_from_matrix(homogeneous)
00033   rpy = euler_from_matrix(homogeneous)
00034   return translation, rpy
00035 
00036 
00037 def homogeneous2pose_msg(homogeneous):
00038   pose = Pose()
00039   translation, quaternion = homogeneous2translation_quaternion(homogeneous)
00040   pose.position.x = translation[0]
00041   pose.position.y = translation[1]
00042   pose.position.z = translation[2]
00043   pose.orientation.x = quaternion[0]
00044   pose.orientation.y = quaternion[1]
00045   pose.orientation.z = quaternion[2]
00046   pose.orientation.w = quaternion[3]
00047   return pose
00048 
00049 
00050 def pose_msg2homogeneous(pose):
00051   trans = translation_matrix((pose.position.x, pose.position.y, pose.position.z))
00052   rot = quaternion_matrix((pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w))
00053   return concatenate_matrices(trans, rot)
00054 
00055 
00056 def array2string(array):
00057   return numpy.array_str(array).strip('[]. ').replace('. ', ' ')
00058 
00059 
00060 def homogeneous2tq_string(homogeneous):
00061   return 't=%s q=%s' % homogeneous2translation_quaternion(homogeneous)
00062 
00063 
00064 def homogeneous2tq_string_rounded(homogeneous):
00065   return 't=%s q=%s' % tuple(rounded(o) for o in homogeneous2translation_quaternion(homogeneous))
00066 
00067 
00068 def string2float_list(s):
00069   return [float(i) for i in s.split()]
00070 
00071 
00072 def pose_string2homogeneous(pose):
00073   pose_float = string2float_list(pose)
00074   translate = pose_float[:3]
00075   angles = pose_float[3:]
00076   homogeneous = compose_matrix(None, None, angles, translate)
00077   #print('pose_string=%s; translate=%s angles=%s homogeneous:\n%s' % (pose, translate, angles, homogeneous))
00078   return homogeneous
00079 
00080 
00081 def rotation_only(homogeneous):
00082   euler = euler_from_matrix(homogeneous)
00083   return euler_matrix(euler[0], euler[1], euler[2])


pysdf
Author(s): Andreas Bihlmaier
autogenerated on Fri Oct 3 2014 22:09:51