Added simple barometric formula to MS5611 driver

This commit is contained in:
dario 2024-08-06 11:44:34 +02:00
parent fa30a28b45
commit afe9b83b01
3 changed files with 32 additions and 8 deletions

View File

@ -169,6 +169,10 @@ namespace sta
* @return float The altitude estimate in meters. * @return float The altitude estimate in meters.
*/ */
float getAltitudeEstimate(); float getAltitudeEstimate();
static float getSeaLevel(float pressRef, float altRef);
static float getAltitudeEstimate(float pressure, float sealevel);
private: private:
/** /**
* @brief Reset the sensor. * @brief Reset the sensor.

View File

@ -121,6 +121,16 @@ namespace sta
return altitude; return altitude;
} }
float MS56xx::getSeaLevel(float pressRef, float altRef)
{
return pressRef / (std::pow((1 - altRef / 44330), 5.255));
}
float MS56xx::getAltitudeEstimate(float pressure, float sealevel)
{
return 44330 * (1 - std::pow(pressure / sealevel, 1 / 5.255));
}
void MS56xx::readPROM() { void MS56xx::readPROM() {
uint8_t buffer[2]; uint8_t buffer[2];
@ -218,4 +228,4 @@ namespace sta
} }
} }
#endif // STA_SPATZ_ENABLED #endif // STA_SPATZ_ENABLED

View File

@ -93,15 +93,25 @@ namespace sta
sealevel_ = pressRef / (std::pow((1 - altRef / 44330), 5.255)); sealevel_ = pressRef / (std::pow((1 - altRef / 44330), 5.255));
} }
float MS56xx::getAltitudeEstimate() float MS56xx::getAltitudeEstimate()
{ {
float pressure = getPressure(Unit::hPa); float pressure = getPressure(Unit::hPa);
// Taken from: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf, page 16 // Taken from: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf, page 16
float altitude = 44330 * (1 - std::pow(pressure / sealevel_, 1 / 5.255)); float altitude = 44330 * (1 - std::pow(pressure / sealevel_, 1 / 5.255));
return altitude; return altitude;
} }
float MS56xx::getSeaLevel(float pressRef, float altRef)
{
return pressRef / (std::pow((1 - altRef / 44330), 5.255));
}
float MS56xx::getAltitudeEstimate(float pressure, float sealevel)
{
return 44330 * (1 - std::pow(pressure / sealevel, 1 / 5.255));
}
void MS56xx::readPROM() { void MS56xx::readPROM() {