pb_vRunExp.m 3.66 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

   block       = handles.block;  
   nblocks     = handles.cfg.Blocks;
   Dat         = pb_dataobj(nblocks);
Jesse Heckman's avatar
Jesse Heckman committed
31
    
Jesse Heckman's avatar
Jesse Heckman committed
32
   %  initialize recordings
Jesse Heckman's avatar
Jesse Heckman committed
33 34
   rc             = pb_runPupil; 
   [ses,str]      = pb_runLSL;
35
   expTime        = tic;
Jesse Heckman's avatar
Jesse Heckman committed
36
   
Jesse Heckman's avatar
Jesse Heckman committed
37 38
   %% START BLOCK 
   %  iterate experimental blocks 
39 40
   
   for iBlck = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
41 42
      
      %  set block information
Jesse Heckman's avatar
Jesse Heckman committed
43
      nTrials          	= length(block(iBlck).trial);
Jesse Heckman's avatar
Jesse Heckman committed
44
      handles          	= pb_updatecount(handles,'trial','reset');
Jesse Heckman's avatar
Jesse Heckman committed
45
      [profile,dur]    	= pb_vSignalVC(handles);
Jesse Heckman's avatar
Jesse Heckman committed
46
      pb_vCheckServo(~ismac && ~debug);
Jesse Heckman's avatar
Jesse Heckman committed
47 48
      
      %  start recording
Jesse Heckman's avatar
Jesse Heckman committed
49 50
      pb_startLSL(ses);
      pb_startPupil(rc);
51
      
Jesse Heckman's avatar
Jesse Heckman committed
52
      %  start vestibular chair
53
      if ~ismac && ~debug     
Jesse Heckman's avatar
Jesse Heckman committed
54 55
         vs            	= pb_sendServo(profile);
         blockTime    	= tic; 
56
         pb_startServo(vs);
Jesse Heckman's avatar
Jesse Heckman committed
57
         pause(4*pi);                                                         % allow vestibular chair to get in sync with input signal
Jesse Heckman's avatar
Jesse Heckman committed
58 59
      end

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

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

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


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