From 1af30d362c9b11dfc4387518e63bc130a394407f Mon Sep 17 00:00:00 2001 From: Bartok9 Date: Wed, 22 Jul 2026 05:23:17 -0400 Subject: [PATCH] fix(python): correct BarometerData field types to scalars BarometerBase::Output and RpcLibAdaptorsBase::BarometerData expose altitude/pressure/qnh as real_T. Python defaults incorrectly used Quaternionr/Vector3r, which misleads clients and nested decode. Signed-off-by: Bartok9 --- PythonClient/airsim/types.py | 6 +-- PythonClient/tests/__init__.py | 0 .../tests/test_barometer_data_types.py | 53 +++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 PythonClient/tests/__init__.py create mode 100644 PythonClient/tests/test_barometer_data_types.py diff --git a/PythonClient/airsim/types.py b/PythonClient/airsim/types.py index 7aef005549..d42923c6e4 100644 --- a/PythonClient/airsim/types.py +++ b/PythonClient/airsim/types.py @@ -428,9 +428,9 @@ class ImuData(MsgpackMixin): class BarometerData(MsgpackMixin): time_stamp = np.uint64(0) - altitude = Quaternionr() - pressure = Vector3r() - qnh = Vector3r() + altitude = 0.0 # meters (matches BarometerBase::Output) + pressure = 0.0 # Pascal + qnh = 0.0 class MagnetometerData(MsgpackMixin): time_stamp = np.uint64(0) diff --git a/PythonClient/tests/__init__.py b/PythonClient/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/PythonClient/tests/test_barometer_data_types.py b/PythonClient/tests/test_barometer_data_types.py new file mode 100644 index 0000000000..626272e479 --- /dev/null +++ b/PythonClient/tests/test_barometer_data_types.py @@ -0,0 +1,53 @@ +"""Offline checks for BarometerData scalars (no AirSim sim required).""" +from __future__ import annotations + +import importlib.util +import math +import sys +import types +import unittest +from pathlib import Path + + +def _load_types(): + # Stub msgpackrpc so types.py imports cleanly without the RPC package. + if "msgpackrpc" not in sys.modules: + sys.modules["msgpackrpc"] = types.ModuleType("msgpackrpc") + root = Path(__file__).resolve().parents[1] / "airsim" / "types.py" + spec = importlib.util.spec_from_file_location("airsim_types_under_test", root) + mod = importlib.util.module_from_spec(spec) + assert spec.loader is not None + spec.loader.exec_module(mod) + return mod + + +class TestBarometerDataTypes(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.types = _load_types() + + def test_defaults_are_real_scalars(self): + b = self.types.BarometerData() + self.assertIsInstance(b.altitude, float) + self.assertIsInstance(b.pressure, float) + self.assertIsInstance(b.qnh, float) + self.assertTrue(math.isfinite(b.altitude)) + self.assertTrue(math.isfinite(b.pressure)) + self.assertTrue(math.isfinite(b.qnh)) + # Must not be pose-like defaults (historical bug). + self.assertFalse(isinstance(b.altitude, self.types.Quaternionr)) + self.assertFalse(isinstance(b.pressure, self.types.Vector3r)) + self.assertFalse(isinstance(b.qnh, self.types.Vector3r)) + + def test_assign_numeric_values(self): + b = self.types.BarometerData() + b.altitude = 120.5 + b.pressure = 101325.0 + b.qnh = 1013.25 + self.assertEqual(b.altitude, 120.5) + self.assertEqual(b.pressure, 101325.0) + self.assertAlmostEqual(b.qnh, 1013.25) + + +if __name__ == "__main__": + unittest.main()