-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main5.m
206 lines (176 loc) · 5.95 KB
/
Main5.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
function multipleShapes()
a_front = arduinoManager('port','/dev/ttyACM1'); a_front.open;
a_back = arduinoManager('port','/dev/ttyACM0'); a_back.open;
%Audio Manager
if ~exist('aM','var') || isempty(aM) || ~isa(aM,'audioManager')
aM=audioManager;
end
aM.silentMode = false;
if ~aM.isSetup; aM.setup; end
stims = {'self', 'none', 'other', 'both'};
trialN = 50 ;
choiceTouch = 1;
debug = false;
dummy = false;
timeOut = 3;
nObjects = length(stims);
stimSize = 9;
circleRadius = 12;
degsPerStep = 360 / nObjects;
pxPerCm = 16;
distance = 20;
centerY = +35;
centerX = -30;
colourSelf = [0.8 0.5 0.3];
colourOther = [0.3 0.5 0.8];
colourBoth = [0.8 0.3 0.5];
colourNone = [0.8 0.5 0.8];
randomise = true;
try
%==============================================CREATE SCREEN
s = screenManager('blend', true,'antiAlias', 8,'backgroundColour', [0 0 0],...
'pixelsPerCm', pxPerCm,'distance', distance,...
'screenXOffset', centerX,'screenYOffset', centerY);
open(s);
%==============================================CREATE STIMULI
self = imageStimulus('size', stimSize, 'colour', colourSelf,...
'fileName',[s.paths.root '/stimuli/star.png']);
other = imageStimulus('size', stimSize, 'colour', colourOther,...
'fileName',[s.paths.root '/stimuli/triangle.png']);
both = imageStimulus('size', stimSize, 'colour', colourBoth,...
'fileName',[s.paths.root '/stimuli/heptagon.png']);
none = imageStimulus('size', stimSize, 'colour', colourNone,...
'fileName',[s.paths.root '/stimuli/circle.png']);
setup(self, s);
setup(other, s);
setup(both, s);
setup(none, s);
%==============================================INITIATE THE TOUCHPANELS
tM = touchManager('device',choiceTouch,'isDummy',dummy);
setup(tM, s);
%==============================================GET SUBJECT NAME
subject= input ("Enter subject name:",'s');
nameExp=[subject,'-',date,'.mat'];
%==============================================
text='Please press ESCAPE to start experiment...';
drawTextNow(s,text);
RestrictKeysForKbCheck(KbName('ESCAPE'));
KbWait;
correctTrials.self = 0;
correctTrials.other = 0;
correctTrials.both = 0;
correctTrials.none = 0;
reactionTime.init = GetSecs;
reactionTime.self = zeros(trialN, 1);
reactionTime.other = zeros(trialN, 1);
reactionTime.both = zeros(trialN, 1);
reactionTime.none = zeros(trialN, 1);
%==============================================START TOUCH QUEUE
try Priority(1); end
createQueue(tM,choiceTouch);
start(tM,choiceTouch);
%==============================================MAIN TRIAL LOOP
for iTrial=1:trialN
fprintf('\n===>>> Running Trial %i\n',iTrial);
% ----- set the positions for this trial
randOffset = round(rand * 360);
for jObj = 1 : nObjects
theta = deg2rad((degsPerStep * jObj) + randOffset);
[x,y] = pol2cart(theta, circleRadius);
eval([stims{jObj} '.xPositionOut = ' num2str(x) ';']);
eval([stims{jObj} '.yPositionOut = ' num2str(y) ';']);
end
% ----- randomise
if randomise
self.colourOut = [lim(rand) lim(rand) lim(rand)];
other.colourOut = [lim(rand) lim(rand) lim(rand)];
both.colourOut = [lim(rand) lim(rand) lim(rand)];
none.colourOut = [lim(rand) lim(rand) lim(rand)];
self.angleOut = rand * 360;
other.angleOut = rand * 360;
both.angleOut = rand * 360;
none.angleOut = rand * 360;
end
% ----- update stimuli with new values
update(self); update(other); update(both); update(none);
% ====================================SHOW STIMULI
textMonkey = 'no touch'; %%
selfReward = false; otherReward = false; bothReward = false; noneReward = false;
x = []; y = []; txt = ''; textMonkey = ''; anyTouch = false; cWins = [];
flush(tM,choiceTouch);
vbl = flip(s); tStart = vbl;
while vbl <= (tStart + timeOut) && anyTouch == false
for jObj = 1 : nObjects
% we use eval as our object names are stored in an array
eval(['draw(' stims{jObj} ');']);
eval(['cWins(jObj,:) = toDegrees(s, ' stims{jObj} '.mvRect, ''rect'');']);
% eval(['cWins(j,:) = toDegrees(s, ' stims{jObj} '.mvRect, ''rect'');']);
end
if debug; drawScreenCenter(s); drawGrid(s); drawText(s, txt); end %#ok<*UNRCH>
vbl = flip(s);
[results, x, y] = checkTouchWindows(tM, cWins,choiceTouch);
if debug && ~isempty(x); txt = sprintf('x = %.2f Y = %.2f',x(1),y(1)); end
if ~any(results); continue; end
for jObj = 1: nObjects
if results(jObj) == true
textMonkey = ['Touched: ' upper(stims{jObj})];
eval([stims{jObj} 'Reward = true;'])
correctTrials.(stims{jObj}) = correctTrials.(stims{jObj})+1;
reactionTime.(stims{jObj})(iTrial,1) = GetSecs-tStart;
disp(textMonkey);
anyTouch = true;
break
end
end
end % END WHILE
flip(s);
% =============================REWARDS
if debug; drawTextNow(s,textMonkey); end
if selfReward
aM.beep(2000,0.1,0.1);
a_front.stepper(46);
elseif otherReward
aM.beep(2000,0.1,0.1);
a_back.stepper(46);
WaitSecs(2);
elseif bothReward
aM.beep(2000,0.1,0.1);
a_back.stepper(46);
% WaitSecs(1);50
a_front.stepper(46);
elseif noneReward
aM.beep(2000,0.1,0.1);
WaitSecs(2);
end
WaitSecs(3);
end
reactionTime.end = GetSecs;
reactionTime.total = reactionTime.end - reactionTime.init;
a_front.close;a_back.close;
% =====================================SAVE DATA
results = struct();
results.stims = stims;
results.correctTrials = correctTrials;
results.reactionTime = reactionTime;
results.subject = subject;
results.trialN = trialN;
results.TotalTime = reactionTime.total;
cd(s.paths.savedData);
save(nameExp, 'results');
% ====================================CLEAN UP
close(s);
close(tM,choiceTouch);
reset(self); reset(other); reset(both); reset(none);
Priority(0); ShowCursor; sca;
catch E
try close(s); end %#ok<*TRYNC>
try close(tM,choiceTouch); end
reset(self); reset(other); reset(both); reset(none);
Priority(0); ShowCursor; sca;
rethrow(E);
end
function out = lim(in)
l = 0.4; h = 0.8;
out = (in * (h - l))+l;
end
end % END FUNCTION`