0
$\begingroup$

Rosanswers logo

Hi!

Is there a package witch transforms the quaternion coordinates automatically in an other system? (Axis-Angle, Kardan, Euler)

Thanks.


Originally posted by JaRu on ROS Answers with karma: 153 on 2012-12-10

Post score: 5

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

The tf::Quaternion class is (currently) built on top of the Bullet quaternion class - here's an overview.

You have all the methods available in btQuaternion. You can also create a btMatrix3x3 from the btQuaternion and use any of the class methods.

After a quick scan, I'm seeing

  • getAngle()
  • getAxis()
  • getEulerYPR(..)
  • getEulerZYX(..)

EDIT: as per narcispr's comment:

Let's say q is your quaternion. This is what I usually do (there might be a more elegant way, but I haven't found it)

tf::Matrix3x3 m(q);
double roll, pitch, yaw;
m.getRPY(roll, pitch, yaw);

Originally posted by Ivan Dryanovski with karma: 4954 on 2012-12-10

This answer was ACCEPTED on the original site

Post score: 23


Original comments

Comment by narcispr on 2013-02-07:
I was also looking for some way to transform from quaternion to euler in C++. Can you post a code snippet please?

$\endgroup$
0
$\begingroup$

Rosanswers logo

Just to complete the previous response:

#include <tf/transform_datatypes.h>
// ...
tf::Quaternion q(quat.x, quat.y, quat.z, quat.w);
tf::Matrix3x3 m(q);
double roll, pitch, yaw;
m.getRPY(roll, pitch, yaw);
std::cout << "Roll: " << roll << ", Pitch: " << pitch << ", Yaw: " << yaw << std::endl;

Where quat contains the quaternion values to be transformed to roll, pitch, yaw.


Originally posted by narcispr with karma: 307 on 2013-02-07

This answer was NOT ACCEPTED on the original site

Post score: 15

$\endgroup$
0
$\begingroup$

Rosanswers logo

It seems that creating a Matrix3X3 from the quaternion is not necessary since a transform already contains the rotation matrix. If you are working with TF, inside every Quaternion there is a Matrix3x3 called m_basis. When you call Transform::getRotation(), what you get is

From http://docs.ros.org/indigo/api/tf/html/c++/Transform_8h_source.html :

00120         Quaternion getRotation() const { 

00121                 Quaternion q;

00122                 m_basis.getRotation(q);

00123                 return q;

00124         }

So it could be that you may get away with:

transform.getBasis().getRPY(roll, pitch, yaw);

Originally posted by PedroGusmao with karma: 66 on 2014-10-14

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by paulbovbel on 2014-10-16:
If you have a transform object, yes. The original question asks how to do this with get rotation from a quaternion object.

$\endgroup$

Your Answer

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