-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoalmaze_pns.sc
More file actions
457 lines (423 loc) · 11.6 KB
/
goalmaze_pns.sc
File metadata and controls
457 lines (423 loc) · 11.6 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
% V2 UPDATES Computes only the components to target and the countdown intervals
% The rest of the maze logic is handled by a matlab script, for reason that
% controlling from matlab also makes it easier to make quick changes and to
% integrate well with continuous result plots.
% Name
% -----
% 2x2 Goal Fetch Maze
%
% Author
% --------
% Ryan Y.
%
% Instructions
% -------
% This statescript file uses the C++ preprocessor to enable more readable code and
% for variables to be extended to callbacks. It enables you to NAME your
% statescript functions. It also prevents having to re-write when changing
% port numbers across the file.
%
% Before using this statescript file, you must send it through the C++
% preprocessor (a painless single command). Simply type,
%
% ' mcpp goalmaze.csc goalmaze.sc '
%
% and it runs the C++ preprocessor, performing simply subsitution on the #define
% directives. The end product is a statescript code. This approach make it EASIER
% for the coder and the reader.
%
% Maze Operation
% --------------
% Every 20 seconds, a new platform is randomly chosen to cue. The animal then
% has an opportunity to visit the well and receive reward.
%
% TODO Update docstring
% ------------------------------------------------
% ==============================================================
% ==================== Digtal I/Os =============================
% ==============================================================
% INPUTS
% Statescript Poke Inputs
int poke1 = 1;
int poke2 = 2
int poke3 = 3
int poke4 = 4
int pokeHome = 5
% Statescript control inputs
int startTask = 21
% OUTPUTS
% Digital output LEDs
int led1 = 17
int led2 = 18
int led3 = 19
int led4 = 20
int ledHome = 21;
% For this first iteration, tone and light are on the same dio channel
% Digital output TONEs
int tone1 = 1
int tone2 = 2
int tone3 = 3
int tone4 = 4;
int toneHome = 5;
% Digital output REWARDs
int reward1 = 6
int reward2 = 7
int reward3 = 8
int reward4 = 9;
int rewardHome = 10;
% ==============================================================
% ==============TASK PARAMETERS AND CONSTANTS===================
% ==============================================================
% TODO BRING ORDER to this :(
int reset_dur = 20000
int reward_dur = 1200
int remind_dur = 10000
int stimstack = 0
int check_cycle = 1
int statescript_end = 0
int remind = 0;
int flash_dur = 150
int flash_iti = 70
int flash_count = 10
int flash_counter = 0
%int flash_stim_duration = 10000
int continuous_flash = 0;
int continuous_flash_period = 575;
% How often to check whether time is up
int timepoint = 1
int initialized = 0 ;
% Output selectors
int light = 0
int reward = 0
int true = 1 ;
int trialstack=0
int flashstack=0;
% ==============================================================
% ==================== FUNCTIONS ===============================
% ==============================================================
% --------------------------------------------------------------
% CUE TYPE 1: Discrete stimulus presentation function
% --------------------------------------------------------------
int stimon=0
int stim_duration = 750
int clear_queue_next_stim=0
function 11
%stimon=0
if clear_queue_next_stim==1 do
clear queue
clear_queue_next_stim = 0
stimstack = 0
end
stimstack = stimstack+1
portout[light] = 1
stimon = 1
statescript_end = 1 % tracks whether or not statescript itself is allowed to perform it's stimulus end: matlab part has its own killswitch -- matlab can flip this to 0 and void a future destrcution
disp(stim_duration)
while stimon == 1 do every check_cycle
%disp('cycle')
then do
%disp('here')
if statescript_end == 1 && stimstack <= 0 do
portout[led1] = 0
portout[led2] = 0
portout[led3] = 0
portout[led4] = 0
portout[ledHome] = 0
stimstack = 0
end
end
end;
% --------------------------------------------------------------
% REWARD PRESENTATION FUNCTION
% --------------------------------------------------------------
int clear_queue_next_rew=0;
function 12
disp('Rewarding ...')
disp(reward)
if clear_queue_next_rew == 0 do
clear queue % somehow this is executing AFTER stimulus restarts ... which seems impossible unless matlab is executing unbelievably fast ... can try to wait for a message
clear_queue_next_rew = 0
disp('...RQC') % reward cue cleared
end
disp('...RF') % reward cue cleared
portout[reward] = 1
do in reward_dur
portout[reward] = 0
end
end;
% --------------------------------------------------------------
% Discrete count flash SUBFUNCTION
% --------------------------------------------------------------%
function 14
flashstack = flashstack - 1
if (flashstack == 0) do
flash_counter = flash_count
if (trialstack == 1) do
while (flash_counter > 0) do every flash_iti
portout[light]=1
do in flash_dur
portout[light] = 0
end
flash_counter=0
end
flashstack = 0
portout[light] = 0
end
end
end;
% --------------------------------------------------------------
% Trial timer
% --------------------------------------------------------------
function 13
trialstack = trialstack + 1
disp(trialstack)
if (trialstack == 1) do
disp('cstart')
if (remind == 1) do in remind_dur
flashstack = flashstack + 1
trigger(14)
end
end
do in reset_dur
trialstack = trialstack - 1
disp(trialstack)
if ( trialstack == 0 ) do
disp('cend')
%trigger(13)
% Just in case there is another asynchronous block that is pushing the the stack during this, make the stack pop to 0
end
end
end;
% --------------------------------------------------------------
% Continuous light flash SUBFUNCTION
% --------------------------------------------------------------
function 15
while continuous_flash == 1 do every continuous_flash_period
portout[light] = 1
do in flash_dur
portout[light] = 0
end
end
end;
% --------------------------------------------------------------
% Sound Error
% --------------------------------------------------------------
int error_on = 0
function 19
sound('error.wav')
end;
% --------------------------------------------------------------
% Block lockout function
% --------------------------------------------------------------
int blocklockout_period = 3000
int block_stack = 0
function 16
disp('blocklockout start')
block_stack = block_stack+1
disp(block_stack)
do in blocklockout_period
block_stack = block_stack - 1
disp(block_stack)
if ( block_stack == 0 ) do
disp('blocklockout end')
end
end
end;
% --------------------------------------------------------------
% Cue Type 2: Time continuous light flash function
% --------------------------------------------------------------
int clear_queue_next_stim=0
function 17
if clear_queue_next_stim == 1 do
clear queue
clear_queue_next_stim = 0
block_stack = 0
trialstack = 0
end
continuous_flash = 1
trigger(15) % turn on cotinuous light flash
end;
% --------------------------------------------------------------
% Nose poke end detection
% ... operationalizes when a poke truly ends (often it triggers
% on and off while the animal licks.
% --------------------------------------------------------------
int pokeend_stack = 0
int pokeend_dur = 1000
function 18
pokeend_stack = pokeend_stack+1
do in pokeend_dur
%disp('Checking')
pokeend_stack= pokeend_stack-1
if pokeend_stack == 0 do
disp('function 18 : port END')
end
end
end;
% --------------------------------------------------------------
% CUE TYPE 1: Extension! Extend length
% Purpose: Extends the length of actively running stimuli
% --------------------------------------------------------------
function 20
disp('stim extension!')
stimstack = stimstack+1
statescript_end = 1
disp(stim_duration)
if stimon == 1 do
%disp('cycle')
if statescript_end == 1 && stimstack <= 0 do
portout[led1] = 0
portout[led2] = 0
portout[led3] = 0
portout[led4] = 0
portout[ledHome] = 0
stimstack = 0
end
end
end;
int terminal_ir_mode = 0
int termirstack = 0
int ir_stim_to_terminate = 11
function 21
disp('function 21 : terminate by ir')
termirstack = termirstack + 1
statescript_end = 1 % tracks whether or not statescript itself is allowed to perform it's stimulus end: matlab part has its own killswitch -- matlab can flip this to 0 and void a future destrcution
%disp(stim_duration)
if (terminal_ir_mode == 1) do in stim_duration
termirstack = termirstack - 1
if termirstack <= 0 do
disp('function 21 : commanding stim to end')
if ir_stim_to_terminate == 11 do
stimon = 0
disp('function 21 : of type 11')
else if ir_stim_to_terminate == 17 do
continuous_flash = 0
disp('function 21 : of type 17')
end
continuous_flash = 0
termirstack = 0
end
end
while stimon == 1 do every check_cycle
%disp('cycle')
then do
%disp('here')
if statescript_end == 1 && termirstack <= 0 do
portout[led1] = 0
portout[led2] = 0
portout[led3] = 0
portout[led4] = 0
portout[ledHome] = 0
termirstack = 0
end
end
end;
% ==============================================================
% ==================== ZONE TRIGGERS ===========================
% ==============================================================
function 1
disp('zone 1 enter')
end;
function 2
disp('zone 2 enter')
end;
function 3
disp('zone 3 enter')
end;
function 4
disp('zone 4 enter')
end;
function 5
disp('zone 1 exit')
end;
function 6
disp('zone 2 exit')
end;
function 7
disp('zone 3 exit')
end;
function 8
disp('zone 4 exit')
end;
% ==============================================================
% ================== CALLBACK REPORTS ==========================
% ==============================================================
% ---- Port 16 ----
callback portin[1] up
%disp('port POKE 1 up')
end
callback portin[1] down
%disp('port POKE 1 down')
trigger(18)
end;
% ---- Port 17 ----
callback portin[2] up
%disp('port POKE 2 up')
end;
callback portin[2] down
%disp('port POKE 2 down')
trigger(18)
end;
% ---- Port 18 ----
callback portin[3] up
%disp('port POKE 3 up')
end;
callback portin[3] down
%disp('port POKE 3 down')
trigger(18)
end;
% ---- Port 19 ----
callback portin[4] up
disp('port POKE 4 up')
end
callback portin[4] down
disp('port POKE 4 down')
trigger(18)
end;
% ---- Port 19 ----
callback portin[5] up
%disp('port POKE 5 up')
end
callback portin[5] down
%disp('port POKE 5 down')
trigger(18)
end;
% ---- Port 19 ----
callback portin[6] up
%disp('port POKE 5 up')
end
callback portin[6] down
%disp('port POKE 5 down')
trigger(18)
end;
% --- IR BEAMS ---
callback portin[13] up
disp('port HOMEIR up')
end
callback portin[13] down
disp('port HOMEIR down')
end;
int hometrial = 0
callback portin[12] up
disp('port TRIALIR up and home trial is')
disp(hometrial)
end
callback portin[12] down
disp('port TRIALIR down')
termirstack=0
if terminal_ir_mode == 1 && hometrial == 0 do
trigger(21)
end
end;
callback portin[15] up
disp('port TRIALIR up and home trial is')
disp(hometrial)
end
callback portin[15] down
disp('port TRIALIR down')
termirstack=0
if terminal_ir_mode == 1 && hometrial == 0 do
trigger(21)
end
end;
disp('compile end');