-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxExperiment.m
More file actions
192 lines (169 loc) · 5.28 KB
/
xExperiment.m
File metadata and controls
192 lines (169 loc) · 5.28 KB
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
clear;
sca;
clc;
% set running mode
% debugging - to test script with minimal number of trials
% dummymodeTracker - to test eyetracker scripts in a dummy mode
% dummymodeLpt - to test LPT scripts in a dummy mode
% smallscreen - to test PTB in a smaller window
% smallscreenhome - to test PTB on a laptop
% gitpush - to push data commits to remote repo (not-recommended)
runmode = {...
... 'debugging', ...
... 'dummymodeTracker', ...
... 'dummymodeLpt', ...
... 'smallscreen', ...
... 'smallscreenhome', ...
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% NO-EDIT ALLOWED BELOW
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set fixed parameters
datarepo = fullfile('..', 'imat-spc1-data-ptb');
dataremote = 'mdrive';
commitmsg = 'add data:';
tasknames = {};
tasknames.visible = {...
'trackersetup', ...
'shockcalibration', ...
'task01-asso', ...
'task02-con', ...
'task03-inf', ...
'task04-afc', ...
};
tasknames.storage = {...
'trackersetup', ...
'shockcalibration', ...
'task01', ...
'task02', ...
'task03', ...
'task04', ...
};
%% check matlab version
VER = version('-release');
if ~any(strcmp(VER, {'2017b', '2022a'}))
fprintf('Wrong matlab version!\n');
fprintf('Switch to matlab 2017b\n');
return
end
%% check if remote repo is available
[status, ~] = system(sprintf('git -C %s ls-remote', datarepo));
if status ~= 0 && ~isempty(find(strcmp(runmode, 'gitpush'),1))
fprintf('Cannot connect to remote data repo...\n');
cleanup;
return
end
%% select task
[ status, indx ] = runlistdlg( tasknames.visible );
if status ~= 0
cleanup;
return;
end
taskname = tasknames.storage{indx};
%% ask for eyetracker
if ismember(taskname, {'task01', 'task02', 'task03'})
answer = questdlg('Do you want to use eyetracker?', ...
'Eyetracker', ...
'Yes', 'No', 'Yes');
switch answer
case 'No'
runmode{end+1} = 'dummymodeTracker';
end
end
%% test the tracker or run shock calibration
switch taskname
case 'trackersetup'
trackersetup( runmode );
return
case 'shockcalibration'
calibShocks( runmode );
return
end
%% read in subject id
[ status, subjid ] = readinsubjid();
if status ~= 0
cleanup;
return;
end
%% init log parameters
[ logpars ] = initlogpars( subjid, taskname, ...
datarepo, dataremote, commitmsg, ...
runmode);
%% check if there are some uncommited data
commitmsg = sprintf('add data outside ptb');
gitcommitdata(logpars.datarepo, commitmsg, logpars.dataremote, 'gitpush', logpars.gitpush);
%% init ptb log
timeStamp = datestr( now(),'yyyy-mm-dd_HH-MM-SS' );
ptlogfile = fullfile(logpars.subjdir, ...
sprintf('%s_ptb_log.txt', logpars.taskname));
if exist(ptlogfile, 'file') == 2
delete(ptlogfile);
end
diary(ptlogfile);
%% save logpars
fprintf('Initialising experiment...\n\n');
%% init LPT port
if all([logpars.dummymodeLpt, logpars.parallelmodeLpt])
[ status, LPT ] = initlpt('dummy', 'parallel');
elseif logpars.dummymodeLpt
[ status, LPT ] = initlpt('dummy');
elseif logpars.parallelmodeLpt
[ status, LPT ] = initlpt('parallel');
else
[ status, LPT ] = initlpt();
end
if status ~= 0
cleanup('LPT', LPT);
return;
end
%% init tracker
if logpars.dummymodeTracker
[ status, EThndl, trackerSettings ] = inittracker( logpars.bgclr, logpars.nPoint, 'dummy' );
else
[ status, EThndl, trackerSettings ] = inittracker( logpars.bgclr, logpars.nPoint );
end
if status ~= 0
cleanup('LPT', LPT, 'ET', EThndl);
return
end
% save eyetracker setting
save(logpars.etfilename, getname(trackerSettings));
%% open PTB
if logpars.smallscreen == 1
[ PTB ] = openPTB( logpars.bgclr, 'smallscreen' );
elseif logpars.smallscreen == 2
[ PTB ] = openPTB( logpars.bgclr, 'smallscreenhome' );
else
[ PTB ] = openPTB( logpars.bgclr );
end
%% run the experiment
try
switch taskname
case 'task01'
task01( logpars,PTB,EThndl,LPT );
case 'task02'
task02( logpars,PTB,EThndl,LPT );
case 'task03'
task03( logpars,PTB,EThndl,LPT );
case 'task04'
task04( logpars,PTB,LPT );
end
catch ME
fprintf('\n\n')
fprintf('Error...\n')
fprintf('Catching data...\n')
% save tracker data
LPT.sendMarker(254);
EThndl.saveData(fullfile(cd,sprintf('%s_catch', logpars.idffilename)), logpars.subjid, logpars.taskname, true);
disp(ME.getReport);
cleanup('LPT', LPT, 'ET', EThndl);
% commit data
commitmsg = sprintf('catch data: subject %s %s', ...
logpars.subjid, logpars.taskname);
gitcommitdata(logpars.datarepo, commitmsg, logpars.dataremote, 'gitpush', logpars.gitpush);
rethrow(ME);
end
%% Clean
cleanup('LPT', LPT, 'ET', EThndl);
%% commit data
gitcommitdata(logpars.datarepo, logpars.commitmsg, logpars.dataremote, 'gitpush', logpars.gitpush);