First time here? Check out the FAQ!


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

tf2 listener: python working example (hydro)

asked Sep 4 '13

liborw gravatar image

updated Oct 24 '16

ngrennan gravatar image

Is there a working example of the tf2 listener under hydro. I have tried to follow tutorials on the wiki but they seems to be outdated.

Just to check if I follow the tutorial right. I have a simple example of tf:

#!/usr/bin/env python

import roslib; roslib.load_manifest('cvut_sandbox')
import rospy
import tf

if __name__ == '__main__':
    rospy.init_node("test_tf_listener")
    tfl = tf.TransformListener()
    (trans, rot) = tfl.waitForTransform('r1_link_1', 'r2_link_2', rospy.Time(0), rospy.Duration(0))

This will fail under hydro due to bug reported here but works under groovy. Trying to follow the tutorial I ended up with version for tf2:

#!/usr/bin/env python

import roslib; roslib.load_manifest('cvut_sandbox')
import rospy
import tf2_ros

if __name__ == '__main__':
    rospy.init_node("test_tf_listener")
    buffer = tf2_ros.Buffer()
    tfl = tf2_ros.TransformListener(buffer)
    (trans, rot) = tfl.waitForTransform('r1_link_1', 'r2_link_2', rospy.Time(0), rospy.Duration(0))

However, it seems that it wont be so easy:

$ rosrun cvut_sandbox test_tf2_listener.py 
Traceback (most recent call last):
  File "/home/wagnelib/Source/hydro/clopema_ws/src/clopema_cvut/cvut_sandbox/scripts/test_tf2_listener.py", line 11, in <module>
    (trans, rot) = tfl.waitForTransform('r1_link_1', 'r2_link_2', rospy.Time(0), rospy.Duration(0))
AttributeError: TransformListener instance has no attribute 'waitForTransform'

Following the Writing a tf2 listener (Python) tutorial I ended with this:

#!/usr/bin/env python

import roslib; roslib.load_manifest('cvut_sandbox')
import rospy
import tf2

if __name__ == '__main__':
    rospy.init_node("test_tf_listener")
    tfl = tf2.TransformListener()
    (trans, rot) = tfl.waitForTransform('r1_link_1', 'r2_link_2', rospy.Time(0), rospy.Duration(0))

But it also fails:

$ rosrun cvut_sandbox test_tf2_listener_2.py 
Traceback (most recent call last):
  File "/home/wagnelib/Source/hydro/clopema_ws/src/clopema_cvut/cvut_sandbox/scripts/test_tf2_listener.py", line 5, in <module>
    import tf2
ImportError: No module named tf2

So is there a working example?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered Nov 6 '15

tfoote gravatar image

See https://github.com/ros/geometry/issue... for the continuing discussion.

Preview: (hide)

Comments

And that ticket seems to be resolved. Marked as an answer.

130s gravatar image 130s  ( Sep 19 '18 )edit

Question Tools

2 followers

Stats

Asked: Sep 4 '13

Seen: 1,863 times

Last updated: Nov 06 '15