ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

tf Python API transform points

asked 2014-03-30 02:23:39 -0500

Sentinal_Bias gravatar image

updated 2016-10-24 09:02:59 -0500

ngrennan gravatar image

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/Rotation...

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-03-30 04:57:27 -0500

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.

edit flag offensive delete link more

Comments

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

Sentinal_Bias gravatar image Sentinal_Bias  ( 2014-03-30 11:54:45 -0500 )edit
7

answered 2017-06-30 16:37:34 -0500

Gayan Brahmanage gravatar image

updated 2017-06-30 16:41:49 -0500

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
edit flag offensive delete link more

Comments

+1 for showing example

db gravatar image db  ( 2017-11-23 17:50:26 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-03-30 02:23:39 -0500

Seen: 9,565 times

Last updated: Jun 30 '17