There's 3 algorithms available for sensor fusion. In general, the better the output desired, the more time and memory the fusion takes!

Note that no algorithm is perfect - you'll always get some drift and wiggle because these sensors are not that great, but you should be able to get basic orientation data.

In order of complexity, they are:

Mahony

This basic but effective algorithm will run on smaller chips like the '328p which makes it a great one for any platform.

The original paper is available here

Madgwick

This algorithm is very popular when you have faster Cortex M0, M3, M4 or faster chips. It isn't going to run on an atmega328p

The original paper is available here

NXP Sensor Fusion

This really nice fusion algorithm was designed by NXP and requires a bit of RAM (so it isnt for a '328p Arduino) but it has great output results.

As described by NXP:

Sensor fusion is a process by which data from several different sensors are fused to compute something more than could be determined by any one sensor alone. An example is computing the orientation of a device in three-dimensional space. That orientation is then used to alter the perspective presented by a 3D GUI or game.

The NXP Sensor Fusion Library for Kinetis MCUs (also referred to as Fusion Library or development kit) provides advanced functions for computation of device orientation, linear acceleration, gyro offset and magnetic interference based on the outputs of NXP inertial and magnetic sensors.
Version 7.00 of the development kit has the following features:

  • Full source code for the sensor fusion libraries
  • IDE-independent software based upon the NXP Kinetis Software Development (KSDK).
  • The Fusion Library no longer requires Processor Expert for component configuration.
  • Supports both bare-metal and RTOS-based project development. Library code is now RTOS agnostic.
  • Optional standby mode powers down power-hungry sensors when no motion is detected.
  • 9-axis Kalman filters require significantly less MIPS to execute
  • All options require significantly less memory than those in the Version 5.xx library.
  • Full documentation including user manual and fusion data sheet

The fusion library is supplied under a liberal BSD open source license, which allows the user to employ this software with NXP MCUs and sensors, or those of our competitors. Support for issues relating to the default distribution running on NXP reference hardware is available via standard NXP support channels. Support for nonstandard platforms and applications is available at https://community.nxp.com/community/sensors/sensorfusion.

This guide was first published on Feb 17, 2020. It was last updated on Feb 17, 2020.

This page (Sensor Fusion Algorithms) was last updated on Apr 22, 2021.

Text editor powered by tinymce.