-
Notifications
You must be signed in to change notification settings - Fork 1
/
Runexp.m
230 lines (181 loc) · 6.19 KB
/
Runexp.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
function FullUserdata = Runexp(testingmode)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Stream
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A multi-purpose experimental toolkit for creating experiments easily using Matlab and Psychtoolbox-3
% Includes optional EEG and Eyelink functionality
% maintained by Brad Wyble, with helpful contributions
% from Patrick Craston, Srivas Chennu, Marcelo Gomez, Syed Rahman & Asli
% Kilic, Michael Romano and especially Greg Wade
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Runexp(testingmode)
%Runexp is the function you will call to run an experiment that you have
%finished editing in Stream.
%
%testingmode:
%
%If testingmode = 0: Will run the designated block files defined in
%Setparameters with the collection of demographic data
%(FullDemographics)
%
%If testingmode >= 0: skip demographics and run just this block number
%
%If testingmode = char: Run the block file with the name testingmode
%
%Runexp.m calls the following Stream functions:
% Setparameters
% FullDemographics
% Preparescreen
% ShowError
% Streamcleanup
% Sendmarkerwpause
% Runblock
% WriteDataFiles
tic %start the timer
if(nargin ==0)
testingmode = 0;
end
try
if ispc
try
ShowHideFullWinTaskbarMex(0);
catch ME
ShowHideWinTaskbarMex(0);
end
end
end
%seed the RNG based on the current millisecond
currtime = GetSecs;
currtime = currtime- floor(currtime);
temp = ceil(currtime*1000);
for(i = 1:temp)
a = rand;
end
addpath 'Blocks';
addpath 'StreamCore';
Parameters = Setparameters([]); %start off with default parameters
if(Parameters.eyetracking && Parameters.TobiiX2)
if IsOSX | IsLinux
addpath 'StreamCore/OtherCode/TobiiUtilities';
addpath 'StreamCore/OtherCode/tetio';
else
addpath 'StreamCore\OtherCode\TobiiUtilities';
addpath 'StreamCore\OtherCode\tetio';
end
end
if IsOSX | IsLinux
save('StreamCore/blockvars','a')
else
save('StreamCore\blockvars','a')
end
%the try/catch command, which we use here, allows us to attempt to execute
%some code, and then catch the error and exit gracefully if it crashes.
try
%collect demographics if we're running the entire experiment
if(testingmode ==0)
FullUserdata.Demodata = Fulldemographics(Parameters);
else
FullUserdata.Demodata.s_num = '999';%otherwise just set the subject number to 999
FullUserdata.Demodata.filename = Parameters.datafilename;
end
Parameters = Preparescreen(Parameters); %initialize the PTB screen
if(Parameters.eyetracking && Parameters.Eyelink)
edfFile=sprintf('%s%s',Parameters.edffilename, FullUserdata.Demodata.s_num );
Eyelink('Openfile', edfFile);
end
catch errormessage %whoops, something went wrong in the previous block of code, display the error and exit
ListenChar(1);%Return keyboard control to the command window
sca
Showerror(errormessage); % These were commented out in the addition of new error catching functions
ShowCursor
Streamcleanup
try
if ispc
try
ShowHideFullWinTaskbarMex(1);
catch ME
ShowHideWinTaskbarMex(1);
end
end
end
return
end
sendmarkerwpause(Parameters, Parameters.MARKERS.STARTEXP); %you will find these marker statements scattered throughout the code
%they send trigger pulses over the parallel port as triggers to an EEG system.
ListenChar(2); %Prevent keyboard input from echoing to the MATLAB command window
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Preparing Stimuli
HideCursor; %take the mouse cursor off the screen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% show the blocks to the subject
% EDITHERE_blocks to change the block ordering as a function of subject number
Parameters = Setparameters(Parameters,FullUserdata); %set the parameters back to their default value
carryover.dummy = 0;
%A simple example of how to do odd/even counterbalancing across subjects
blocklist = Parameters.blocklist; %list of block types to run
if(testingmode > 0) %if we are in testing mode, ignore the block list and just use the block that was passed in as an argument
blocklist = {testingmode};
end
blocknum = 0;
for(blocktype = blocklist) %loop through the list of blocks one at a time
if(Parameters.blockrestart)
Parameters = Preparescreen(Parameters); %initialize the PTB screen
end
blocknum = blocknum + 1;
if IsOSX | IsLinux
save('StreamCore/blockvars','a')
else
save('StreamCore\blockvars','a')
end
[FullUserdata carryover] = Runblock(Parameters,FullUserdata, blocktype, blocknum,carryover);
if(Parameters.blockrestart)
sca
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%
%At this point the experiment is over!
%%%%%%%%%%%%%%%%%%%
%Time for cleanup
%save the data to disk
fname = sprintf('%s%s%s',Parameters.datadir,Parameters.datafilename,FullUserdata.Demodata.s_num);
save(fname,'FullUserdata');
ListenChar(1);%Return keyboard control to the command window
if(Parameters.eyetracking) %if we were eyetracking, stop, and download the datafile
if(Parameters.Eyelink)
Eyelink('StopRecording');
Eyelink('CloseFile');
try
sprintf('Receiving data file ''%s''\n', edfFile)
status=Eyelink('ReceiveFile');%,edfFile,edfFile,Parameters.datadir );
if status > 0
sprintf('ReceiveFile status %d\n', status)
end
if 2==exist(edfFile, 'file')
sprintf('Data file ''%s'' can be found in ''%s''\n', edfFile, pwd )
end
catch
sprintf('Problem receiving data file ''%s''\n', edfFile )
end
end
end
sca %shutdown PTB
expduration = num2str(ceil(toc/60));
disp(['This experiment run took ' expduration ' minutes.']);
if(testingmode ==0)
msg = msgbox('The experiment is over!','Farewell');
uiwait(msg);
end
ShowCursor;
WriteDataFiles(FullUserdata);
sendmarkerwpause(Parameters,Parameters.MARKERS.ENDEXP);
Streamcleanup;
try
if ispc
try
ShowHideFullWinTaskbarMex(1);
catch ME
ShowHideWinTaskbarMex(1);
end
end
end
%so long!