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

How do I handle quaternions?

asked 2017-04-13 17:06:14 -0500

mclambchops gravatar image

I have read many tutorials and publications on the subject; however, I am still unclear on how to use them for causing rotation. I am working on an AUV, and I see that quaternions seem to be fundamental to motion. Are there any recommended learning materials that could help me to get a complete understanding of using them with robot motion? I am very new to ROS, so I greatly appreciate any response.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
8

answered 2017-04-14 03:03:00 -0500

Mark Rose gravatar image

updated 2017-04-14 03:04:20 -0500

There are at least three popular ways to specify a rotation in 3-D.

  • 3x3 rotation matrix (or 4x4 matrix in homogeneous coördinates)
  • Euler angles (such as angles of roll, pitch, and yaw, often X, Y, and Z axis rotations, though there are many variations on Euler angles)
  • Quaternions (specifies an axis of rotation and an angle of rotation about that axis)

The main thing to know about a quaternion is that it encodes two things in a 4-tuple: 1) an axis of rotation (a 3-D vector), and 2) an angle of rotation, measured as the counter-clockwise rotation in radians about that vector (right-hand rule). This can represent any 3-D rotation using four elements, only slightly more memory than used by Euler angles, and considerably less than the matrix representation.

The 4-tuple quaternion mixes the axis of rotation and angle in a strange way. Let's say the axis of rotation is the vector <x, y, z> and the angle of rotation is theta, measured as the right-hand rotation in radians about <x, y, z>. Then the quaternion that represents that rotation is:

<cos(theta/2), x*sin(theta/2), y*sin(theta/2), z*sin(theta/2)>

That's really all there is to it, it's just a fairly compact representation of an arbitrary rotation. Quaternions have several advantages over Euler angles and matrix representations.

  • More compact than matrix representations.
  • Can perform rotations with fewer multiplications, and mathematically more stable.
  • Can interpolate rotations component-by-component to generate intermediate states smoothly.
  • No "gimbal lock" problem. (Google this.)

(Note: There are actually multiple forms of quaternion representations, but only one in ROS.)

edit flag offensive delete link more

Comments

1

One small point: There are libraries in ROS that cover all the computation of quaternions (transforming them to or from rotation matrices for example) so you do not need to implement a quaterion-quaternion multiplication by hand. I can't transform a point with a quat by hand and still work with it.

NEngelhard gravatar image NEngelhard  ( 2017-04-14 04:21:46 -0500 )edit

Yes, certainly. I didn't mean to imply that one should implement the manipulations. I was just trying to demystify quaternions a little. (The algebra definition using i, j, k can be daunting, whereas if you think about axis of rotation and angle they aren't mysterious at all.)

Mark Rose gravatar image Mark Rose  ( 2017-04-14 10:31:34 -0500 )edit

Thanks for your responses. This definitely demystifies things for me.

mclambchops gravatar image mclambchops  ( 2017-04-14 10:43:41 -0500 )edit

please, accept this answer then

eugene.katsevman gravatar image eugene.katsevman  ( 2017-04-14 17:36:57 -0500 )edit

Yes, please accept the answer. It's easier for others to find good answers if they are accepted.

Mark Rose gravatar image Mark Rose  ( 2017-04-17 18:33:43 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-13 17:06:14 -0500

Seen: 1,560 times

Last updated: Apr 14 '17