pb_vRunExp.m 4.1 KB
Newer Older
1
function pb_vRunExp(handles)
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
   
14
15
16
   pb_setupShow(handles);
   handles        = pb_gethandles(handles);
   handles        = pb_getblock(handles);
Jesse Heckman's avatar
Jesse Heckman committed
17
   
Jesse Heckman's avatar
Jesse Heckman committed
18
   
19
20
21
22
23
24
25
26
27
28
29
30
   %[block, cfg]  	= pb_vReadExp(handles);
  
   handles        = pb_createdir(handles);
   handles        = pb_vInitialize(handles,true);
   
   % NOT SURE WETHER THIS REMAINS	%  %  %  %  %  %  %  %  % %
   nblocks       	= handles.cfg.Blocks;                             % %
   nTotTrials    	= handles.cfg.Trials;                             % %
                                                            % %
   bDat(nblocks)     = struct('v',[],'h',[]);               % %                             % pre-allocate data for speed
   tDat(nTotTrials)  = struct;                              % %
   % NOT SURE WETHER THIS REMAINS   %  %  %  %  %  %  %  %  % % 
Jesse Heckman's avatar
Jesse Heckman committed
31
32
   
   %% BODY
Jesse Heckman's avatar
Jesse Heckman committed
33
   %  Iterate experiment
34
35
   
   block = handles.block;
Jesse Heckman's avatar
Jesse Heckman committed
36
      
37
   for iBlck = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
38
39
      % Runs blocks of trials with a vestibular condition
      
40
41
      nTrials                       = length(block(iBlck).trial);
      [bDat(iBlck),profile,dur]    = pb_vSignalVC(handles,block,iBlck);       % reads, checks, creates & plots vestibular signals
42
      
Jesse Heckman's avatar
Jesse Heckman committed
43
44
45
46
47
48
49
50
51
52
53
      %% 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
54
55
      for iTrial = 1:nTrials
         % Runs all trials within one block
56
57
58
         cnt = handles.cfg.trialnumber;
         updateTrial(handles, iTrial, cnt, nTotTrials);
         %pb_vSetupTrial(block(iBlock).trial(iTrial).stim,cfg);
Jesse Heckman's avatar
Jesse Heckman committed
59
            
60
61
62
         pb_vClearTrial(cnt,iBlck,iTrial);
         handles = pb_vRecordData(handles);
         
Jesse Heckman's avatar
Jesse Heckman committed
63
64
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
65
66
67
         pb_vTraces(handles);
         pause(1)
         handles.cfg.trialnumber    = handles.cfg.trialnumber+1;
Jesse Heckman's avatar
Jesse Heckman committed
68
69
70
71
72
73
74
75
76
77
      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
78
         
Jesse Heckman's avatar
Jesse Heckman committed
79
80
81
         [sv,pv]  = read_profile;
         Dat.sv   = sv;
         Dat.pv   = pv;
Jesse Heckman's avatar
Jesse Heckman committed
82
      end
83
      handles.cfg.blocknumber	= handles.cfg.blocknumber+1;
Jesse Heckman's avatar
Jesse Heckman committed
84
   end 
Jesse Heckman's avatar
Jesse Heckman committed
85
   %% CHECK OUT
86
87
88
89
90
91
   pb_vInitialize(handles,false);
   
   % THIS CAN BE MOVED ELSEWHERE TO CLEAN UP CODE
   handles.cfg.recording = num2str(str2double(handles.cfg.recording)+1,'%04d');
   set(handles.editRec,'string',handles.cfg.recording)
   % THIS CAN BE MOVED ELSEWHERE TO CLEAN UP CODE 
Jesse Heckman's avatar
Jesse Heckman committed
92
93
end

Jesse Heckman's avatar
Jesse Heckman committed
94
function updateTrial(h, iTrial, cnt, nTotTrials)
Jesse Heckman's avatar
Jesse Heckman committed
95
96
   % Updates the trial information to the GUI
   
97
   h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials'];      % counting title
Jesse Heckman's avatar
Jesse Heckman committed
98
   
99
   tn = num2str(iTrial,'%03d');                                                        % blocktrial
Jesse Heckman's avatar
Jesse Heckman committed
100
101
102
   set(h.Tn,'string',tn)
end

Jesse Heckman's avatar
Jesse Heckman committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%-- 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
121

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