Open bradcar opened 1 day ago
Hi Brad. Thank you for your comment. This can be done, following the data sheet. But I do not expect a substantial change. The resulting number will be slightly different, smaller than the error of the sensor. I do not know if the number 5.255 is precise or some rounded quantity. I assume the latter.
your choice of course. The more important thing is for people to set the nearest sea level pressure (airport) at local time, or set the altitude to set the sea level pressure.
BTW, in my searching I found a more authoritative source: NSF's NCAR formula: https://ncar.github.io/aircraft_ProcessingAlgorithms/www/PressureAltitude.pdf
In your code for altitude you have return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903)) In the Bosch Sensor guide (ex: in bmp180 they show a different formula page 16 of: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf). Since you are raising the difference in pressure & SLP to a power, then small differences can make a difference.
Consider this return value instead: return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, (1.0 / 5.255)))
Or if you want to not divide, fp32 has 6-9 digits of accuracy, so you could pre-calculate. return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.190294957))
Generally But I find it best to stick to letting the divider keep things full accuracy, so I’d suggest (1.0 / 5.255)