ROS Answers: Open Source Q&A Forum - RSS feedhttps://answers.ros.org/questions/Open source question and answer forum written in Python and DjangoenROS Answers is licensed under Creative Commons Attribution 3.0Wed, 09 Dec 2015 14:46:16 -0600Get vector representation of x, y, z axis from geometry_msgs Posehttps://answers.ros.org/question/222101/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. Mon, 07 Dec 2015 17:22:26 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/Comment by jarvisschultz for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222148#post-id-222148... 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?Tue, 08 Dec 2015 09:07:03 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222148#post-id-222148Comment by jarvisschultz for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222146#post-id-222146Could 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....Tue, 08 Dec 2015 09:05:37 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222146#post-id-222146Comment by 2ROS0 for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222156#post-id-222156After 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?Tue, 08 Dec 2015 10:15:37 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222156#post-id-222156Comment by 2ROS0 for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222154#post-id-222154Your first comment is exactly what I want.Tue, 08 Dec 2015 10:10:52 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?comment=222154#post-id-222154Answer by jarvisschultz for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?answer=222179#post-id-222179Here'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]
Tue, 08 Dec 2015 17:55:01 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?answer=222179#post-id-222179Answer by sloretz for <p>Hi, </p>
<p>I have a geometry_msgs/Pose message that contains a certain position and orientation. </p>
<p>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?</p>
<p>Thank you. </p>
https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?answer=222241#post-id-222241It 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](/upfiles/14496933798027564.png)
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.Wed, 09 Dec 2015 14:46:16 -0600https://answers.ros.org/question/222101/get-vector-representation-of-x-y-z-axis-from-geometry_msgs-pose/?answer=222241#post-id-222241