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.0Tue, 31 May 2011 09:34:37 -0500Relative Rotation Between two Quaternionshttps://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/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?Tue, 31 May 2011 07:47:39 -0500https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/Answer by Ivan Dryanovski for <p>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?</p>
https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14818#post-id-14818Try using [tf::Quaterion](http://www.ros.org/wiki/tf/Overview/Data%20Types). 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.
Tue, 31 May 2011 08:07:55 -0500https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14818#post-id-14818Answer by Wim for <p>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?</p>
https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14822#post-id-14822There is a Python version of the [KDL](http://www.ros.org/wiki/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](http://www.ros.org/wiki/kdl/Tutorials/Frame%20transformations%20%28Python%29) that will give you some more background.
Tue, 31 May 2011 09:34:37 -0500https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14822#post-id-14822Answer by Subodh for <p>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?</p>
https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14821#post-id-14821Are you sure tf::Quaternion is a valid data type? This is not working.
Tue, 31 May 2011 09:06:21 -0500https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?answer=14821#post-id-14821Comment by Ivan Dryanovski for <p>Are you sure tf::Quaternion is a valid data type? This is not working.</p>
https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?comment=25382#post-id-25382I 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?Tue, 31 May 2011 09:15:55 -0500https://answers.ros.org/question/10124/relative-rotation-between-two-quaternions/?comment=25382#post-id-25382