Skip to content

change from dps->rads for gyro to fix #9 #14

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 3 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Usage Example
while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2"%(sox.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s"%(sox.gyro))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s"%(sox.gyro))
print("")
time.sleep(0.5)
Expand Down
9 changes: 5 additions & 4 deletions adafruit_lsm6ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
_LSM6DS_TAP_CFG = const(0x58)

_MILLI_G_TO_ACCEL = 0.00980665
_DPS_TO_RADS = 0.017453293


class CV:
Expand Down Expand Up @@ -293,11 +294,11 @@ def acceleration(self):

@property
def gyro(self):
"""The x, y, z angular velocity values returned in a 3-tuple and are in degrees / second"""
"""The x, y, z angular velocity values returned in a 3-tuple and are in radians / second"""
raw_gyro_data = self._raw_gyro_data
x = self._scale_gyro_data(raw_gyro_data[0])
y = self._scale_gyro_data(raw_gyro_data[1])
z = self._scale_gyro_data(raw_gyro_data[2])
x = self._scale_gyro_data(raw_gyro_data[0]) * _DPS_TO_RADS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use math.radians(self._scale_gyro_data....) instead, and lose the _DPS_TO_RADS constant. math.radians() is standard in Python and I checked for its presence in CircuitPython.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siddacious try a x, y, z = [math.radians(self._scale_gyro_data(i)) for in raw_gyro_data]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

y = self._scale_gyro_data(raw_gyro_data[1]) * _DPS_TO_RADS
z = self._scale_gyro_data(raw_gyro_data[2]) * _DPS_TO_RADS

return (x, y, z)

Expand Down
2 changes: 1 addition & 1 deletion examples/lsm6ds_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

while True:
print(
"Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f degrees/s"
"Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f radians/s"
% (sensor.acceleration + sensor.gyro)
)
time.sleep(0.05)
2 changes: 1 addition & 1 deletion examples/lsm6ds_ism330dhct_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s" % (sensor.gyro))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
print("")
time.sleep(0.5)
2 changes: 1 addition & 1 deletion examples/lsm6ds_lsm6ds33_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s" % (sensor.gyro))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
print("")
time.sleep(0.5)
2 changes: 1 addition & 1 deletion examples/lsm6ds_lsm6dsox_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s" % (sensor.gyro))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
print("")
time.sleep(0.5)
118 changes: 0 additions & 118 deletions register_map.json

This file was deleted.