Skip to content

Commit 27e4038

Browse files
authored
Merge pull request #40 from EthChil/gravity
added gravity vector validated with BNO085
2 parents bcbde08 + 4046c60 commit 27e4038

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

adafruit_bno08x/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
BNO_REPORT_LINEAR_ACCELERATION = const(0x04)
8282
# Rotation Vector
8383
BNO_REPORT_ROTATION_VECTOR = const(0x05)
84+
# Gravity Vector (m/s2). Vector direction of gravity
85+
BNO_REPORT_GRAVITY = const(0x06)
86+
# Game Rotation Vector
8487
BNO_REPORT_GAME_ROTATION_VECTOR = const(0x08)
8588

8689
BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR = const(0x09)
@@ -139,6 +142,7 @@
139142
}
140143
_AVAIL_SENSOR_REPORTS = {
141144
BNO_REPORT_ACCELEROMETER: (_Q_POINT_8_SCALAR, 3, 10),
145+
BNO_REPORT_GRAVITY: (_Q_POINT_8_SCALAR, 3, 10),
142146
BNO_REPORT_GYROSCOPE: (_Q_POINT_9_SCALAR, 3, 10),
143147
BNO_REPORT_MAGNETOMETER: (_Q_POINT_4_SCALAR, 3, 10),
144148
BNO_REPORT_LINEAR_ACCELERATION: (_Q_POINT_8_SCALAR, 3, 10),
@@ -370,15 +374,6 @@ def _separate_batch(packet, report_slices):
370374
next_byte_index = next_byte_index + required_bytes
371375

372376

373-
# class Report:
374-
# _buffer = bytearray(DATA_BUFFER_SIZE)
375-
# _report_obj = Report(_buffer)
376-
377-
# @classmethod
378-
# def get_report(cls)
379-
# return cls._report_obj
380-
381-
382377
class Packet:
383378
"""A class representing a Hillcrest LaboratorySensor Hub Transport packet"""
384379

@@ -597,6 +592,16 @@ def acceleration(self):
597592
except KeyError:
598593
raise RuntimeError("No accel report found, is it enabled?") from None
599594

595+
@property
596+
def gravity(self):
597+
"""A tuple representing the gravity vector in the X, Y, and Z components
598+
axes in meters per second squared"""
599+
self._process_available_packets()
600+
try:
601+
return self._readings[BNO_REPORT_GRAVITY]
602+
except KeyError:
603+
raise RuntimeError("No gravity report found, is it enabled?") from None
604+
600605
@property
601606
def gyro(self):
602607
"""A tuple representing Gyro's rotation measurements on the X, Y, and Z

0 commit comments

Comments
 (0)