This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
forked from StefanPitur/AstroPi-ESA-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.py
192 lines (147 loc) · 3.75 KB
/
program.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#### Libraries #####
from sense_hat import SenseHat
from datetime import datetime
from time import sleep
from math import sqrt
##### Logging Settings #####
FILENAME = ""
WRITE_FREQUENCY = 1
##### Variable #####
sense = SenseHat()
sense.clear()
g=[0,200,0]
initial = [
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g,
g,g,g,g,g,g,g,g
]
r = [255,0,0]
w = [0,0,0]
y = [255,255,0]
aurora = [
w,w,w,r,r,w,w,w,
w,w,w,r,r,w,w,w,
w,w,w,r,r,w,w,w,
w,w,w,r,r,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,
w,w,w,r,r,w,w,w,
w,w,w,r,r,w,w,w
]
here = [
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y,
y,y,y,y,y,y,y,y
]
sense.set_pixels(initial)
hi = 50 # trebuie modificata pentru valorile de pe ISS
##### Functions #####
def log_data():
output_string = ",".join( str(value) for value in sense_data )
batch_data.append(output_string)
def file_setup(filename):
header = ["row_id","temp_h","temp_p",
"humidity","pressure",
"pitch","roll","yaw",
"mag_x","mag_y","mag_z",
"accel_x","accel_y","accel_z",
"gyro_x","gyro_y","gyro_z",
"timestamp"]
with open(filename,"w") as f:
f.write(",".join(str(value) for value in header)+ "\n")
def get_sense_data(numar): # collecting data
sense_data=[]
sense_data.append(numar)
sense_data.append(sense.get_temperature_from_humidity())
sense_data.append(sense.get_temperature_from_pressure())
sense_data.append(sense.get_humidity())
sense_data.append(sense.get_pressure())
o = sense.get_orientation()
yaw = o["yaw"]
pitch = o["pitch"]
roll = o["roll"]
sense_data.extend([pitch,roll,yaw])
mag = sense.get_compass_raw()
mag_x = mag["x"]
mag_y = mag["y"]
mag_z = mag["z"]
sense_data.extend([mag_x,mag_y,mag_z])
acc = sense.get_accelerometer_raw()
x = acc["x"]
y = acc["y"]
z = acc["z"]
sense_data.extend([x,y,z])
gyro = sense.get_gyroscope_raw()
gyro_x = gyro["x"]
gyro_y = gyro["y"]
gyro_z = gyro["z"]
sense_data.extend([gyro_x,gyro_y,gyro_z])
sense_data.append(datetime.now())
return sense_data
##### Main Program #####
sense = SenseHat()
batch_data = []
numar = 1
if FILENAME == "":
filename = "SenseLog-"+str(datetime.now())+".csv"
else:
filename = FILENAME +"-"+str(datetime.now())+".csv"
file_setup(filename)
human=0
while True:
acceleration = sense.get_accelerometer_raw()
h = sense.get_humidity()
h = round( h , 5 )
print(h)
x = acceleration['x']
y = acceleration['y']
z = acceleration['z']
x = abs(x)
y = abs(y)
z = abs(z)
x = round(x, 3)
y = round(y, 3)
z = round(z, 3)
dh=h-hi
if h == hi :
sense.set_pixels(initial)
human = 0
if dh >= 2 and human == 0:
sense.show_message("We got you!")
sense.set_pixels(here)
human = 1
if x > 1 or y > 1 or z > 1 and human == 0:
sense.show_message("We got you!")
sense.set_pixels(here)
human = 1
mg = sense.get_compass_raw()
x = mg['x']
y = mg['y']
z = mg['z']
B = x*x + y*y + z*z
B = sqrt(B)
if B > 55:
sense.set_pixels(aurora)
else:
if B<55 and human == 1:
sense.set_pixels(here)
sleep(1)
sense_data = get_sense_data(numar)
numar = numar + 1
log_data()
if len(batch_data) >= WRITE_FREQUENCY:
print("Writing to file ... ")
with open(filename,"a") as f:
for line in batch_data:
f.write(line + "\n")
batch_data = []