Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal_filesystem/lib/mpos/imu/drivers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def read_gyroscope(self):
"""Returns (x, y, z) in deg/s"""
raise NotImplementedError

def read_magnetometer(self):
"""Returns (x, y, z) in uT"""
raise NotImplementedError

def read_temperature(self):
"""Returns temperature in °C"""
raise NotImplementedError
Expand Down
10 changes: 9 additions & 1 deletion internal_filesystem/lib/mpos/imu/drivers/iio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class IIODriver(IMUDriverBase):
"""

accel_path: str
mag_path: str

def __init__(self):
super().__init__()
self.accel_path = self.find_iio_device_with_file("in_accel_x_raw")
print("path:", self.accel_path)
self.mag_path = self.find_iio_device_with_file("in_magn_x_raw")

def _p(self, name: str):
return self.accel_path + "/" + name
Expand Down Expand Up @@ -138,3 +139,10 @@ def read_gyroscope(self):
gy - self.gyro_offset[1],
gz - self.gyro_offset[2],
)

def read_magnetometer(self) -> tuple[float, float, float]:
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")

return (gx, gy, gz)
13 changes: 13 additions & 0 deletions internal_filesystem/lib/mpos/imu/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mpos.imu.constants import (
TYPE_ACCELEROMETER,
TYPE_GYROSCOPE,
TYPE_MAGNETIC_FIELD,
TYPE_IMU_TEMPERATURE,
TYPE_SOC_TEMPERATURE,
TYPE_TEMPERATURE,
Expand Down Expand Up @@ -50,6 +51,15 @@ def init(self, i2c_bus, address=0x6B, mounted_position=FACING_SKY):
def init_iio(self):
self._imu_driver = IIODriver()
self._sensor_list = [
Sensor(
name="Magnetometer",
sensor_type=TYPE_MAGNETIC_FIELD,
vendor="Linux IIO",
version=1,
max_range="?",
resolution="?",
power_ma=0.2
),
Sensor(
name="Accelerometer",
sensor_type=TYPE_ACCELEROMETER,
Expand Down Expand Up @@ -156,6 +166,9 @@ def read_sensor_once(self, sensor):
elif sensor.type == TYPE_GYROSCOPE:
if self._imu_driver:
return self._imu_driver.read_gyroscope()
elif sensor.type == TYPE_MAGNETIC_FIELD:
if self._imu_driver:
return self._imu_driver.read_magnetometer()
elif sensor.type == TYPE_IMU_TEMPERATURE:
if self._imu_driver:
return self._imu_driver.read_temperature()
Expand Down
Loading