Using even Madgwick provided raw data, algorithm gives inaccuracies on roll and yaw when only pitch angle applied. This is also valid for our data which is collected with BMX055. We apply only pitch, the algorithm gives roll and yaw angles too. But there is a point I doubt about mathematics with positive pitch, roll&yaw show similar characteristics, with negative pitch their response similar to mirrored to each other. I'm sure about pure pitch with 1 axis motor. Why is such behaviour of the algorithm?
enter image description here

  • \$\begingroup\$ 1) Please describe in detail the setup : number, type and orientation of sensors. The equations used as part of the algorithm, frame representation scheme (Euler angles, Quaternion, other) etc. 2) If pitch is the middle Euler angle, perhaps you are running into a singularity when pitch angle approaches 90 deg. 3) Please also confirm if the algorithm works for pitch angles between -80 deg and +80 deg. \$\endgroup\$
    – AJN
    Commented Nov 17, 2020 at 13:22
  • \$\begingroup\$ 1) Algorithm works in quaternion base in its math. Euler only represantation, after getting quaternion. So Euler post-processed. \$\endgroup\$ Commented Nov 17, 2020 at 14:43
  • \$\begingroup\$ Wikipedia indicates that a division operation is present in the \$\phi, \psi\$ components when converting from quaternions to Euler. The denominator is very likely close to zero. The gimbal lock problem is inherent to Euler angle representation and You should restrict your testing to pitch angles away from \$\pm 90\$ deg. The conversion is simply an ill-posed problem for middle angle near 90 deg; i.e. arctan2(.,.) also wont fundamentally solve the problem. \$\endgroup\$
    – AJN
    Commented Nov 17, 2020 at 16:15
  • \$\begingroup\$ See this figure in Wikipedia. The \$\psi\$ angle is drawn from the fixed X axis to the new x axis obtained from the "shadow" of the titled aircraft onto the horizontal plane. At +-90 deg pitch, this shadow is zero length and becomes a dot instead of a line. The \$psi\$ angle becomes ill-defined. \$\endgroup\$
    – AJN
    Commented Nov 17, 2020 at 16:26

2 Answers 2


From the figure it looks like the yaw and roll angles become significant only when the pitch angle come close to +-90 deg. If pitch angle is the middle angle in the Euler angle representation for your algorithm, perhaps your algorithm calculations are running into a singularity.

Wikipedia - Euler angles

Wikipedia - gimbal lock.


  1. Choose a different algorithm or
  2. A different representation of attitude other than Euler angles or
  3. Don't operate your platform (aircraft / quad copter / other) at high pitch angles.


OP has commented

Algorithm works in quaternion base in its math. Euler only represantation, after getting quaternion. So Euler post-processed.

The conversion from quaternion to Euler also has singularity / gimbal lock. The conversion equation taken from Wikipedia is

$$ \begin{bmatrix}\phi \\\theta \\\psi \end{bmatrix} = \begin{bmatrix} \arctan{\frac {2(q_{0}q_{1}+q_{2}q_{3})}{1-2(q_{1}^{2}+q_{2}^{2})}} \\ \arcsin(2(q_{0}q_{2}-q_{3}q_{1})) \\ \arctan{\frac {2(q_{0}q_{3}+q_{1}q_{2})}{1-2(q_{2}^{2}+q_{3}^{2})}}\end{bmatrix} $$

At pitch angle \$\rightarrow 90\$ deg, \$q_2 \rightarrow sin(90/2)\cdot1 = \frac{1}{\sqrt2}\$. The denominator in the calculation of \$\psi\$ becomes

$$ 1-2(q_{2}^{2}+q_{3}^{2}) = 1 - 2 (\frac{1}{\sqrt2^2} + 0^2) = 0 $$

Division by zero results. Using \$\arctan2\$ may stop any software error from occurring, but it doesn't solve the illposedness of the underlying problem.

  • \$\begingroup\$ Now, how to solve this problem? There're a lot of commercial products, they don't say, don't use the sensor out of +-80 degrees. \$\endgroup\$ Commented Nov 24, 2020 at 17:01
  • \$\begingroup\$ You have indicated that the algorithm uses quaternion math inside. If is provides a quaternion as output, use it directly without converting to Euler angles. I think most (or all) navigation / guidance / control algorithms have quaternion based alternatives to Euler angle methods. Can't say more without a description of the equations used and the final application where the IMU is used. \$\endgroup\$
    – AJN
    Commented Nov 24, 2020 at 17:36

Seems like almost ok enter image description here

If image a plain whitch make a pitch to more then 90 or - 90 degrees as an example 180 deg. After that the plain will fly upside pown (rol chamges to 180 deg) and curse (yaw) also changes to 180 deg (plain fly back)

The points 1, 2, 3 at the picture is place where pitch had besame more than 90 or - 90 deg, the yaw and roll changes on 180 deg


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.