We use an orientation sensor that produces a quaternion output using NED convention.
I can convert the quaternion output to heading, pitch and roll using the following:
roll = atan(2.0 * (Qz * Qy + Qw * Qx) , 1.0 - 2.0 * (Qx * Qx + Qy * Qy));
pitch = asin(2.0 * (Qy * Qw - Qz * Qx));
heading = atan(2.0 * (Qz * Qw + Qx * Qy) , - 1.0 + 2.0 * (Qw * Qw + Qx * Qx));
as an example, Qw = 0.582, Qx = -0.553, Qy = 0.404, Qz = -0.439, gives me a heading of -73.23°, Pitch of -0.87° and Roll of -86.42°.
This works fine in most use cases, but we have a scenario where the sensor has had to be mounted in a different physical orientation which is prone to gimbal lock.
If we can map heading to the Qz axis (instead of Qx axis) then we can avoid gimbal lock as this particular sensor will never be orientated with the Z axis aligned vertically.
Can anyone advise the easiest way of achieving this?