mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-08-01 09:01:54 +00:00
Added model for estimating altitude based on pressure
This commit is contained in:
parent
58d362c8f9
commit
dd3346085b
44
spatz/models/pressure.py
Normal file
44
spatz/models/pressure.py
Normal file
@ -0,0 +1,44 @@
|
||||
from typing import Any
|
||||
import numpy as np
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class PressUnit:
|
||||
Pa = 0
|
||||
hPa = 1
|
||||
|
||||
|
||||
class Altimeter:
|
||||
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)**5255)
|
||||
|
||||
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 / 5255))
|
Loading…
x
Reference in New Issue
Block a user