File size: 6,306 Bytes
227148b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
%% Choice Bias AKA Value of Volition Task - 4 stims ---------------- JOYSTICK + EEG
% Adapted from Jeff Cockburn's script by JFC 02/18/2015

% clear screen
clc;
% clear memory
clear all;
close all;

%%%%%%%%%%%%%%%%%%
% struct holding info need to present and track data
disp_struct = struct();
% struct to hold experiment parameters
task_struct = struct();

% will store all subject trials
allTrainTrials = [];
allTestTrials = [];
% start time for the experiment
task_struct.startTime = GetSecs();

% set the randome seed
RandStream.setGlobalStream(RandStream('mt19937ar','seed',sum(100*clock)));

% track the start time for the experiment
experiemtn_start = GetSecs();

% get the subject number for data storage
subject_number = input('Enter the subject number :\n','s');
session = input('Is this the first or second visit? (enter 1 or 2):\n','s'); session=str2num(session);
% Pick 1 or 2 screens  (if 1, put 0, if 2, put 1)
SCREENS=2;
% build the file name
file_name = [num2str(subject_number) '_S' num2str(session) '_' datestr(now, 'mm-dd-yyyy_HH-MM-SS')];

% *********% *********% *********% *********% *********% *********% *********
% Initialize joystick
addpath(genpath('C:\Users\GA217B\Desktop\PDDys Suite\JoyMEX'));
JoyMEX('init',0);
% ********* Call JoyTest to get these trigger numbers for each device
LEFTKEY=5;
RIGHTKEY=6;
% Initialize EEG triggers
ioObject = io64;
LTP1address = hex2dec('C050'); 
status = io64(ioObject);
% *********% *********% *********% *********% *********% *********% *********

% hide the cursor
HideCursor();

% skip the screen test for now
Screen('Preference', 'SkipSyncTests', 1);
% disable user responses from being displayed
ListenChar(2);
% ensure similar keyboard capture across platforms
KbName('UnifyKeyNames');

% initialize
[disp_struct, task_struct] = taskInit(disp_struct, task_struct, SCREENS, session, LEFTKEY, RIGHTKEY);

%%%%%%%%%%%%%%%%%%%%%%%%%
% INSTRUCT
train_Inst1(disp_struct);
train_Inst2(disp_struct);
%
instruct_slide = Screen('MakeTexture', disp_struct.wPtr, imread(['../images/Slide1.jpg']));
Screen('DrawTexture', disp_struct.wPtr, instruct_slide);
Screen(disp_struct.wPtr, 'Flip');KbWait([],3); %Waits for keyboard(any) press
%
train_Inst3(disp_struct);
%
instruct_slide = Screen('MakeTexture', disp_struct.wPtr, imread(['../images/Slide2.jpg']));
Screen('DrawTexture', disp_struct.wPtr, instruct_slide);
Screen(disp_struct.wPtr, 'Flip');KbWait([],3); %Waits for keyboard(any) press
instruct_slide = Screen('MakeTexture', disp_struct.wPtr, imread(['../images/Slide3.jpg']));
Screen('DrawTexture', disp_struct.wPtr, instruct_slide);
Screen(disp_struct.wPtr, 'Flip');KbWait([],3); %Waits for keyboard(any) press
%
train_Inst4(disp_struct);
%
instruct_slide = Screen('MakeTexture', disp_struct.wPtr, imread(['../images/Slide4.jpg']));
Screen('DrawTexture', disp_struct.wPtr, instruct_slide);
Screen(disp_struct.wPtr, 'Flip');KbWait([],3); %Waits for keyboard(any) press
%
train_Inst5(disp_struct);
runPractice(disp_struct, task_struct, ioObject, LTP1address);
train_Inst_Xtra(disp_struct);
train_Inst_Xtra2(disp_struct);
train_Inst6(disp_struct);

%%%%%%%%%%%%%%%%%%%
% TRAIN
trainDone = false;
trainBlock = 0;
while ~trainDone
    trainBlock = trainBlock + 1;
    
    % build the training trials
    trainTrials = buildTrainTrials(disp_struct, task_struct);
    trainTrials(:, task_struct.cBlock) = trainBlock;
    trainTrials(:, task_struct.cTrialType) = task_struct.TRAIN;
    
    % loop through each trial
    tI = 1;
    while tI <= size(trainTrials,1)
        trainTrials(tI,:) = runTrainTrial(disp_struct, task_struct, trainTrials(tI,:), ioObject, LTP1address);
        
        % was this a free-choice trial?
        if trainTrials(tI, task_struct.cTrialCond) == task_struct.FC
            % find it's no-choice pair, and set the resp/feedback
            ncI = find( trainTrials(:, task_struct.cTrialID) == trainTrials(tI, task_struct.cTrialID) & trainTrials(:, task_struct.cTrialCond) == task_struct.NC );
            trainTrials(ncI, task_struct.cRespAct) = trainTrials(tI, task_struct.cRespAct) + task_struct.ncAdjust;
            trainTrials(ncI, task_struct.cRespRew) = trainTrials(tI, task_struct.cRespRew);
        end
        
        % move trial if FC or match under RT limit - otherwise repeat
        if trainTrials(tI, task_struct.cRespAct) ~= disp_struct.RESP_SLOW && (trainTrials(tI, task_struct.cTrialCond) == task_struct.FC || trainTrials(tI, task_struct.cMatch))
            tI = tI + 1;
        end
    end
    
    % store all training from the current block
    allTrainTrials = [allTrainTrials; trainTrials];
    
    % check to see if we've exceeded the max # of blocks
    if trainBlock >= task_struct.maxTrain
        trainDone = true;
    elseif trainBlock >= task_struct.minTrain
        % check performance for each stim pair
        perfAB = mean(trainTrials(trainTrials(:, task_struct.cS1) == task_struct.sCodes.Afc, task_struct.cRespAct) == task_struct.sCodes.Afc);
        perfCD = mean(trainTrials(trainTrials(:, task_struct.cS1) == task_struct.sCodes.Cfc, task_struct.cRespAct) == task_struct.sCodes.Cfc);
        
        % did they meet performance threshold on all stim pairs
        trainDone = perfAB >= task_struct.minPerf(1) && perfCD >= task_struct.minPerf(2);
    end
    
    % take a break
    if ~trainDone
        trainBreak(disp_struct);
    end
end % while still training


%%%%%%%%%%%%%%%%%%%
% TEST
test_Inst1(disp_struct);
testTrials = buildTestTrials(disp_struct, task_struct);
tI = 1;
% run through all the test trials
while tI <= size(testTrials,1)
    testTrials(tI,:) = runTestTrial(disp_struct, task_struct, testTrials(tI,:), ioObject, LTP1address);
    
    % move to the next trial if valid response
    if testTrials(tI, task_struct.cRespAct) ~= disp_struct.RESP_SLOW
        tI = tI + 1;
    end
end % while not done test trials
% store all test trials
allTestTrials = testTrials;

% final note to the subject
taskDone(disp_struct);

% store task data
task_struct.endTime = GetSecs();
task_struct.expTime = task_struct.endTime - task_struct.startTime;
task_struct.trainTrials = allTrainTrials;
task_struct.testTrials = allTestTrials;
% save to file
save( fullfile('..', 'Data', file_name), 'task_struct', 'disp_struct');


% clean up
sca;
ListenChar();
ShowCursor();