-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunStereoCheck.m
162 lines (131 loc) · 4.7 KB
/
RunStereoCheck.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
% Runs an experiment testing stereo acuity and fixation disparity
%% Ensure everything is OK with MATLAB, PTB, git, etc.
tempDiaryName = tempname();
diary(tempDiaryName); % Temporary diary
VerifyEnvironment;
%% Subject information
sessionIDStr = input('Subject code: ', 's');
amblyEye = [];
while isempty(amblyEye)
amblyEyeStr = input('Amblyopic eye: ', 's');
switch lower(amblyEyeStr)
case {'l', 'left', 'os'}
amblyEye = 0;
case {'r', 'right', 'od'}
amblyEye = 1;
otherwise
fprintf('Huh? Try ''os'', ''od'', ''left'', or ''right''... ');
end
end
%% File output directory and file setup
parentFolder = DataFile.DEFAULT_SUBFOLDER;
curdate = datestr(now, 'yyyy_mm_dd HHMMSS');
if isempty(sessionIDStr)
subfolder = curdate;
else
subfolder = [sessionIDStr ' ' curdate];
end
dataFolder = [parentFolder filesep subfolder];
mkdir(dataFolder);
% Move diary to the correct location
diaryFile = [dataFolder filesep 'diary.log'];
diary('off');
movefile(tempDiaryName, diaryFile);
diary(diaryFile);
% Prepare for opening files
metadata = [subfolder sprintf('\n')];
% Open files
sdColumns = StereoDisks.getColumns();
practiceFilePath = [dataFolder filesep 'practice.csv'];
practiceDataFile = DataFile(practiceFilePath, sdColumns, metadata);
experimentFilePath = [dataFolder filesep 'stereodisks.csv'];
experimentDataFile = DataFile(experimentFilePath, sdColumns, metadata);
noniusColumns = NoniusAdjustmentTask.getColumns();
preNoniusFilePath = [dataFolder filesep 'prenonius.csv'];
preNoniusDataFile = DataFile(preNoniusFilePath, noniusColumns, metadata);
postNoniusFilePath = [dataFolder filesep 'postnonius.csv'];
postNoniusDataFile = DataFile(postNoniusFilePath, noniusColumns, metadata);
pracDSColumns = RectSinusoidControlStimulus.getColumns();
pracDSFilePath = [dataFolder filesep 'pracDingSperling.csv'];
pracDSDataFile = DataFile(pracDSFilePath, pracDSColumns, metadata);
dSColumns = RectSinusoidStimulus.getColumns();
dSFilePath = [dataFolder filesep 'dingSperling.csv'];
dSDataFile = DataFile(dSFilePath, dSColumns, metadata);
%% Define the experiment's trials
fullExperiment = Group();
% One demo trial for Ding-Sperling
demoDSTrial = RectSinusoidControlStimulus();
demoDSTrial.OutFile = pracDSDataFile;
fullExperiment.addChoice(demoDSTrial);
% Ding-Sperling trials
dsInitVals = num2cell(log10([1/0.6, 0.6, 1.0, 0.6, 1/0.6]));
nDingSperlingTrials = 5;
dSTrials(nDingSperlingTrials) = RectSinusoidStimulus();
[dSTrials.initValue] = dsInitVals{:};
[dSTrials.OutFile] = deal(dSDataFile);
fullExperiment.addChoices(dSTrials);
% One demo trial for stereo disks
demoTrial = StereoDisks();
demoTrial.DurationSec = Inf;
demoTrial.OutFile = practiceDataFile;
fullExperiment.addChoice(demoTrial);
% Practice trials
nPracticeTrials = 10;
pracTrials(nPracticeTrials) = StereoDisks();
[pracTrials.DurationSec] = deal(1.5);
[pracTrials.DisparityDeg] = deal(0.1);
[pracTrials.OutFile] = deal(practiceDataFile);
fullExperiment.addChoices(pracTrials);
% Nonius pre-test
nNoniusPretest = 3;
noniusPretest(nNoniusPretest) = NoniusAdjustmentTask();
if amblyEye == 0
[noniusPretest.leftLuminance] = deal(1.00);
[noniusPretest.rightLuminance] = deal(0.45);
else
[noniusPretest.leftLuminance] = deal(0.45);
[noniusPretest.rightLuminance] = deal(1.00);
end
[noniusPretest.OutFile] = deal(preNoniusDataFile);
fullExperiment.addChoices(noniusPretest);
% Main trials
mainGroup = StereoDisksGroup(1.0);
mainGroup.OutFile = experimentDataFile;
halfGroup = StereoDisksGroup(0.5);
halfGroup.OutFile = experimentDataFile;
doubleGroup = StereoDisksGroup(2.0);
doubleGroup.OutFile = experimentDataFile;
fullExperiment.addChoice(mainGroup);
fullExperiment.addChoice(halfGroup);
fullExperiment.addChoice(doubleGroup);
% Nonius lines post-test
nNoniusPosttest = 3;
noniusPosttest(nNoniusPosttest) = NoniusAdjustmentTask();
if amblyEye == 0
[noniusPosttest.leftLuminance] = deal(1.00);
[noniusPosttest.rightLuminance] = deal(0.45);
else
[noniusPosttest.leftLuminance] = deal(0.45);
[noniusPosttest.rightLuminance] = deal(1.00);
end
[noniusPosttest.OutFile] = deal(postNoniusDataFile);
fullExperiment.addChoices(noniusPosttest);
%% Run experiment
% Hold hardware open (ready) until end of experiment
HWRef = HWReference();
caughtError = [];
try
fullExperiment.runAll();
catch caughtError
end
% Allow hardware to close
delete(HWRef);
%% Cleanup
workspaceSavePath = [dataFolder filesep 'workspace.mat'];
save(workspaceSavePath);
if isempty(caughtError)
diary off
clear; % all finished as expected!
else
rethrow(caughtError);
end