From 94401dbbded3317df5b542d218b48f27318ae9e0 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 11 Mar 2026 15:10:48 +0100 Subject: [PATCH] SensorManager: skip if no iio sensor connected This fixes: Traceback (most recent call last): File "", line 31, in File "lib/mpos/main.py", line 150, in File "lib/mpos/board/linux.py", line 133, in File "lib/mpos/sensor_manager.py", line 286, in class_method File "lib/mpos/sensor_manager.py", line 109, in init_iio File "lib/mpos/imu/manager.py", line 52, in init_iio File "lib/mpos/imu/drivers/iio.py", line 21, in __init__ File "lib/mpos/imu/drivers/iio.py", line 129, in ensure_sampling_frequency_max TypeError: unsupported types for __add__: 'NoneType', 'str' --- .../lib/mpos/imu/drivers/iio.py | 25 +++++++++++++++---- internal_filesystem/lib/mpos/imu/manager.py | 6 +++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/internal_filesystem/lib/mpos/imu/drivers/iio.py b/internal_filesystem/lib/mpos/imu/drivers/iio.py index d849a2a3..37a0a0db 100644 --- a/internal_filesystem/lib/mpos/imu/drivers/iio.py +++ b/internal_filesystem/lib/mpos/imu/drivers/iio.py @@ -18,12 +18,21 @@ class IIODriver(IMUDriverBase): def __init__(self): super().__init__() self.accel_path = self.find_iio_device_with_file("in_accel_x_raw") - self.ensure_sampling_frequency_max(self.accel_path) self.mag_path = self.find_iio_device_with_file("in_magn_x_raw") - self.ensure_sampling_frequency_max(self.mag_path) self.gyro_path = self.find_iio_device_with_file("in_anglvel_x_raw") - self.ensure_sampling_frequency_max(self.gyro_path) - + self.available = any((self.accel_path, self.mag_path, self.gyro_path)) + + if not self.available: + print("IIO: no IIO sensors detected") + return + + if self.accel_path: + self.ensure_sampling_frequency_max(self.accel_path) + if self.mag_path: + self.ensure_sampling_frequency_max(self.mag_path) + if self.gyro_path: + self.ensure_sampling_frequency_max(self.gyro_path) + def _p(self, name: str): return self.accel_path + "/" + name @@ -126,6 +135,9 @@ class IIODriver(IMUDriverBase): Returns: (changed: bool, max_freq: float or None, current: float or None) """ + if not dev_path: + return (False, None, None) + sf = dev_path + "/sampling_frequency" sfa = dev_path + "/sampling_frequency_available" @@ -280,8 +292,11 @@ class IIODriver(IMUDriverBase): ) def read_magnetometer(self) -> tuple[float, float, float]: + if not self.mag_path: + return (0.0, 0.0, 0.0) + gx = self._read_raw_scaled(self.mag_path + "/" + "in_magn_x_raw", self.mag_path + "/" + "in_magn_x_scale") gy = self._read_raw_scaled(self.mag_path + "/" + "in_magn_y_raw", self.mag_path + "/" + "in_magn_y_scale") - gz = self._read_raw_scaled(self.mag_path + "/" + "in_magn_z_raw", self.mag_path + "/" + "in_magn_z_scale") + gz = self._read_raw_scaled(self.mag_path + "/" + "in_magn_z_raw", self.mag_path + "/" + "in_magn_z_scale") return self._apply_mount_matrix(gx, gy, gz, self.mag_path) diff --git a/internal_filesystem/lib/mpos/imu/manager.py b/internal_filesystem/lib/mpos/imu/manager.py index 0c5f9b61..87eb9b95 100644 --- a/internal_filesystem/lib/mpos/imu/manager.py +++ b/internal_filesystem/lib/mpos/imu/manager.py @@ -50,6 +50,12 @@ class ImuManager: def init_iio(self): self._imu_driver = IIODriver() + if not getattr(self._imu_driver, "available", True): + self._imu_driver = None + self._sensor_list = [] + self._initialized = False + return False + self._sensor_list = [ Sensor( name="Magnetometer",