BNO055 Quaternion to EulerIn the previous blog, I mentioned getting quaternion output from BMO055 and this time I just confirmed that the quaternion to euler (Pitch, Roll, Yaw) conversion is same as the euler output from BNO055.
The quaternion to euler conversion has several sequences depending on how you rotate the axis.
For example, X axis - Y axis - Z axis, Y axis - X axis - Z axis, Z axis - X axis- Y axis, and so on.
This time, I just wanted to compare the conversion with the euler output from BNO055, so I simply calculated the euler from quaternion and compared with pre-calculated euler output.
EquationSo here is the equation.
The sequence used here is Y - X - Z (2 - 1 - 3) and part of my processing code is listed below.
euler = -atan2(2 * q * q + 2 * q * q, 1 - 2 * q*q - 2 * q * q)*180/PI;
euler = asin(2 * q * q - 2 * q * q)*180/PI;
euler = -atan2(2 * q * q + 2 * q * q, 1 - 2 * q * q - 2 * q * q)*180/PI;
Here, euler is pitch, euler is roll, and euler is yaw angle. Also, q is w, q is x, q is y, and q is z.
You may notice the yaw angle is different around the +180 degree and -180 degree since the euler output from BNO055 is actually 0 degree to 360 degree.
To make it exactly same, you would need to generate case statement to convert the range from +/-180 degree to 0-360 degree.
With this equation, I was able to obtain the same result with the pre-calculated euler angle from BNO055.
So my code is basically just getting quaternion from BNO055 and convert it to euler if needed.
Quaternion is actually better to handle graphical rotations, and now I created simple graphical software using processing.
It is quite messy, so I will consider sharing the source code in the future if demand is high. :)
For the people who wants better performance, I would recommend BNO080.
BNO055 is really old components although it is still widely used.