pb_vRunExp.m 3.71 KB
Newer Older
1
function pb_vRunExp(handles)
2
% PB_VRUNEXP
Jesse Heckman's avatar
Jesse Heckman committed
3
%
4
% PB_VRUNEXP(handles) forms the core body of experimental paradigms run in 
5
% the VC, and will loop over the blocks and trials provided by the exp-file.
6 7
% Note that PB_VRUNEXP is called from the vPrime GUI, from which it
% receives its experimental handles.
Jesse Heckman's avatar
Jesse Heckman committed
8
%
9
% See also PB_VPRIME, PB_VPRIMEGUI.
Jesse Heckman's avatar
Jesse Heckman committed
10 11 12 13 14 15

% PBToolbox (2018): JJH: j.heckman@donders.ru.nl

   %% INITIALIZE
   %  load & read experiment
   
Jesse Heckman's avatar
Jesse Heckman committed
16
   %  set debug mode
Jesse Heckman's avatar
Jesse Heckman committed
17
   debug = true;
Jesse Heckman's avatar
Jesse Heckman committed
18
   
Jesse Heckman's avatar
Jesse Heckman committed
19
   %  set handles
20
   pb_setupShow(handles);
Jesse Heckman's avatar
Jesse Heckman committed
21 22 23 24
   handles     = pb_gethandles(handles);
   handles     = pb_getblock(handles);
   handles     = pb_createdir(handles);
   handles     = pb_vInitialize(handles, true);
Jesse Heckman's avatar
Jesse Heckman committed
25
   
Jesse Heckman's avatar
Jesse Heckman committed
26
   %  set block information
Jesse Heckman's avatar
Jesse Heckman committed
27 28 29 30 31
   if ~debug
      block       = handles.block;  
      nblocks     = handles.cfg.Blocks;
      Dat         = pb_dataobj(nblocks);
   end
Jesse Heckman's avatar
Jesse Heckman committed
32
    
Jesse Heckman's avatar
Jesse Heckman committed
33
   %  initialize recordings
Jesse Heckman's avatar
Jesse Heckman committed
34 35 36 37
   if ~debug
      rc             = pb_runPupil; 
      [ses,str]      = pb_runLSL;
   end
38
   expTime        = tic;
Jesse Heckman's avatar
Jesse Heckman committed
39
   
Jesse Heckman's avatar
Jesse Heckman committed
40 41
   %% START BLOCK 
   %  iterate experimental blocks 
42 43
   
   for iBlck = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
44 45
      
      %  set block information
Jesse Heckman's avatar
Jesse Heckman committed
46
      nTrials          	= length(block(iBlck).trial);
Jesse Heckman's avatar
Jesse Heckman committed
47
      handles          	= pb_updatecount(handles,'trial','reset');
Jesse Heckman's avatar
Jesse Heckman committed
48
      [profile,dur]    	= pb_vSignalVC(handles);
Jesse Heckman's avatar
Jesse Heckman committed
49
      pb_vCheckServo(~ismac && ~debug);
Jesse Heckman's avatar
Jesse Heckman committed
50 51
      
      %  start recording
Jesse Heckman's avatar
Jesse Heckman committed
52
      pb_startLSL(ses);
53
      pb_startPupil(rc);
54
      
Jesse Heckman's avatar
Jesse Heckman committed
55
      %  start vestibular chair
56
      if ~ismac && ~debug     
Jesse Heckman's avatar
Jesse Heckman committed
57 58
         vs            	= pb_sendServo(profile);
         blockTime    	= tic; 
59
         pb_startServo(vs);
Jesse Heckman's avatar
Jesse Heckman committed
60
         pause(6);                                                         % allow vestibular chair to get in sync with input signal
Jesse Heckman's avatar
Jesse Heckman committed
61 62
      end

Jesse Heckman's avatar
Jesse Heckman committed
63
      %% RUN TRIALS
Jesse Heckman's avatar
Jesse Heckman committed
64
      %  iterate over trials per block
Jesse Heckman's avatar
Jesse Heckman committed
65
      
66
      for iTrl = 1:nTrials
Jesse Heckman's avatar
Jesse Heckman committed
67
         
Jesse Heckman's avatar
Jesse Heckman committed
68
         %  setup trial
Jesse Heckman's avatar
Jesse Heckman committed
69
         handles              = pb_vUpdateTrial(handles);
