1
1
2
+ import machine
2
3
from machine import Pin , I2C
3
4
from mpu6886 import MPU6886
4
5
@@ -14,6 +15,11 @@ def mean(arr):
14
15
m = sum (arr ) / float (len (arr ))
15
16
return m
16
17
18
+ def copy_array_into (source , target ):
19
+ assert len (source ) == len (target )
20
+ for i in range (len (target )):
21
+ target [i ] = source [i ]
22
+
17
23
def main ():
18
24
19
25
dataset = 'har_exercise_1'
@@ -50,6 +56,10 @@ def main():
50
56
z_values = empty_array ('h' , hop_length )
51
57
windower = TriaxialWindower (window_length )
52
58
59
+ x_window = empty_array ('h' , window_length )
60
+ y_window = empty_array ('h' , window_length )
61
+ z_window = empty_array ('h' , window_length )
62
+
53
63
features_typecode = timebased .DATA_TYPECODE
54
64
n_features = timebased .N_FEATURES
55
65
features = array .array (features_typecode , (0 for _ in range (n_features )))
@@ -66,18 +76,24 @@ def main():
66
76
if windower .full ():
67
77
# compute features
68
78
#print('xyz', mean(x_values), mean(y_values), mean(z_values))
69
- ff = timebased .calculate_features_xyz ((x_values , y_values , z_values ))
79
+
80
+ copy_array_into (windower .x_values , x_window )
81
+ copy_array_into (windower .y_values , y_window )
82
+ copy_array_into (windower .z_values , z_window )
83
+
84
+ ff = timebased .calculate_features_xyz ((x_window , y_window , z_window ))
70
85
for i , f in enumerate (ff ):
71
86
features [i ] = int (f )
72
87
73
88
# Cun classifier
89
+ #print(features)
74
90
result = model .predict (features )
75
91
activity = class_index_to_name [result ]
76
92
77
93
d = time .ticks_diff (time .ticks_ms (), start )
78
94
print ('class' , activity , d )
79
95
80
- time . sleep_ms ( 1 )
96
+ machine . lightsleep ( 100 )
81
97
82
98
83
99
if __name__ == '__main__' :
0 commit comments