-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinal_DAQ.py
79 lines (56 loc) · 2.49 KB
/
Final_DAQ.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
import RPi.GPIO as GPIO
import time as time
import sys
import numpy as np
import math
import statistics
import matplotlib
# %matplotlib inline
import matplotlib.pylot as plt
class Final:
def __init__(self, efficiency, data, count=0, timestamp=0):
"""This method initializes a class instance.
Args:
efficiency (double): Efficiency coefficient of our detector
timestamp (integer): Sets a relative timestamp of 0 for our data acquisition method
count (integer): Stores the number of detections we get with our system
data (array): Stores our data with two columns: counts and timestamp
"""
self.efficiency = efficiency
self.timestamp = timestamp
self.count = count
self.data = data
def acquire_data(self, interval, num_intervals, name):
"""This method acquires data from our system and returns an array of our counts and timestamps.
Args:
interval (integer): This is the interval of seconds for which our system will measure counts
num_intervals (integer): This is the number of time intervals our system will measure for
name (string): This is the name of the file our system will store the data in
Returns:
array: Array of counts and timestamps
"""
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
def my_callback(channel):
"""This functions increments our count variable by 1 every time a detection is registered with our sensor.
Args:
channel (GPIO Channel): Channel that our RPi communicates with (GPIO)
"""
self.count += 1
print("fallen")
GPIO.add_event_detect(17, GPIO.FALLING, callback = my_callback)
myFile2 = open(name + "_" + str(round(time.time()))+".csv", "w")
myFile2.write("Counts," + " Timestamp" + "\n")
while self.timestamp <= num_intervals * interval:
self.timestamp += 1
if self.timestamp % interval == 0:
self.data.append([self.count, self.timestamp])
myFile2.write(str(self.count) + ", " + str(self.timestamp) + "\n")
count = 0
self.timestamp = 0
print("looped", count, self.data)
time.sleep(1)
return self.data
def parse_data(self):
# Check the Jupyter Notebook for the data analysis
pass