Skip to content

Commit c379369

Browse files
committed
har_trees: Actually use windowed data
Was just using the last hop of data for feature processing This caused erratic feature values and classification results
1 parent 18f5703 commit c379369

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

examples/har_trees/har_live.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import machine
23
from machine import Pin, I2C
34
from mpu6886 import MPU6886
45

@@ -14,6 +15,11 @@ def mean(arr):
1415
m = sum(arr) / float(len(arr))
1516
return m
1617

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+
1723
def main():
1824

1925
dataset = 'har_exercise_1'
@@ -50,6 +56,10 @@ def main():
5056
z_values = empty_array('h', hop_length)
5157
windower = TriaxialWindower(window_length)
5258

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+
5363
features_typecode = timebased.DATA_TYPECODE
5464
n_features = timebased.N_FEATURES
5565
features = array.array(features_typecode, (0 for _ in range(n_features)))
@@ -66,18 +76,24 @@ def main():
6676
if windower.full():
6777
# compute features
6878
#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))
7085
for i, f in enumerate(ff):
7186
features[i] = int(f)
7287

7388
# Cun classifier
89+
#print(features)
7490
result = model.predict(features)
7591
activity = class_index_to_name[result]
7692

7793
d = time.ticks_diff(time.ticks_ms(), start)
7894
print('class', activity, d)
7995

80-
time.sleep_ms(1)
96+
machine.lightsleep(100)
8197

8298

8399
if __name__ == '__main__':

0 commit comments

Comments
 (0)