-
Notifications
You must be signed in to change notification settings - Fork 1
/
sessionStart.m
210 lines (174 loc) · 5.86 KB
/
sessionStart.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
%=========================================================================%
% individual states are
%sessionStart
%prepareNextTrial
%run
%timeOut
%trialEnd
%enOfExperiment
%=========================================================================%
% sessionStart-------------(session initiates with experimenter's input
% this can be modified later for animal initiation
function fhandle = sessionStart
global EXP;
global SESSION;
global TRIAL;
global SESSION2REPLAY;
global TRIAL_COUNT;
global oBeepSTART;
global oBeepCORRECT;
global oBeepTIMEOUT;
global oBeepWRONG;
global ScanImageUDP; % the UDP port
global EyeCameraUDP; % the UDP port
global TimelineUDP; % the UDP port
global OptiStimUDP;
global DIRS;
global OFFLINE;
global EXPREF;
global ROOM;
%% defining the sounds for sound signals
sRate = Snd('DefaultRate');
beepSTART = 0.5*MakeBeep(3300, 0.1, sRate);
beepCORRECT = 0.5*MakeBeep(6600, 0.1, sRate);
beepTIMEOUT = rand(round(sRate*EXP.timeOutSoundDuration), 1)-0.5;
beepWRONG = rand(round(sRate*0.2), 1)-0.5;
oBeepSTART = audioplayer(beepSTART, sRate);
oBeepCORRECT = audioplayer(beepCORRECT, sRate);
oBeepTIMEOUT = audioplayer(beepTIMEOUT, sRate);
oBeepWRONG = audioplayer(beepWRONG, sRate);
%% Asking if everything is ready
% MK moved it here, so that folders are not created unless everything is ready
if OFFLINE
start = 1;
else
button = MFquestdlg([-0.2 0.5], 'Ready to go?', '', 'GO!', 'Abort', 'Abort');
if isequal(button, 'GO!')
start = 1;
else
start = 0;
end
HideCursor;
end
if (start == 1)
fhandle = @prepareNextTrial;
else
fprintf('Aborting the experiment\n');
fhandle = [];
abortExperiment;
return;
end
TRIAL_COUNT = 0;
fprintf('\nStarting MouseBall session %s\n', EXPREF);
%% defining the paths (both server and local)
[folders, filename] = dat.expFilePath(EXPREF, 'tmaze');
DIRS.localFolder = fileparts(folders{1});
DIRS.serverFolder = fileparts(folders{2});
DIRS.fileName = filename;
try
if ~isdir(DIRS.serverFolder)
mkdir(DIRS.serverFolder);
end
catch
warning('There was a problem creating the folder %s on the server', DIRS.serverFolder);
end
try
if ~isdir(DIRS.localFolder)
mkdir(DIRS.localFolder);
end
catch
warning(['There was a problem creating a local folder %s', DIRS.localFolder]);
end
%% setting experimental params----------------------------------------------
if isequal(EXP.stimType, 'REPLAY')
% this bit of code is potentially not working (with the new file/pathnames
% used)
[FileName, PathName]=uigetfile('*_TMaze.mat', '', fullfile(DIRS.localFolder, '..'));
data=load([PathName filesep FileName]);
EXP=data.EXP;
EXP.expRef = EXPREF;
EXP.stimType='REPLAY';
% ind=data.SESSION.allTrials
nTrials=length(data.SESSION.allTrials);
ind=true(1, nTrials);
for iTrial=1:nTrials
if isequal(EXP.replayMode, 'notTIMEOUT') && ...
isequal(data.SESSION.allTrials(iTrial).info.outcome, 'TIMEOUT')
ind(iTrial)=false;
end
end
data.SESSION.allTrials=data.SESSION.allTrials(ind);
data.SESSION.stimSequence=data.SESSION.stimSequence(ind);
data.SESSION.contrastSequence=data.SESSION.contrastSequence(ind);
EXP.maxNTrials=length(data.SESSION.allTrials);
if isequal(data.SESSION.allTrials(end).info.outcome, 'USER ABORT')
EXP.maxNTrials=EXP.maxNTrials-1;
end
SESSION2REPLAY=data.SESSION;
end
if isequal(EXP.stimType, 'REPLAY_SCRAMBLED')
% this bit of code is potentially not working (with the new file/pathnames
% used)
[FileName, PathName]=uigetfile('*_TMaze.mat', '', fullfile(DIRS.localFolder, '..'));
data=load([PathName filesep FileName]);
% ind=data.SESSION.allTrials
EXP.expRef = EXPREF;
EXP.maxNTrials=1;
TRIAL = makeScrambled(data);
end
%% MK - a simple geometry correction
% this one meaning that if the stimulus is on both sides we imply that the
% corridor is strictly linear (might not be true in general), and if it is
% not on both sides, then it must be a T-Maze
if isequal(EXP.stimType, 'BOTH')
EXP.roomWidth=EXP.corridorWidth;
else
EXP.roomWidth=3*EXP.corridorWidth;
end
if isequal(EXP.stimType, 'REPLAY_SCRAMBLED')
ROOM = getRoomData(data.EXP);
else
ROOM = getRoomData(EXP);
end
%% MK - this part builds a set of textures suitable for the t-maze task
% in addition it builds a sequence of stimuli to be used in the experiment
% options.gratingContrasts=[0 6 12 25 50];
if isequal(EXP.stimType, 'REPLAY')
SESSION.textures=SESSION2REPLAY.textures;
SESSION.options=SESSION2REPLAY.options;
elseif isequal(EXP.stimType, 'REPLAY_SCRAMBLED')
SESSION.textures=data.SESSION.textures;
SESSION.options = data.SESSION.options;
else
options.gratingContrasts=EXP.contrasts;
options.noiseContrast=EXP.noiseContrast;
options.floorContrast=EXP.floorContrast;
options.sfMultiplier=EXP.sfMultiplier;
options.size=EXP.texturePatchSize;
SESSION.options=options;
[SESSION.textures tx]=buildTextures(options);
end
buildStimSequence;
% generating an empty structure. Log events will go here
SESSION.Log = struct;
%% now send UDPs to all the data hosts
if ~OFFLINE
[animalID, dateID, sessionID] = dat.expRefToMpep(EXPREF);
msgString = sprintf('ExpStart %s %d %d', animalID, dateID, sessionID);
pnet(ScanImageUDP, 'write', msgString);
pnet(ScanImageUDP, 'writePacket');
pnet(EyeCameraUDP, 'write', msgString);
pnet(EyeCameraUDP, 'writePacket');
pnet(TimelineUDP, 'write', msgString);
pnet(TimelineUDP, 'writePacket');
if EXP.optiStim
msgStruct = struct('instruction', 'ExpStart', 'ExpRef', EXPREF);
msgJson = savejson('msg', msgStruct);
pnet(OptiStimUDP, 'write', msgJson);
pnet(OptiStimUDP, 'writePacket');
end
% wait for everybody to start
pause(7);
end
return;
end