Skip to content

Commit 3654834

Browse files
committed
Rename the movement properties
1 parent 938ea1a commit 3654834

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

examples/movement.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
movement = ModulinoMovement()
1212

1313
while True:
14-
acc = movement.accelerometer
15-
gyro = movement.gyro
14+
acc = movement.acceleration
15+
gyro = movement.angular_velocity
1616

17-
print(f"🏃 Accelerometer: x:{acc.x:>8.3f} y:{acc.y:>8.3f} z:{acc.z:>8.3f}")
18-
print(f"🌐 Gyroscope: x:{gyro.x:>8.3f} y:{gyro.y:>8.3f} z:{gyro.z:>8.3f}")
17+
print(f"🏃 Acceleration: x:{acc.x:>8.3f} y:{acc.y:>8.3f} z:{acc.z:>8.3f}")
18+
print(f"💪 Acceleration Magnitude: {movement.acceleration_magnitude:>8.3f} g")
19+
print(f"🌐 Angular Velocity: x:{gyro.x:>8.3f} y:{gyro.y:>8.3f} z:{gyro.z:>8.3f}")
1920
print("")
2021
sleep_ms(100)

src/modulino/movement.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, i2c_bus = None, address: int | None = None) -> None:
2727
self.sensor = LSM6DSOX(self.i2c_bus, address=self.address)
2828

2929
@property
30-
def accelerometer(self) -> MovementValues:
30+
def acceleration(self) -> MovementValues:
3131
"""
3232
Returns:
3333
MovementValues: The acceleration values in the x, y, and z axes.
@@ -38,7 +38,17 @@ def accelerometer(self) -> MovementValues:
3838
return MovementValues(sensor_values[0], sensor_values[1], sensor_values[2])
3939

4040
@property
41-
def gyro(self) -> MovementValues:
41+
def acceleration_magnitude(self) -> float:
42+
"""
43+
Returns:
44+
float: The magnitude of the acceleration vector in g.
45+
When the Modulino is at rest (on planet earth), this value should be approximately 1.0g due to gravity.
46+
"""
47+
x, y, z = self.accelerometer
48+
return (x**2 + y**2 + z**2) ** 0.5
49+
50+
@property
51+
def angular_velocity(self) -> MovementValues:
4252
"""
4353
Returns:
4454
MovementValues: The gyroscope values in the x, y, and z axes.

0 commit comments

Comments
 (0)