1
1
from .modulino import Modulino
2
2
from lsm6dsox import LSM6DSOX
3
+ from collections import namedtuple
4
+
5
+ MovementValues = namedtuple ('MovementValues' , ['x' , 'y' , 'z' ])
6
+ """A named tuple to store the x, y, and z values of the movement sensors."""
3
7
4
8
class ModulinoMovement (Modulino ):
5
9
"""
@@ -23,17 +27,23 @@ def __init__(self, i2c_bus = None, address: int | None = None) -> None:
23
27
self .sensor = LSM6DSOX (self .i2c_bus , address = self .address )
24
28
25
29
@property
26
- def accelerometer (self ) -> tuple [ float , float , float ] :
30
+ def accelerometer (self ) -> MovementValues :
27
31
"""
28
32
Returns:
29
- tuple[float, float, float]: The acceleration values in the x, y, and z axes.
33
+ MovementValues: The acceleration values in the x, y, and z axes.
34
+ These values can be accessed as .x, .y, and .z properties
35
+ or by using the index operator for tuple unpacking.
30
36
"""
31
- return self .sensor .accel ()
37
+ sensor_values = self .sensor .accel ()
38
+ return MovementValues (sensor_values [0 ], sensor_values [1 ], sensor_values [2 ])
32
39
33
40
@property
34
- def gyro (self ) -> tuple [ float , float , float ] :
41
+ def gyro (self ) -> MovementValues :
35
42
"""
36
43
Returns:
37
- tuple[float, float, float]: The angular velocity values in the x, y, and z axes.
44
+ MovementValues: The gyroscope values in the x, y, and z axes.
45
+ These values can be accessed as .x, .y, and .z properties
46
+ or by using the index operator for tuple unpacking.
38
47
"""
39
- return self .sensor .gyro ()
48
+ sensor_values = self .sensor .gyro ()
49
+ return MovementValues (sensor_values [0 ], sensor_values [1 ], sensor_values [2 ])
0 commit comments