Ask Your Question

Transforming Euler angle to Quaternion

asked 2017-01-12 02:56:18 -0500

Oded gravatar image

Hello, I have a new inertial sensor that provides the orientation of the robot in RPY. I want to load the information in an sensors_msgs/Imu ROS message using:

tf::Matrix3x3 obs_mat;

tf::Quaternion q_tf;
INS_msg.orientation.x = q_tf.getX();
INS_msg.orientation.y = q_tf.getY();
INS_msg.orientation.z = q_tf.getZ();
INS_msg.orientation.w = q_tf.getW();

The problem is when the yaw changes from +pi to -pi, the quaternion angle also has a "jump" in the angle from w=-0.99 to w=0.99 How can I transform the angle correctly?


edit retag flag offensive close merge delete



What do you think would be the correct behaviour of the quaternion? Why do you think that a jump in the input should not produce a jump in the output?

NEngelhard gravatar image NEngelhard  ( 2017-01-12 03:33:32 -0500 )edit

The idea behind quaternion is that you avoid these jumps by adding an extra dimension

Oded gravatar image Oded  ( 2017-01-12 04:51:10 -0500 )edit

Note that there are always two possible unit quaternions that represent that same orientation. If q is thought of as an axis and a rotation about that axis then -q is an axis in the opposite direction with a rotation in the opposite direction (same overall rotation).

jarvisschultz gravatar image jarvisschultz  ( 2017-01-12 09:07:40 -0500 )edit

My guess the "jump" you are seeing is the flipping to the "negative" quaternion.

jarvisschultz gravatar image jarvisschultz  ( 2017-01-12 09:08:51 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-01-12 09:04:43 -0500

BrettHemes gravatar image

updated 2017-01-12 09:05:59 -0500

A quaternion multiplied by any real number represents the same rotation. If they are assumed/enforced to be of unit length (pretty much always) that leaves you with two possible quaternion representations for any rotation, q and -q. If you want the result to always be the same, you can check which hemisphere the quaternion lies in and change the sign accordingly (i.e., if w < 0 then q = -q).

I think the only time the sign might be of interest is when interpolating between two quaternions (e.g., with SLERP). Depending on the respective signs of the two quaternions of interest you will get one of two interpolated paths (geodesics on the unit sphere in R4 representing all quaternions). One will be the "long" and the other the "short" path.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-01-12 02:56:18 -0500

Seen: 5,452 times

Last updated: Jan 12 '17