-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,639 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/*========================================================================================== | ||
alt.h - madflight altitude estimator | ||
MIT License | ||
Copyright (c) 2025 https://madflight.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
===========================================================================================*/ | ||
|
||
|
||
/*================================================================================================= | ||
Each ALT_USE_xxx section in this file defines a specific altimeter estimator class | ||
=================================================================================================*/ | ||
|
||
#pragma once | ||
|
||
#define ALT_USE_NONE 1 | ||
#define ALT_USE_KALMAN2 2 // Kalman filter estimates h and v from barometer and acceleration | ||
#define ALT_USE_KALMAN3 3 // Kalman filter estimates h, v, and abias from barometer and acceleration | ||
#define ALT_USE_BARO 4 // Filtered barometer | ||
#define ALT_USE_COMP 5 // Complementary filter | ||
|
||
#include "../interface.h" //declares AltEst - Altimeter Estimator class | ||
|
||
//================================================================================================= | ||
// None or undefined | ||
//================================================================================================= | ||
#if ALT_USE == ALT_USE_NONE || !defined ALT_USE | ||
|
||
class AltEst_None : public AltEst { | ||
public: | ||
void setup(float alt) { | ||
Serial.printf("ALT: ALT_USE_NONE\n"); | ||
} | ||
void updateAccelUp(float a, uint32_t ts) {}; | ||
void updateBaroAlt(float alt, uint32_t ts) {} | ||
float getH() {return 0;} | ||
float getV() {return 0;} | ||
void print() {} | ||
}; | ||
|
||
AltEst_None alt_instance; | ||
|
||
//================================================================================================= | ||
// ALT_USE_KALMAN2 - Simple Kalman filter estimates h and vup from barometer and acceleration | ||
//================================================================================================= | ||
#elif ALT_USE == ALT_USE_KALMAN2 | ||
|
||
#include "alt_kalman2/alt_kalman2.h" | ||
|
||
AltEst_Kalman2 alt_instance; | ||
|
||
|
||
//================================================================================================= | ||
// ALT_USE_KALMAN3 - Kalman filter estimates h, vup, and abias from barometer and acceleration | ||
//================================================================================================= | ||
#elif ALT_USE == ALT_USE_KALMAN3 | ||
|
||
#include "alt_kalman3/alt_kalman3.h" | ||
|
||
AltEst_Kalman3 alt_instance; | ||
|
||
|
||
//================================================================================================= | ||
// ALT_USE_BARO - Filtered barometer only | ||
//================================================================================================= | ||
#elif ALT_USE == ALT_USE_BARO | ||
|
||
#include "alt_baro/alt_baro.h" | ||
|
||
AltEst_Baro alt_instance; | ||
|
||
|
||
//================================================================================================= | ||
// ALT_USE_COMP - Complementary filter altitude and accelation | ||
//================================================================================================= | ||
#elif ALT_USE == ALT_USE_COMP | ||
|
||
#include "alt_comp/alt_comp.h" | ||
|
||
AltEst_Comp alt_instance; | ||
|
||
|
||
//================================================================================================= | ||
// ERROR OTHER VALUE | ||
//================================================================================================= | ||
#else | ||
#error "Invalid #define ALT_USE value" | ||
#endif | ||
|
||
AltEst &alt = alt_instance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*========================================================================================== | ||
alt_baro.h - madflight altitude estimator based on filtered barometer readings | ||
MIT License | ||
Copyright (c) 2025 https://madflight.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
===========================================================================================*/ | ||
|
||
#pragma once | ||
|
||
#include "../../interface.h" //baro.getSampleRate() | ||
#include "../../common/common.h" //lowpass_to_beta() | ||
|
||
class AltEst_Baro : public AltEst { | ||
public: | ||
void setup(float alt) { | ||
Serial.printf("ALT: ALT_USE_BARO\n"); | ||
|
||
float sampleRate = baro.getSampleRate(); | ||
float filterHHertz = 2.0; | ||
float filterVHertz = 0.5; | ||
|
||
B_h = lowpass_to_beta(filterHHertz, sampleRate); | ||
B_v = lowpass_to_beta(filterVHertz, sampleRate); | ||
h = alt; | ||
v = 0; | ||
ts = 0; | ||
} | ||
|
||
void updateAccelUp(float a, uint32_t ts) {}; //a: accel up in [m/s^2], ts: timestamp in [us] | ||
|
||
void updateBaroAlt(float alt, uint32_t ts) { //altitude: barometric altitude in [m], ts: timestamp in [us] | ||
if(this->ts != 0) { | ||
float dt = 1e-6 * (ts - this->ts); | ||
float hnew = h + B_h * (alt - h); //Low-pass filtered altitude | ||
float vnew = (hnew - h) / dt; | ||
v += B_v * (vnew - v); //Low-pass filtered velocity | ||
h = hnew; | ||
} | ||
this->ts = ts; | ||
} | ||
|
||
float getH() {return h;} //altitude estimate in [m] | ||
float getV() {return v;} //vertical up speed (climb rate) estimate in [m/s] | ||
|
||
void print() { | ||
Serial.printf("alt.h:%.2f\t", h); | ||
Serial.printf("alt.v:%+.2f\t", v); | ||
} | ||
|
||
float h = 0; // Filtered approximate International Standard Atmosphere (ISA) Altitude in [m] | ||
float v = 0; // Filtered vertical speed in [m/s], up is positive | ||
|
||
protected: | ||
float B_h = 1.0; //alt filter constant | ||
float B_v = 1.0; //vz filter constant | ||
uint32_t ts = 0; | ||
}; |
Oops, something went wrong.