← Back to the chapter · Previous detail · Next detail →

Technical detail · Complementary Filters: Tuning and Validity

Rotate calibrated magnetic evidence into yaw

Roll and pitch provide the missing geometry for magnetometer heading. First calibrate hard-iron offset and soft-iron scale, then rotate the body-frame magnetic vector (mx,my,mz)(m_x,m_y,m_z) onto the horizontal plane. For one common right-handed roll-ϕ\phi, pitch-θ\theta convention,

mx,h=mxcos⁡θ+mzsin⁡θ,m_{x,h}=m_x\cos\theta+m_z\sin\theta, my,h=mxsin⁡ϕsin⁡θ+mycos⁡ϕ−mzsin⁡ϕcos⁡θ,m_{y,h}=m_x\sin\phi\sin\theta+m_y\cos\phi-m_z\sin\phi\cos\theta, ψ=atan2⁡(−my,h,mx,h).\psi=\operatorname{atan2}(-m_{y,h},m_{x,h}).

The signs and axis order change with ENU/NED coordinates and sensor mounting, so prove the implementation with known north/east headings and positive roll/pitch rotations rather than copying the equations without a frame definition. Tilt compensation removes the geometric projection error; it does not remove magnetic distortion, gyro drift during magnetic rejection, or the need to apply local magnetic declination when the product requires true rather than magnetic north.

← Back to the chapter · Previous detail · Next detail →