This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
101 lines (76 loc) · 2.5 KB
/
test.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
from enum import Enum
from utils import *
class State(Enum):
NORMAL = 0,
FALLING = 1,
ON_GROUND = 2,
CHIA_DUH = 3
if __name__ == "__main__":
MPU_Init()
print (" Reading Data of Gyroscope and Accelerometer")
state = State.NORMAL
# Read Accelerometer raw value
acc_x = read_raw_data(ACCEL_XOUT_H)
acc_y = read_raw_data(ACCEL_YOUT_H)
acc_z = read_raw_data(ACCEL_ZOUT_H)
# Read Gyroscope raw value
gyro_x = read_raw_data(GYRO_XOUT_H)
gyro_y = read_raw_data(GYRO_YOUT_H)
gyro_z = read_raw_data(GYRO_ZOUT_H)
# Full scale range +/- 250 degree/C as per sensitivity scale factor
Gx = gyro_x/131.0
Gy = gyro_y/131.0
Gz = gyro_z/131.0
# Ax = acc_x/16384.0
# Ay = acc_y/16384.0
# Az = acc_z/16384.0
Ax = acc_x/2048.0
Ay = acc_y/2048.0
Az = acc_z/2048.0
# gyro
gx_off = Gx
gy_off = Gy
gz_off = Gz
# accel
ax_off = 0
ay_off = 0
az_off = 0
gyro_y_abs = 0
while True:
prev_state = state
# Read Accelerometer raw value
acc_x = read_raw_data(ACCEL_XOUT_H)
acc_y = read_raw_data(ACCEL_YOUT_H)
acc_z = read_raw_data(ACCEL_ZOUT_H)
# Read Gyroscope raw value
gyro_x = read_raw_data(GYRO_XOUT_H)
gyro_y = read_raw_data(GYRO_YOUT_H)
gyro_z = read_raw_data(GYRO_ZOUT_H)
# Full scale range +/- 250 degree/C as per sensitivity scale factor
Gx = gyro_x/131.0 - gx_off
Gy = gyro_y/131.0 - gy_off
Gz = gyro_z/131.0 - gz_off
# Ax = acc_x/16384.0
# Ay = acc_y/16384.0
# Az = acc_z/16384.0
Ax = acc_x/4096.0 - ax_off
Ay = acc_y/4096.0 - ay_off
Az = acc_z/4096.0 - az_off
gravity = (Ax ** 2 + Ay ** 2 + Az ** 2) ** 0.5
# print(f"{Ax:.2f} {Ay:.2f} {Az:.2f} {gravity:.2f}", end="\n")
# print(f"{state.name}", end="\r")
# if gravity < 0.2:
# requests.post(WEBHOOK_URL, json={
# "content": "i'm falling ><" + f"g={Ax}cg",
# "username": "TX2",
# "avatar_url": JENSEN_URL
# })
if abs(Gy) > 0.5:
gyro_y_abs += Gy
print(f"gyro y abs: {gyro_y_abs}")
# system("clear")
# print(f"Gx={Gx:+03.2f} deg/s \nGy={Gy:+03.2f} deg/s \nGz={Gz:+03.2f} deg/s")
# print(f"Ax={Ax:+03.2f} g \nAy={Ay:+03.2f} g \nAz={Az:+03.2f} g", end="\n")
sleep(0.1)
# if gravity > 5:
# print(f"gravity: {gravity:.2f}")