# Transforming Euler angle to Quaternion

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;
obs_mat.setEulerYPR(Yaw,Pitch,Roll);

tf::Quaternion q_tf;
obs_mat.getRotation(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?

Thanks,

Originally posted by Oded on ROS Answers with karma: 105 on 2017-01-12

Post score: 0

Comment by NEngelhard on 2017-01-12:
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?

Comment by Oded on 2017-01-12:
The idea behind quaternion is that you avoid these jumps by adding an extra dimension

Comment by jarvisschultz on 2017-01-12:
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).

Comment by jarvisschultz on 2017-01-12:
My guess the "jump" you are seeing is the flipping to the "negative" quaternion.