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

tf transformPoint() equivalent on tf2?

asked 2013-10-29 15:24:38 -0600

ssafarik gravatar image

updated 2015-06-19 03:34:20 -0600

BennyRe gravatar image

It used to be that, with tf, we would use a TransformListener and its transformDATA() methods, e.g.

import tf
listener = tf.TransformListener()
...
ptNew = listener.transformPoint('frameNew', ptOld)

but now with tf2 (i.e. tf2_ros), there doesn't seem to be a transformPoint(). The only place I can find something close is in tf2_geometry_msgs.do_transform_point(), which requires PyKDL (not installed by default with ROS). I can't find any docs on the api for the do_transform_DATA(), however, and I see that the code is called "geometry_experimental" on github. Am I just trying to use this before it's ready for prime time, or is there something I'm missing as far as docs and using the tf2 listener?

Edit: Bump. I'm also facing this problem.

edit retag flag offensive close merge delete

Comments

1

Is there an update on this? Transforming points from one coordinate system to the other is, for me, the essential use-case of tf2. But it seems that this is supported only poorly and documented even more poorly.

BennyRe gravatar image BennyRe  ( 2015-06-19 03:32:33 -0600 )edit

3 Answers

Sort by » oldest newest most voted
5

answered 2015-06-19 11:39:27 -0600

tfoote gravatar image

updated 2016-12-13 05:58:59 -0600

Procópio gravatar image

You can use the transform or transform_full methods from the BufferInterface on any datatype which implements do_transform

tf2 is now recommended. It is still in the geometry_experimental repository but only for legacy reasons.

edit flag offensive delete link more

Comments

2

hey @tfoote, I tried using the transform method to transform a stamped pose, and got this error: File "/opt/ros/indigo/lib/python2.7/dist-packages/tf2_ros/buffer_interface.py", line 43, in transform do_transform = self.registration.get(type(object_stamped))

Procópio gravatar image Procópio  ( 2016-12-14 02:09:21 -0600 )edit
2

File "/opt/ros/indigo/lib/python2.7/dist-packages/tf2_ros/buffer_interface.py", line 105, in get raise TypeException('Type %s if not loaded or supported'% str(key)) TypeException

Procópio gravatar image Procópio  ( 2016-12-14 02:09:39 -0600 )edit
5

For anyone that comes across this, to transform PoseStamped messages you can try installing ros-kinetic-tf2-geometry-msgs and then importing tf2_geometry_msgs

dhood gravatar image dhood  ( 2017-03-07 10:55:43 -0600 )edit

Is there an update on this? I am following this tutorial and can't figure out the tf2 equivalent of the listener.transformPoint() part, I tried including buffer_interface.h but the methods mentioned above were still not available

Alkrick gravatar image Alkrick  ( 2021-03-08 03:48:27 -0600 )edit
1

answered 2022-01-21 15:07:17 -0600

zkytony gravatar image

updated 2022-01-21 15:08:08 -0600

This is very tricky. I had to do

 import tf2_geometry_msgs.tf2_geometry_msgs

in order for the do_transform interfaces for PoseStamped and other geometry_msgs messages to be registered. The registration is done while importing as shown in the source code for tf2_geometry_msgs.py.

The comments by @Procópio and @Alkrick can be resolved by this.

This does not appear (from an end-user's perspective) to be relevant for the transform function. Either documentation should say this or the way to use tf2_ros should be improved (why not import the above automatically when doing import tf2_ros?)

edit flag offensive delete link more
0

answered 2022-02-26 23:02:50 -0600

Arif Rahman gravatar image

Here's a sample script to do it, following @zkytony 's answer:

#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import PoseStamped, TransformStamped
import tf2_ros
import tf2_geometry_msgs.tf2_geometry_msgs

one = PoseStamped()

trans = TransformStamped()
trans.transform.translation.x = 1

print(one)

two = tf2_geometry_msgs.do_transform_pose(one, trans)
print(two)

The output will be:

header:
  seq: 0
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
pose:
  position: 
    x: 0.0
    y: 0.0
    z: 0.0
  orientation: 
    x: 0.0
    y: 0.0
    z: 0.0
    w: 0.0  

header:
  seq: 0
  stamp: 
    secs: 0
    nsecs:         0
  frame_id: ''
pose:
  position: 
    x: 1.0
    y: 0.0
    z: 0.0
  orientation: 
    x: 0.0
    y: 0.0
    z: 0.5
    w: 0.0
edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2013-10-29 15:24:38 -0600

Seen: 8,909 times

Last updated: Feb 26 '22