function runstim_THINGS(T_Trl) global Par %global parameters Par.Mouserun = 0; dasusemouse( 0 ); preloaded_pics = 40; ncount = 4; monkey = 'monkeyF'; % cogstd('sPriority','high') LOG.fn = 'runstim_THINGS'; DateString = datestr(now,'yyyymmddHHMMSS'); % get date-timestamp ds_yyyymmdd = DateString(1:8); % date for session logs_dir = ['\\vs03\VS03-VandC-3\THINGS\Passive_fixation\',monkey,'\_logs\']; data_dir = ['\\vs03\VS03-VandC-3\THINGS\Passive_fixation\',monkey,'\',ds_yyyymmdd,'\']; fn_randtab = [logs_dir,'RANDTAB_THINGS_',monkey,'.mat']; fn_paths = [logs_dir,'things_imgs.mat']; load(fn_paths) load(fn_randtab) fn = input('Enter BLOCK number (e.g. 1), blank = don"t save logs\n','s'); if ~isempty(fn) if ~exist(data_dir, 'dir') mkdir(data_dir); end %Copy the run stime logname = ['THINGS_',monkey,'_',ds_yyyymmdd,'_B',fn]; fnrs = [logs_dir,logname,'_','runstim.m']; disp(['logfile: ',logname]) cfn = [mfilename('fullpath') '.m']; copyfile(cfn,fnrs) block_dir = [data_dir,'Block_',fn,'\']; if ~exist(block_dir, 'dir') mkdir(block_dir); end %Save json metadata json.version = '1.0'; json.project = 'THINGS'; json.dataset = 'passive_fixation'; json.date = ds_yyyymmdd; json.subject = monkey; json.investigator = 'Paolo_Papale'; json.setup = 'RN3s130'; json.condition = 'awake'; json.stimulus = 'natural_images'; json.logfile = logname; savejson('', json, [block_dir,logname,'_session.json']); end if isempty(fn) logon = 0; else logon = 1; fn_randtab_hist = [logs_dir,'RANDTAB_',logname,'.mat']; fn = [logs_dir,'THINGS_',monkey,'_',ds_yyyymmdd,'_B',fn]; save(fn,'LOG') end %Tracker times FIXT = 200; %time to fix before stim onset STIMT = 200; %Exposure ITI_short = 200; ITI = 200; FixWinSizex = 1.0; %1.1 FixWinSizey = 1.0; %1.1 rand('state',sum(clock)) cgfont('Arial' ,30) %Global properties frame = 1./85; FixDotSize = 0.3; FixPix = Par.PixPerDeg.*FixDotSize; Px = 0; Py = 0; picx = 100; picy = -100; %Set grey to be halfway between darkest and brightest luminace to acheive %maxuimum possible contrast range %gammacon converts between rgb and luminace given the known gamma curve of %the montior % maxlum = gammacon2(1,'rgb2lum'); % minlum = gammacon2(0,'rgb2lum'); % greylum = (maxlum+minlum)./2; % grey = gammacon2(greylum,'lum2rgb'); grey = .5; Par.grey = grey; Times = Par.Times; %copy timing structure %timing PREFIXT = Times.ToFix; %time to enter fixation window %Create log file LOG.Par = Par; LOG.Times = Times; LOG.Frame = frame; LOG.FIXT = FIXT; LOG.STIMT = STIMT; LOG.ScreenX = 1024; LOG.Screeny = 768; %pre-LOAD n-imgs imgs all_remainings = 1:size(RANDTAB,1); for p = 1:preloaded_pics if RANDTAB(p,2) > 0 trl = RANDTAB(p,2); cgloadbmp(p,train_imgs(trl).local_path); else trl = RANDTAB(p,3); cgloadbmp(p,test_imgs(trl).local_path) end end [~] = input('Ready? Press ENTER to start!'); %////YOUR STIMULATION CONTROL LOOP ///////////////////////////////// Hit = 2; TZ = 0; Par.ESC = false; %escape has not been pressed while ~Par.ESC %Windows (fix and target) WIN = [0 0 Par.PixPerDeg.*FixWinSizex Par.PixPerDeg.*FixWinSizey 0]; Par.WIN = WIN'; %///////////////////////////////////////////////////////////////////// %START THE TRIAL %set control window positions and dimensions refreshtracker(1) %for your control display SetWindowDas %for the dascard Abort = false; %whether subject has aborted before end of trial ncount_done = 0; sprites_to_delete = []; %///////// EVENT 0 START FIXATING ////////////////////////////////////// Par.Updatxy = 1; cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen drawdiode(0) %the diode cue cgflip(grey,grey,grey) dasreset(0) %subject has to start fixating central dot Par.SetZero = false; %set key to false to remove previous presses Par.Updatxy = 1; %centering key is enabled Time = 1; Hit = 0; while Time < PREFIXT && Hit == 0 dasrun(5) [Hit Time] = DasCheck; %retrieve position values and plot on Control display end %///////// EVENT 1 KEEP FIXATING or REDO //////////////////////////////////// Par.Updatxy = 1; if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time dasreset(1); %test for exiting fix window Time = 1; Hit = 0; while Time < FIXT && Hit == 0 %Check for 5 ms dasrun(5) %or just pause for 5ms? [Hit Time] = DasCheck; end if Hit ~= 0 %eye has left fixation to early %possibly due to eye overshoot, give another chance dasreset(0); Time = 1; Hit = 0; while Time < PREFIXT && Hit == 0 dasrun(5) [Hit Time] = DasCheck; %retrieve position values and plot on Control display end if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time dasreset(1); %test for exiting fix window Time = 1; Hit = 0; while Time < FIXT && Hit == 0 %Check for 5 ms dasrun(5) % dasrun(5) [Hit Time] = DasCheck; end else Hit = -1; %the subject did not fixate end end else Hit = -1; %the subject did not fixate end %///////// EVENT 2 DISPLAY STIMULUS ////////////////////////////////////// if Hit == 0 %subject kept fixation, display stimulus Par.Updatxy = 1; for count = 1:ncount TrialPic = all_remainings(1); dasreset(1); %test for exiting fix window Time = 0; %StimFlg = true; stimbitdone = 0; stimcorrdone = 0; while Time < STIMT+ITI_short && Hit == 0 %Keep fixating till target onset if Time < STIMT %present stim no longer than stim time cgdrawsprite(TrialPic,picx,picy); cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f'); %the red fixation dot on the screen drawdiode(1); %the diode cue if ~stimbitdone dasbit(Par.StimB, 1); stimbitdone = 1; %This means file will be created %Update counter end end %.............................................................. if Time > STIMT %&& StimFlg %present stim no longer than stim time if ~stimcorrdone dasbit(Par.CorrectB, 1); Par.Corrcount = Par.Corrcount + 1; stimcorrdone = 1; end %StimFlg = false; cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f'); %the red fixation dot on the screen drawdiode(0); %the diode cue end cgflip(grey,grey,grey); %Check for 5 ms dasrun(2); %%%%%%%%%%%%%%% was 2 [Hit Time] = DasCheck; end if stimbitdone TZ = TZ+1; if stimcorrdone ncount_done = ncount_done + 1; sprites_to_delete = [sprites_to_delete TrialPic]; MAT(TZ,:) = [RANDTAB(1,:) count 1]; if size(RANDTAB,1) == 1 save(fn,'*'); end RANDTAB(1,:) = []; all_remainings(1) = []; else MAT(TZ,:) = [RANDTAB(1,:) count 0]; end end for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct, dasbit(i, 0); end dasclearword; end %///////// EVENT 3 TARGET ONSET, REACTION TIME ////////////////////////////////////// Par.Updatxy = 1; if Hit == 0 %subject kept fixation, subject may make an eye movement cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen cgflip(grey,grey,grey); Hit = 2; else Abort = true; end %END EVENT 3 else Abort = true; end %END EVENT 2 for i=1:ncount_done p = preloaded_pics + sprites_to_delete(i); r_idx = preloaded_pics - ncount_done + i; if r_idx <= size(RANDTAB,1) cgfreesprite(sprites_to_delete(i)) if RANDTAB(r_idx,2) > 0 trl = RANDTAB(r_idx,2); cgloadbmp(p,train_imgs(trl).local_path); else trl = RANDTAB(r_idx,3); cgloadbmp(p,test_imgs(trl).local_path); end end end %///////// POSTTRIAL AND REWARD ////////////////////////////////////// if Hit ~= 0 && ~Abort %has entered a target window (false or correct) if Par.Mouserun HP = line('XData', Par.ZOOM * (LPStat(2) + Par.MOff(1)), 'YData', Par.ZOOM * (LPStat(3) + Par.MOff(2)), 'EraseMode','none'); else HP = line('XData', Par.ZOOM * LPStat(2), 'YData', Par.ZOOM * LPStat(3), 'EraseMode','none'); end set(HP, 'Marker', '+', 'MarkerSize', 20, 'MarkerEdgeColor', 'm'); if Hit == 2 dasbit(Par.RewardB, 1); dasjuice(8); pause(Par.RewardTime); %RewardTime is in seconds dasjuice(0.0); dasbit(Par.RewardB, 0); else Hit = 0; end %keep following eye motion dasrun(5); DasCheck; %keep following eye motion end %///////////////////////INTERTRIAL AND CLEANUP %reset all bits to null for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct, dasbit(i, 0); end dasclearword; %Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session %tracker('update_trials', gcbo, [], guidata(gcbo)) %displays number of trials, corrects and errors Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session SCNT = {'TRIALS'}; SCNT(2) = { ['N: ' num2str(Par.Trlcount) ]}; SCNT(3) = { ['C: ' num2str(Par.Corrcount) ] }; SCNT(4) = { ['E: ' num2str(Par.Errcount) ] }; set(T_Trl, 'String', SCNT ) %display updated numbers in GUI cgflip(grey,grey,grey) Time = 0; dasreset(1); while Time < ITI dasrun(5) [Hit Time] = DasCheck; end if TZ > 0 save(fn,'LOG','MAT','RANDTAB') end end %WHILE_NOT_ESCAPED%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if TZ > 0 save(fn,'*') if logon save(fn_randtab,'RANDTAB') save(fn_randtab_hist,'RANDTAB') end end cogstd('sPriority','normal')