Skip to content

Use angular momentum (rad/s) not acceleration #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2018
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
17 changes: 9 additions & 8 deletions adafruit_l3gd20.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ def __init__(self, rng=L3DS20_RANGE_250DPS):


@property
def acceleration(self):
def gyro(self):
"""
x, y, z acceleration tuple floats, rescaled appropriately for range selected
x, y, z angular momentum tuple floats, rescaled appropriately for
range selected
"""
raw = self.acceleration_raw
raw = self.gyro_raw
return tuple(self.scale*v for v in raw)


Expand All @@ -206,8 +207,8 @@ class L3GD20_I2C(L3GD20):
:param address: the optional device address, 0x68 is the default address
"""

acceleration_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, '<hhh')
"""Gives the raw acceleration readings, in units of the scaled mdps."""
gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, '<hhh')
"""Gives the raw gyro readings, in units of rad/s."""

def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
import adafruit_bus_device.i2c_device as i2c_device
Expand Down Expand Up @@ -283,7 +284,7 @@ def read_register(self, register):

def read_bytes(self, register, buffer):
"""
Low level register streem reading over SPI, returns a list of values
Low level register stream reading over SPI, returns a list of values

:param register: the register to read bytes
:param bytearray buffer: buffer to fill with data from stream
Expand All @@ -295,8 +296,8 @@ def read_bytes(self, register, buffer):
spi.readinto(buffer)

@property
def acceleration_raw(self):
"""Gives the raw acceleration readings, in units of the scaled mdps."""
def gyro_raw(self):
"""Gives the raw gyro readings, in units of rad/s."""
buffer = self._spi_bytearray6
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
return unpack('<hhh', buffer)
2 changes: 1 addition & 1 deletion examples/l3gd20_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)

while True:
print('Acceleration (m/s^2): {}'.format(SENSOR.acceleration))
print('Angular Momentum (rad/s): {}'.format(SENSOR.gyro))
print()
time.sleep(1)