• Stars
    star
    499
  • Rank 88,341 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tags Build Pypi Python License

Fusion

Fusion is a sensor fusion library for Inertial Measurement Units (IMUs), optimised for embedded systems. Fusion is a C library but is also available as the Python package, imufusion. Two example Python scripts, simple_example.py and advanced_example.py are provided with example sensor data to demonstrate use of the package.

AHRS algorithm

The Attitude And Heading Reference System (AHRS) algorithm combines gyroscope, accelerometer, and magnetometer data into a single measurement of orientation relative to the Earth. The algorithm also supports systems that use only a gyroscope and accelerometer, and systems that use a gyroscope and accelerometer combined with an external source of heading measurement such as GPS.

The algorithm is based on the revised AHRS algorithm presented in chapter 7 of Madgwick's PhD thesis. This is a different algorithm to the better-known initial AHRS algorithm presented in chapter 3, commonly referred to as the Madgwick algorithm.

The algorithm calculates the orientation as the integration of the gyroscope summed with a feedback term. The feedback term is equal to the error in the current measurement of orientation as determined by the other sensors, multiplied by a gain. The algorithm therefore functions as a complementary filter that combines high-pass filtered gyroscope measurements with low-pass filtered measurements from other sensors with a corner frequency determined by the gain. A low gain will 'trust' the gyroscope more and so be more susceptible to drift. A high gain will increase the influence of other sensors and the errors that result from accelerations and magnetic distortions. A gain of zero will ignore the other sensors so that the measurement of orientation is determined by only the gyroscope.

Initialisation

Initialisation occurs when the algorithm starts for the first time. During initialisation, the acceleration and magnetic rejection features are disabled and the gain is ramped down from 10 to the final value over a 3 second period. This allows the measurement of orientation to rapidly converges from an arbitrary initial value to the value indicated by the sensors. The algorithm outputs should be regarded as unreliable during initialisation.

Acceleration rejection

The acceleration rejection feature reduces the errors that result from the accelerations of linear and rotational motion. Acceleration rejection works by calculating an error as the angular difference between the instantaneous measurement of inclination indicated by the accelerometer, and the current measurement of inclination provided by the algorithm output. If the error is greater than a threshold then the accelerometer will be ignored for that algorithm update. This is equivalent to a dynamic gain that deceases as accelerations increase.

Prolonged accelerations risk an overdependency on the gyroscope and will trigger an acceleration recovery. Acceleration recovery activates when the error exceeds the threshold for more than 90% of algorithm updates over a period of t / (0.1p - 9), where t is the recovery trigger period and p is the percentage of algorithm updates where the error exceeds the threshold. The recovery will remain active until the error exceeds the threshold for less than 90% of algorithm updates over the period -t / (0.1p - 9). The accelerometer will be used by every algorithm update during recovery.

Magnetic rejection

The magnetic rejection feature reduces the errors that result from temporary magnetic distortions. Magnetic rejection works using the same principle as acceleration rejection, operating on the magnetometer instead of the accelerometer and by comparing the measurements of heading instead of inclination.

Algorithm outputs

The algorithm provides three outputs: quaternion, linear acceleration, and Earth acceleration. The quaternion describes the orientation of the sensor relative to the Earth. This can be converted to a rotation matrix using the FusionQuaternionToMatrix function or to Euler angles using the FusionQuaternionToEuler function. The linear acceleration is the accelerometer measurement with the 1 g of gravity removed. The Earth acceleration is the accelerometer measurement in the Earth coordinate frame with the 1 g of gravity removed. The algorithm supports North-West-Up (NWU), East-North-Up (ENU), and North-East-Down (NED) axes conventions.

Algorithm settings

The AHRS algorithm settings are defined by the FusionAhrsSettings structure and set using the FusionAhrsSetSettings function.

