Rospy callback attribute error
Am following a youtube tutorial ( https://www.youtube.com/watch?v=DLVyc... ) with my own code:
Executable:
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__':
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/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/username/catkin_ws/src/pkgname/src/location_monitor_node.py", 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.