-
Notifications
You must be signed in to change notification settings - Fork 2
/
realtime.py
50 lines (45 loc) · 1.62 KB
/
realtime.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
import serial
import main
import dataprocessing
from scipy.interpolate import interp1d
import time
serialport = serial.Serial("/dev/ttyACM0", 9600, timeout=0.5)
readbuffer = ""
datacollectionarray = []
maxdatasize = 15000
sampletake_secoonds = 20
main.initialize_classifier()
m = interp1d([0,1023],[0,720])
while True:
start = time.time()
while True:
command = serialport.read()
if command == " ":
continue
if command == "\n" or command == "\r":
# if maxdatasize == len(datacollectionarray):
# print "Flushing collected data", datacollectionarray
# # preprocessed = icatest.preprocess_data_array(datacollectionarray)
# extracted = dataprocessing.find_signals(datacollectionarray)
# result = icatest.classify(extracted)
# print result
# datacollectionarray = []
stripped = readbuffer.strip()
if stripped != '':
mappedvalue = int(stripped)/4
try:
mappedvalue = float(m(mappedvalue))
except:
continue
datacollectionarray.append(mappedvalue)
print mappedvalue
readbuffer = ""
continue
readbuffer+=command
if time.time() - start > sampletake_secoonds:
print "Flushing collected data", len(datacollectionarray)
extracted = dataprocessing.find_signals(datacollectionarray)
result = main.classify(extracted)
print result
datacollectionarray = []
break