-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVTS_doExperiment.m
80 lines (62 loc) · 2.54 KB
/
VTS_doExperiment.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
function quitProg = VTS_doExperiment(params, VTSOptions, VTSDevice, VTSStimulusOptions)
% Set screen params
params = setScreenParams(params);
% Set fixation params
params.dstRect = [592 172 1328 908]; %for NYU3T
params = VTS_setFixationParams(params);
% WARNING! ListChar(2) enables Matlab to record keypresses while disabling
% output to the command window or editor window. This is good for running
% experiments because it prevents buttonpresses from accidentally
% overwriting text in scripts. But it is dangerous because if the code
% quits prematurely, the user may be left unable to type in the command
% window. Command window access can be restored by control-C.
ListenChar(2);
% loading mex functions for the first time can be
% extremely slow (seconds!), so we want to make sure that
% the ones we are using are loaded.
KbCheck;GetSecs;WaitSecs(0.001);
PsychDebugWindowConfiguration(0,0.5);
% Turn off screen warnings
Screen('Preference','VisualDebugLevel', 0);
% check for OpenGL
AssertOpenGL;
Screen('Preference','SkipSyncTests', params.skipSyncTests);
% Open the screen
params.display = openScreen(params.display);
% to allow blending
Screen('BlendFunction', params.display.windowPtr, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
% set priority
Priority(params.runPriority);
%create vibrotactile stimulus
[vibrotactileStimulus, tsv] =...
VTS_createVibrotactileStimulus(params, VTSOptions, VTSStimulusOptions);
% queue the data
queueOutputData(VTSDevice, vibrotactileStimulus);
% wait for go signal
[triggerTime, quitProg] = VTS_pressKey2Begin(params);
%
if ~quitProg
% present the stimulus
[startTime,endTime] = VTS_presentStimulus(VTSDevice);
fprintf(['\nstart delay (ms): ', num2str(round((startTime - triggerTime)*1000)),'\n'])
fprintf(['\nstimulus duration (ms): ', num2str(round((endTime - startTime)*1000)),'\n'])
% After experiment
fName = sprintf('sub-%s_ses-%s%s_task-%s_run-%d', ...
params.subjID, params.site, params.sessionID, params.experiment, params.runID);
% Write out the tsv file
onset = tsv.onsets';
duration = tsv.duration';
stimNums = tsv.stimNums';
stimFile = tsv.stimFile';
trialType = tsv.trialType';
stimulus = table(onset, duration, stimNums, stimFile , trialType);
% Reset priority
Priority(0);
% Save TSV
writetable(stimulus, fullfile('./Stimuli', sprintf('%s.tsv', fName)), ...
'FileType','text', 'Delimiter', '\t');
end
% Close the one on-screen and many off-screen windows
closeScreen(params.display);
ListenChar(1)
return;