Setting Description
convention Earth axes convention (NWD, ENU, or NED).
gain Determines the influence of the gyroscope relative to other sensors. A value of zero will disable initialisation and the acceleration and magnetic rejection features. A value of 0.5 is appropriate for most applications.
accelerationRejection Threshold (in degrees) used by the acceleration rejection feature. A value of zero will disable this feature. A value of 10 degrees is appropriate for most applications.
magneticRejection Threshold (in degrees) used by the magnetic rejection feature. A value of zero will disable the feature. A value of 10 degrees is appropriate for most applications.
recoveryTriggerPeriod Acceleration and magnetic recovery trigger period (in samples). A value of zero will disable the acceleration and magnetic rejection features. A period of 5 seconds is appropriate for most applications.

Algorithm internal states

The AHRS algorithm internal states are defined by the FusionAhrsInternalStates structure and obtained using the FusionAhrsGetInternalStates function.

State Description
accelerationError Angular error (in degrees) of the algorithm output relative to the instantaneous measurement of inclination indicated by the accelerometer. The acceleration rejection feature will ignore the accelerometer if this value exceeds the accelerationRejection threshold set in the algorithm settings.
accelerometerIgnored true if the accelerometer was ignored by the previous algorithm update.
accelerationRecoveryTrigger Acceleration recovery trigger value between 0.0 and 1.0. Acceleration recovery will activate when this value reaches 1.0 and then deactivate when when the value reaches 0.0.
magneticError Angular error (in degrees) of the algorithm output relative to the instantaneous measurement of heading indicated by the magnetometer. The magnetic rejection feature will ignore the magnetometer if this value exceeds the magneticRejection threshold set in the algorithm settings.
magnetometerIgnored true if the magnetometer was ignored by the previous algorithm update.
magneticRecoveryTrigger Magnetic recovery trigger value between 0.0 and 1.0. Magnetic recovery will activate when this value reaches 1.0 and then deactivate when when the value reaches 0.0.

Algorithm flags

The AHRS algorithm flags are defined by the FusionAhrsFlags structure and obtained using the FusionAhrsGetFlags function.

Flag Description
initialising true if the algorithm is initialising.
accelerationRecovery true if acceleration recovery is active.
magneticRecovery true if a magnetic recovery is active.

Gyroscope offset correction algorithm

The gyroscope offset correction algorithm provides run-time calibration of the gyroscope offset to compensate for variations in temperature and fine-tune existing offset calibration that may already be in place. This algorithm should be used in conjunction with the AHRS algorithm to achieve best performance.

The algorithm calculates the gyroscope offset by detecting the stationary periods that occur naturally in most applications. Gyroscope measurements are sampled during these periods and low-pass filtered to obtain the gyroscope offset. The algorithm requires that gyroscope measurements do not exceed +/-3 degrees per second while stationary. Basic gyroscope offset calibration may be necessary to ensure that the initial offset plus measurement noise is within these bounds.

Sensor calibration

Sensor calibration is essential for accurate measurements. This library provides functions to apply calibration parameters to the gyroscope, accelerometer, and magnetometer. This library does not provide a solution for calculating the calibration parameters.

Inertial calibration

The FusionCalibrationInertial function applies gyroscope and accelerometer calibration parameters using the calibration model:

ic = Ms(iu - b)

  • ic is the calibrated inertial measurement and return value
  • iu is the uncalibrated inertial measurement and uncalibrated argument
  • M is the misalignment matrix and misalignment argument
  • s is the sensitivity diagonal matrix and sensitivity argument
  • b is the offset vector and offset argument

Magnetic calibration

The FusionCalibrationMagnetic function applies magnetometer calibration parameters using the calibration model:

mc = Smu - h

  • mc is the calibrated magnetometer measurement and return value
  • mu is the uncalibrated magnetometer measurement and uncalibrated argument
  • S is the soft iron matrix and softIronMatrix argument
  • h is the hard iron offset vector and hardIronOffset argument

Fast inverse square root

