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

Transform Quaternion

asked 2012-12-10 10:21:47 -0600

JaRu gravatar image

updated 2013-02-08 21:27:15 -0600

Hi!

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

Thanks.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
23

answered 2012-12-10 12:39:33 -0600

updated 2013-02-07 05:20:55 -0600

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);
edit flag offensive delete link more

Comments

I was also looking for some way to transform from quaternion to euler in C++. Can you post a code snippet please?

narcispr gravatar image narcispr  ( 2013-02-07 04:45:33 -0600 )edit
15

answered 2013-02-07 21:51:29 -0600

narcispr gravatar image

updated 2013-02-07 22:26:57 -0600

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.

edit flag offensive delete link more
4

answered 2014-10-14 04:14:30 -0600

PedroGusmao gravatar image

updated 2014-10-16 01:57:03 -0600

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/htm... :

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);
edit flag offensive delete link more

Comments

4

If you have a transform object, yes. The original question asks how to do this with get rotation from a quaternion object.

paulbovbel gravatar image paulbovbel  ( 2014-10-16 07:56:01 -0600 )edit

Question Tools

5 followers

Stats

Asked: 2012-12-10 10:21:47 -0600

Seen: 43,774 times

Last updated: Oct 16 '14