-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathFigureGroundStateInfo.m
426 lines (386 loc) · 17.7 KB
/
FigureGroundStateInfo.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
% FIGURE GROUND state configuration file, this gets loaded by opticka via
% runExperiment class. See Jones et al., 2015 PNAS for the description of
% this task
%
% State files control the logic of a behavioural task, switching between
% states and executing functions on ENTER, WITHIN and on EXIT of states. In
% addition there are TRANSITION function sets which can test things like eye
% position to conditionally jump to another state. This state control file
% will usually be run in the scope of the calling runExperiment.runTask()
% method and other objects will be available at run time (with easy to use
% names listed below). The following class objects are already loaded by
% runTask() and available to use; each object has methods (functions) useful
% for running the task:
%
% me = runExperiment object ('self' in OOP terminology)
% s = screenManager object
% aM = audioManager object
% stims = our list of stimuli (metaStimulus class)
% sM = State Machine (stateMachine class)
% task = task sequence (taskSequence class)
% eT = eyetracker manager
% io = digital I/O to recording system
% rM = Reward Manager (LabJack or Arduino TTL trigger to reward system/Magstim)
% bR = behavioural record plot (on-screen GUI during a task run)
% tS = structure to hold general variables, will be saved as part of the data
%==================================================================
%------------------------General Settings--------------------------
tS.useTask = true; %==use taskSequence (randomises stimulus variables)
tS.rewardTime = 250; %==TTL time in milliseconds
tS.rewardPin = 2; %==Output pin, 2 by default with Arduino.
tS.checkKeysDuringStimulus = false; %==allow keyboard control within stimulus state? Slight drop in performance…
tS.recordEyePosition = false; %==record local copy of eye position, **in addition** to the eyetracker?
tS.askForComments = true; %==UI requestor asks for comments before/after run
tS.saveData = true; %==save behavioural and eye movement data?
tS.includeErrors = false; %==do we update the trial number even for incorrect saccade/fixate, if true then we call updateTask for both correct and incorrect, otherwise we only call updateTask() for correct responses
tS.name = 'figure-ground'; %==name of this protocol
tS.nStims = stims.n; %==number of stimuli, taken from metaStimulus object
tS.tOut = 5; %==if wrong response, how long to time out before next trial
tS.CORRECT = 1; %==the code to send eyetracker for correct trials
tS.BREAKFIX = -1; %==the code to send eyetracker for break fix trials
tS.INCORRECT = -5; %==the code to send eyetracker for incorrect trials
tS.luminancePedestal = [0.5 0.5 0.5]; %used during training, it sets the clip behind the figure to a different luminance which makes the figure more salient and thus easier to train to.
tS.correctSound = [2000, 0.1, 0.1]; %==freq,length,volume
tS.errorSound = [300, 1, 1]; %==freq,length,volume
%==================================================================
%----------------Debug logging to command window------------------
% uncomment each line to get specific verbose logging from each of these
% components; you can also set verbose in the opticka GUI to enable all of
% these…
%sM.verbose = true; %==print out stateMachine info for debugging
%stims.verbose = true; %==print out metaStimulus info for debugging
%io.verbose = true; %==print out io commands for debugging
%eT.verbose = true; %==print out eyelink commands for debugging
%rM.verbose = true; %==print out reward commands for debugging
%task.verbose = true; %==print out task info for debugging
%==================================================================
%-----------------INITIAL Eyetracker Settings----------------------
% These settings define the initial fixation window and set up for the
% eyetracker. They may be modified during the task (i.e. moving the
% fixation window towards a target, enabling an exclusion window to stop
% the subject entering a specific set of display areas etc.)
%
eT.name = tS.name;
if tS.saveData == true; eT.recordData = true; end %===save ET data?
% initial fixation X position in degrees (0° is screen centre)
tS.fixX = 0;
% initial fixation Y position in degrees
tS.fixY = 0;
% time to search and enter fixation window
tS.firstFixInit = 1;
% time to maintain fixation within window, can be single value or a range
% to randomise between
tS.firstFixTime = [0.7 1];
% circular fixation window radius in degrees
tS.firstFixRadius = 1;
% do we forbid eye to enter-exit-reenter fixation window?
tS.strict = true;
% do we add an exclusion zone where subject cannot saccade to...
tS.exclusionZone = [];
% historical log of X and Y position, and exclusion zone
me.lastXPosition = tS.fixX;
me.lastYPosition = tS.fixY;
me.lastXExclusion = [];
me.lastYExclusion = [];
% target fixation parameters
tS.targetFixInit = 1;
tS.targetFixTime = [0.5 0.7];
tS.targetRadius = 5;
%Initialise the eyeTracker object with X, Y, FixInitTime, FixTime, Radius, StrictFix
eT.updateFixationValues(tS.fixX, tS.fixY, tS.firstFixInit, tS.firstFixTime, tS.firstFixRadius, tS.strict);
%Ensure we don't start with any exclusion zones set up
resetAll(eT);
%==================================================================
%----WHICH states assigned as correct or break for online plot?----
%----You need to use regex patterns for the match (doc regexp)-----
bR.correctStateName = "correct";
bR.breakStateName = ["breakfix","incorrect"];
%randomise stimulus variables every trial? useful during initial training but not for
%data collection.
stims.choice = [];
stims.stimulusTable = [];
% allows using arrow keys to control this table during the main loop
% ideal for mapping receptive fields so we can twiddle parameters, normally not used
% for normal tasks
stims.controlTable = [];
stims.tableChoice = 1;
% this allows us to enable subsets from our stimulus list. So each set is a
% particular display like fixation spot only, background. During the trial you can
% use the showSet method of stims to change to a particular stimulus set.
% numbers are the stimuli in the opticka UI
stims.stimulusSets = {[1 2 3 4],[1,4]};
stims.setChoice = 1;
hide(stims);
%which stimulus in the list is used for a fixation target? For this protocol it means
%the subject must fixate this stimulus (the figure is #3 in the list) to get the
%reward.
stims.fixationChoice = 3;
%===================================================================
%===================================================================
%===================================================================
%-----------------State Machine Task Functions---------------------
% Each cell {array} holds a set of anonymous function handles which are
% executed by the state machine to control the experiment. The state
% machine can run sets at entry ['entryFcn'], during ['withinFcn'], to
% trigger a transition jump to another state ['transitionFcn'], and at exit
% ['exitFcn'. Remember these {sets} need to access the objects that are
% available within the runExperiment context (see top of file). You can
% also add global variables/objects then use these. The values entered here
% are set on load, if you want up-to-date values then you need to use
% methods/function wrappers to retrieve/set them.
%====================================================PAUSE
%pause entry
pauseEntryFcn = {
% hide all our stimuli
@()hide(stims);
% blank the subject display
@()drawBackground(s);
@()drawTextNow(s,'PAUSED, press [p] to resume...');
@()disp('PAUSED, press [p] to resume...');
% blank the eyetracker screen
@()trackerClearScreen(eT);
@()trackerDrawText(eT,'PAUSED, press [P] to resume...');
% send message to eyetracker data stream
@()trackerMessage(eT,'TRIAL_RESULT -100');
% make sure we set offline (only for eyelink, ignored by tobii)
@()setOffline(eT);
% stop recording eye position data (true means tobii also stops)
@()stopRecording(eT, true);
% no need to flip the PTB screen
@()needFlip(me, false);
% no need to check eye position
@()needEyeSample(me,false);
};
%--------------------pause exit
pauseExitFcn = {
@()needFlip(me, true);
@()resumeRecording(io); %for plexon
};
%--------------------prefixate entry
prefixEntryFcn = {
% make sure we set offline (only for eyelink, ignored by tobii)
@()setOffline(eT);
%reset all fixation counters ready for a new trial
@()resetFixationHistory(eT); %reset the stored X and Y values
@()updateFixationValues(eT,tS.fixX,tS.fixY,tS.firstFixInit,tS.firstFixTime,tS.firstFixRadius);
@()show(stims);
@()getStimulusPositions(stims); %make a struct the eT can use for drawing stim positions
@()trackerClearScreen(eT);
@()trackerDrawFixation(eT); %draw fixation window on eyelink computer
@()trackerDrawStimuli(eT,stims.stimulusPositions); %draw location of stimulus on eyelink
@()edit(stims,4,'colourOut',[0.5 0.5 0.5]); %dim fix spot
@()logRun(me,'PREFIX'); %fprintf current trial info
};
%--------------------prefixate
prefixFcn = { @()draw(stims); };
%--------------------prefixate exit
prefixExitFcn = {
% messages that define trial start for eyetracker
@()trackerMessage(eT,'V_RT MESSAGE END_FIX END_RT');
@()trackerMessage(eT,sprintf('TRIALID %i',getTaskIndex(me)));
@()trackerMessage(eT,['UUID ' UUID(sM)]); %add in the uuid of the current state for good measure
%start eyelink recording eye data
@()startRecording(eT);
%status text on the eyetracker display
@()statusMessage(eT,'Get Fixation...');
@()needEyeSample(me,true);
};
%--------------------fixate entry
fixEntryFcn = {
% edit fixation cross to have a yellow background
@()edit(stims,4,'colourOut',[1 1 0]); %edit fixation spot to be yellow
% send I/O strobe for start of fixation
@()startFixation(io);
};
%--------------------fix within
fixFcn = {
@()draw(stims);
@()drawPhotoDiodeSquare(s,[0 0 0])
};
%--------------------test we are fixated for a certain length of time
initFixFcn = {
@()testSearchHoldFixation(eT,'stimulus','incorrect');
};
%--------------------exit fixation phase
fixExitFcn = {
% updateFixationTarget(me) checks the current X and Y position of the
% stimuli assigned by stims.fixationChoice and sets fixation windows
% around those stimuli. This allows you to move the fixation from the
% fixation cross to a stimulus target very easily.
@()updateFixationTarget(me, true, tS.targetFixInit, tS.targetFixTime, tS.targetRadius);
@()edit(stims,4,'colourOut',[0.6 0.6 0.5 0.5]); %dim fix spot
@()trackerDrawFixation(eT);
@()trackerMessage(eT,'END_FIX');
};
%--------------------what to run when we enter the stim presentation state
stimEntryFcn = {
@()doStrobe(me,true);
@()doSyncTime(me);
};
%--------------------what to run when we are showing stimuli
stimFcn = {
@()draw(stims);
@()drawPhotoDiodeSquare(s,[1 1 1]);
@()animate(stims); % animate stimuli for subsequent draw
};
%--------------------test we are finding target
testFixFcn = {
@()testSearchHoldFixation(eT,'correct','breakfix');
};
%--------------------as we exit stim presentation state
stimExitFcn = {
@()sendStrobe(io,255);
};
%--------------------if the subject is correct (small reward)
correctEntryFcn = {
@()trackerMessage(eT,'END_RT');
@()timedTTL(rM,0,tS.rewardTime); % labjack sends a TTL to Crist reward system
@()beep(aM,2000); % correct beep
@()statusMessage(eT,'Correct! :-)');
@()hide(stims{4});
@()needEyeSample(me,false);
@()logRun(me,'CORRECT'); %fprintf current trial info
};
%--------------------correct stimulus
correctFcn = {
@()draw(stims);
@()drawTimedSpot(s, 0.5, [0 1 0 1]);
};
%--------------------when we exit the correct state
correctExitFcn = {
%send correct value via I/O
@()correct(io);
@()trackerMessage(eT,['TRIAL_RESULT ' num2str(tS.CORRECT)]);
@()stopRecording(eT); % stop recording in eyelink [tobii ignores this]
@()setOffline(eT); % set eyelink offline [tobii ignores this]
% tell taskSequence to update to the next trial.
@()updatePlot(bR, me); %update our behavioural plot
@()updateTask(task, tS.CORRECT);
% modify our stimuli based on updated trial (find the values from
% taskSequence and set them on metaStimulus), sets strobe value for new
% trial (but doesn't trigger it)
@()updateVariables(me);
% trigger update() for each stimulus in metaStimulus to calculate
% stimuli based on updated variables
@()update(stims);
@()drawTimedSpot(s, 0.5, [0 1 0 1], 0.2, true); %reset the timer on the green spot
@()checkTaskEnded(me); %check if task is finished
@()drawnow;
};
%--------------------incorrect entry
incEntryFcn = {
% send END_RT message to eyetracker
@()trackerMessage(eT,'END_RT');
@()trackerDrawText(eT,'Incorrect! :-(');
@()beep(aM,tS.errorSound);
% hide fixation spot
@()hide(stims{4});
@()needEyeSample(me,false);
@()logRun(me,'INCORRECT'); %fprintf current trial info
};
%--------------------our incorrect stimulus
incFcn = {
@()draw(stims); %we draw but don't animate, therefore static dots…
};
%--------------------incorrect / break exit
incExitFcn = {
@()incorrect(io);
@()trackerMessage(eT,['TRIAL_RESULT ' num2str(tS.INCORRECT)]); %trial incorrect message
@()stopRecording(eT); % stop recording in eyelink [tobii ignores this]
@()updatePlot(bR, me); %update our behavioural plot, must come before updateTask() / updateVariables()
@()resetRun(task);... %we randomise the run within this block to make it harder to guess next trial
@()updateVariables(me,[],true,false); %update the variables via taskSequence if used
@()update(stims); %update our stimuli ready for display
@()checkTaskEnded(me); %check if task is finished
@()drawnow;
};
%--------------------break entry
breakEntryFcn = {
@()trackerMessage(eT,'END_RT');
@()trackerDrawText(eT,'Broke Fixation!');
@()beep(aM,tS.errorSound);
@()hide(stims{4});
@()needEyeSample(me,false);
@()logRun(me,'BREAKFIX'); %fprintf current trial info
};
%--------------------incorrect / break exit
breakExitFcn = {
@()breakFixation(io);
@()trackerMessage(eT,['TRIAL_RESULT ' num2str(tS.BREAKFIX)]);
@()stopRecording(eT);
@()setOffline(eT); % set eyelink offline [tobii ignores this]
@()updatePlot(bR, me); %update our behavioural plot, must come before updateTask() / updateVariables()
@()resetRun(task);... %we randomise the run within this block to make it harder to guess next trial
@()updateVariables(me,[],true,false); %update the variables
@()update(stims); %update our stimuli ready for display
@()checkTaskEnded(me); %check if task is finished
@()drawnow;
};
%--------------------calibration function
calibrateFcn = {
@()drawBackground(s); %blank the display
@()stopRecording(eT); % stop recording in eyelink [tobii ignores this]
@()setOffline(eT); % set eyelink offline [tobii ignores this]
@()rstop(io);
@()trackerSetup(eT); %enter tracker calibrate/validate setup mode
};
%--------------------drift correction function
driftFcn = {
@()drawBackground(s); %blank the display
@()stopRecording(eT); % stop recording in eyelink [tobii ignores this]
@()setOffline(eT); % set eyelink offline [tobii ignores this]
@()rstop(io);
@()driftCorrection(eT) % enter drift correct (only eyelink)
};
offsetFcn = {
@()drawBackground(s); %blank the display
@()stopRecording(eT); % stop recording in eyelink [tobii ignores this]
@()setOffline(eT); % set eyelink offline [tobii ignores this]
@()driftOffset(eT) % enter drift offset (works on tobii & eyelink)
};
%--------------------debug override
overrideFcn = {
% a special mode which enters a matlab debug state so we can manually edit
% object values
@()keyOverride(me);
};
%--------------------screenflash
flashFcn = {
@()drawBackground(s);
@()flashScreen(s, 0.2); % fullscreen flash mode for visual background activity detection
};
%--------------------show 1deg size grid
gridFcn = { @()drawGrid(s); };
% N x 2 cell array of regexpi strings, list to skip the current -> next state's exit functions; for example
% skipExitStates = {'fixate',{'incorrect','breakfix'}}; means that if the currentstate is
% 'fixate' and the next state is either incorrect OR breakfix, then skip the FIXATE exit
% state. Add multiple rows for skipping multiple state's exit states.
sM.skipExitStates = {'fixate',{'incorrect','breakfix'}};
%==============================================================================
%----------------------State Machine Table-------------------------
% specify our cell array that is read by the stateMachine
% remember that transitionFcn can override the time value, so for example
% stimulus shows 2 seconds time, but the transitionFcn can jump to other
% states (correct or breakfix) sooner than this, so this is an upper limit.
stateInfoTmp = {
'name' 'next' 'time' 'entryFcn' 'withinFcn' 'transitionFcn' 'exitFcn';
'pause' 'prefix' inf pauseEntryFcn {} {} pauseExitFcn;
'prefix' 'fixate' 2 prefixEntryFcn prefixFcn {} prefixExitFcn;
'fixate' 'incorrect' 2 fixEntryFcn fixFcn initFixFcn fixExitFcn;
'stimulus' 'incorrect' 2 stimEntryFcn stimFcn testFixFcn stimExitFcn;
'incorrect' 'timeout' 0.25 incEntryFcn incFcn {} incExitFcn;
'breakfix' 'timeout' 0.25 breakEntryFcn incFcn {} breakExitFcn;
'correct' 'prefix' 0.5 correctEntryFcn correctFcn {} correctExitFcn;
'timeout' 'prefix' tS.tOut {} incFcn {} {};
'calibrate' 'pause' 0.5 calibrateFcn {} {} {};
'drift' 'pause' 0.5 driftFcn {} {} {};
'override' 'pause' 0.5 overrideFcn {} {} {};
'flash' 'pause' 0.5 flashFcn {} {} {};
'showgrid' 'pause' 10 {} gridFcn {} {};
};
%----------------------State Machine Table-------------------------
%==============================================================================
disp('================>> Building state info file <<================')
disp(stateInfoTmp)
disp('================>> Loaded state info file <<================')
clearvars -regexp '.+Fcn$' % clear the cell array Fcns in the current workspace