Fusion uses Pizer's implementation of the fast inverse square root algorithm for vector and quaternion normalisation. Including the definition FUSION_USE_NORMAL_SQRT in FusionMath.h or adding this as a preprocessor definition will use normal square root operations for all normalisation calculations. This will slow down execution speed for a small increase in accuracy. The increase in accuracy will typically be too small to observe on any practical system.

More Repositories

1

Gait-Tracking-With-x-IMU

MATLAB
887
star
2

Open-Source-AHRS-With-x-IMU

C#
384
star
3

Oscillatory-Motion-Tracking-With-x-IMU

MATLAB
349
star
4

Serial-Oscilloscope

C#
235
star
5

Gait-Tracking

Python
71
star
6

x-IMU-MATLAB-Library

MATLAB
36
star
7

x-IMU3-Software

C++
35
star
8

x-IMU-GUI

C#
29
star
9

x-IMU-Arduino-Example

C++
23
star
10

DAQ32

C#
21
star
11

Quaternion-MATLAB-Library

MATLAB
19
star
12

NGIMU-Software-Public

C#
16
star
13

Rolling-Ball-Tracking-With-Gyro

C#
16
star
14

NGIMU-Unity-Example

ShaderLab
12
star
15

Ideal-Diode

Shell
11
star
16

OSC99

C
11
star
17

Dummy-Micro-SD-Card

Shell
10
star
18

Dub-Siren

Objective-C
9
star
19

NGIMU-MATLAB-Real-Time-Example

MATLAB
9
star
20

NeoPixel-Screen

C
8
star
21

NGIMU-C-Cpp-Example

C
8
star
22

Camera-Control-And-Stabilisation-Via-PC

C#
8
star
23

x-BIMU-Terminal

C#
6
star
24

NGIMU-Python-Example

Python
6
star
25

GyroScratch

Max
6
star
26

x-BIMU-Arduino-Example

C++
6
star
27

PIC32MZ-Bare-Bones

Eagle
5
star
28

OSC-illoscope

Processing
5
star
29

NGIMU-MATLAB-Import-Logged-Data-Example

MATLAB
4
star
30

NGIMU-Breakout-Boards

Eagle
4
star
31

BMX055-Breakout

Shell
4
star
32

x-IMU3-SA-D3

C
3
star
33

RGB-Control-With-Processing

Processing
3
star
34

NGIMU-Teensy-IO-Expansion-Example

C++
3
star
35

Wii-Mote-Style-Mouse-For-PC

C#
3
star
36

OSC-Sync-Master

C
3
star
37

x-io-Altium-Library

3
star
38

Calibration-Cube

3
star
39

Data-Logger-Prototyping-Board

Batchfile
2
star
40

Oscillatory-Motion-Tracking-With-NGIMU

MATLAB
2
star
41

NGIMU-MaxMSP-Example

Max
2
star
42

QAM-Audio

MATLAB
2
star
43

IR-Theremin

Max
2
star
44

x-BIMU-Bluetooth

Shell
2
star
45

x-io-PIC32-Library

C
2
star
46

GNS-902-Carrier-Board

Eagle
2
star
47

LiPo-Battery-Meter

Shell
2
star
48

XYZ-Stickers

2
star
49

DressCode-Firmware

C
1
star
50

serialport-rs-rts-test

Rust
1
star
51

CAM-M8Q-Breakout

Batchfile
1
star
52

Gloves-Flex-PCB

Shell
1
star
53

x-OSC-Programmer

Shell
1
star
54

Hexapod

C#
1
star
55

x-OSC-Firmware-Uploader

C#
1
star
56

Gait-Tracking-With-NGIMU

MATLAB
1
star
57

RS9110-N-11-22-Breakout

Shell
1
star
58

x-BIMU-Android-Example

Java
1
star
59

SAM-M8Q-Breakout

Batchfile
1
star
60

DressCode-PCB

Shell
1
star
61

monome-sixteen

1
star
62

OSC-Terminal

C#
1
star
63

Human-Harp-Player

Eagle
1
star
64

x-BIMU-Housing

1
star
65

WiFi-Arcade-Controller

Java
1
star