Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fusion/FusionAhrs.h@1:57502185804c, 2021-10-30 (annotated)
- Committer:
- natvich
- Date:
- Sat Oct 30 17:17:07 2021 +0000
- Revision:
- 1:57502185804c
Projet ATTITUDE IMU
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| natvich | 1:57502185804c | 1 | /** |
| natvich | 1:57502185804c | 2 | * @file FusionAhrs.h |
| natvich | 1:57502185804c | 3 | * @author Seb Madgwick |
| natvich | 1:57502185804c | 4 | * @brief The AHRS sensor fusion algorithm to combines gyroscope, accelerometer, |
| natvich | 1:57502185804c | 5 | * and magnetometer measurements into a single measurement of orientation |
| natvich | 1:57502185804c | 6 | * relative to the Earth (NWU convention). |
| natvich | 1:57502185804c | 7 | * |
| natvich | 1:57502185804c | 8 | * The algorithm behaviour is governed by a gain. A low gain will decrease the |
| natvich | 1:57502185804c | 9 | * influence of the accelerometer and magnetometer so that the algorithm will |
| natvich | 1:57502185804c | 10 | * better reject disturbances causes by translational motion and temporary |
| natvich | 1:57502185804c | 11 | * magnetic distortions. However, a low gain will also increase the risk of |
| natvich | 1:57502185804c | 12 | * drift due to gyroscope calibration errors. A typical gain value suitable for |
| natvich | 1:57502185804c | 13 | * most applications is 0.5. |
| natvich | 1:57502185804c | 14 | * |
| natvich | 1:57502185804c | 15 | * The algorithm allows the application to define a minimum and maximum valid |
| natvich | 1:57502185804c | 16 | * magnetic field magnitude. The algorithm will ignore magnetic measurements |
| natvich | 1:57502185804c | 17 | * that fall outside of this range. This allows the algorithm to reject |
| natvich | 1:57502185804c | 18 | * magnetic measurements that do not represent the direction of magnetic North. |
| natvich | 1:57502185804c | 19 | * The typical magnitude of the Earth's magnetic field is between 20 uT and |
| natvich | 1:57502185804c | 20 | * 70 uT. |
| natvich | 1:57502185804c | 21 | * |
| natvich | 1:57502185804c | 22 | * The algorithm can be used without a magnetometer. Measurements of |
| natvich | 1:57502185804c | 23 | * orientation obtained using only gyroscope and accelerometer measurements |
| natvich | 1:57502185804c | 24 | * can be expected to drift in the yaw component of orientation only. The |
| natvich | 1:57502185804c | 25 | * application can reset the drift in yaw by setting the yaw to a specified |
| natvich | 1:57502185804c | 26 | * angle at any time. |
| natvich | 1:57502185804c | 27 | * |
| natvich | 1:57502185804c | 28 | * The algorithm provides the measurement of orientation as a quaternion. The |
| natvich | 1:57502185804c | 29 | * library includes functions for converting this quaternion to a rotation |
| natvich | 1:57502185804c | 30 | * matrix and Euler angles. |
| natvich | 1:57502185804c | 31 | * |
| natvich | 1:57502185804c | 32 | * The algorithm also provides a measurement of linear acceleration and Earth |
| natvich | 1:57502185804c | 33 | * acceleration. Linear acceleration is equal to the accelerometer measurement |
| natvich | 1:57502185804c | 34 | * with the 1 g of gravity removed. Earth acceleration is a measurement of |
| natvich | 1:57502185804c | 35 | * linear acceleration in the Earth coordinate frame. |
| natvich | 1:57502185804c | 36 | */ |
| natvich | 1:57502185804c | 37 | |
| natvich | 1:57502185804c | 38 | #ifndef FUSION_AHRS_H |
| natvich | 1:57502185804c | 39 | #define FUSION_AHRS_H |
| natvich | 1:57502185804c | 40 | |
| natvich | 1:57502185804c | 41 | //------------------------------------------------------------------------------ |
| natvich | 1:57502185804c | 42 | // Includes |
| natvich | 1:57502185804c | 43 | |
| natvich | 1:57502185804c | 44 | #include "FusionTypes.h" |
| natvich | 1:57502185804c | 45 | #include <stdbool.h> |
| natvich | 1:57502185804c | 46 | |
| natvich | 1:57502185804c | 47 | //------------------------------------------------------------------------------ |
| natvich | 1:57502185804c | 48 | // Definitions |
| natvich | 1:57502185804c | 49 | |
| natvich | 1:57502185804c | 50 | /** |
| natvich | 1:57502185804c | 51 | * @brief AHRS algorithm structure. Structure members are used internally and |
| natvich | 1:57502185804c | 52 | * should not be used by the user application. |
| natvich | 1:57502185804c | 53 | */ |
| natvich | 1:57502185804c | 54 | typedef struct { |
| natvich | 1:57502185804c | 55 | float gain; |
| natvich | 1:57502185804c | 56 | float minimumMagneticFieldSquared; |
| natvich | 1:57502185804c | 57 | float maximumMagneticFieldSquared; |
| natvich | 1:57502185804c | 58 | FusionQuaternion quaternion; // describes the Earth relative to the sensor |
| natvich | 1:57502185804c | 59 | FusionVector3 linearAcceleration; |
| natvich | 1:57502185804c | 60 | float rampedGain; |
| natvich | 1:57502185804c | 61 | bool zeroYawPending; |
| natvich | 1:57502185804c | 62 | } FusionAhrs; |
| natvich | 1:57502185804c | 63 | |
| natvich | 1:57502185804c | 64 | //------------------------------------------------------------------------------ |
| natvich | 1:57502185804c | 65 | // Function prototypes |
| natvich | 1:57502185804c | 66 | |
| natvich | 1:57502185804c | 67 | void FusionAhrsInitialise(FusionAhrs * const fusionAhrs, const float gain); |
| natvich | 1:57502185804c | 68 | void FusionAhrsSetGain(FusionAhrs * const fusionAhrs, const float gain); |
| natvich | 1:57502185804c | 69 | void FusionAhrsSetMagneticField(FusionAhrs * const fusionAhrs, const float minimumMagneticField, const float maximumMagneticField); |
| natvich | 1:57502185804c | 70 | void FusionAhrsUpdate(FusionAhrs * const fusionAhrs, const FusionVector3 gyroscope, const FusionVector3 accelerometer, const FusionVector3 magnetometer, const float samplePeriod); |
| natvich | 1:57502185804c | 71 | void FusionAhrsUpdateWithoutMagnetometer(FusionAhrs * const fusionAhrs, const FusionVector3 gyroscope, const FusionVector3 accelerometer, const float samplePeriod); |
| natvich | 1:57502185804c | 72 | FusionQuaternion FusionAhrsGetQuaternion(const FusionAhrs * const fusionAhrs); |
| natvich | 1:57502185804c | 73 | FusionVector3 FusionAhrsGetLinearAcceleration(const FusionAhrs * const fusionAhrs); |
| natvich | 1:57502185804c | 74 | FusionVector3 FusionAhrsGetEarthAcceleration(const FusionAhrs * const fusionAhrs); |
| natvich | 1:57502185804c | 75 | void FusionAhrsReinitialise(FusionAhrs * const fusionAhrs); |
| natvich | 1:57502185804c | 76 | bool FusionAhrsIsInitialising(const FusionAhrs * const fusionAhrs); |
| natvich | 1:57502185804c | 77 | void FusionAhrsSetYaw(FusionAhrs * const fusionAhrs, const float yaw); |
| natvich | 1:57502185804c | 78 | |
| natvich | 1:57502185804c | 79 | #endif |
| natvich | 1:57502185804c | 80 | |
| natvich | 1:57502185804c | 81 | //------------------------------------------------------------------------------ |
| natvich | 1:57502185804c | 82 | // End of file |