I am using an IMU which provides absolute orientation of the sensors frame S relative to an earth-fixed frame N in form of a unit quaternion (i.e. rotation from frame N to frame S). The first field of the provided quaternion is the scalar part, which I believe agrees with MATLAB notation. In my experiments, I first obtain an initial orientation (when the sensor is relatively static) , and I would like to obtain the relative orientation of the sensor in the form of ZYX Euler angles (more precisely).
Here is the procedure that I have tried:
First, I invert the initial orientation,
then, I use the result the obtain the relative quaternion as follows,
= (I have also tried , but that does not give the correct result either).
Finally, to visualize the results, I convert the relative orientation to Euler angles. I also have reference trajectories calculated in a motion capture software which uses the same data. However, my result looks completely different (and wrong) as seen below,
Curiously, if I manually set the Z and Y rotations of to zero (and then convert the result back to quaternion form), the angle trajectories match exactly (except for the offset of Z and Y).
What am I doing wrong?
This is the MATLAB code that I'm using. Note that initQ is and `relQ` is .
[q(1), q(2), q(3), q(4)] = parts(meanrot(quaternion(initData));
initQ = q;
relQ = quatmultiply(mocapData,quatinv(initQ));
eulerAngles = quat2eul(quaternion(relQ),'ZYX')*180/pi;