I have a 6DOF sensor outputting a quaternion and I need to convert the quaternion into euler angles. The problem is that when I use the following equations:
$$ \begin{bmatrix} \phi \\ \theta \\ \psi \end{bmatrix} = \begin{bmatrix} Y \\ P \\ R \end{bmatrix} = \begin{bmatrix} \mathrm{atan2}\left( -2q_1q_2 + 2q_0q_3,\; q_0^2 + q_1^2 - q_3^2 - q_2^2 \right) \\ \mathrm{asin}\left( 2q_1q_3 + 2q_0q_2 \right) \\ \mathrm{atan2}\left( -2q_2q_3 + 2q_0q_1,\; q_3^2 - q_2^2 - q_1^2 + q_0^2 \right) \end{bmatrix} $$
The output is limited to +-90 degrees because of the inverse trigonometric functions.
What set of equations should I use to convert quaternion to euler without losing information.
Slightly askew-topic, if not off-topic, but let me just give you the comment section of my code for the function whose input is a quaternion and whose output is the corresponding $3\times3$ rotation matrix. The "Notes:" section explains the requisite algebra.