0
$\begingroup$

Rosanswers logo

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.


Originally posted by 2ROS0 on ROS Answers with karma: 1133 on 2015-12-07

Post score: 0


Original comments

Comment by jarvisschultz on 2015-12-08:
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....

Comment by jarvisschultz on 2015-12-08:
... 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?

Comment by 2ROS0 on 2015-12-08:
Your first comment is exactly what I want.

Comment by 2ROS0 on 2015-12-08:
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?

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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]

Originally posted by jarvisschultz with karma: 9031 on 2015-12-08

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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

http://docs.ros.org/jade/api/tf2/html/namespacetf2.html#aa066c1c13ee857e7c53e747698297d03

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.


Originally posted by sloretz with karma: 3061 on 2015-12-09

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

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