pb_vRunExp.m 3.16 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
1
function pb_vRunExp(expinfo,h)
Jesse Heckman's avatar
Jesse Heckman committed
2
3
4
5
6
7
8
9
10
11
12
13
% PB_VRUNEXP(varargin)
%
% PB_VRUNEXP() forms the core body of experimental paradigms in the VC, and 
% will loop over the trials.
%
% See also ...

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

   %% INITIALIZE
   %  load & read experiment
   
Jesse Heckman's avatar
Jesse Heckman committed
14
15
16
   [block, cfg]  	= pb_vReadExp(expinfo.expfile);
   cnt            = pb_vInitialize(h,true);
   
Jesse Heckman's avatar
Jesse Heckman committed
17
18
   nblocks       	= cfg.Blocks;
   nTotTrials    	= cfg.Trials;
Jesse Heckman's avatar
Jesse Heckman committed
19
   
Jesse Heckman's avatar
Jesse Heckman committed
20
   bDat(nblocks)     = struct('v',[],'h',[]);                                             % pre-allocate data for speed
Jesse Heckman's avatar
Jesse Heckman committed
21
   tDat(nTotTrials)  = struct;
Jesse Heckman's avatar
Jesse Heckman committed
22
23
   
   %% BODY
Jesse Heckman's avatar
Jesse Heckman committed
24
   %  Iterate experiment
Jesse Heckman's avatar
Jesse Heckman committed
25
      
Jesse Heckman's avatar
Jesse Heckman committed
26
   for iBlock = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
27
28
      % Runs blocks of trials with a vestibular condition
      
Jesse Heckman's avatar
Jesse Heckman committed
29
30
      nTrials                       = length(block(iBlock).trial);
      [bDat(iBlock),profile,dur]    = pb_vSignalVC(h,block,iBlock);       % reads, checks, creates & plots vestibular signals
31
      
Jesse Heckman's avatar
Jesse Heckman committed
32
33
34
35
36
37
38
39
40
41
42
      %% START CHAIR
      if ~ismac                                                            % in order to debug at my own laptop withouth getting servo related errors.                                           
         send_profile(profile); 
         vs = vs_servo;
         vs.enable;  
         pause(1); 
         vs.start;   
         tic;
      end

      %% RUN TRIALS
Jesse Heckman's avatar
Jesse Heckman committed
43
44
45
      for iTrial = 1:nTrials
         % Runs all trials within one block
         cnt = cnt+1; 
Jesse Heckman's avatar
Jesse Heckman committed
46
         updateTrial(h, iTrial, cnt, nTotTrials);
Jesse Heckman's avatar
Jesse Heckman committed
47
            
48
49
         pb_vClearTrial(cnt,iBlock,iTrial);
         pb_vRecordData(expinfo,cnt);
Jesse Heckman's avatar
Jesse Heckman committed
50
51
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
Jesse Heckman's avatar
Jesse Heckman committed
52
         pb_vTraces(h);
53
         pause(1);
Jesse Heckman's avatar
Jesse Heckman committed
54
         
Jesse Heckman's avatar
Jesse Heckman committed
55
56
57
58
59
60
61
62
63
64
      end
      
      %% STOP CHAIR
      if ~ismac
         elapsedTime = toc;                 
         if elapsedTime < dur; pause(dur-floor(elapsedTime)); end          % wait untill chair is finished running before disabling.

         vs.stop;
         vs.disable;
         delete(vs);
Jesse Heckman's avatar
Jesse Heckman committed
65
         
Jesse Heckman's avatar
Jesse Heckman committed
66
67
68
         [sv,pv]  = read_profile;
         Dat.sv   = sv;
         Dat.pv   = pv;
Jesse Heckman's avatar
Jesse Heckman committed
69
70
      end
   end 
Jesse Heckman's avatar
Jesse Heckman committed
71
   %% CHECK OUT
Jesse Heckman's avatar
Jesse Heckman committed
72
   pb_vInitialize(h,false);
Jesse Heckman's avatar
Jesse Heckman committed
73
74
end

Jesse Heckman's avatar
Jesse Heckman committed
75
function updateTrial(h, iTrial, cnt, nTotTrials)
Jesse Heckman's avatar
Jesse Heckman committed
76
77
   % Updates the trial information to the GUI
   
78
   h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials'];      % counting title
Jesse Heckman's avatar
Jesse Heckman committed
79
   
80
   tn = num2str(iTrial,'%03d');                                                        % blocktrial
Jesse Heckman's avatar
Jesse Heckman committed
81
82
83
   set(h.Tn,'string',tn)
end

Jesse Heckman's avatar
Jesse Heckman committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
%-- Run VC functions --%
function send_profile(profile)
   disp('writing profile to servo...');
   
   vs   = vs_servo;
   vs.write_profile(profile.v,profile.h);
   delete(vs);
end

function [sv,pv] = read_profile
   disp('read profile...');
   
   vs=vs_servo;
   [sv.vertical,sv.horizontal] = vs.read_profile_sv;
   [pv.vertical,pv.horizontal] = vs.read_profile_pv;
   delete(vs);
end

Jesse Heckman's avatar
Jesse Heckman committed
102

Jesse Heckman's avatar
Jesse Heckman committed
103
104
105
106
107
108
109
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %