pb_vRunExp.m 3.83 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
27
28
29
   block       = handles.block;  
   nblocks     = handles.cfg.Blocks;
   Dat         = pb_dataobj(nblocks);
Jesse Heckman's avatar
Jesse Heckman committed
30
    
Jesse Heckman's avatar
Jesse Heckman committed
31
   %  initialize recordings
Jesse Heckman's avatar
Jesse Heckman committed
32
33
34
   rc          = pb_runPupil; 
   [ses,str]   = pb_runLSL;
   expTime     = tic;
Jesse Heckman's avatar
Jesse Heckman committed
35
   
Jesse Heckman's avatar
Jesse Heckman committed
36
37
   %% START BLOCK 
   %  iterate experimental blocks 
38
39
   
   for iBlck = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
40
41
      
      %  set block information
Jesse Heckman's avatar
Jesse Heckman committed
42
      nTrials          	= length(block(iBlck).trial);
Jesse Heckman's avatar
Jesse Heckman committed
43
      handles          	= pb_updatecount(handles,'trial','reset');
Jesse Heckman's avatar
Jesse Heckman committed
44
      [profile,dur]    	= pb_vSignalVC(handles);
Jesse Heckman's avatar
Jesse Heckman committed
45
46
      
      %  start recording
Jesse Heckman's avatar
Jesse Heckman committed
47
      pb_startLSL(ses);
48
      pb_startPupil(rc);
49
      
Jesse Heckman's avatar
Jesse Heckman committed
50
      %  start vestibular chair
51
52
      if ~ismac && ~debug     
         pb_vCheckServo;
Jesse Heckman's avatar
Jesse Heckman committed
53
54
55
         
         vs            	= pb_sendServo(profile);
         blockTime    	= tic; 
56
         pb_startServo(vs);
Jesse Heckman's avatar
Jesse Heckman committed
57
         pause(6);                                                         % 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.trialdur);
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
78
         handles              = pb_vStoreData(handles, profile);
         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)+6); 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
100
101
      Dat(iBlck).event_data    = str(1).read;
      Dat(iBlck).pupil_labs    = str(2).read;
      Dat(iBlck).optitrack     = str(3).read;
Jesse Heckman's avatar
Jesse Heckman committed
102
      Dat(iBlck).block_info    = handles.block(iBlck);
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
114
   pb_vStoreBlockDat(handles.cfg, Dat);
   pb_vInitialize(handles, false);
Jesse Heckman's avatar
Jesse Heckman committed
115
116
   
   delete([ses, rc, str]);
Jesse Heckman's avatar
Jesse Heckman committed
117
   toc(expTime);
Jesse Heckman's avatar
Jesse Heckman committed
118
119
120
end


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