-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstateMatrix.m
490 lines (441 loc) · 23.3 KB
/
stateMatrix.m
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
function sma = stateMatrix(iTrial)
global BpodSystem
global TaskParameters
%% Define ports
LeftPort = floor(mod(TaskParameters.GUI.Ports_LMR/100,10));
CenterPort = floor(mod(TaskParameters.GUI.Ports_LMR/10,10));
RightPort = mod(TaskParameters.GUI.Ports_LMR,10);
SwitchPort=TaskParameters.GUI.Ports_Switch;
LeftPortOut = strcat('Port',num2str(LeftPort),'Out');
CenterPortOut = strcat('Port',num2str(CenterPort),'Out');
RightPortOut = strcat('Port',num2str(RightPort),'Out');
SwitchPortOut=strcat('Port',num2str(SwitchPort),'Out');
LeftPortIn = strcat('Port',num2str(LeftPort),'In');
CenterPortIn = strcat('Port',num2str(CenterPort),'In');
RightPortIn = strcat('Port',num2str(RightPort),'In');
SwitchPortIn = strcat('Port',num2str(SwitchPort),'In');
%reward ports and amount
LeftValve = 2^(LeftPort-1);
RightValve = 2^(RightPort-1);
SwitchValve = 2^(SwitchPort-1);
LeftValveTime = GetValveTimes(BpodSystem.Data.Custom.RewardMagnitude(iTrial,1), LeftPort);
RightValveTime = GetValveTimes(BpodSystem.Data.Custom.RewardMagnitude(iTrial,2), RightPort);
SwitchValveTime = GetValveTimes(TaskParameters.GUI.SwitchRewardAmount, SwitchPort);
%port LEDs
if TaskParameters.GUI.PortLEDs
PortLEDs = 255;
else
PortLEDs = 0;
end
if BpodSystem.Data.Custom.AuditoryTrial(iTrial) %auditory trial
LeftRewarded = BpodSystem.Data.Custom.LeftRewarded(iTrial);
else %olfactory trial
LeftRewarded = BpodSystem.Data.Custom.OdorID(iTrial) == 1;
end
%add in switch action - rewarded if switch if advantageous, else nothing
if BpodSystem.Data.Custom.SwitchBaited(iTrial) == 1
SwitchPokeAction = 'rewarded_Sin_start';
elseif BpodSystem.Data.Custom.SwitchBaited(iTrial) == 0
SwitchPokeAction = 'unrewarded_Sin_start';
else
error('Bpod:Olf2AFC:unknownStim','Undefined stimulus');
end
if LeftRewarded == 1
LeftPokeAction = 'rewarded_Lin_start';
RightPokeAction = 'unrewarded_Rin_start';
elseif LeftRewarded == 0
LeftPokeAction = 'unrewarded_Lin_start';
RightPokeAction = 'rewarded_Rin_start';
else
error('Bpod:Olf2AFC:unknownStim','Undefined stimulus');
end
if BpodSystem.Data.Custom.CatchTrial(iTrial)
FeedbackDelayCorrect = 20;
else
FeedbackDelayCorrect = TaskParameters.GUI.FeedbackDelay;
end
if TaskParameters.GUI.CatchError
FeedbackDelayError = 20;
else
FeedbackDelayError = TaskParameters.GUI.FeedbackDelay;
end
%Wire1 settings
%no video default
Wire1OutError = {};
Wire1OutCorrect = {};
Wire1Out = {};
if TaskParameters.GUI.Wire1VideoTrigger % video
Wire1OutError = {'WireState', 1};
switch TaskParameters.GUI.VideoTrials
case 1 %only catch & error
if BpodSystem.Data.Custom.CatchTrial(iTrial)
Wire1OutCorrect = {'WireState', 1};
else
Wire1OutCorrect = {};
end
case 2 %all trials
Wire1Out = {'WireState', 1};
end
end
%BNC2 settings -- assumes connection from Bpod BNC2 out to Trigger 2 of
%PulsePal to trigger PulsePal's output channel 3+4 connected to laser & recording
%system to switch laser on
%default: no laser, no BNC to high.
BNC2OutWT = 0;
BNC2OutST = 0;
BNC2OutPre = 0;
BNC2OutMT = 0;
BNC2OutReward = 0;
BNC2OutFB = 0;
BNC2OutITI = 0;
BNC2OutWaitC=0;
if BpodSystem.Data.Custom.LaserTrial(iTrial) %laser trial. BNC2 to high (1 still low).
if TaskParameters.GUI.LaserTimeInvestment
BNC2OutWT = 2;%waiting time states
end
if TaskParameters.GUI.LaserStim
BNC2OutST = 2;%stimulus time states
end
if TaskParameters.GUI.LaserPreStim
BNC2OutPre = 2;%pre stimulus states
end
if TaskParameters.GUI.LaserMov
BNC2OutMT = 2;%movement states
end
if TaskParameters.GUI.LaserRew
BNC2OutReward = 2;%reward delivery
end
if TaskParameters.GUI.LaserFeedback
BNC2OutFB = 2;%feedback states (delays)
end
if TaskParameters.GUI.LaserITI
BNC2OutITI = 2; %iti (iti at end of trial)
end
end
if BpodSystem.Data.Custom.LaserTrial(max([1,iTrial-1]))%last trial was laser trial
if TaskParameters.GUI.LaserITI
BNC2OutWaitC = 2; %'iti' (pre center poke enter)
end
end
%% Build state matrix
sma = NewStateMatrix();
sma = SetGlobalTimer(sma,1,FeedbackDelayCorrect);
sma = SetGlobalTimer(sma,2,FeedbackDelayError);
sma = SetGlobalTimer(sma,3,TaskParameters.GUI.MinSampleAud);
sma = AddState(sma, 'Name', 'PreITI_start',...
'Timer', 0.05,...
'StateChangeConditions', {'Tup','preITI'},...
'OutputActions', Wire1Out);
sma = AddState(sma, 'Name', 'preITI',...
'Timer', TaskParameters.GUI.PreITI,...
'StateChangeConditions', {'Tup','wait_Cin'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'wait_Cin',...
'Timer', TaskParameters.GUI.CenterWaitMax,...
'StateChangeConditions', {CenterPortIn, 'stay_Cin','Tup','ITI'},...
'OutputActions', {'SoftCode',1,strcat('PWM',num2str(CenterPort)),PortLEDs,'BNCState',BNC2OutWaitC});
% sma = AddState(sma, 'Name', 'pre_odor_delivery',...
% 'Timer', 0.1,... % Time for odor to reach nostrils (Junya filtered these trials out offline)
% 'StateChangeConditions', {CenterPortOut,'ITI','Tup','odor_delivery'},...
% 'OutputActions', {'SoftCode',BpodSystem.Data.Custom.OdorPair(iTrial)});
if BpodSystem.Data.Custom.AuditoryTrial(iTrial)
if BpodSystem.Data.Custom.ClickTask(iTrial)
sma = AddState(sma, 'Name', 'stay_Cin',...
'Timer', TaskParameters.GUI.StimDelay,...
'StateChangeConditions', {CenterPortOut,'broke_fixation','Tup', 'StartStimTimer'},...
'OutputActions',{'BNCState',BNC2OutPre});
sma = AddState(sma, 'Name', 'broke_fixation',...
'Timer',0,...
'StateChangeConditions',{'Tup','timeOut_BrokeFixation'},...
'OutputActions',{});
sma = AddState(sma, 'Name', 'StartStimTimer',...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'stimulus_delivery_min'},...
'OutputActions',{'GlobalTimerTrig',3});
sma = AddState(sma, 'Name', 'stimulus_delivery_min',...
'Timer', TaskParameters.GUI.MinSampleAud,...
'StateChangeConditions', {'Tup','stimulus_delivery', CenterPortOut, 'CenterGrace', 'GlobalTimer3_End', 'stimulus_delivery'},...
'OutputActions', {'BNCState',1+BNC2OutST});
sma = AddState(sma, 'Name', 'CenterGrace',...
'Timer', TaskParameters.GUI.CenterGrace,...
'StateChangeConditions', {'Tup','early_withdrawal', 'GlobalTimer3_End','stimulus_delivery', CenterPortIn, 'stimulus_delivery_min'},...
'OutputActions', {'BNCState',1+BNC2OutST});
sma = AddState(sma, 'Name', 'early_withdrawal',...
'Timer',0,...
'StateChangeConditions',{'Tup','timeOut_EarlyWithdrawal'},...
'OutputActions',{'BNCState',0});
sma = AddState(sma, 'Name', 'stimulus_delivery',...
'Timer', TaskParameters.GUI.AuditoryStimulusTime - TaskParameters.GUI.MinSampleAud,...
'StateChangeConditions', {CenterPortOut,'wait_Sin_start','Tup','wait_Sin_start'},...
'OutputActions', {'BNCState',1+BNC2OutST});
if TaskParameters.GUI.LaserSoftCode
sma=AddState(sma,'Name','wait_Sin_start',...
'Timer',.3,...
'StateChangeConditions', {'Tup','ITI','SoftCode2','wait_Sin'},...%listen back for softcode
'OutputActions',{'SoftCode',31});
else
sma=AddState(sma,'Name','wait_Sin_start',...
'Timer',0,...
'StateChangeConditions', {'Tup','wait_Sin'},...%move on directly
'OutputActions',{});
end
sma = AddState(sma, 'Name', 'wait_Sin',...
'Timer',TaskParameters.GUI.ChoiceDeadLine,...
'StateChangeConditions', {LeftPortIn,'start_Lin',RightPortIn,'start_Rin',SwitchPortIn,'start_Swin','Tup','missed_choice'},...
'OutputActions',{'BNCState',0+BNC2OutMT,strcat('PWM',num2str(SwitchPort)),PortLEDs, strcat('PWM',num2str(LeftPort)),PortLEDs,strcat('PWM',num2str(RightPort)),PortLEDs});
else %frequency task
sma = AddState(sma, 'Name', 'stay_Cin',...
'Timer', TaskParameters.GUI.StimDelay,...
'StateChangeConditions', {CenterPortOut,'broke_fixation','Tup', 'stimulus_delivery_trigger'},...
'OutputActions',{'BNCState',BNC2OutPre});
sma = AddState(sma, 'Name', 'stimulus_delivery_trigger',...
'Timer', 0.1,...
'StateChangeConditions', {CenterPortOut,'broke_fixation','Tup','No_Stim','BNC1High','stimulus_delivery_min'},...
'OutputActions', {'SoftCode',21,'BNCState',BNC2OutST});%play stim
sma = AddState(sma, 'Name', 'No_Stim',...
'Timer', 0.01,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', {'SoftCode',22});%stop stim
sma = AddState(sma, 'Name', 'stimulus_delivery_min',...
'Timer', TaskParameters.GUI.MinSampleAud,...
'StateChangeConditions', {CenterPortOut,'early_withdrawal','Tup','stimulus_delivery'},...
'OutputActions', {'BNCState',BNC2OutST});
sma = AddState(sma, 'Name', 'early_withdrawal',...
'Timer',0,...
'StateChangeConditions',{'Tup','timeOut_EarlyWithdrawal'},...
'OutputActions',{'SoftCode',22});%stop stim
sma = AddState(sma, 'Name', 'stimulus_delivery',...
'Timer', TaskParameters.GUI.AuditoryStimulusTime - TaskParameters.GUI.MinSampleAud,...
'StateChangeConditions', {CenterPortOut,'wait_Sin','Tup','wait_Sin'},...
'OutputActions', {'BNCState',BNC2OutST});
sma = AddState(sma, 'Name', 'wait_Sin',...
'Timer',TaskParameters.GUI.ChoiceDeadLine,...
'StateChangeConditions', {LeftPortIn,'start_Lin',RightPortIn,'start_Rin',SwitchPortIn,'start_Swin','Tup','missed_choice'},...
'OutputActions',{'BNCState',BNC2OutMT,'SoftCode',22,strcat('PWM',num2str(SwitchPort)),PortLEDs,strcat('PWM',num2str(LeftPort)),PortLEDs,strcat('PWM',num2str(RightPort)),PortLEDs});
end
else
sma = AddState(sma, 'Name', 'stay_Cin',...
'Timer', TaskParameters.GUI.StimDelay,...
'StateChangeConditions', {CenterPortOut,'broke_fixation','Tup', 'stimulus_delivery_min'},...
'OutputActions',{'BNCState',BNC2OutPre});
sma = AddState(sma, 'Name', 'stimulus_delivery_min',...
'Timer', TaskParameters.GUI.OdorStimulusTimeMin,...
'StateChangeConditions', {CenterPortOut,'early_withdrawal','Tup','stimulus_delivery'},...
'OutputActions', {'BNCState',BNC2OutST,'SoftCode',BpodSystem.Data.Custom.OdorPair(iTrial)});
sma = AddState(sma, 'Name', 'early_withdrawal',...
'Timer',0,...
'StateChangeConditions',{'Tup','timeOut_EarlyWithdrawal'},...
'OutputActions',{});
sma = AddState(sma, 'Name', 'stimulus_delivery',...
'Timer', 0,...
'StateChangeConditions', {CenterPortOut,'wait_Sin'},...
'OutputActions', {'BNCState',BNC2OutST});
sma = AddState(sma, 'Name', 'wait_Sin',...
'Timer',TaskParameters.GUI.ChoiceDeadLine,...
'StateChangeConditions', {LeftPortIn,'start_Lin',RightPortIn,'start_Rin',SwitchPortIn,'start_Swin','Tup','missed_choice'},...
'OutputActions',{'BNCState',BNC2OutMT,'SoftCode',1,strcat('PWM',num2str(SwitchPort)),PortLEDs,strcat('PWM',num2str(LeftPort)),PortLEDs,strcat('PWM',num2str(RightPort)),PortLEDs});
end
sma = AddState(sma, 'Name','start_Lin',...
'Timer',0,...
'StateChangeConditions', {'Tup','start_Lin2'},...
'OutputActions',{'GlobalTimerTrig',1});%there are two start_Lin states to trigger each global timer separately (Bpod bug)
sma = AddState(sma, 'Name','start_Lin2',...
'Timer',0,...
'StateChangeConditions', {'Tup',LeftPokeAction},...
'OutputActions',{'GlobalTimerTrig',2});
sma = AddState(sma, 'Name','start_Rin',...
'Timer',0,...
'StateChangeConditions', {'Tup','start_Rin2'},...
'OutputActions',{'GlobalTimerTrig',1});%there are two start_Rin states to trigger each global timer separately (Bpod bug)
sma = AddState(sma, 'Name','start_Rin2',...
'Timer',0,...
'StateChangeConditions', {'Tup',RightPokeAction},...
'OutputActions',{'GlobalTimerTrig',2});
sma = AddState(sma, 'Name','start_Swin',...
'Timer',0,...
'StateChangeConditions', {'Tup','start_Swin2'},...
'OutputActions',{'GlobalTimerTrig',1});%there are two start_Lin states to trigger each global timer separately (Bpod bug)
sma = AddState(sma, 'Name','start_Swin2',...
'Timer',0,...
'StateChangeConditions', {'Tup',SwitchPokeAction},...
'OutputActions',{'GlobalTimerTrig',2});
%rewarded left in
sma = AddState(sma, 'Name', 'rewarded_Lin_start',...
'Timer', 0.05,...
'StateChangeConditions', {LeftPortOut,'rewarded_Lin_grace','Tup','rewarded_Lin'},...
'OutputActions', [Wire1OutCorrect, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'rewarded_Lin',...
'Timer', FeedbackDelayCorrect,...
'StateChangeConditions', {LeftPortOut,'rewarded_Lin_grace','Tup','water_L','GlobalTimer1_End','water_L'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'rewarded_Lin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',LeftPortIn,'rewarded_Lin','GlobalTimer1_End','skipped_feedback',CenterPortIn,'skipped_feedback',RightPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%rewarded right in
sma = AddState(sma, 'Name', 'rewarded_Rin_start',...
'Timer', 0.05,...
'StateChangeConditions', {RightPortOut,'rewarded_Rin_grace','Tup','rewarded_Rin'},...
'OutputActions', [Wire1OutCorrect, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'rewarded_Rin',...
'Timer', FeedbackDelayCorrect,...
'StateChangeConditions', {RightPortOut,'rewarded_Rin_grace','Tup','water_R','GlobalTimer1_End','water_R'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'rewarded_Rin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',RightPortIn,'rewarded_Rin','GlobalTimer1_End','skipped_feedback',CenterPortIn,'skipped_feedback',LeftPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%rewarded switch in
sma = AddState(sma, 'Name', 'rewarded_Sin_start',...
'Timer', 0.05,...
'StateChangeConditions', {SwitchPortOut,'rewarded_Sin_grace','Tup','rewarded_Sin'},...
'OutputActions', [Wire1OutCorrect, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'rewarded_Sin',...
'Timer', FeedbackDelayCorrect,...
'StateChangeConditions', {SwitchPortOut,'rewarded_Sin_grace','Tup','water_S','GlobalTimer1_End','water_S'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'rewarded_Sin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',SwitchPortIn,'rewarded_Sin','GlobalTimer1_End','skipped_feedback',CenterPortIn,'skipped_feedback',RightPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%unrewarded left in
sma = AddState(sma, 'Name', 'unrewarded_Lin_start',...
'Timer', 0.05,...
'StateChangeConditions', {LeftPortOut,'unrewarded_Lin_grace','Tup','unrewarded_Lin'},...
'OutputActions', [Wire1OutError, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'unrewarded_Lin',...
'Timer', FeedbackDelayError,...
'StateChangeConditions', {LeftPortOut,'unrewarded_Lin_grace','Tup','timeOut_IncorrectChoice','GlobalTimer2_End','timeOut_IncorrectChoice'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'unrewarded_Lin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',LeftPortIn,'unrewarded_Lin','GlobalTimer2_End','skipped_feedback',CenterPortIn,'skipped_feedback',RightPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%unrewarded right in
sma = AddState(sma, 'Name', 'unrewarded_Rin_start',...
'Timer', 0.05,...
'StateChangeConditions', {RightPortOut,'unrewarded_Rin_grace','Tup','unrewarded_Rin'},...
'OutputActions', [Wire1OutError, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'unrewarded_Rin',...
'Timer', FeedbackDelayError,...
'StateChangeConditions', {RightPortOut,'unrewarded_Rin_grace','Tup','timeOut_IncorrectChoice','GlobalTimer2_End','timeOut_IncorrectChoice'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'unrewarded_Rin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',RightPortIn,'unrewarded_Rin','GlobalTimer2_End','skipped_feedback',CenterPortIn,'skipped_feedback',LeftPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%unrewarded switch in
sma = AddState(sma, 'Name', 'unrewarded_Sin_start',...
'Timer', 0.05,...
'StateChangeConditions', {SwitchPortOut,'unrewarded_Sin_grace','Tup','unrewarded_Sin'},...
'OutputActions', [Wire1OutError, {'BNCState',BNC2OutWT}]);
sma = AddState(sma, 'Name', 'unrewarded_Sin',...
'Timer', FeedbackDelayError,...
'StateChangeConditions', {SwitchPortOut,'unrewarded_Sin_grace','Tup','timeOut_IncorrectChoice','GlobalTimer2_End','timeOut_IncorrectChoice'},...
'OutputActions', {'BNCState',BNC2OutWT});
sma = AddState(sma, 'Name', 'unrewarded_Sin_grace',...
'Timer', TaskParameters.GUI.FeedbackDelayGrace,...
'StateChangeConditions',{'Tup','skipped_feedback',SwitchPortIn,'unrewarded_Sin','GlobalTimer2_End','skipped_feedback',CenterPortIn,'skipped_feedback',LeftPortIn,'skipped_feedback'},...
'OutputActions', {'BNCState',BNC2OutWT});
%water states
sma = AddState(sma, 'Name', 'water_L',...
'Timer', LeftValveTime,...
'StateChangeConditions', {'Tup','DrinkingL'},...
'OutputActions', {'ValveState', LeftValve,'BNCState',BNC2OutReward});
sma = AddState(sma, 'Name', 'water_R',...
'Timer', RightValveTime,...
'StateChangeConditions', {'Tup','DrinkingR'},...
'OutputActions', {'ValveState', RightValve,'BNCState',BNC2OutReward});
sma = AddState(sma, 'Name', 'water_S',...
'Timer', SwitchValveTime,...
'StateChangeConditions', {'Tup','DrinkingS'},...
'OutputActions', {'ValveState', SwitchValve,'BNCState',BNC2OutReward});
sma = AddState(sma, 'Name', 'DrinkingL',...
'Timer', TaskParameters.GUI.DrinkingTime,...
'StateChangeConditions', {'Tup','ITI', LeftPortOut, 'DrinkingGraceL'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'DrinkingR',...
'Timer', TaskParameters.GUI.DrinkingTime,...
'StateChangeConditions', {'Tup','ITI', RightPortOut, 'DrinkingGraceR'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'DrinkingS',...
'Timer', TaskParameters.GUI.DrinkingTime,...
'StateChangeConditions', {'Tup','ITI', SwitchPortOut, 'DrinkingGraceS'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'DrinkingGraceR',...
'Timer', TaskParameters.GUI.DrinkingGrace,...
'StateChangeConditions', {'Tup','ITI', RightPortIn, 'DrinkingR'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'DrinkingGraceL',...
'Timer', TaskParameters.GUI.DrinkingGrace,...
'StateChangeConditions', {'Tup','ITI', LeftPortIn, 'DrinkingL'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'DrinkingGraceS',...
'Timer', TaskParameters.GUI.DrinkingGrace,...
'StateChangeConditions', {'Tup','ITI', SwitchPortIn, 'DrinkingS'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'timeOut_BrokeFixation',...
'Timer',TaskParameters.GUI.TimeOutBrokeFixation,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'SoftCode',11,'BNCState',BNC2OutFB});
sma = AddState(sma, 'Name', 'timeOut_EarlyWithdrawal',...
'Timer',TaskParameters.GUI.TimeOutEarlyWithdrawal,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'SoftCode',11,'BNCState',BNC2OutFB});
if TaskParameters.GUI.IncorrectChoiceFeedbackType == 2 % IncorrectChoiceFeedbackType == Tone
sma = AddState(sma, 'Name', 'timeOut_IncorrectChoice',...
'Timer',TaskParameters.GUI.TimeOutIncorrectChoice,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'SoftCode',11,'BNCState',BNC2OutFB});
elseif TaskParameters.GUI.IncorrectChoiceFeedbackType == 3 % IncorrectChoiceFeedbackType == PortLED
sma = AddState(sma, 'Name', 'timeOut_IncorrectChoice',...
'Timer',0.1,...
'StateChangeConditions',{'Tup','timeOut_IncorrectChoice2'},...
'OutputActions',{strcat('PWM',num2str(LeftPort)),PortLEDs,strcat('PWM',num2str(CenterPort)),PortLEDs,strcat('PWM',num2str(RightPort)),PortLEDs,'BNCState',BNC2OutFB});
sma = AddState(sma, 'Name', 'timeOut_IncorrectChoice2',...
'Timer',TaskParameters.GUI.TimeOutIncorrectChoice,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'BNCState',BNC2OutFB});
else % IncorrectChoiceFeedbackType == None
sma = AddState(sma, 'Name', 'timeOut_IncorrectChoice',...
'Timer',TaskParameters.GUI.TimeOutIncorrectChoice,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'BNCState',BNC2OutFB});
end
if TaskParameters.GUI.SkippedFeedbackFeedbackType == 2 % SkippedFeedbackFeedbackType == Tone
sma = AddState(sma, 'Name', 'timeOut_SkippedFeedback',...
'Timer',TaskParameters.GUI.TimeOutSkippedFeedback,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'SoftCode',12,'BNCState',BNC2OutFB});
elseif TaskParameters.GUI.SkippedFeedbackFeedbackType == 3 % SkippedFeedbackFeedbackType == PortLED
sma = AddState(sma, 'Name', 'timeOut_SkippedFeedback',...
'Timer',0.1,...
'StateChangeConditions',{'Tup','timeOut_SkippedFeedback2'},...
'OutputActions',{strcat('PWM',num2str(LeftPort)),PortLEDs,strcat('PWM',num2str(CenterPort)),PortLEDs,strcat('PWM',num2str(RightPort)),PortLEDs,'BNCState',BNC2OutFB});
sma = AddState(sma, 'Name', 'timeOut_SkippedFeedback2',...
'Timer',TaskParameters.GUI.TimeOutSkippedFeedback,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'BNCState',BNC2OutFB});
else % SkippedFeedbackFeedbackType == None
sma = AddState(sma, 'Name', 'timeOut_SkippedFeedback',...
'Timer',TaskParameters.GUI.TimeOutSkippedFeedback,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{'BNCState',BNC2OutFB});
end
sma = AddState(sma, 'Name', 'skipped_feedback',...
'Timer', 0,...
'StateChangeConditions', {'Tup','timeOut_SkippedFeedback'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'missed_choice',...
'Timer',0,...
'StateChangeConditions',{'Tup','ITI'},...
'OutputActions',{});
sma = AddState(sma, 'Name', 'ITI',...
'Timer',max(TaskParameters.GUI.ITI,0.5),...
'StateChangeConditions',{'Tup','exit'},...
'OutputActions',{'SoftCode',9,'BNCState',BNC2OutITI}); % Sets flow rates for next trial
% sma = AddState(sma, 'Name', 'state_name',...
% 'Timer', 0,...
% 'StateChangeConditions', {},...
% 'OutputActions', {});
end