Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.33 KB | None | 0 0
  1. from sense_hat import SenseHat
  2. import time
  3. sense = SenseHat()
  4.  
  5. # Functions
  6. def Message(data, i):
  7. if i == -1:
  8. if data == 0:
  9. sense.show_message("Crew member detected", scroll_speed = 0.066)
  10. sense.set_pixels([
  11. e,e,e,e,e,e,e,e,
  12. e,w,w,e,e,w,w,e,
  13. e,w,w,e,e,w,w,e,
  14. e,e,e,e,e,e,e,e,
  15. e,w,e,e,e,e,w,e,
  16. e,w,e,e,e,e,w,e,
  17. e,w,w,w,w,w,w,e,
  18. e,e,e,e,e,e,e,e ])
  19. else:
  20. string = ["temperature", "humidity", "pressure"]
  21. if (data == 0):
  22. sense.show_message("no_variation_in: " + string[i])
  23. if (data == 1):
  24. sense.show_message("variation_at: +/-52 -- -/+52; in: " + string[i])
  25. if (data == 2):
  26. sense.show_message("variation_at: +/-52 -- 0; in: " + string[i])
  27. if (data == 3):
  28. sense.show_message("variation_at: +/-52 -- 0 -- -/+52; in: " + string[i])
  29.  
  30. def LoadingTime(number_of_times):
  31. sense.clear()
  32. for x in range(number_of_times):
  33. n = 1
  34. while n < 16:
  35. for i in range(n):
  36. for j in range(n):
  37. if i + j == n - 1 and i < 8 and j < 8:
  38. sense.set_pixel(i, j, image[2][i + j * 8][0], image[2][i + j * 8][1], image[2][i + j * 8][2])
  39. time.sleep(0.5)
  40. n += 1
  41. n = 1
  42. while n < 16:
  43. for i in range(n):
  44. for j in range(n):
  45. if i + j == n - 1 and i < 8 and j < 8:
  46. sense.set_pixel(i, j, e)
  47. time.sleep(0.5)
  48. n += 1
  49.  
  50. # Startup
  51. r = [255,0,0]
  52. o = [255,127,0]
  53. y = [255,255,0]
  54. g = [0,127,0]
  55. b = [0,0,255]
  56. m = [75,0,130]
  57. v = [159,0,255]
  58. w = [255,255,255]
  59. e = [0,0,0]
  60. colours = [r, o, o, y, y, y, g, g]
  61. image = [
  62. [ g,g,g,g,g,g,g,g,
  63. g,g,g,g,g,g,g,g,
  64. g,g,g,g,g,g,g,g,
  65. g,g,g,g,g,g,g,g,
  66. g,g,g,g,g,g,g,g,
  67. g,g,g,g,g,g,g,g,
  68. g,g,g,g,g,g,g,g,
  69. g,g,g,g,g,g,g,g ],
  70. [ r,r,r,r,r,r,r,r,
  71. r,r,r,r,r,r,r,r,
  72. r,r,r,r,r,r,r,r,
  73. r,r,r,r,r,r,r,r,
  74. r,r,r,r,r,r,r,r,
  75. r,r,r,r,r,r,r,r,
  76. r,r,r,r,r,r,r,r,
  77. r,r,r,r,r,r,r,r ],
  78. [ [255, 0, 0], [255, 0, 0], [255, 87, 0], [255, 196, 0], [205, 255, 0], [95, 255, 0], [0, 255, 13], [0, 255, 122],
  79. [255, 0, 0], [255, 96, 0], [255, 205, 0], [196, 255, 0], [87, 255, 0], [0, 255, 22], [0, 255, 131], [0, 255, 240],
  80. [255, 105, 0], [255, 214, 0], [187, 255, 0], [78, 255, 0], [0, 255, 30], [0, 255, 140], [0, 255, 248], [0, 152, 255],
  81. [255, 223, 0], [178, 255, 0], [70, 255, 0], [0, 255, 40], [0, 255, 148], [0, 253, 255], [0, 144, 255], [0, 34, 255],
  82. [170, 255, 0], [61, 255, 0], [0, 255, 48], [0, 255, 157], [0, 243, 255], [0, 134, 255], [0, 26, 255], [83, 0, 255],
  83. [52, 255, 0], [0, 255, 57], [0, 255, 166], [0, 235, 255], [0, 126, 255], [0, 17, 255], [92, 0, 255], [201, 0, 255],
  84. [0, 255, 66], [0, 255, 174], [0, 226, 255], [0, 117, 255], [0, 8, 255], [100, 0, 255], [210, 0, 255], [255, 0, 192],
  85. [0, 255, 183], [0, 217, 255], [0, 109, 255], [0, 0, 255], [110, 0, 255], [218, 0, 255], [255, 0, 183], [255, 0, 74]
  86. ]]
  87.  
  88. # Initialisation
  89.  
  90. # Tables
  91. # Register of 180 elements (each element corresponds to a minute, as the total time will be of 180 minutes)
  92. register = [
  93. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  94. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  95. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  96. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  97. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  98. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  99. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  100. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  101. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  102. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  103. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  104. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  105. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  106. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  107. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  108. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  109. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  110. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  111. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],
  112. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]
  113. ]
  114. # List of the values when the ISS is at +52(North), 0(Equator), -52(South)
  115. list_of_critical_points = [
  116. [0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]
  117. ]
  118.  
  119. # Variables
  120. # Mission 1
  121. baseline_humidity = [0.0, 0.0]
  122. number_of_detections = 0
  123.  
  124. # Mission 2
  125. mag = sense.get_compass_raw()
  126. min = mag['x']
  127. time_keeper = 0
  128. check_for_starting_position = 0
  129. first_critical_point = False
  130. index = 0
  131. start_point = 0
  132. end_of_critical_list = 0
  133.  
  134. while time_keeper < 85:
  135. # Baseline Establishment
  136. sense.clear()
  137. baseline_humidity[0] = baseline_humidity[1]
  138. presence = False
  139. baseline_accel = [0.0, 0.0, 0.0]
  140. for j in range(8):
  141. for i in range(8):
  142. baseline_humidity[1] = baseline_humidity[1] + sense.get_humidity()
  143. acc = sense.get_accelerometer_raw()
  144. baseline_accel[0] = baseline_accel[0] + acc['x']
  145. baseline_accel[1] = baseline_accel[1] + acc['y']
  146. baseline_accel[2] = baseline_accel[2] + acc['z']
  147. sense.set_pixel(i,j,colours[j])
  148. time.sleep(.9375)
  149. baseline_humidity[1] /= 64
  150. for k in range(3):
  151. baseline_accel[k] /= 64
  152. if baseline_humidity[0] == 0:
  153. baseline_humidity[0] = baseline_humidity[1]
  154.  
  155. # Crew detector
  156. ok = 0
  157. while presence == False:
  158. sense.clear()
  159. acc = sense.get_accelerometer_raw()
  160. max = [acc['x'], acc['y'], acc['z']]
  161. for i in range(8):
  162. for j in range(8):
  163. acc = sense.get_accelerometer_raw()
  164. if max[0] < acc['x']:
  165. max[0] = acc['x']
  166. if max[1] < acc['y']:
  167. max[2] = acc['y']
  168. if max[2] < acc['z']:
  169. max[2] = acc['z']
  170. sense.set_pixel(i,j,w)
  171. time.sleep(1.25)
  172. h = sense.get_humidity()
  173. variationOfH1 = h - baseline_humidity[1]
  174. variationOfH2 = baseline_humidity[1] - baseline_humidity[0]
  175. variationOfA = False
  176. if max[0] - baseline_accel[0] > 0.0006 or max[0] - baseline_accel[0] < -0.0006 or max[1] - baseline_accel[1] > 0.005 or max[1] - baseline_accel[1] < -0.005 or max[2] - baseline_accel[2] > 0.0005 or max[2] - baseline_accel[2] < -0.0005:
  177. variationOfA = True
  178. if variationOfH1 > 0.04 * baseline_humidity[1] or variationOfH2 > variationOfH1 * 0.04 or variationOfA == True:
  179. presence = True
  180. else:
  181. presence = False
  182. if presence == True:
  183. sense.clear()
  184. sense.set_pixels(image[0])
  185. time.sleep(3)
  186. Message(0, -1)
  187. ok = ok + 2
  188. time.sleep(2)
  189. else:
  190. sense.set_pixels(image[1])
  191. time.sleep(3)
  192. ok = ok + 1
  193. if ok >= 3:
  194. presence = True
  195. sense.clear()
  196. time.sleep(2)
  197. # Time Waiter (for 2 minutes completition)
  198. if ok != 4:
  199. LoadingTime(4 - ok)
  200.  
  201. # Mission 2
  202. # Determining the "point" where the ISS passes through the Equator(0): {+52} -> {0} -> {-52}
  203. if first_critical_point == False:
  204. mag = sense.get_compass_raw()
  205. x = mag['x']
  206. register[index][0] = sense.get_temperature()
  207. register[index][1] = sense.get_humidity()
  208. register[index][2] = sense.get_pressure()
  209. if min > x:
  210. min = x
  211. else:
  212. first_critical_point = True
  213. # Determining the earliest registration of either one of the Poles or the Equator
  214. if first_critical_point == True:
  215. start_point = index
  216. while start_point - 23 > 0:
  217. start_point -= 23
  218. check += 1
  219. index += 1
  220. else:
  221. # Registration
  222. if index < 180:
  223. register[index][0] = sense.get_temperature()
  224. register[index][1] = sense.get_humidity()
  225. register[index][2] = sense.get_pressure()
  226. index += 1
  227. time_keeper += 1
  228.  
  229. # The final steps
  230. # Assigning the found values to {list_of _critical_points}, as well as determining the end
  231. while start_point + 23 < 180:
  232. list_of_critical_points[end_of_critical_list][0] = register[start_point][0]
  233. list_of_critical_points[end_of_critical_list][1] = register[start_point][1]
  234. list_of_critical_points[end_of_critical_list][2] = register[start_point][2]
  235. start_point += 23
  236. end_of_critical_list += 1
  237.  
  238. # Mean Calculation
  239. mean1 = [0, 0, 0]
  240. meanE = [0, 0, 0]
  241. mean2 = [0, 0, 0]
  242.  
  243. # The value of {check_for_starting_position} will determine which point will the ISS pass the earliest (Poles or Equator)
  244. # If the list starts at one of the Poles (either +52(North) or -52(South))
  245. if check_for_starting_position == 3 or check_for_starting_position == 1:
  246. # Mean value for +52(North) or -52(South)
  247. counter = 0
  248. i = 0
  249. while i < end_of_critical_list:
  250. for j in range(3):
  251. mean1[j] += list_of_critical_points[i][j]
  252. counter += 1
  253. i += 4
  254. for j in range(3):
  255. mean1[j] /= counter
  256. # Mean value for -52(South) or +52(North)
  257. counter = 0
  258. i = 2
  259. while i < end_of_critical_list:
  260. for j in range(3):
  261. mean2[j] += list_of_critical_points[i][j]
  262. counter += 1
  263. i += 4
  264. for j in range(3):
  265. mean2[j] /= counter
  266. # Mean value for 0(Equator)
  267. counter = 0
  268. i = 1
  269. while i < end_of_critical_list:
  270. for j in range(3):
  271. meanE[j] += list_of_critical_points[i][j]
  272. counter += 1
  273. i += 2
  274. for j in range(3):
  275. meanE[j] /= counter
  276. # If the list starts at 0(Equator)
  277. else:
  278. # Mean value for +52(North) or -52(South)
  279. counter = 0
  280. i = 1
  281. while i < end_of_critical_list:
  282. for j in range(3):
  283. mean1[j] += list_of_critical_points[i][j]
  284. counter += 1
  285. i += 4
  286. for j in range(3):
  287. mean1[j] /= counter
  288. # Mean value for -52(South) or +52(North)
  289. counter = 0
  290. i = 3
  291. while i < end_of_critical_list:
  292. for j in range(3):
  293. mean2[j] += list_of_critical_points[i][j]
  294. counter += 1
  295. i += 4
  296. for j in range(3):
  297. mean2[j] /= counter
  298. # Mean value for 0(Equator)
  299. counter = 0
  300. i = 0
  301. while i < end_of_critical_list:
  302. for j in range(3):
  303. meanE[j] += list_of_critical_points[i][j]
  304. counter += 1
  305. i += 2
  306. for j in range(3):
  307. meanE[j] /= counter
  308.  
  309. # Values of {varies_between}: 0 - (no_variation), 1 - (+52/-52 -- -52/+52), 2 - (+52/-52 -- 0), 3 - (+52/-52 -- 0 -- -52/+52)
  310. varies_between = [0, 0, 0]
  311. for i in range(3):
  312. if mean1[i] - mean2[i] > 5.0 or mean1[i] - mean2[i] < -5.0:
  313. varies_between[i] = 1
  314. if mean1[i] - meanE[i] > 5.0 or mean1[i] - meanE[i] < -5.0 or mean2[i] - meanE[i] > 5.0 or mean2[i] - meanE[i] < -5.0:
  315. varies_between[i] = 3
  316. if mean1[i] - meanE[i] > 5.0 or mean1[i] - meanE[i] < -5.0 or mean2[i] - meanE[i] > 5.0 or mean2[i] - meanE[i] < -5.0:
  317. varies_between[i] = 2
  318.  
  319. # Main Conclusion (Message)
  320. sense.show_message("The conclusions of this experiments will be shown 3(three) times")
  321. for j in range(3):
  322. for i in range(3):
  323. sense.show_message("Conclusions of Mission 1: ")
  324. sense.show_message("The Astro Pi has detected the presence of an astro-thing {x} time(s)!".format(number_of_detections))
  325. time.sleep(1)
  326. sense.show_message("Conclusions of Mission 2: ")
  327. Message(varies_between[i], i)
  328. time.sleep(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement