Skip to content

Commit 0f446db

Browse files
committed
tweaks, docs
1 parent c31682a commit 0f446db

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ Usage Example
6868
uart = busio.UART(board.TX, board.RX, baudrate=115200, receiver_buffer_size=2048)
6969
rvc = BNO08x_RVC(uart)
7070
while True:
71-
print("Roll: %2.2f Pitch: %2.2f Yaw: %2.2f Degrees Accel-X: %2.2f Accel-Y: %2.2f Accel-Z: %2.2f m/s^2"%rvc.heading)
71+
roll, pitch, yaw, x_accel, y_accel, z_accel = rvc.heading
72+
print("Roll: %2.2f Pitch: %2.2f Yaw: %2.2f Degrees" % (roll, pitch, yaw))
73+
print("Acceleration X: %2.2f Y: %2.2f Z: %2.2f m/s^2" % (x_accel, y_accel, z_accel))
74+
print("")
7275
time.sleep(0.1)
7376
7477
Contributing

adafruit_bno08x_rvc.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
A simple helper library for using the UART-RVC mode of the BNO08x IMUs
88
9-
109
* Author(s): Bryan Siepert
1110
1211
Implementation Notes
@@ -15,40 +14,59 @@
1514
**Hardware:**
1615
1716
* `Adafruit BNO08x Breakout <https:www.adafruit.com/products/4754>`_
17+
1818
**Software and Dependencies:**
1919
2020
* Adafruit CircuitPython firmware for the supported boards:
2121
https://github.com/adafruit/circuitpython/releases
22-
22+
2323
"""
2424
import time
2525
from struct import unpack_from
2626

2727
__version__ = "0.0.0-auto.0"
2828
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BNO08x_RVC.git"
2929

30+
3031
class RVCReadTimeoutError(Exception):
3132
"""Raised if a UART-RVC message cannot be read before the given timeout"""
3233

34+
3335
class BNO08x_RVC:
36+
"""A simple class for reading heading from the BNO08x IMUs using the UART-RVC mode"""
37+
3438
def __init__(self, uart, timeout=1.0):
3539
self._uart = uart
36-
self._debug=True
40+
self._debug = True
3741
self._read_timeout = timeout
3842

39-
def _parse_frame(self, frame):
43+
@staticmethod
44+
def _parse_frame(frame):
4045
heading_frame = unpack_from("<BhhhhhhBBBB", frame)
41-
_index, yaw, roll, pitch, x_accel, y_accel, z_accel, _res1, _res2, _res3, _checksum = heading_frame
42-
checksum_calc = sum(frame[0:16])%256
46+
(
47+
_index,
48+
yaw,
49+
roll,
50+
pitch,
51+
x_accel,
52+
y_accel,
53+
z_accel,
54+
_res1,
55+
_res2,
56+
_res3,
57+
_checksum,
58+
) = heading_frame
59+
checksum_calc = sum(frame[0:16]) % 256
4360
if checksum_calc != _checksum:
4461
return None
4562
yaw *= 0.01
4663
roll *= 0.01
4764
pitch *= 0.01
48-
x_accel *= 0.0098067
49-
y_accel *= 0.0098067
50-
z_accel *= 0.0098067
65+
x_accel *= 0.0098067
66+
y_accel *= 0.0098067
67+
z_accel *= 0.0098067
5168
return (yaw, roll, pitch, x_accel, y_accel, z_accel)
69+
5270
@property
5371
def heading(self):
5472
"""The current heading made up of
@@ -64,7 +82,7 @@ def heading(self):
6482
# try to read initial packet start byte
6583
data = None
6684
start_time = time.monotonic()
67-
while time.monotonic()-start_time < self._read_timeout:
85+
while time.monotonic() - start_time < self._read_timeout:
6886
data = self._uart.read(2)
6987
# print("data", data)
7088
if data[0] == 0xAA and data[1] == 0xAA:
@@ -73,4 +91,4 @@ def heading(self):
7391
if heading is None:
7492
continue
7593
return heading
76-
raise RVCReadTimeoutError("Unable to read RVC heading message")
94+
raise RVCReadTimeoutError("Unable to read RVC heading message")

docs/index.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
34-
3529
.. toctree::
3630
:caption: Other Links
3731

examples/bno08x_rvc_simpletest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
uart = busio.UART(board.TX, board.RX, baudrate=115200, receiver_buffer_size=2048)
1010
rvc = BNO08x_RVC(uart)
1111
while True:
12-
print("Roll: %2.2f Pitch: %2.2f Yaw: %2.2f Degrees Accel-X: %2.2f Accel-Y: %2.2f Accel-Z: %2.2f m/s^2"%rvc.heading)
12+
roll, pitch, yaw, x_accel, y_accel, z_accel = rvc.heading
13+
print("Roll: %2.2f Pitch: %2.2f Yaw: %2.2f Degrees" % (roll, pitch, yaw))
14+
print("Acceleration X: %2.2f Y: %2.2f Z: %2.2f m/s^2" % (x_accel, y_accel, z_accel))
15+
print("")
1316
time.sleep(0.1)
14-

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
# Author details
3535
author="Adafruit Industries",
3636
author_email="[email protected]",
37-
install_requires=[
38-
"Adafruit-Blinka",
39-
],
37+
install_requires=["Adafruit-Blinka",],
4038
# Choose your license
4139
license="MIT",
4240
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
@@ -52,7 +50,7 @@
5250
],
5351
# What does your project relate to?
5452
keywords="adafruit blinka circuitpython micropython bno08x_rvc IMU RVC UART Hillcrest "
55-
"Laboratories Sensor Fusion Heading AHRS",
53+
"Laboratories Sensor Fusion Heading AHRS",
5654
# You can just specify the packages manually here if your project is
5755
# simple. Or you can use find_packages().
5856
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,

0 commit comments

Comments
 (0)