Ask Your Question

Rospy callback attribute error

asked 2017-11-24 05:48:02 -0500

anonymous user


Am following a youtube tutorial ( ) with my own code:


import rospy
from tf2_msgs.msg import TFMessage
import math #mathsssss
def callback(msg): #global cariable
    x = msg.transforms.transform.translation.x
    y = msg.transforms.transform.translation.y
    rospy.loginfo('x: {}, y: {}'.format(x,y))
def main():
    rospy.init_node('location_monitor')  #makes this code into a ROS node
    rospy.Subscriber("/tf", TFMessage, callback)
    # to sub: give (name of topic, messageclass, callback you want to do
    rospy.spin() # loop
if __name__ == '__main__':

Shell returns:

[ERROR] [1511523182.758203]: bad callback: <function callback at 0x7f1cd923e668>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 750, in _invoke_callback
  File "/home/username/catkin_ws/src/pkgname/src/", line 9, in callback
    x = msg.transforms.translation.x
AttributeError: 'list' object has no attribute 'translation'

Have searched other questions. Tried importing things from TFMessage, checking my capital letters, using it with .transform, and such. Nothing works. Am pretty new to ROS.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-11-24 08:09:52 -0500

gvdhoorn gravatar image

According to the documentation for tf2_msgs/TFMessage (here), the transforms field is a list/array, so you'll need to index into it:

geometry_msgs/TransformStamped[] transforms

Something like msg.transforms[0].transform.translation.x.

But realise that you may receive multiple TransformStampeds in a single message, so always using the first might not be what you want.

edit flag offensive delete link more



Note btw that subscribing to /tf like that is not typical usage. It's possible, but you might want to use the tf2 infrastructure (with Listeners, Buffers, etc).

gvdhoorn gravatar image gvdhoorn  ( 2017-11-24 08:11:11 -0500 )edit

answered 2019-02-25 07:35:52 -0500

Richard Christo gravatar image

Hello, right now i am doing my project which is a 3 d printed arm robot and connected to my laptop using USB2dynamixel. I want to control this robot using MoveIt, but everytime I want to launch the robot_state.launch, this error always comes up

Traceback (most recent call last): File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 750, in _invoke_callback cb(msg) File "/home/richard/robot_ws/src/dxl_tutorial/scripts/", line 37, in process joint_states.position.append((x.position-offset[])(300.0/1023)(pi/180)) IndexError: list index out of range

I have already checked the, but it seems like there is nothing wrong there. Can somebody please give some advice? I am also new to ROS.

edit flag offensive delete link more



This does not seem related to the issue posted here in this Q&A.

Please don't post questions as answers, but post a new question.

gvdhoorn gravatar image gvdhoorn  ( 2019-02-25 08:25:07 -0500 )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


Asked: 2017-11-24 05:48:02 -0500

Seen: 2,168 times

Last updated: Feb 25 '19