Ask Your Question
5

tf2 listener: python working example (hydro)

asked 2013-09-03 21:21:08 -0600

liborw gravatar image

updated 2016-10-24 08:33:20 -0600

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-11-06 16:13:03 -0600

tfoote gravatar image

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

edit flag offensive delete link more

Comments

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

130s gravatar image130s ( 2018-09-19 14:18:13 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2013-09-03 21:21:08 -0600

Seen: 1,363 times

Last updated: Nov 06 '15