mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 01:55:59 +00:00
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from typing import Any
|
|
import numpy as np
|
|
|
|
from enum import Enum
|
|
|
|
|
|
class PressUnit:
|
|
Pa = 0
|
|
hPa = 1
|
|
|
|
|
|
class AltitudeModel:
|
|
def __init__(self, press_b: float = 1013.25, alt_b: float = 0, unit: PressUnit = PressUnit.hPa):
|
|
"""A simple model for estimating the altitude based on pressure measurements.
|
|
A reference height and the corresponding pressure value can be provided for a more precise model.
|
|
|
|
Args:
|
|
press_b (float, optional): The pressure measured at the reference altitude. Defaults to 1013.25 hPa.
|
|
alt_b (float, optional): The reference altitude in meters. Defaults to 0m.
|
|
unit (PressUnit, optional): The unit used for all pressure values. Defaults to PressUnit.hPa.
|
|
"""
|
|
self.__press_0 = press_b / (1 - (alt_b / 44330)**5.255)
|
|
|
|
def predict(self, press: float, unit: PressUnit = PressUnit.hPa) -> float:
|
|
"""Estimates the altitude based on a pressure measurement.
|
|
|
|
Based on the formulas provided here:
|
|
https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
|
|
|
|
Args:
|
|
press (float): The pressure measurement.
|
|
unit (PressUnit, optional): The unit of the pressure measurement. Defaults to PressUnit.hPa.
|
|
|
|
Returns:
|
|
float: Returns the estimated altitude in meters.
|
|
"""
|
|
if unit != PressUnit.hPa:
|
|
to_hpa = {
|
|
PressUnit.Pa: press / 1e2
|
|
}
|
|
|
|
press = to_hpa[unit]
|
|
|
|
return 44330 * (1 - (press / self.__press_0)**(1 / 5.255))
|