tf2 listener: python working example (hydro)
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?