From 350d313db30cd845204f722b57187feb08f52822 Mon Sep 17 00:00:00 2001 From: siddacious Date: Thu, 16 Apr 2020 15:21:00 -0700 Subject: [PATCH 1/3] BREAKING CHANGE - change from dps->rads for gyro to fix #9 --- README.rst | 2 +- adafruit_lsm6ds.py | 9 +- examples/lsm6ds_full_test.py | 2 +- examples/lsm6ds_ism330dhct_simpletest.py | 2 +- examples/lsm6ds_lsm6ds33_simpletest.py | 2 +- examples/lsm6ds_lsm6dsox_simpletest.py | 2 +- register_map.json | 118 ----------------------- 7 files changed, 10 insertions(+), 127 deletions(-) delete mode 100644 register_map.json diff --git a/README.rst b/README.rst index 3d416f6..f5ac48f 100644 --- a/README.rst +++ b/README.rst @@ -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) diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index 436e670..b37a4d5 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -95,6 +95,7 @@ _LSM6DS_TAP_CFG = const(0x58) _MILLI_G_TO_ACCEL = 0.00980665 +_DPS_TO_RADS = 0.017453293 class CV: @@ -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 + 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) diff --git a/examples/lsm6ds_full_test.py b/examples/lsm6ds_full_test.py index d455f2e..2c89ad0 100644 --- a/examples/lsm6ds_full_test.py +++ b/examples/lsm6ds_full_test.py @@ -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) diff --git a/examples/lsm6ds_ism330dhct_simpletest.py b/examples/lsm6ds_ism330dhct_simpletest.py index e6a99ec..a5fca83 100644 --- a/examples/lsm6ds_ism330dhct_simpletest.py +++ b/examples/lsm6ds_ism330dhct_simpletest.py @@ -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) diff --git a/examples/lsm6ds_lsm6ds33_simpletest.py b/examples/lsm6ds_lsm6ds33_simpletest.py index ccb3e35..c4b4fed 100644 --- a/examples/lsm6ds_lsm6ds33_simpletest.py +++ b/examples/lsm6ds_lsm6ds33_simpletest.py @@ -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) diff --git a/examples/lsm6ds_lsm6dsox_simpletest.py b/examples/lsm6ds_lsm6dsox_simpletest.py index b2355d5..961a679 100644 --- a/examples/lsm6ds_lsm6dsox_simpletest.py +++ b/examples/lsm6ds_lsm6dsox_simpletest.py @@ -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) diff --git a/register_map.json b/register_map.json deleted file mode 100644 index 2d67414..0000000 --- a/register_map.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "sensor_name": "LSM6DS0X", - "default_address": 106, - "registers": { - "FUNC_CFG_ACCESS" : { - "address" : "01h", - "fields" :[ - "FUNC_CFG_ACCESS", - "SHUB_REG_ACCESS", - null, - null, - null, - null, - null, - "OIS_CTRL_FROM_UI" - ] - }, - "PIN_CTRL": { - "address" : "02h", - "fields" : ["OIS_PU_DIS","SDO_PU_EN", null, null, null, null, null, null] - }, - "UI_INT_OIS": { - "address": "6Fh", - "fields" : ["INT2_DRDY_OIS", "LVL2_OIS", "DEN_LH_OIS", null, "SPI2_READ_EN", null, null, null] - }, - "WHOAMI": { - "address": "0Fh", - "length" : 1, - "format_str" : ">b", - "human_name" : "chip_id" - }, - "CTRL1_XL": { - "address" : "10h", - "fields" :["ODR_XL3", "ODR_XL2", "ODR_XL1", "ODR_XL0", "FS1_XL", "FS0_XL", "LPF2_XL_EN", null] - }, - "CTRL2_G": { - "address" : "11h", - "fields" :["ODR_G3", "ODR_G2", "ODR_G1", "ODR_G0", "FS1_G", "FS0_G", "FS_125", null], - "cvs" : { - "ODR": [ - ["250 DPS", 0], - ["500 DPS", 1], - ["1000 DPS", 2], - ["2000 DPS", 3] - ] - - } - }, - "CTRL3_C": { - "address" : "12h", - "fields":["BOOT", "BDU", "H_LACTIVE", "PP_OD", "SIM", "IF_INC", null, "SW_RESET"] - }, - "CTRL_5_C" : { - "address" : "14h", - "fields" : [ - - "XL_ULP_EN", - "ROUNDING1", - "ROUNDING0", - "ROUNDING_STATUS", - "ST1_G", - "ST0_G", - "ST1_XL", - "ST0_XL" - - ] - }, - "MASTER_CONFIG": { - "address" : "14h", - "fields" : [ - "RST_MASTER_REGS", - "WRITE_ONCE", - "START_CONFIG", - "PASS_THROUGH_MODE", - "SHUB_PU_EN", - "MASTER_ON", - "AUX_SENS_ON1", - "AUX_SENS_ON0" - ] - }, - "CTRL9_XL" : { - "address" : "18h", - "fields" : [ - "DEN_X", - "DEN_Y", - "DEN_Z", - "DEN_XL_G", - "DEN_XL_EN", - "DEN_LH", - "I3C_DISABLE", - null - ] - }, - "OUT_TEMP_L": { - "address": "20h", - "format_str" : " Date: Mon, 20 Apr 2020 13:27:35 -0700 Subject: [PATCH 2/3] switch to math.radians --- adafruit_lsm6ds.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index b37a4d5..c2a6fa3 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -50,6 +50,7 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" from time import sleep from micropython import const +from math import radians import adafruit_bus_device.i2c_device as i2c_device from adafruit_register.i2c_struct import ROUnaryStruct, Struct from adafruit_register.i2c_bits import RWBits @@ -95,7 +96,6 @@ _LSM6DS_TAP_CFG = const(0x58) _MILLI_G_TO_ACCEL = 0.00980665 -_DPS_TO_RADS = 0.017453293 class CV: @@ -296,10 +296,7 @@ def acceleration(self): def gyro(self): """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]) * _DPS_TO_RADS - y = self._scale_gyro_data(raw_gyro_data[1]) * _DPS_TO_RADS - z = self._scale_gyro_data(raw_gyro_data[2]) * _DPS_TO_RADS - + x, y, z = [radians(self._scale_gyro_data(i)) for i in raw_gyro_data] return (x, y, z) def _scale_xl_data(self, raw_measurement): From 472b71b21c5eacb62dc93ab3df5db926e16fa4a5 Mon Sep 17 00:00:00 2001 From: siddacious Date: Mon, 20 Apr 2020 13:28:41 -0700 Subject: [PATCH 3/3] fix import order --- adafruit_lsm6ds.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_lsm6ds.py b/adafruit_lsm6ds.py index c2a6fa3..3671121 100644 --- a/adafruit_lsm6ds.py +++ b/adafruit_lsm6ds.py @@ -49,8 +49,8 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" from time import sleep -from micropython import const from math import radians +from micropython import const import adafruit_bus_device.i2c_device as i2c_device from adafruit_register.i2c_struct import ROUnaryStruct, Struct from adafruit_register.i2c_bits import RWBits