ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Relative Rotation Between two Quaternions

asked 2011-05-31 07:47:39 -0500

Subodh gravatar image

updated 2011-05-31 07:53:39 -0500

kwc gravatar image

I want to find a relative rotation between two quaternions quatA and quatB, i.e. quatC is a quaternion rotation that if applied to quatA would result in quatB. Is there a command/library in ROS which does this? Will tf be of any help?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2011-05-31 09:34:37 -0500

Wim gravatar image

updated 2011-06-01 18:26:29 -0500

kwc gravatar image

There is a Python version of the KDL library (PyKDL), which allows you to do all sorts of conversions between rotation representations. An example would look like this:

import PyKDL
a = PyKDL.Rotation.Quaternion(x, y, z, w)
b = PyKDL.Rotation.Quaternion(x, y, z, w)

c = a * b.Inverse()
c.GetQuaternion()  # get quaternion result
c.GetRPY()  # get roll pitch yaw result
c.GetEulerZYX()   # get euler angle result in zyx format

There is a small tutorial here that will give you some more background.

edit flag offensive delete link more

answered 2011-05-31 08:07:55 -0500

updated 2011-05-31 09:14:55 -0500

Try using tf::Quaterion. You need to include the following line in the manifest.xml file of your pacakge:

<depend package="tf"/>

This should compile:

#include <tf/transform_datatypes.h>

tf::Quaternion a, b, c;
c = b * a.inverse();

I assume it will do what you're asking for, but you should double-check that.

edit flag offensive delete link more

answered 2011-05-31 09:06:21 -0500

Subodh gravatar image

Are you sure tf::Quaternion is a valid data type? This is not working.

edit flag offensive delete link more


I updated the original post with more info. tf::Quaternion is a valid datatype. When you say it doesn't work, do you mean in doesn't compile? Or that it runs, but it doesn't produce the desired rotation?
Ivan Dryanovski gravatar image Ivan Dryanovski  ( 2011-05-31 09:15:55 -0500 )edit

Question Tools


Asked: 2011-05-31 07:47:39 -0500

Seen: 12,190 times

Last updated: Jun 01 '11