-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 matlab: minimal choice+isi+feedback+iti
- Loading branch information
Showing
11 changed files
with
197 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [onset, output] = choice(system, t, varargin) | ||
|
||
ideal = GetSecs()+t.onset; | ||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); | ||
Screen('DrawTexture', system.w, system.tex.astronaut{1,1}); | ||
|
||
%% positon choice options | ||
chest_w = 27;chest_h = 27; %TODO: use sprite | ||
% TODO: use DrawTextures (many at once) | ||
Screen('DrawTexture', system.w, system.tex.chest,... | ||
[], [ system.pos.left.x system.pos.left.y system.pos.left.x+chest_w system.pos.left.y+chest_h] ); | ||
Screen('DrawTexture', system.w, system.tex.chest,... | ||
[], [ system.pos.up.x system.pos.up.y system.pos.up.x+chest_w system.pos.up.y+chest_h] ); | ||
Screen('DrawTexture', system.w, system.tex.chest,... | ||
[], [ system.pos.right.x system.pos.right.y system.pos.right.x+chest_w system.pos.right.y+chest_h] ); | ||
|
||
onset = Screen('Flip', system.w, ideal); | ||
|
||
keys = KbName({'Left','Up', 'Right'}); | ||
[k rt] = waitForKeys(keys, onset + t.max_rt); | ||
if rt > 0 | ||
idx = find(keys == k,1); | ||
well_prob = t.chance(idx); | ||
output.score = (rand(1) <= well_prob); | ||
else | ||
output.score = 0 | ||
end | ||
oupput.onset_ideal = ideal; | ||
output.key = k; | ||
output.rt = rt; | ||
|
||
% TODO: animate avatar walk in while loop? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function closedown() | ||
% CLOSEDOWN - clean up PTB connections | ||
% originally from https://github.com/LabNeuroCogDevel/froggerRPG/blob/master/private/closedown.m | ||
ListenChar(0); | ||
ShowCursor; | ||
Screen('CloseAll'); | ||
Priority(0); | ||
sca; | ||
diary off; | ||
close all; | ||
%openPTBSnd('close'); | ||
% TODO: close DAQ? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function escclose(keyCode) | ||
if keyCode(KbName('escape')) | ||
closedown() | ||
error('early exit') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function [onset, output] = feedback(system, t, record) | ||
ideal = t.onset + GetSecs(); % relative time | ||
|
||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); | ||
% reach back in time and find the previous choice event | ||
choice = record(t.i-2).output, | ||
if choice.score | ||
msg = 'REWARD!' | ||
else | ||
msg = 'NO REWARD!' | ||
end | ||
|
||
% TODO: find chosen direction using choice.key | ||
% TODO: show open/closed chest over choice location | ||
% TODO: animate chest sprite | ||
DrawFormattedText(system.w, msg ,... | ||
'center','center', [255,255,255]); | ||
|
||
onset = Screen('Flip', system.w, ideal); | ||
output.ideal = ideal; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
function [onset, output] = fixation(system, t) | ||
function [onset, output] = fixation(system, t, varargin) | ||
|
||
% show the background | ||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); | ||
DrawFormattedText(system.w, '+' ,'center','center', t.cross_color); | ||
|
||
% run | ||
onset = t.onset + system.starttime; | ||
onset = Screen('Flip', system.w, onset); | ||
output = []; | ||
%onset = t.onset + system.starttime; % abs time | ||
ideal = t.onset + GetSecs(); % relative time | ||
onset = Screen('Flip', system.w, ideal); | ||
output.onset_ideal = ideal; | ||
output.onset = onset; | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
function [onset, output] = instructions(system, number, t) | ||
function [onset, output] = instructions(system, number, varargin) | ||
output.instruction = number; | ||
output.msg = 'example output'; | ||
|
||
% show the background | ||
Screen('DrawTexture', system.w, system.tex.ocean_bottom); | ||
Screen('DrawTexture', system.w, system.tex.chest); | ||
%Screen('DrawTexture', system.w, system.tex.chest); | ||
DrawFormattedText(system.w, 'Push any key to start' ,... | ||
'center','center', [255,255,255]); | ||
|
||
% run | ||
onset = Screen('Flip', system.w, t.onset); | ||
onset = Screen('Flip', system.w, 0); | ||
acceptkeys = KbName({'Space','Left','Up','Right','Return','1'}); | ||
[output.k output.rt] = waitForKeys(acceptkeys,Inf); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function pos = setup_pos(w, varargin); | ||
% TODO: use screen size? | ||
pos.left.x=10; | ||
pos.left.y=400; | ||
|
||
pos.up.x=200; | ||
pos.up.y=200; | ||
|
||
pos.right.x=400; | ||
pos.right.y=400; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function [key,RT] = waitForKey(acceptkeysidx,timeout) | ||
% WAITFORKEY -- wait for given key index (e.g from KbName()) until timeout | ||
% return key=0 and RT=-Inf if no acceptable key push given before timeout | ||
% originally from https://github.com/LabNeuroCogDevel/audodd/blob/master/waitForKey.m | ||
% | ||
% Usage: | ||
% % 2 seconds to respond a (return k=1) or b (return k=2) | ||
% % no response, k=0, rt=-Inf | ||
% [k rt] = waitForKey( KbName({'a','b'}), GetSecs() + 2); | ||
% | ||
% % wait forever for the scanner to send a trigger (trg key is = ) | ||
% [k rt] = waitForKey( KbName({'=+'}), Inf); | ||
% | ||
% Note: | ||
% accepts multiple keys down as response endorsing first acceptable key | ||
|
||
|
||
% no response can be meaningful if too fast | ||
% wait 60ms before trying to record a response | ||
% TODO: determine more approprate min response time limit | ||
% also reduce hold over from previous trial errors | ||
fastestResponseTime=.06; | ||
WaitSecs(fastestResponseTime); | ||
|
||
key=0; | ||
RT=-Inf; | ||
% continue until we get a keypress we like | ||
% or we run out of time | ||
while(RT<=0 && GetSecs() < timeout ) | ||
[keyPressed, thisRT, keyCode] = KbCheck; | ||
if keyPressed && any( keyCode(acceptkeysidx) ) | ||
RT=thisRT; | ||
|
||
%NB! we only pick the first (in order of acceptkeys) | ||
% if subject is holding down more than one key, will not record both! | ||
% will warn to screen about mutliple pushes though | ||
key=find(keyCode(acceptkeysidx) ,1); | ||
if(nnz(keyCode(acceptkeysidx) ) > 1) | ||
fprintf('WARNING: multple good button pushes! reporting first button is pushed\n'); | ||
end | ||
end | ||
end | ||
end |