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

get variable from topic with python

asked 2015-05-20 06:16:33 -0600

Porti77 gravatar image

updated 2015-05-20 07:32:31 -0600

gvdhoorn gravatar image

I created a node and subscribe a topic (nav_msgs/Odometry Message) i want operate with the quaternion, how i can get it value? With python

i try it this way:

rospy.Subscriber('/odometry/filtered', Odometry) 
x = Odometry.pose.pose.pose.orientation.x

but not work well

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-20 11:11:35 -0600

yohtm gravatar image

updated 2015-05-20 11:11:55 -0600

First, your subscriber must use a callback, I suggest trying the ROS publisher subscriber tutorial.

I suppose you want to get the orientation in the Euler angle format (rotations around the x-y-z axis). Once you're able to receive the message through the callback, you can use the following code to access the angles.

import tf
orientation_euler = tf.transformations.euler_from_quaternion( odom_msg.pose.pose.orientation)
# use the angles with orientation_euler.x, orientation_euler.y, orientation_euler.z
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-05-20 06:16:33 -0600

Seen: 1,567 times

Last updated: May 20 '15