tf not found using python in ros noetic
Hi
I have followed the tutorial here to find a transformation between 2 frames using Python in ROS Noetic, but I can't get it even though I'm sure the tf exists because I can find it in the terminal.
Here is what I get in the terminal:
$ rosrun tf tf_echo /base_link /tool0
At time 1667484434.367
- Translation: [-0.197, 0.704, 0.486]
- Rotation: in Quaternion [1.000, 0.000, -0.000, -0.000]
in RPY (radian) [-3.141, 0.001, 0.000]
in RPY (degree) [-179.967, 0.041, 0.028]
At time 1667484434.967
- Translation: [-0.197, 0.704, 0.486]
- Rotation: in Quaternion [1.000, 0.000, -0.000, -0.000]
in RPY (radian) [-3.141, 0.001, 0.000]
in RPY (degree) [-179.967, 0.041, 0.028]
At time 1667484435.967
- Translation: [-0.197, 0.704, 0.486]
- Rotation: in Quaternion [1.000, 0.000, -0.000, -0.000]
in RPY (radian) [-3.141, 0.001, 0.000]
in RPY (degree) [-179.967, 0.041, 0.028]
Here is a minimal code:
#!/usr/bin/env python3
import sys
import rospy
import moveit_commander
import tf2_ros
class ourbot(object):
def __init__(self):
super(ourbot, self).__init__()
moveit_commander.roscpp_initialize(sys.argv)
rospy.init_node("get_tf", anonymous=True)
def main():
try:
demorobot = ourbot()
tfBuffer = tf2_ros.Buffer()
listener = tf2_ros.TransformListener(tfBuffer)
try:
trans = tfBuffer.lookup_transform('base_link', 'tool0', rospy.Duration(3.0))
pose_transformed = tf2_geometry_msgs.do_transform_pose(pose_robot, trans)
print(pose_transformed)
except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException):
print('not found')
except rospy.ROSInterruptException:
return
except KeyboardInterrupt:
return
if __name__ == "__main__":
main()