ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

'hector_quadrotor' 'TypeError: 'instancemethod' object has no attribute '__geitem__''

asked 2014-07-16 20:34:29 -0500

Glen gravatar image

updated 2014-07-16 20:35:32 -0500


I was running "hector_quadrotor_demo outdoor_flight_gazebo.launch". And I build a publisher "auto_fly", to publish message to control the quadrotor. The code is showed below:

#!/usr/bin/env python

import rospy from geometry_msgs.msg import Twist

def auto_fly(): pub= rospy.Publisher('/uav/uav2/cmd_vel',Twist,queue_size=10) rospy.init_node('auto_fly',anonymous=True) r=rospy.Rate(10) # 10Hz

while not rospy.is_shutdown(): pub.publish['x=0,y=1,z=0.2' 'x=0,y=0,z=0'] r.sleep(1.0)

if __name__== '__main__': try: auto_fly() except rospy.ROSInterruptException: pass

When I run it, it shows,

TypeError: 'instancemethod' object has no attribute '__getitem__'

What does this error mean and how to fix it?

Thanks a lot Glen

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-17 12:29:53 -0500

ahendrix gravatar image

This error: TypeError: 'instancemethod' object has no attribute '__getitem__' means that you're trying to use square brackets ( __getitem__ ) on something that doesn't support them; namely a method.

For the publish method call, you should be using parentheses, just like any other method call in python. You'll also need to revise the argument to your publish call; it should be a python message object:

msg = Twist() # create a new Twist message object
msg.linear.y = 1 # set the linear y component to 1
pub.publish(msg) # publish your message
edit flag offensive delete link more


It works now, thanks a lot!

Glen gravatar image Glen  ( 2014-07-17 19:01:55 -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

1 follower


Asked: 2014-07-16 20:34:29 -0500

Seen: 763 times

Last updated: Jul 17 '14