Ask Your Question
1

TypeError for built-in operation

asked 2011-06-24 04:50:04 -0500

David Lu gravatar image

updated 2014-01-28 17:09:55 -0500

ngrennan gravatar image

In working with tf.Transformer, I've run into this error many times.

TypeError: bad argument type for built-in operation

The most frustrating part of getting this message is that the traceback blames seemingly random lines of code for the error. Here's one reduced way to get the error.

#!/usr/bin/python

import roslib; roslib.load_manifest('tf')
import tf, rospy
from geometry_msgs.msg import TransformStamped

if __name__ == '__main__':
    tfman = tf.Transformer(True, rospy.Duration(10.0))
    angle = tf.transformations.quaternion_from_euler(0,0,0)

    m = TransformStamped()
    m.header.frame_id = 'root'
    m.child_frame_id = 'child'
    print type(angle), type(m.transform.rotation)
    m.transform.rotation = angle
    tfman.setTransform(m)

    for i in range(1):
        print i

This outputs:

<type 'numpy.ndarray'=""> <class 'geometry_msgs.msg._quaternion.quaternion'="">
0
Traceback (most recent call last):
  File "src/error.py", line 18, in <module>
    for i in range(1):
TypeError: bad argument type for built-in operation

The clearest way to fix this is to set the rotation using a quaternion, not a numpy array. However, is there some way to get a clearer error message?

Edit: I guess the clearer question is: Why would this mistake cause a TypeError on line 18? Also, I put the error here so that the next person who searches for the error message on the board will find it here.

edit retag flag offensive close merge delete

Comments

The error is actually coming from CPython from another thread (so it has nothing to do with the command on line 18).

Dany gravatar imageDany ( 2016-05-10 03:53:15 -0500 )edit

This type of print-outs happen in cases when python cannot raise an exception (e.g. if an exception was thrown in __del__). TypeError probably means a non-existing method was called, which makes sense, since you changed the type of m.transform.rotation.

Dany gravatar imageDany ( 2016-05-10 03:54:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-06-27 18:19:54 -0500

tfoote gravatar image

This would be better as a enhancment ticket than a question.

edit flag offensive delete link more

Comments

Has this issue been fixed (link to Trac doesn't work any more)? I had this weird error popping up when trying to use the result of lookupTransform in a message. Took me a while to figure out, what the problem was (sth with the returned tuple).

bit-pirate gravatar imagebit-pirate ( 2013-10-21 21:38:20 -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

Stats

Asked: 2011-06-24 04:50:04 -0500

Seen: 755 times

Last updated: Jun 28 '11