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

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

... 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?

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?

Sort by » oldest newest most voted

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

more 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]
more