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

Error assigning a python quaternion

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

Jack Sparrow gravatar image

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

130s gravatar image

Hi,

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/my_robot_nav.py", line 127, in <module>
    pub_odom.publish(odom)
  File "/opt/ros/diamondback/stacks/ros_comm/clients/rospy/src/rospy/topics.py", line 677, in publish
    self.impl.publish(data)
...
    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 = rospy.Time.now()

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
pub_odom.publish(odom)

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

Comments

Which tutorial are you following?
Eric Perko gravatar image Eric Perko  ( 2011-04-11 08:08:29 -0600 )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 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
12

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

tfoote gravatar image

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

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 transformations.py 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

Comments

Yeah, that's it. Thank you
Jack Sparrow gravatar image Jack Sparrow  ( 2011-04-14 10:31:42 -0600 )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 -0600 )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 -0600 )edit
thanks Jack ^^
raphael favier gravatar image raphael favier  ( 2011-04-21 04:46:28 -0600 )edit
1
felix k gravatar image felix k  ( 2012-04-22 23:32:54 -0600 )edit

Highly recommend ros_numpy: https://github.com/eric-wieser/ros_numpy , for everyday simple conversions

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

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

raphael favier gravatar image

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

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
...
pub_odom.publish(msg)

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?

Raph

==================

UDPATE

Here is my solution:

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

Comments

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

Question Tools

Stats

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

Seen: 9,117 times

Last updated: Jan 28 '16