I am using a BNO055 sensor to generate quaternion orientation data. My goal is to calculate accurate compass heading angles from quaternion orientation data.
Interpreting compass headings using Euler angles is a trivial task, however it is susceptible to Gimbal Lock, which is why the sensor I am currently using is pushing out quaternion orientation data.
However, my question is how can we interpret quaternion orientation data into compass headings? All of the methods I have seen online require converting quaternion orientation data into euler angles and from there converting the "roll", "pitch", and "yaw" of the euler angles into compass heading angles.
I want to avoid this and only use quaternion orientation data, however I'm not sure how to interpret:
x, y, z, w
into compass heading angles?
Is there no way to avoid converting quaternion orientation data to euler angles before I can get my desired compass heading angle?
I know that:
x = 0
y = 0
z = 0
w = 1
would be displayed as North on a compass. However, how do I move on from there?
Your quaternion $q$, I assume, give a rotation from some reference vector $v$. So all we have to do is rotate $v$ with $q$. Represent $v$ as an imaginary quaternion. Then it rotates $v$ via $qvq^{-1}$ where $q^{-1} = \bar q/(q\bar q)$ with $\bar q$ the conjugate. Note that if $q$ is normalized properly then $q^{-1} = \bar q$; I will assume this. The quantity $qvq^{-1}$ can now be interpreted as a vector describing your heading.
Since you say $x = y = z = 0$ and $w = 1$ correspond to north, then $v$ is the north-pointing vector. Let's say $v = (1,0,0)$. Then we represent this as an imaginary quaternion $v = i$; if $q = w + xi + yj + zk$ then $$\begin{aligned} qv\bar q &= (w + xi + yj + zk)i(w - xi - yj - zk) \\ &= (wi - x - yk + zj)(w - xi - yj - zk) \\ &= wx - xw - yz + zy + (w^2 + x^2 - y^2 - z^2)i + (wz + xy + yx + zw)j + (-wy + xz - yw + zx)k \\ &= (w^2 + x^2 - y^2 - z^2)i + (wz + xy + yx + zw)j + (-wy + xz - yw + zx)k. \end{aligned}$$ So if $(0,1,0)$ is east, corresponding to $j$, then angle $\theta$ from north to east is given by $$ \tan\theta = \frac{w^2 + x^2 - y^2 - z^2}{wz + xy + yx + zw}. $$