-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbno08x_more_reports.py
executable file
·163 lines (146 loc) · 5.32 KB
/
bno08x_more_reports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
import busio
import adafruit_bno08x
from adafruit_bno08x.i2c import BNO08X_I2C
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)
bno = BNO08X_I2C(i2c)
ALT_METHOD = True # use feature loop with delay vs list
if ALT_METHOD:
bno.begin_calibration()
time.sleep(0.01)
_features = [
adafruit_bno08x.BNO_REPORT_ACCELEROMETER,
adafruit_bno08x.BNO_REPORT_GYROSCOPE,
adafruit_bno08x.BNO_REPORT_MAGNETOMETER,
adafruit_bno08x.BNO_REPORT_LINEAR_ACCELERATION,
adafruit_bno08x.BNO_REPORT_ROTATION_VECTOR,
adafruit_bno08x.BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR,
adafruit_bno08x.BNO_REPORT_GAME_ROTATION_VECTOR,
adafruit_bno08x.BNO_REPORT_STEP_COUNTER,
adafruit_bno08x.BNO_REPORT_STABILITY_CLASSIFIER,
adafruit_bno08x.BNO_REPORT_ACTIVITY_CLASSIFIER,
adafruit_bno08x.BNO_REPORT_SHAKE_DETECTOR,
adafruit_bno08x.BNO_REPORT_RAW_ACCELEROMETER,
adafruit_bno08x.BNO_REPORT_RAW_GYROSCOPE,
adafruit_bno08x.BNO_REPORT_RAW_MAGNETOMETER
]
for feature in _features:
print('feature {}'.format(feature))
bno.enable_feature(feature)
time.sleep(0.01)
else:
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ACCELEROMETER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GYROSCOPE)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_MAGNETOMETER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_LINEAR_ACCELERATION)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ROTATION_VECTOR)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_GAME_ROTATION_VECTOR)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_STEP_COUNTER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_STABILITY_CLASSIFIER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_ACTIVITY_CLASSIFIER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_SHAKE_DETECTOR)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_RAW_ACCELEROMETER)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_RAW_GYROSCOPE)
bno.enable_feature(adafruit_bno08x.BNO_REPORT_RAW_MAGNETOMETER)
while True:
time.sleep(0.1)
print("Acceleration:")
accel_x, accel_y, accel_z = bno.acceleration # pylint:disable=no-member
print("X: %0.6f Y: %0.6f Z: %0.6f m/s^2" % (accel_x, accel_y, accel_z))
print("")
print("Gyro:")
gyro_x, gyro_y, gyro_z = bno.gyro # pylint:disable=no-member
print("X: %0.6f Y: %0.6f Z: %0.6f rads/s" % (gyro_x, gyro_y, gyro_z))
print("")
print("Magnetometer:")
mag_x, mag_y, mag_z = bno.magnetic # pylint:disable=no-member
print("X: %0.6f Y: %0.6f Z: %0.6f uT" % (mag_x, mag_y, mag_z))
print("")
print("Linear Acceleration:")
(
linear_accel_x,
linear_accel_y,
linear_accel_z,
) = bno.linear_acceleration # pylint:disable=no-member
print(
"X: %0.6f Y: %0.6f Z: %0.6f m/s^2"
% (linear_accel_x, linear_accel_y, linear_accel_z)
)
print("")
print("Rotation Vector Quaternion:")
quat_i, quat_j, quat_k, quat_real = bno.quaternion # pylint:disable=no-member
print(
"I: %0.6f J: %0.6f K: %0.6f Real: %0.6f" % (quat_i, quat_j, quat_k, quat_real)
)
print("")
print("Geomagnetic Rotation Vector Quaternion:")
(
geo_quat_i,
geo_quat_j,
geo_quat_k,
geo_quat_real,
) = bno.geomagnetic_quaternion # pylint:disable=no-member
print(
"I: %0.6f J: %0.6f K: %0.6f Real: %0.6f"
% (geo_quat_i, geo_quat_j, geo_quat_k, geo_quat_real)
)
# print("")
print("Game Rotation Vector Quaternion:")
(
game_quat_i,
game_quat_j,
game_quat_k,
game_quat_real,
) = bno.game_quaternion # pylint:disable=no-member
print(
"I: %0.6f J: %0.6f K: %0.6f Real: %0.6f"
% (game_quat_i, game_quat_j, game_quat_k, game_quat_real)
)
print("")
print("Steps detected:", bno.steps)
print("")
print("Stability classification:", bno.stability_classification)
print("")
activity_classification = bno.activity_classification
most_likely = activity_classification["most_likely"]
print(
"Activity classification:",
most_likely,
"confidence: %d/100" % activity_classification[most_likely],
)
print("Raw Acceleration:")
(raw_accel_x, raw_accel_y, raw_accel_z,) = bno.raw_acceleration
print(
"X: 0x{0:04X} Y: 0x{1:04X} Z: 0x{2:04X} LSB".format(
raw_accel_x, raw_accel_y, raw_accel_z
)
)
print("")
print("Raw Gyro:")
(raw_accel_x, raw_accel_y, raw_accel_z,) = bno.raw_gyro
print(
"X: 0x{0:04X} Y: 0x{1:04X} Z: 0x{2:04X} LSB".format(
raw_accel_x, raw_accel_y, raw_accel_z
)
)
print("")
print("Raw Magnetometer:")
(raw_mag_x, raw_mag_y, raw_mag_z,) = bno.raw_magnetic
print(
"X: 0x{0:04X} Y: 0x{1:04X} Z: 0x{2:04X} LSB".format(
raw_mag_x, raw_mag_y, raw_mag_z
)
)
print("")
time.sleep(0.4)
if bno.shake:
print("SHAKE DETECTED!")
print("")