Jesse Heckman's avatar
Jesse Heckman committed
70
         stim                 = handles.block(iBlck).trial(iTrl).stim;
Jesse Heckman's avatar
Jesse Heckman committed
71
         handles.cfg          = pb_vClearTrial(stim, handles.cfg); 
Jesse Heckman's avatar
Jesse Heckman committed
72
         [~, handles.cfg]     = pb_vSetupTrial(stim, handles.cfg);
Jesse Heckman's avatar
Jesse Heckman committed
73
         trialTime            = tic;
Jesse Heckman's avatar
dbg  
Jesse Heckman committed
74
         
Jesse Heckman's avatar
Jesse Heckman committed
75
         %  run trial
Jesse Heckman's avatar
Jesse Heckman committed
76
         pb_vRunTrial(handles.cfg.zBus, handles.cfg);
77
         pb_vTraces(handles);       
Jesse Heckman's avatar
Jesse Heckman committed
78
         
Jesse Heckman's avatar
Jesse Heckman committed
79
         %  save trial
Jesse Heckman's avatar
Jesse Heckman committed
80
         handles              = pb_vStoreTrial(handles, profile);
Jesse Heckman's avatar
Jesse Heckman committed
81
         handles.cfg          = pb_updatecount(handles.cfg,'trial','count');
Jesse Heckman's avatar
Jesse Heckman committed
82
         toc(trialTime);
Jesse Heckman's avatar
Jesse Heckman committed
83 84
      end
      
Jesse Heckman's avatar
Jesse Heckman committed
85 86 87 88
      %% END BLOCK
      %  stop chair, pupil labs, optitrack and LSL, save data
      
      %  stop vestibular chair
Jesse Heckman's avatar
Jesse Heckman committed
89
      if ~ismac && ~debug  
Jesse Heckman's avatar
check  
Jesse Heckman committed
90
         elapsedTime = toc(blockTime);                
Jesse Heckman's avatar
Jesse Heckman committed
91
         if elapsedTime < dur; pause(dur-floor(elapsedTime)+6); end        % wait untill chair is finished running before disabling.
Jesse Heckman's avatar
Jesse Heckman committed
92
         pb_stopServo(vs);
Jesse Heckman's avatar
Jesse Heckman committed
93
         Dat(iBlck) = pb_readServo(vs, Dat(iBlck));
Jesse Heckman's avatar
Jesse Heckman committed
94
         delete(vs);
Jesse Heckman's avatar
Jesse Heckman committed
95
      end
Jesse Heckman's avatar
Jesse Heckman committed
96 97

      %  stop recording
98
      pb_stopPupil(rc);
Jesse Heckman's avatar
Jesse Heckman committed
99
      pb_stopLSL(ses); 
Jesse Heckman's avatar
Jesse Heckman committed
100
      
Jesse Heckman's avatar
Jesse Heckman committed
101
      %  store data
Jesse Heckman's avatar
Jesse Heckman committed
102
      pb_vStoreData(handles, Dat, iBlck,str);
Jesse Heckman's avatar
Jesse Heckman committed
103

Jesse Heckman's avatar
Jesse Heckman committed
104
      %  update block information
Jesse Heckman's avatar
Jesse Heckman committed
105
      handles.cfg = pb_updatecount(handles.cfg,'block','count');
Jesse Heckman's avatar
Jesse Heckman committed
106
   end
Jesse Heckman's avatar
Jesse Heckman committed
107
   
Jesse Heckman's avatar
Jesse Heckman committed
108 109
   %% CHECK OUT
   %  finalizes experiment, and resets handles.
Jesse Heckman's avatar
Jesse Heckman committed
110
   
Jesse Heckman's avatar
Jesse Heckman committed
111
   %  check out experiment
Jesse Heckman's avatar
Jesse Heckman committed
112
   pb_vEndExp;
Jesse Heckman's avatar
Jesse Heckman committed
113
   pb_vInitialize(handles, false);
Jesse Heckman's avatar
Jesse Heckman committed
114
   pb_delobj(ses, rc, str);
Jesse Heckman's avatar
Jesse Heckman committed
115
   toc(expTime);
Jesse Heckman's avatar
Jesse Heckman committed
116 117 118
end


Jesse Heckman's avatar
Jesse Heckman committed
119 120 121 122 123 124 125
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %