-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattenuation_measurement
63 lines (53 loc) · 1.41 KB
/
attenuation_measurement
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
#! /bin/bash
#find the photodiode directory with help_num as an input argument
help_num=$1
SYSFS_ADC_DIR="/sys/devices/ocp.3/helper."$help_num"/AIN0"
#find and touch the file_name that it will output to it
file1=$2
touch $file1
#set up averaging variables
toAverage=25
average=0
rms=0
count=0
#set trigger level to loop over
Trigger3="/sys/class/gpio/gpio46"
trig3=`cat "$Trigger3/value"`
buf1=2
buf2=3
buf3=4
#always loops while trigger3 is activated
while (( $trig3 == 1 )); do
#gets the value of trigger3 from the directory
buf1=`cat "$Trigger3/value"`
if [ $buf1 == $buf2 ] && [ $buf2 == $buf3 ]; then
trig3=$buf1
else
buf3=$buf2
buf2=$buf1
fi
total=0
#finds the voltage from the photodiode and reads 25 times
for i in {0..24}; do
adc=`cat "$SYSFS_ADC_DIR"`
volts[$i]=$adc
total=$(( $total + $adc ))
sleep 0.02
done
#finds the average from the total voltage read over 25 times
averages=`./divide $total $toAverage`
#finds the error on the mean for the voltage
rmsSum=0
k=0
for k in {0..24}; do
foilvar=`./foil ${volts[$k]} $averages`
rmsSum=`./add $rmsSum $foilvar`
done
rms=`./find_error $rmsSum $toAverage`
#temperature=`./temp_read`
#reads the values out to the file_name
echo `date +%s.%3N`" "$averages" "$rms>> $file1
echo `date +%s.%3N`" "$averages" "$rms
#increments the time count
count=`./add $count 0.5`
done