Skip to content

Commit 92155c7

Browse files
authored
Merge pull request #23 from jposada202020/correcting_measuremnt_units
correcting_measurement_units
2 parents 58ab117 + 738ffe9 commit 92155c7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

adafruit_l3gd20.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_l3gd20.git"
3636

3737

38+
from math import radians
3839
from micropython import const
3940
from adafruit_register.i2c_struct import Struct
4041

@@ -195,10 +196,10 @@ def __init__(self, rng=L3DS20_RANGE_250DPS, rate=L3DS20_RATE_100HZ):
195196
def gyro(self):
196197
"""
197198
x, y, z angular momentum tuple floats, rescaled appropriately for
198-
range selected
199+
range selected in rad/s
199200
"""
200201
raw = self.gyro_raw
201-
return tuple(self.scale * v for v in raw)
202+
return tuple(radians(self.scale * v) for v in raw)
202203

203204

204205
class L3GD20_I2C(L3GD20):
@@ -364,7 +365,7 @@ def read_bytes(self, register, buffer):
364365

365366
@property
366367
def gyro_raw(self):
367-
"""Gives the raw gyro readings, in units of rad/s."""
368+
"""Gives the dynamic rate raw gyro readings, in units rad/s."""
368369
buffer = self._spi_bytearray6
369370
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
370-
return unpack("<hhh", buffer)
371+
return tuple(radians(x) for x in unpack("<hhh", buffer))

examples/l3gd20_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
# )
3939

4040
while True:
41-
print("Angular Momentum (rad/s): {}".format(SENSOR.gyro))
41+
print("Angular Velocity (rad/s): {}".format(SENSOR.gyro))
4242
print()
4343
time.sleep(1)

0 commit comments

Comments
 (0)