0
$\begingroup$

Rosanswers logo

Hi

The TF documentation mentions that there are methods to convert points from one frame to another. I am currently using the python tf api.

I have a list of [x,y,z] points in the sensor frame and I want to transform these points into the map frame.

calling this

 (tran, rot) = self.tf_listener.lookupTransform('/body', '/map', rospy.Time(0.0))

gives a translation vector and a quaternion for the rotation. I am not really familiar with quaternions... but I heard they are hard...

Anyway Is there a method in the python api to convert my vector of points to another frame? I noticed in the c++ tf api there was a function called transformPoint. Is this what I need?

My other idea is to use the transformation.py module to convert the quaternions and the translation vector to a homogeneous transformation matrix and transform the vector of points manually. (by using the transformations.py module) http://wiki.ros.org/geometry/RotationMethods#transformations.py


Originally posted by Sentinal_Bias on ROS Answers with karma: 418 on 2014-03-30

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

The python tf API has transformPoint, and transformPointCloud. I'm not sure why they don't show up in the API docs, but here's how they work:

transformPoint(self, target_frame, ps) method of tf.listener.TransformListener instance
    :param target_frame: the tf target frame, a string
    :param ps: the geometry_msgs.msg.PointStamped message
    :return: new geometry_msgs.msg.PointStamped message, in frame target_frame
    :raises: any of the exceptions that :meth:`~tf.Transformer.lookupTransform` can raise
    
    Transforms a geometry_msgs PointStamped message to frame target_frame, returns a new PointStamped message.


transformPointCloud(self, target_frame, point_cloud) method of tf.listener.TransformListener instance
    :param target_frame: the tf target frame, a string
    :param ps: the sensor_msgs.msg.PointCloud message
    :return: new sensor_msgs.msg.PointCloud message, in frame target_frame
    :raises: any of the exceptions that :meth:`~tf.Transformer.lookupTransform` can raise
    
    Transforms a geometry_msgs PoseStamped message to frame target_frame, returns a new PoseStamped message.

You'll have to either loop over your vector and create PointStamped objects, or pack all the points into a PointCloud.


Originally posted by Dan Lazewatsky with karma: 9115 on 2014-03-30

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Sentinal_Bias on 2014-03-30:
Hi thanks I use the pointcloud method. I found some documentation here http://mirror.umd.edu/roswiki/doc/diamondback/api/tf/html/python/tf_python.html. But the official link is missing sections

$\endgroup$
0
$\begingroup$

Rosanswers logo

You can transform points in base_link frame to odom frame using TF as follows

listener = tf.TransformListener()
listener.waitForTransform("/base_link", "/odom", rospy.Time(0),rospy.Duration(4.0))
laser_point=PointStamped()
laser_point.header.frame_id = "base_link"
laser_point.header.stamp =rospy.Time(0)
laser_point.point.x=1.0
laser_point.point.y=1.0
laser_point.point.z=0.0
p=listener.transformPoint("odom",laser_point)

Output look likes

[ INFO] [1498858767.555667233]: Current: [X= 0.105044,Y= -0.020144,Theta= -22.776758]

header: 
  seq: 0
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: odom
point: 
  x: 1.41420562607
  y: 0.514734522986
  z: 1.0

Originally posted by Gayan Brahmanage with karma: 929 on 2017-06-30

This answer was NOT ACCEPTED on the original site

Post score: 7


Original comments

Comment by db on 2017-11-23:
+1 for showing example

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.