0
$\begingroup$

Rosanswers logo

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


Originally posted by Jack Sparrow on ROS Answers with karma: 83 on 2011-04-11

Post score: 4


Original comments

Comment by Jack Sparrow on 2011-04-11:
the problem starts after running move_base.launch, not after robot_configuration.launch

Comment by Jack Sparrow on 2011-04-11:
I followed http://www.ros.org/wiki/navigation/Tutorials/RobotSetup and the section http://www.ros.org/wiki/navigation/Tutorials/RobotSetup/Odom for odometry

Comment by Eric Perko on 2011-04-11:
Which tutorial are you following?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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


Originally posted by tfoote with karma: 58457 on 2011-04-13

This answer was ACCEPTED on the original site

Post score: 12


Original comments

Comment by raphael favier on 2011-04-21:
thanks Jack ^^

Comment by Jack Sparrow on 2011-04-19:
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]

Comment by raphael favier on 2011-04-15:
Could you show an example of how to convert the quaternion? My Python skills are quite weak

Comment by Jack Sparrow on 2011-04-14:
Yeah, that's it. Thank you

Comment by felix k on 2012-04-22:
Even simpler via tuple expanding with *: http://answers.ros.org/question/12903/quaternions-with-python?answer=19040#post-id-19040

Comment by zephirefaith on 2017-03-08:
Highly recommend ros_numpy: https://github.com/eric-wieser/ros_numpy, for everyday simple conversions

$\endgroup$
0
$\begingroup$

Rosanswers logo

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)

Originally posted by raphael favier with karma: 1382 on 2011-04-15

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by raphael favier on 2011-04-24:
Thanks. Feel free to vote the answer up ^^

Comment by Charles on 2011-04-23:
Thanks. I met the same problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.