# Ros quaternion component w not behaving as it should.

The quaternions in ros are supposed to be (x,y,z,w), where w = cos(theta/2) where theta is the angle of the rotation.

I did the following, I used tf_listener to get the position of my robot t_base,r_base = tf_listener.lookupTransform('/map','/base_link',rospy.Time(0))

and then I printed the last component of r_base as I did a 360° continuous turn with the robot. What I get is values between -0.3 and 0.3 with a jump in sign between -0.3 and 0.3. (So I start from -0.3 it goes up to 1 then down to 0.3 where it jumps to -0.3) as if the robot were missing around 30°from the 360°.

What is happening here?

edit retag close merge delete

I prefer to think in euler angles rather than quaternions .. use (r,p,y) = tf.transformations.euler_from_quaternion(quaternion=r_base) to save yourself a headahe