-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5CS3UUS protocol.py
More file actions
182 lines (164 loc) · 4.17 KB
/
5CS3UUS protocol.py
File metadata and controls
182 lines (164 loc) · 4.17 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 14 15:17 2019
@author: wpiper
Time practice
"""
import serial
import time
import datetime
def IRon(ser):
ser.write(b'A')
print('IR on!')
def IRoff(ser):
ser.write(b'B')
print('IR off!')
def FIBERon(ser):
ser.write(b'C')
print('FIBER on!')
def FIBERoff(ser):
ser.write(b'D')
print('FIBER off!')
def AUDIOon(ser):
ser.write(b'E')
print('AUDIO on!')
def AUDIOoff(ser):
ser.write(b'F')
print('AUDIO off!')
def SHOCKERon(ser):
ser.write(b'G')
print('SHOCKER on!')
def SHOCKERoff(ser):
ser.write(b'H')
print('SHOCKER off!')
def StartProt(ser):
IRon(ser)
FIBERon(ser)
print('PROTOCOL START')
print(datetime.datetime.now() -tzero)
def StartProtEnd(ser):
IRoff(ser)
FIBERoff(ser)
def CS(ser):
IRon(ser)
FIBERon(ser)
AUDIOon(ser)
print('CS on')
print(datetime.datetime.now() -tzero)
def CSint(ser):
IRoff(ser)
FIBERoff(ser)
def US(ser):
IRon(ser)
FIBERon(ser)
SHOCKERon(ser)
print('US on')
print(datetime.datetime.now() -tzero)
def USend(ser):
IRoff(ser)
FIBERoff(ser)
SHOCKERoff(ser)
AUDIOoff(ser)
print('CS and US off')
print(datetime.datetime.now() -tzero)
def CSend(ser):
IRoff(ser)
FIBERoff(ser)
AUDIOoff(ser)
print('CS off')
print(datetime.datetime.now() -tzero)
def UUSend(ser):
IRoff(ser)
FIBERoff(ser)
SHOCKERoff(ser)
print('US off')
print(datetime.datetime.now() -tzero)
def EndProtStart(ser):
IRon(ser)
FIBERon(ser)
def EndProtEnd(ser):
IRoff(ser)
FIBERoff(ser)
print(datetime.datetime.now() -tzero)
#tfunclist = [StartProt,StartProtEnd,CS,CSint,US,USend,EndProtStart,EndProtEnd]
funclist = [StartProt,StartProtEnd]
startendbuffertime = 4
acctime = 300 - startendbuffertime
cooldowntime = 150 - startendbuffertime
tlist=[1]
tlist.append(tlist[-1]+startendbuffertime)
#first ITItimes is acclimation time
#ITI times must be integers!!!
ITItimes = iter([acctime,200,150,190,180,120,150,135])#]200,150,190,180,150])#,210,160,140,170,220]) #middle 150 is before U-US
#300 CS1, 530 CS2, 710 CS3, 930 CS4, 1140 CS5, 1320 UUS, 1470
for i in range(8):
if i < 5:
funclist.append(CS)
tlist.append(tlist[-1]+next(ITItimes))
funclist.append(CSend)
tlist.append(tlist[-1]+30) #CS length
if i >=5:
funclist.append(US)
tlist.append(tlist[-1]+next(ITItimes))
funclist.append(UUSend)
tlist.append(tlist[-1]+5) #UUS length
funclist.append(EndProtStart)
funclist.append(EndProtEnd)
tlist.append(tlist[-1]+cooldowntime)
tlist.append(tlist[-1]+startendbuffertime)
print(len(funclist))
print(funclist)
print(len(tlist))
flist=[]
for t in tlist:
flist.append(t-1)
print(flist)
tfunclist = funclist
endtime = tlist[-1]+5
print(endtime)
for i,j in zip(tlist, funclist): print(i-1), print(j), print('\n')
with serial.Serial('COM4', 9600, timeout=1) as ser:
t0 = time.time()
timechecked = False
timer = 0
tzero = datetime.datetime.now()
time.sleep(2)
ser.write(b'B')
ser.write(b'D')
ser.write(b'F')
ser.write(b'H')
t1 = time.time()
delta_t0 = t1 - t0
while delta_t0 < endtime:
t1 = time.time()
delta_t0 = t1 - t0
if timechecked == False:
t2 = time.time()
timechecked = True
delta_t1 = t1 - t2
if delta_t1 > 0.999:
timer += 1
#print(delta_t1)
#print(time.time())
#print(datetime.datetime.now()-tzero)
print(timer)
timechecked = False
if timer in tlist:
a = tlist.index(timer)
tfunclist[a](ser)
ser.write(b'B')
ser.write(b'D')
ser.write(b'F')
ser.write(b'H')
print('COMPLETE')
"""
with serial.Serial('COM5', 9600, timeout=1) as ser:
time.sleep(2)
ser.write(b'G')
ser.write(b'A')
ser.write(b'C')
time.sleep(5)
ser.write(b'H')
ser.write(b'B')
ser.write(b'D')
"""