Skip to content

Commit 8227f37

Browse files
committed
Updated Examples for new Fusion Library
1 parent 652ad2c commit 8227f37

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
![version](https://img.shields.io/github/v/tag/Reefwing-Software/Reefwing-AHRS) ![License](https://img.shields.io/badge/license-MIT-green)
1+
![version](https://img.shields.io/github/v/tag/Reefwing-Software/Reefwing-AHRS) ![license](https://img.shields.io/badge/license-MIT-green) ![release](https://img.shields.io/github/release-date/Reefwing-Software/Reefwing-AHRS?color="red") ![open source](https://badgen.net/badge/open/source/blue?icon=github)
2+
23
# Reefwing AHRS
34

45
The Reefwing flight controller for quadcopters is based around the Arduino Nano 33 BLE board. This board includes the LSM9DS1 chip which we use as an Inertial Measurement Unit (IMU). The IMU determines the current orientation of the drone.
@@ -283,14 +284,12 @@ Increasing beta (GyroMeasError) by about a factor of fifteen (beta = 0.6), the r
283284
```c++
284285
imu.setFusionAlgorithm(SensorFusion::FUSION);
285286
imu.setFusionPeriod(0.01f); // Estimated sample period = 0.01 s = 100 Hz
286-
imu.setFusionThreshold(0.5f); // Stationary threshold = 0.5 degrees per second
287287
imu.setFusionGain(0.5); // Default Fusion Filter Gain
288288
```
289289

290290
The fusion AHRS sketch is similar to the other examples, apart from the Fusion specific configuration shown above. This is what we will focus on.
291291

292292
- `imu.setFusionPeriod(0.01f)`: One difference with this filter is that you need to know the frequency that the model will be updated in advance. This is normally either the sensor sample rate or the loop frequency of the Arduino board (whichever is slower). In this example we tweaked the delay amount in `loop()` to get 100 Hz (i.e., a period of 0.01 seconds).
293-
- `imu.setFusionThreshold(0.5f)`: The gyroscope bias correction algorithm provides run-time calibration of the gyroscope bias. The algorithm will detect when the gyroscope is stationary for a set period of time (`fusionThreshold`) and then begin to sample gyroscope measurements to calculate the bias as an average. This is why the fusion filter doesn't require prior calibration.
294293
- `imu.setFusionGain(0.5)`: The fusion algorithm is governed by a gain. A low gain will decrease the influence of the accelerometer and magnetometer so that the algorithm will better reject disturbances causes by translational motion and temporary magnetic distortions. However, a low gain will also increase the risk of drift due to gyroscope calibration errors. Madgwick suggests a gain value of 0.5, but this results in a lagging angle resolution. For a drone we think a gain of around 7.5 is better. This provides a much faster angle response without appearing to sacrifice too much accuracy.
295294

296-
295+
For more details of how this algorithm operates, refer to the [Fusion Readme](theory/FUSION_README.md) in the theory folder of this repository.

examples/testAndCalibrate/testAndCalibrate.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1.0.0 Original Release. 22/02/22
1212
1.1.0 Added NONE fusion option. 25/05/22
1313
2.0.0 Changed Repo & Branding 15/12/22
14+
2.0.1 Invert Gyro Values PR 24/12/22
1415
2.1.0 Updated Fusion Library 30/12/22
1516
1617
******************************************************************/

src/ReefwingAHRS.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,12 @@ void LSM9DS1::setFusionAlgorithm(SensorFusion algo) {
802802
fusion = algo;
803803
}
804804

805+
void LSM9DS1::setFusionPeriod(float p) {
806+
sampleRate = (int)(1.0/p);
807+
fusionSettings.rejectionTimeout = 5 * sampleRate;
808+
FusionAhrsSetSettings(&fusionAhrs, &fusionSettings);
809+
}
810+
805811
void LSM9DS1::setDeclination(float dec) {
806812
declination = dec;
807813
}
@@ -949,7 +955,6 @@ void LSM9DS1::setMagResolution(Mscale mscale) {
949955
break;
950956
}
951957

952-
hardIronBias.axis = { 0.0f, 0.0f, 0.0f }; // replace these values with actual hard-iron bias in uT if known
953958
}
954959

955960
float LSM9DS1::getAccResolution() {

src/ReefwingAHRS.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class LSM9DS1 {
154154
void calibrateAccGyro();
155155
void calibrateMag();
156156
void setFusionPeriod(float p);
157-
void setFusionThreshold(float t);
158157
void setFusionAlgorithm(SensorFusion algo);
159158
void setAlpha(float a);
160159
void setBeta(float b);
@@ -207,6 +206,7 @@ class LSM9DS1 {
207206
FusionVector accelerometerOffset = {0.0f, 0.0f, 0.0f};
208207
FusionMatrix softIronMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
209208
FusionVector hardIronOffset = {0.0f, 0.0f, 0.0f};
209+
FusionVector hardIronBias = {0.0f, 0.0f, 0.0f};
210210

211211
void updateEulerAngles();
212212
void complementaryUpdate();
@@ -224,10 +224,6 @@ class LSM9DS1 {
224224
float declination;
225225
float gyroMeasError, alpha, beta, Kp, Ki; // Sensor Fusion free parameters
226226

227-
FusionVector gyroscopeSensitivity;
228-
FusionVector accelerometerSensitivity;
229-
FusionVector hardIronBias;
230-
231227
SensorData sensorData; // variables to hold latest sensor data values
232228
Quaternion quaternion;
233229
EulerAngles eulerAngles;

0 commit comments

Comments
 (0)