ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# How to retrieve the quaternion in (x,y,z,w) format from tf

When we use tf to retrieve the rotation relationship of two coordinate in quaternion form, according to the API of Quaternion, we can only get the rotation axis and its angle.

However, the commonly required quaternion in ROS, such as quaternion in geometry_msgs::Pose, is always in (x,y,z,w) format. Therefore, is there any function to get the quaternion from tf in (x,y,z,w) form? That will be very convienent.

edit retag close merge delete

Sort by ยป oldest newest most voted

tf::Quaternion inherits from tf::QuadWord which has m_floats[0] through m_floats[3] which are x,y,z,w respectively. http://docs.ros.org/hydro/api/tf/html/c++/QuadWord_8h_source.html

more

Thanks for that! It works fine and can be verified by the relationship between (x,y,z,w) and the rotation axis plus the angle returned by quaternion.getAxis() and quaternion.getAngle().

( 2013-12-08 19:54:27 -0600 )edit

But I would like to ask how to find this information? It is not in the tutorial and it is not obviously written out in the documentation. Although I can trace the code to get this info, are there any better approach to learn it? Thanks very much

( 2013-12-08 19:58:00 -0600 )edit
1

It should show in the doxygen docs better but for some reason it doesn't show the inheritance correctly.

( 2013-12-08 21:11:28 -0600 )edit

Yeah, I expect to see the inheritance diagram too. Do you have any idea about how to deal with such condition? Thanks

( 2013-12-10 18:13:19 -0600 )edit

It's something about how doxygen is configured. If you want to dig into it you can checkout the package and run doxygen yourself. http://wiki.ros.org/rosdoc_lite has documentation about how to run the documentation like it is on the farm.

( 2013-12-10 19:51:03 -0600 )edit

m_floats is a protected variable. In stead access x,y,z,w through quaternion.x() etcetera.

more

Worked for me, on ROS Indigo! Thanks!

( 2017-01-20 22:48:48 -0600 )edit