-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwater_att
executable file
·191 lines (158 loc) · 3.9 KB
/
water_att
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
191
#! /bin/bash
#set variables
fillpump="P9_14"
drainpump="P9_16"
Trig1="/sys/class/gpio/gpio44"
Trig2="/sys/class/gpio/gpio26"
Trig3="/sys/class/gpio/gpio46"
Trig4="/sys/class/gpio/gpio65"
fill_relay="/sys/class/gpio/gpio67"
drain_relay="/sys/class/gpio/gpio68"
power_relay="/sys/class/gpio/gpio49"
#temperature sensor directory
echo BB-W1:00A0 > /sys/devices/bone_capemgr.9/slots
#set output for power relay for 5V supply line
if [ -f $power_relay/direction ]; then
echo
else
echo 49 > "/sys/class/gpio/export"
echo "out" > $power_relay/direction
fi
sleep 0.01
#set the pins to read voltage
if [ `grep "cape-bone-iio" /sys/devices/bone_capemgr.*/slots | wc -l` -eq "1" ]; then
echo
else
echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
fi
sleep 0.01
#check if the trigger directories/files are set. if not, create them
if [ -f $Trig1/direction ]; then
echo
else
echo 44 > "/sys/class/gpio/export"
echo "in" > $Trig1/direction
fi
sleep 0.01
if [ -f $Trig2/direction ]; then
echo
else
echo 26 > "/sys/class/gpio/export"
echo "in" > $Trig2/direction
fi
sleep 0.01
if [ -f $Trig3/direction ]; then
echo
else
echo 46 > "/sys/class/gpio/export"
echo "in" > $Trig3/direction
fi
sleep 0.01
if [ -f $Trig4/direction ]; then
echo
else
echo 65 > "/sys/class/gpio/export"
echo "in" > $Trig4/direction
fi
sleep 0.01
if [ -f $fill_relay/direction ]; then
echo
else
echo 67 > "/sys/class/gpio/export"
echo "out" > $fill_relay/direction
fi
sleep 0.01
if [ -f $drain_relay/direction ]; then
echo
else
echo 68 > "/sys/class/gpio/export"
echo "out" > $drain_relay/direction
fi
sleep 0.01
echo "Turning on 5V power supply..."
echo 1 > "$power_relay/value"
#Turn both pumps off
echo "Turning both pumps off..."
./servo $fillpump 0
./servo_angle $drainpump 0
#run trigger check
echo "Checking triggers..."
trigger1=`cat "$Trig1/value"`
trigger2=`cat "$Trig2/value"`
trigger3=`cat "$Trig3/value"`
trigger4=`cat "$Trig4/value"`
#echo out the trigger values
echo "$trigger1" "$trigger2" "$trigger3" "$trigger4"
#check the level (if trig_1 is active) then fill pump if it is
echo "Checking trigger level 1..."
if [ "$trigger1" -eq "0" ]; then
echo "Trigger 1 is not active..."
echo "Filling water column..."
./servo $fillpump 1
echo 1 > "$fill_relay/value"
fi
#turn off fill pump when full
isfull="0"
while [ $isfull -eq "0" ]; do
isfull=`cat "$Trig1/value"`
sleep 0.01
done
#tube is full so stop the pump
echo "Stopping fill pump..."
./servo $fillpump 0
echo 0 > "$fill_relay/value"
#wait for 20 min
#sleep 20m
echo "Switching off power to triggers..."
echo 0 > "$power_relay/value"
echo "Waiting for water to settle..."
sleep 20m
echo "Turning power back on to triggers..."
echo 1 > "$power_relay/value"
sleep 1m
#start drain pump
echo "Starting drain pump..."
./servo_angle $drainpump 1
echo 1 > "$drain_relay/value"
#run attenuation measurement when trig_2 is deactive
isempty="1"
buffer1=2
buffer2=3
buffer3=4
while [ "$isempty" -eq "1" ]; do
buffer1=`cat "$Trig2/value"`
if [ $buffer1 == $buffer2 ] && [ $buffer2 == $buffer3 ]; then
isempty=$buffer1
else
buffer3=$buffer2
buffer2=$buffer1
fi
sleep 0.01
done
#take data until trig_3 is deactivated checked by the executable ./att_meas <filename>
helper_num=`./find_helper`
echo "Taking data..."
file_name="attnRun_"`date "+%Y_%m_%d_%H_%M"`".txt"
. attenuation_measurement $helper_num $file_name
#stop drain pump when trig_4 is deactive
fourisempty="1"
buffer1=2
buffer2=3
buffer3=4
while [ "$fourisempty" -eq "1" ]; do
buffer1=`cat "$Trig4/value"`
if [ $buffer1 == $buffer2 ] && [ $buffer2 == $buffer3 ]; then
fourisempty=$buffer1
else
buffer3=$buffer2
buffer2=$buffer1
fi
sleep 0.01
done
echo "Stopping drain pump..."
./servo_angle $drainpump 0
echo 0 > "$drain_relay/value"
echo "Turning off 5V power supply..."
echo 0 > "$power_relay/value"
echo "Water attenuation run status: COMPLETE"
#emergency turn off script