This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathacquire.py
executable file
·79 lines (75 loc) · 1.97 KB
/
acquire.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
#!/usr/bin/python
# -*- coding: utf-8 -*
import numpy as np
from Communication import bserver,tcp_server
from misc import isNaN,shape_dict
######################################################
# This module contains all the functions for getting data
#
# getdata_file :read data from the specific file
# getdata_b :start bluetooth server and getdata
# getdata_tcp :get data via WiFi or internet
# get_train_data :get data for training which may return
# the input and target as out put
######################################################
def getdata_file(a):
from os import getcwd,chdir,path
input=open(a)
if path.basename(getcwd()) != 'Shapes':
chdir('Shapes')
data=[]
for line in input:
line=line[0:line.find('\n')]
for val in line.split(' '):
if not isNaN(val):
data.append(float(val))
data=np.reshape(data,[-1,3])
data[:,1]=data[:,1]-9.8
data[:,2]= 1
return data
#read data from bluwtooth instead of file
def getdata_b():
data=[]
try:
data=bserver()
except:
data=[0,0,0]
finally:
return data
#getdata via tcp
def getdata_tcp():
data=[]
try:
data=tcp_server()
except:
data=[0,0,0]
finally:
print data
return data
########################################################
# the data will be send to the calling function as
# two list of data one indicating the input
# while thw other is indicating the output target
# input n*14 and output n
#######################################################
def get_train_data():
from os import listdir,chdir,remove,rename
from filtering import filter_xyz
from clustering import cluster
table=shape_dict()
in_put=[]
target=[]
chdir('./Shapes')
for i in listdir('.'):
try:
data=getdata_file(i)
data=filter_xyz(data)
data14=cluster(data,14);
in_put.append(data14)
target.append(table[i[0]])
except:
print '\t\t\tERROR in file ',i,'removing ',i
remove(i)
pass
chdir('..')
return in_put,target