-
Notifications
You must be signed in to change notification settings - Fork 0
/
imuExample.py
46 lines (34 loc) · 1.28 KB
/
imuExample.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
import time
import board
import busio
from adafruit_icm20649 import ICM20649, AccelRange, GyroRange
def printNewMax(value, current_max, axis):
if value > current_max:
current_max = value
print(axis, "Max:", current_max)
return current_max
# pylint:disable=no-member
i2c = busio.I2C(board.SCL, board.SDA)
ism = ICM20649(i2c)
ism.accelerometer_range = AccelRange.RANGE_30G
print("Accelerometer range set to: %d G" % AccelRange.string[ism.accelerometer_range])
ism.gyro_range = GyroRange.RANGE_500_DPS
print("Gyro range set to: %d DPS" % GyroRange.string[ism.gyro_range])
ax_max = ay_max = az_max = 0
gx_max = gy_max = gz_max = 0
ism.gyro_data_rate = 125
ism.accelerometer_data_rate = 4095
st = time.monotonic()
while time.monotonic() - st < 0.250:
print(
"Accel X:%.2f Y:%.2f Z:%.2f ms^2 Gyro X:%.2f Y:%.2f Z:%.2f degrees/s"
% (ism.acceleration + ism.gyro)
)
# acceleration = ism.acceleration
# # ax_max = printNewMax(acceleration[0], ax_max, "AX")
# # ay_max = printNewMax(acceleration[1], ay_max, "AY")
# # az_max = printNewMax(acceleration[2], az_max, "AZ")
# gyro = ism.gyro
# # gx_max = printNewMax(gyro[0], gx_max, "GX")
# # gy_max = printNewMax(gyro[1], gy_max, "GY")
# # gz_max = printNewMax(gyro[2], gz_max, "GZ")