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

Error assigning a python quaternion

asked 2011-04-11 08:00:42 -0500

Jack Sparrow gravatar image

updated 2016-01-28 16:50:22 -0500

130s gravatar image


I have tried to setup navigation stack to work with the robot from USARSim the same way as in tutorials, but when I start robot_configuration.launch and move_base.launch I get this error related to odometry:

Traceback (most recent call last):
  File "/home/my_name/ros/usarsim/nodes/", line 127, in <module>
  File "/opt/ros/diamondback/stacks/ros_comm/clients/rospy/src/rospy/", line 677, in publish
    buff.write(_struct_7d.pack(_x.pose.pose.position.x, _x.pose.pose.position.y, _x.pose.pose.position.z, _x.pose.pose.orientation.x, _x.pose.pose.orientation.y, _x.pose.pose.orientation.z, _x.pose.pose.orientation.w))
AttributeError: 'numpy.ndarray' object has no attribute 'x'
[usarsim-1] process has died [pid 11052, exit code 1].
log files: /home/hrvoje/.ros/log/1bf16950-642a-11e0-894b-000c29c48bc7/usarsim-1*.log*

Section of code that publish odom:

odom_quat = tf.transformations.quaternion_from_euler(0,0,some_odom_theta_data)

odom.header.stamp =

odom.header.frame_id = "odom"

odom.pose.pose.position.x = some_odom_x_data
odom.pose.pose.position.y = some_odom_y_data
odom.pose.pose.position.z = 0.0
odom.pose.pose.orientation = odom_quat

odom.child_frame_id = "base_link"
odom.twist.twist.linear.x = 0.0
odom.twist.twist.linear.y = 0.0
odom.twist.twist.linear.z = 0.0

My odometry returns only position and orientation, but not the values for velocity!

Any suggestions will be helpful. Thanks in advance. hv

edit retag flag offensive close merge delete


Which tutorial are you following?
Eric Perko gravatar image Eric Perko  ( 2011-04-11 08:08:29 -0500 )edit
the problem starts after running move_base.launch, not after robot_configuration.launch
Jack Sparrow gravatar image Jack Sparrow  ( 2011-04-11 08:35:25 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2011-04-13 21:16:43 -0500

tfoote gravatar image

updated 2011-04-15 07:06:38 -0500

I would guess that it's this line:

odom.pose.pose.orientation = odom_quat

odom.pose.pose.orientation is a quaternion message, but odom_quat is a numpy array (which is what uses natively) You need to convert the data type before assigning it. The numpy array uses index notation, while the message uses .x .y .z and .w

edit flag offensive delete link more


Yeah, that's it. Thank you
Jack Sparrow gravatar image Jack Sparrow  ( 2011-04-14 10:31:42 -0500 )edit
Could you show an example of how to convert the quaternion? My Python skills are quite weak
raphael favier gravatar image raphael favier  ( 2011-04-15 03:56:40 -0500 )edit
odom_quat = tf.transformations.quaternion_from_euler(0,0,some_odom_theta_data), odom.pose.pose.orientation.x = odom_quat[0], odom.pose.pose.orientation.y = odom_quad[1], odom.pose.pose.orientation.z = odom_quad[2], odom.pose.pose.orientation.w = odom_quad[3]
Jack Sparrow gravatar image Jack Sparrow  ( 2011-04-19 18:52:57 -0500 )edit
thanks Jack ^^
raphael favier gravatar image raphael favier  ( 2011-04-21 04:46:28 -0500 )edit
felix k gravatar image felix k  ( 2012-04-22 23:32:54 -0500 )edit

Highly recommend ros_numpy: , for everyday simple conversions

zephirefaith gravatar image zephirefaith  ( 2017-03-08 21:06:12 -0500 )edit

answered 2011-04-15 03:51:26 -0500

raphael favier gravatar image

updated 2011-04-15 04:00:25 -0500

If I understand well what Tully says, how come is your code not crashing like mine does when you assign odom.pose.pose.position.x = [something]?

In my case, I crash as soon as I try to assign a value as you do in your code:

msg = Odometry()
msg.pose.pose.position.x = 0.0

always results in:

msg.pose.pose.position.x = 0.0
AttributeError: 'tuple' object has no attribute 'x'

From the documentation, I see that pose.pose.position is a Geometry_msgs/Point message. Should I cast my values in Point and then assign them to position?




Here is my solution:

from geometry_msgs.msg import Point
msg = Odometry()
msg.pose.pose.position = Point(x,y,0.0)
edit flag offensive delete link more


Thanks. I met the same problem.
Charles gravatar image Charles  ( 2011-04-23 01:52:26 -0500 )edit
Thanks. Feel free to vote the answer up ^^
raphael favier gravatar image raphael favier  ( 2011-04-24 13:27:54 -0500 )edit

Question Tools


Asked: 2011-04-11 08:00:42 -0500

Seen: 8,938 times

Last updated: Jan 28 '16