Attitude estimation with accelerometer&gyro and magnetometer

Table of contents
  1. Intro
  2. Attitude from gyro
  3. Attitude from accelerometer or magnetometer
  4. Complementary filter
    1. Quaternion version
  5. Mahony filter
    1. Quaternion version
  6. Magdwick filter
    1. Quaternion version
  7. Summary

Intro

One of the most important information about the mobile robot is its attitude and position. For UAVs especially multi-rotors, the first one is essential for even taking off the ground. Knowing your current orientation (in relation to the Earth) is one of the foundations of most modern systems. However, no sensor measures our attitude directly and we need to use a combination of the few other sensors to get it.

Attitude from gyro

A gyroscope measures the angular speeds and can be integrated to achieve orientation with respect to some starting point. But because of the drift, it quickly becomes unreliable.

Attitude from accelerometer or magnetometer

Accelerometer measurements allow us to determine the absolute attitude (in 2 axes) however its measurements are vulnerable to noise and they can not be used without filtering which introduces a notable delay which for UAVs’ application becomes unacceptable and accelerometer can not be used alone.

Sensor fusion of these allows us to take their benefits and reduce defects. In this post, we will discuss 3 methods for combining acc and gyro measurements to achieve absolute pitch and roll estimation. A magnetometer can be additionally used to get yaw value (absolute value) but in the basic case (acc&gyro) we will focus on pitch and roll.

Complementary filter

The most simple version of combining data.

\[roll = (1-\alpha)roll_{g} + \alpha roll_{a}\]

Quaternion version

Mahony filter

Quaternion version

Magdwick filter

Quaternion version

Summary