ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Get vector representation of x, y, z axis from geometry_msgs Pose

asked 2015-12-07 17:22:26 -0500

2ROS0 gravatar image


I have a geometry_msgs/Pose message that contains a certain position and orientation.

I want to get the equation of the x axis of that position and orientation. What ROS library function can I use to achieve this?

Thank you.

edit retag flag offensive close merge delete


Could you clarify what you're looking for a bit? In your scenario, the Pose message specifies a translation and rotation from some parent coordinate system to a child coordinate system (correct?). You want a description of the x-axis of the child coordinate system expressed in the parent system....

jarvisschultz gravatar image jarvisschultz  ( 2015-12-08 09:05:37 -0500 )edit

... Is that correct? What description do you want? Are you interested in the vector components of the child x-axis expressed in the parent frame? Do you want some sort of parametric equation that returns points on the x-axis?

jarvisschultz gravatar image jarvisschultz  ( 2015-12-08 09:07:03 -0500 )edit

Your first comment is exactly what I want.

2ROS0 gravatar image 2ROS0  ( 2015-12-08 10:10:52 -0500 )edit

After a bit of looking around this I did - used tf_conversions package to convert geometry_msgs Pose to tf Transform. Then used the getBasis() function on the transform to get the rotation matrix and used the first column of that matrix. Does this seem correct or should I invert the transform?

2ROS0 gravatar image 2ROS0  ( 2015-12-08 10:15:37 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-12-09 14:46:16 -0500

sloretz gravatar image

It sounds like you're using C++ and looking for a vector in the parent frame with the same direction as the x axis of the child frame, or vector D in this picture.

image description

You've got the geometry_msgs/Pose expressed as a tf::Transform, that's great! The basis of the transform is the rotation matrix to go from the child frame to the parent frame. An x axis vector is (1,0,0). To transform an x axis vector from the child frame to the parent frame you can use operator*(Matrix3x3, Vector3) from the following link

tf::Transform my_pose = ... //You already have this
tf::Vector3 x_axis(1,0,0);
tf::Vector3 D = myPose.getBasis() * x_axis;

Make sure to do matrix * vector and not vector * matrix. The latter will return the parent x axis expressed in the child frame.

edit flag offensive delete link more

answered 2015-12-08 17:55:01 -0500

Here's a simple Python version:

import numpy as np
import geometry_msgs.msg
import tf
import tf_conversions

p = geometry_msgs.msg.Pose()
# let's define a positive rotation of pi/4 rad about the reference frame's z-axis:
q = tf.transformations.quaternion_from_euler(np.pi/4, 0, 0, 'szyx')
p.orientation = geometry_msgs.msg.Quaternion(*q)

# now let's compute the desired x-axis components in a few ways:
print "x1 =",tf_conversions.fromMsg(p).M.UnitX()
print "x2 =",(tf.transformations.quaternion_matrix(q))[0:3,0]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-12-07 17:22:26 -0500

Seen: 3,671 times

Last updated: Dec 09 '15