forked from tsgouvea/TaskMatching
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stateMatrix.m
184 lines (175 loc) · 6.72 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
function sma = stateMatrix()
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);
ValveTimes = GetValveTimes(TaskParameters.GUI.rewardAmount, [LeftPort RightPort]);
LeftPortOut = strcat('Port',num2str(LeftPort),'Out');
CenterPortOut = strcat('Port',num2str(CenterPort),'Out');
RightPortOut = strcat('Port',num2str(RightPort),'Out');
LeftPortIn = strcat('Port',num2str(LeftPort),'In');
CenterPortIn = strcat('Port',num2str(CenterPort),'In');
RightPortIn = strcat('Port',num2str(RightPort),'In');
LeftValve = 2^(LeftPort-1);
RightValve = 2^(RightPort-1);
LeftValveTime = GetValveTimes(TaskParameters.GUI.rewardAmount, LeftPort);
RightValveTime = GetValveTimes(TaskParameters.GUI.rewardAmount, RightPort);
if BpodSystem.Data.Custom.Baited.Left(end)
LeftPokeAction = 'rewarded_Lin';
else
LeftPokeAction = 'unrewarded_Lin';
end
if BpodSystem.Data.Custom.Baited.Right(end)
RightPokeAction = 'rewarded_Rin';
else
RightPokeAction = 'unrewarded_Rin';
end
%%
sma = NewStateMatrix();
sma = SetGlobalTimer(sma,1,TaskParameters.GUI.FeedbackDelay);
sma = AddState(sma, 'Name', 'state_0',...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'wait_Cin'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'wait_Cin',...
'Timer', 0,...
'StateChangeConditions', {CenterPortIn, 'Cin'},...
'OutputActions', {strcat('PWM',num2str(CenterPort)),255});
sma = AddState(sma, 'Name', 'Cin',...
'Timer', TaskParameters.GUI.StimDelay,...
'StateChangeConditions', {CenterPortOut, 'EarlyCout','Tup','stillSampling'},...
'OutputActions', {});
if TaskParameters.GUI.LoopbackFix
smaChange = {'Tup','wait_Cin'};
smaOut = {};
else
smaChange = {'Tup','exit'};
smaOut = {'SoftCode',1};
end
sma = AddState(sma, 'Name', 'EarlyCout',...
'Timer', TaskParameters.GUI.EarlyCoutPenalty,...
'StateChangeConditions', smaChange,...
'OutputActions', smaOut);
sma = AddState(sma, 'Name', 'stillSampling',...
'Timer', 0,...
'StateChangeConditions', {CenterPortOut, 'wait_Sin'},...
'OutputActions', {'SoftCode',2});
sma = AddState(sma, 'Name', 'wait_Sin',...
'Timer',TaskParameters.GUI.ChoiceDeadline,...
'StateChangeConditions', {LeftPortIn,'start_Lin',RightPortIn,'start_Rin','Tup','ITI'},...
'OutputActions',{strcat('PWM',num2str(LeftPort)),255,strcat('PWM',num2str(RightPort)),255});
sma = AddState(sma,'Name', 'start_Lin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','Lin'},...
'OutputActions',{'GlobalTimerTrig',1});
sma = AddState(sma,'Name', 'start_Rin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','Rin'},...
'OutputActions',{'GlobalTimerTrig',1});
smaChange = {LeftPortOut, 'Lin_grace'};
switch LeftPokeAction
case 'rewarded_Lin'
smaChange = {smaChange{:},'GlobalTimer1_End','rewarded_Lin','Tup','rewarded_Lin'};
case 'unrewarded_Lin'
if TaskParameters.GUI.CatchUnrwd
smaChange = {smaChange{:},'GlobalTimer1_End','stillLin','Tup','stillLin'};
else
smaChange = {smaChange{:},'GlobalTimer1_End','unrewarded_Lin','Tup','unrewarded_Lin'};
end
end
sma = AddState(sma, 'Name', 'Lin',...
'Timer', TaskParameters.GUI.FeedbackDelay,...
'StateChangeConditions', smaChange,...
'OutputActions', {});
sma = AddState(sma, 'Name', 'stillLin',...
'Timer', 0,...
'StateChangeConditions', {LeftPortOut,'stillLin_grace'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Lin_grace',...
'Timer', TaskParameters.GUI.Grace,...
'StateChangeConditions', {LeftPortIn,'Lin','Tup', 'EarlyLout','GlobalTimer1_End','EarlyLout'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'stillLin_grace',...
'Timer', TaskParameters.GUI.Grace,...
'StateChangeConditions', {LeftPortIn,'stillLin','Tup', 'unrewarded_Lin'},...
'OutputActions', {});
smaChange = {RightPortOut, 'Rin_grace'};
switch RightPokeAction
case 'rewarded_Rin'
smaChange = {smaChange{:},'GlobalTimer1_End','rewarded_Rin','Tup','rewarded_Rin'};
case 'unrewarded_Rin'
if TaskParameters.GUI.CatchUnrwd
smaChange = {smaChange{:},'GlobalTimer1_End','stillRin','Tup','stillRin'};
else
smaChange = {smaChange{:},'GlobalTimer1_End','unrewarded_Rin','Tup','unrewarded_Rin'};
end
end
sma = AddState(sma, 'Name', 'Rin',...
'Timer', TaskParameters.GUI.FeedbackDelay,...
'StateChangeConditions', smaChange,...
'OutputActions', {});
sma = AddState(sma, 'Name', 'stillRin',...
'Timer', 0,...
'StateChangeConditions', {RightPortOut,'stillRin_grace'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Rin_grace',...
'Timer', TaskParameters.GUI.Grace,...
'StateChangeConditions', {RightPortIn,'Rin','Tup', 'EarlyRout','GlobalTimer1_End','EarlyRout'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'stillRin_grace',...
'Timer', TaskParameters.GUI.Grace,...
'StateChangeConditions', {RightPortIn,'stillRin','Tup', 'unrewarded_Rin'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'rewarded_Lin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','water_L'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'rewarded_Rin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','water_R'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'water_L',...
'Timer', LeftValveTime,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', {'ValveState', LeftValve});
sma = AddState(sma, 'Name', 'water_R',...
'Timer', RightValveTime,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', {'ValveState', RightValve});
smaOut = {'SoftCode',3};
if TaskParameters.GUI.CatchUnrwd
smaOut = {};
end
sma = AddState(sma, 'Name', 'unrewarded_Lin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', smaOut);
sma = AddState(sma, 'Name', 'unrewarded_Rin',...
'Timer', 0,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', smaOut);
smaOut = {'SoftCode',1};
smaTimer = TaskParameters.GUI.EarlySoutPenalty;
if TaskParameters.GUI.CatchUnrwd
smaOut = {};
smaTimer = 0;
end
sma = AddState(sma, 'Name', 'EarlyLout',...
'Timer', smaTimer,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', smaOut);
sma = AddState(sma, 'Name', 'EarlyRout',...
'Timer', smaTimer,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', smaOut);
smaTimer = TaskParameters.GUI.ITI;
if TaskParameters.GUI.VI
smaTimer = exprnd(smaTimer);
end
sma = AddState(sma, 'Name', 'ITI',...
'Timer',smaTimer,...
'StateChangeConditions',{'Tup','exit'},...
'OutputActions',{});
end