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

Unable to get odom->base_footprint transform on tf2 lookup

asked 2017-06-15 15:13:14 -0500

karanchawla gravatar image

updated 2017-06-15 16:59:20 -0500

Hello all,

I'm working on a mobile robot simulation which has three components.

  1. Gazebo simulation

  2. Robot Control node

  3. TF listener node

Robot control node is publishing the odom->base_footprint tf and I can see it on the terminal. My terminal output looks something like this

karan@Chawla:~$ rosrun tf_echo odom base_footprint
At time 1518.792
- Translation: [0.073, -2.682, 0.000]
- Rotation: in Quaternion [0.002, 0.001, -0.860, 0.510]
            in RPY (radian) [0.000, 0.006, -2.072]
            in RPY (degree) [0.001, 0.332, -118.733]

I'm trying to access this information using the following node:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rospy
import tf2_ros
import math

if __name__ == "__main__":
  rospy.init_node("tf_listener")
  tfBuffer = tf2_ros.Buffer()
  listener = tf2_ros.TransformListener(tfBuffer)
  rate = rospy.Rate(10.0)
  while not rospy.is_shutdown():
    try:
      (trans,rot) = tfBuffer.lookup_transform('odom', 'base_footprint', rospy.Time.now(), rospy.Duration(3.0))
    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException):
      rospy.loginfo("No transform")
      rate.sleep()
      continue

This is the terminal output when I try to run this node:

Traceback (most recent call last):
  File "/tf_listener.py", line 14, in <module>
    (trans,rot) = tfBuffer.lookup_transform('odom', 'base_footprint', rospy.Time.now(), rospy.Duration(3.0))
TypeError: 'TransformStamped' object is not iterable

I have read all the tutorials thoroughly and I have also checked out the questions asked on here. Does anybody know what part of the logic I'm missing?

Edit: This is what my tf tree looks like: https://pasteboard.co/bM0M3Wfk.png

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-06-15 18:13:13 -0500

ufr3c_tjc gravatar image

The error isn't saying that it can't get the transform. If you read it, it clearly says that TypeError: 'TransformStamped' object is not iterable. Change the lookup line to:

transformObject = tfBuffer.lookup_transform('odom', 'base_footprint', rospy.Time.now(), rospy.Duration(3.0))

Then, to get the translation and rotation, set:

trans = transformObject.transform.translation
rot = transformObject.transform.rotation

It was easy to see this was the case if you read the error type.

edit flag offensive delete link more

Comments

Sorry I think I uploaded the last terminal output. I changed that and it still says it can't get any transform i.e. no transform.

karanchawla gravatar image karanchawla  ( 2017-06-15 18:35:33 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-15 15:13:14 -0500

Seen: 974 times

Last updated: Jun 15 '17