-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard.py
231 lines (174 loc) · 4.83 KB
/
standard.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import RPi.GPIO as GPIO
import sys
import time
import csv
from datetime import datetime
from numpy.random import seed
from numpy.random import shuffle
from . import function_DD
#definisco il vettore parametri
param=[
"type_of_exp", "Fixed_2_choice",
"t_drop", 0.1,
"t_vac", 10.0,
"dt_vac",10.0,
"after_session_delay", 20,
"light_on_secs", 20.0,
"punishment_seconds", 0.0,
"cycle_number", 100.0,
"sampling_time", 0.1,
"n_drop1", 20,
"n_drop2", 20,
"delay_1", 0,
"delay_2", 0,
"after_session_delay", 0.0,
"n_flash", 4,
"dt_flash", .1,
"training", 1, # 1 per farlo, 0 per saltarlo
"N_trining", 4, #AGGIUNGERE I PARAMETRI DEL TRAINING QUI SOTTO
"light_on_training", 300.0,
"punishment_training", 0.0,
"training_after_session_delay", 6,
"date", datetime.today(),
"rat_id", "1_control",
]
file1 = open("./In_case_of_emergency.txt","a") #salviamo i dati in questo foglio txt (da creare se non esiste)
file1.write(str(param)+"\n")
file1.close()
#definisco le porte e le spengo tutte
led1=0
led2=0
poke1=0
poke2=0
val_juice=0
val_vac=0
GPIO.setmode(GPIO.BCM)
GPIO.setup(poke1,GPIO.IN)
GPIO.setup(poke2,GPIO.IN)
GPIO.setup(led1,GPIO.OUT)
GPIO.output(led1,GPIO.LOW)
GPIO.setup(led2,GPIO.OUT)
GPIO.output(led2,GPIO.LOW)
GPIO.setup(val_juice,GPIO.OUT)
GPIO.output(val_juice,GPIO.LOW)
GPIO.setup(val_vac,GPIO.OUT)
GPIO.output(val_vac,GPIO.LOW)
#lancio l'algoritmo
choice=[]
d1=param[23]
d2=param[25]
m1=param[19]
m2=param[21]
CHOICHE=0
if param[33]==1: #facciamo N sessioni di training in cui il ratto è obbligato a scegliere
led=led1
poke=poke1
for session_training in range(param[35]):
print("Training session n°")
print(session)
start = time.time()
if CHOICE==1: #inverto le porte (per eliminare mettere choiche >-1)
if led==led1:
led=led2
poke=poke2
d=d2
m=m2
else:
led=led1
poke=poke1
d=d1
m=m1
counter=0
CHOICE=0
GPIO.output(led,GPIO.HIGH)
while counter<(param[37]*(1/param[17])): #sono in cerca dello stimolo per il tempo in cui la luce è accesa
if GPIO.input(poke)==FALSE:
CHOICE=1
counter=(param[37]*(1/param[17]))
stop = time.time()
rt=stop-start
print(rt)
hit=1
flashing(led,param[21],param[23])
sleep(param[17])
counter=counter+1
if CHOICE==1:
print("HIT!")
sleep(d)
J_flow(param[3], m, param[7],param[5])
else:
print("Failed!")
if param[39]>0.0:
GPIO.output(led,GPIO.LOW)
sleep(param[39])
stop = time.time()
rt=stop-start
print(rt)
hit=0
outcomes=['training', 1, 'hit', hit, 'rt', rt, 'poke', poke, 'session', session]
file1 = open("./In_case_of_emergency.txt","a") #salviamo i dati in questo foglio txt (da creare se non esiste)
file1.write(str(outcomes)+"\n")
file1.close()
f = open('/home/pi/Desktop/data.csv', 'a') #salviamo il .csv perchè più facile da importare e analizzare
listone= otucomes + param
writer = csv.writer(f)
writer.writerow(listone)
print("I'm recording...")
sleep(param[41])
#serie sperimentale
for session in range(param[15]):
print("Serious session n°")
print(session)
start = time.time()
counter=0
CHOICE=0
GPIO.output(led1,GPIO.HIGH)
GPIO.output(led2,GPIO.HIGH)
while counter<(param[11]*(1/param[17])): #sono in cerca dello stimolo per il tempo in cui la luce è accesa
if GPIO.input(poke1)==FALSE:
CHOICE=1
counter=(param[11]*(1/param[17]))
stop = time.time()
rt=stop-start
print(rt)
flashing(led1,param[29],param[31])
flashing(led2,param[29],param[31])
if GPIO.input(poke2)==FALSE:
CHOICE=2
counter=(param[11]*(1/param[17]))
stop = time.time()
rt=stop-start
print(rt)
flashing(led1,param[29],param[31])
flashing(led2,param[29],param[31])
sleep(param[17])
counter=counter+1
if CHOICE==1:
print("Rat in 1")
print(rt)
sleep(d1)
J_flow(param[3], m1, param[7],param[5])
if CHOICE==2:
print("Rat in 2")
print(rt)
sleep(d2)
J_flow(param[3], m2, param[7],param[5])
else:
print("Failed!")
if param[13]>0.0:
GPIO.output(led1,GPIO.LOW)
GPIO.output(led2,GPIO.LOW)
sleep(param[13])
stop = time.time()
rt=stop-start
print(rt)
outcomes=['training', 0,'hit', CHOICE, 'rt', rt, 'poke', poke, 'session', session, 'M1', m1,'M2', m2,'D1', d1,'D2', d2]
file1 = open("./In_case_of_emergency.txt","a") #salviamo i dati in questo foglio txt (da creare se non esiste)
file1.write(str(outcomes)+"\n")
file1.close()
f = open('/home/pi/Desktop/data.csv', 'a') #salviamo il .csv perchè più facile da importare e analizzare
listone= otucomes + param
writer = csv.writer(f)
writer.writerow(listone)
print("I'm recording...")
sleep(param[9])