-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIOcontrol.py
executable file
·144 lines (111 loc) · 4.68 KB
/
SIOcontrol.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
#!/usr/bin/env python3
# Uncomment for use of pi
import RPi.GPIO as GPIO
#import Adafruit_DHT
import time, threading
import argparse
import sys, select
def cannonforward(pin_cannonposition):
print("Advancing the cannon")
GPIO.output(pin_cannonposition,GPIO.HIGH)
def powerupsensors(pin_sensorpower):
GPIO.output(pin_sensorpower,GPIO.HIGH)
def powerdownsensors(pin_sensorpower):
GPIO.output(pin_sensorpower,GPIO.LOW)
def cannonreverse(pin_cannonposition,cannonreversedelay):
time.sleep(cannonreversedelay)
print("reversing the cannon")
GPIO.output(pin_cannonposition,GPIO.LOW)
def timeprocess(pin_irsensor,exittime):
tic = time.time()
print('***',exittime)
while GPIO.input(pin_irsensor)==0 and time.time()-tic<exittime:
pass
toc=time.time()
#print GPIO.input(pin_irsensor)
total = toc - tic
print("Time from start to immersion:", total)
def applysample(pin_cannon,wait,duration):
time.sleep(wait)
GPIO.output(pin_cannon,GPIO.HIGH)
time.sleep(duration)
GPIO.output(pin_cannon,GPIO.LOW)
def releaseplunger(pin_plunger,wait):
time.sleep(wait)
GPIO.output(pin_plunger,GPIO.HIGH)
def resetplunger(pin_plunger):
GPIO.output(pin_plunger,GPIO.LOW)
def readenvironment(pin_dht22):
humidity, temperature = Adafruit_DHT.read_retry(22, pin=pin_dht22)
return humidity, temperature
if __name__=='__main__':
parser = argparse.ArgumentParser(description='Arguments for SIOcontrol')
parser.add_argument('--stime', help='Duration of sample application (seconds)',type=float,required=True)
parser.add_argument('--sdelay', help='Time to wait before applying (seconds)',default = 0, type=float,required=False)
parser.add_argument('--pdelay', help='Time to wait before plunging (seconds)',default = 0, type=float,required=False)
parser.add_argument('--donotplunge',help='Do not fire the plunger (diagnostic)',action = 'store_true')
args = parser.parse_args()
# Define pins
pin_cannon = 25 ##
pin_plunger = 19
pin_dht22 = 24
pin_cannonposition = 26
pin_sensorpower = 12 ##
pin_irsensor = 16
pin_interlock = 27
# Default timing
cannontimetoreverse = 0.000
cannonreversedelay = args.stime + args.sdelay+ cannontimetoreverse
timeout = 1 # withdraw the plunger to avoid overheating
kuhnketime = 1
GPIO.setwarnings(False)
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_cannon,GPIO.OUT)
GPIO.setup(pin_plunger,GPIO.OUT)
GPIO.setup(pin_cannonposition,GPIO.OUT)
GPIO.setup(pin_sensorpower,GPIO.OUT)
GPIO.setup(pin_irsensor,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(pin_interlock,GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
# Report environmental conditions
# humidity, temperature = readenvironment(pin_dht22)
# print('Temp={0:0.1f}\'C Humidity={1:0.1f}% RH'.format(temperature, humidity))
# Display timing and avoid crash
print("Timings:")
print("Specimen application will start at time: ",args.sdelay)
print("Specimen application will end at time: ",args.sdelay + args.stime)
print("Cannon will reverse at time: ",cannonreversedelay)
print("Plunger will fall at time: ",args.pdelay)
exittime = kuhnketime+args.pdelay+args.sdelay
print("Program will exit after: ",exittime)
if cannonreversedelay > args.pdelay:
print("The cannon does not have sufficient time to reverse before plunging!!")
exit()
# Power up sensors and check interlock
powerupsensors(pin_sensorpower)
if GPIO.input(pin_interlock)==1:
print("Interlock fail: cryogen container is not in place")
powerdownsensors(pin_sensorpower)
exit()
else:
print("Safety interlock pass: cryogen container is in place")
# put cannon into place and wait
cannonforward(pin_cannonposition)
input("Press Enter to continue...")
# set up processes
sample = threading.Thread(target=applysample, args=(pin_cannon,args.sdelay,args.stime))
plunger = threading.Thread(target=releaseplunger, args=(pin_plunger,args.pdelay))
cannonposition = threading.Thread(target=cannonreverse, args=(pin_cannonposition,cannonreversedelay))
clockit = threading.Thread(target=timeprocess, args=(pin_irsensor,exittime))
# start processes
if not args.donotplunge:
plunger.start()
sample.start()
cannonposition.start()
clockit.start()
# Kuhnke plunger
time.sleep(kuhnketime+args.pdelay+args.sdelay)
resetplunger(pin_plunger)
powerdownsensors(pin_sensorpower)
print("Done!")
#print GPIO.input(pin_irsensor)