pb_vRunExp.m 3.99 KB
Newer Older
1
function pb_vRunExp(handles)
2
% PB_VRUNEXP(HANDLES)
Jesse Heckman's avatar
Jesse Heckman committed
3
%
4
5
% PB_VRUNEXP(HANDLES) forms the core body of experimental paradigms run in 
% the VC, and will loop over the blocks and trials provided by the exp-file.
Jesse Heckman's avatar
Jesse Heckman committed
6
%
7
% See also PB_VPRIME, PB_VPRIMEGUI.
Jesse Heckman's avatar
Jesse Heckman committed
8
9
10
11
12
13

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

   %% INITIALIZE
   %  load & read experiment
   
14
   pb_setupShow(handles);
15
16
17
18
   handles	= pb_gethandles(handles);
   handles 	= pb_getblock(handles);
   handles 	= pb_createdir(handles);
   handles	= pb_vInitialize(handles,true);
Jesse Heckman's avatar
Jesse Heckman committed
19
   
20
21
22
   block          = handles.block;  
   nblocks        = handles.cfg.Blocks;
   bDat(nblocks)  = struct('v',[],'h',[]);
Jesse Heckman's avatar
Jesse Heckman committed
23
   
24
25
   %% CORE BODY 
   %  iterate experiment
26
27
   
   for iBlck = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
28
29
      % Runs blocks of trials with a vestibular condition
      
30
      nTrials                       = length(block(iBlck).trial);
31
32
      handles                       = updateCount(handles,'trial','reset');
      [bDat(iBlck),profile,dur]     = pb_vSignalVC(handles);               % reads, checks, creates & plots vestibular signals
33
      
34
35
      %  START CHAIR
      if ~ismac                                         
Jesse Heckman's avatar
Jesse Heckman committed
36
         send_profile(profile); 
37
         
Jesse Heckman's avatar
Jesse Heckman committed
38
         vs = vs_servo;
39
40
         vs.enable;        pause(1); 
         vs.start;         tic;
Jesse Heckman's avatar
Jesse Heckman committed
41
42
      end

43
      %  RUN TRIALS
Jesse Heckman's avatar
Jesse Heckman committed
44
45
      for iTrial = 1:nTrials
         % Runs all trials within one block
46
         
47
48
49
50
51
52
53
54
         updateTrial(handles);
         pb_vClearTrial(handles); 
         
         handles                    = pb_vStoreData(handles, bDat);
         handles                    = updateCount(handles,'trial','count');
         pb_vTraces(handles);       pause(1);
         
         %pb_vSetupTrial(block(iBlock).trial(iTrial).stim,cfg);
Jesse Heckman's avatar
Jesse Heckman committed
55
56
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
Jesse Heckman's avatar
Jesse Heckman committed
57
58
      end
      
59
      %  STOP CHAIR
Jesse Heckman's avatar
Jesse Heckman committed
60
61
62
63
64
65
66
      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
67
         
Jesse Heckman's avatar
Jesse Heckman committed
68
69
70
         [sv,pv]  = read_profile;
         Dat.sv   = sv;
         Dat.pv   = pv;
Jesse Heckman's avatar
Jesse Heckman committed
71
      end
72
      handles = updateCount(handles,'block','count');
Jesse Heckman's avatar
Jesse Heckman committed
73
   end 
Jesse Heckman's avatar
Jesse Heckman committed
74
   %% CHECK OUT
75
   pb_vInitialize(handles,false);
Jesse Heckman's avatar
Jesse Heckman committed
76
77
end

78
79
%-- Feedback functions --%
function updateTrial(handles)
Jesse Heckman's avatar
Jesse Heckman committed
80
   % Updates the trial information to the GUI
81
82
83
84
85
86
87
88
89
90
91
   tn = handles.cfg.trialnumber;
   handles.figure1.Name = ['vPrime - ' num2str(tn(2)) '/' num2str(handles.cfg.Trials) ' Trials'];       % counting title

   str = num2str(tn(1),'%03d');                                                                       % blocktrial
   set(handles.Tn,'string',str)
end

function handles = updateCount(handles,varargin)
   % Updates the count of trialnumber and block number during experiment
   
   cfg = handles.cfg;
Jesse Heckman's avatar
Jesse Heckman committed
92
   
93
94
95
96
97
98
99
100
101
102
103
   trial = pb_keyval('trial',varargin);
   block = pb_keyval('block',varargin);
   
   if ~isempty(trial)
      switch trial
         case 'count'
            cfg.trialnumber      = cfg.trialnumber+1;
         case 'reset'
            cfg.trialnumber(1)   = 1;
      end
   end
Jesse Heckman's avatar
Jesse Heckman committed
104
   
105
106
107
108
109
110
111
   if ~isempty(block)
      switch block
         case 'count'
            cfg.blocknumber      = cfg.blocknumber+1;
      end
   end
   handles.cfg = cfg;
Jesse Heckman's avatar
Jesse Heckman committed
112
113
end

Jesse Heckman's avatar
Jesse Heckman committed
114
115
%-- Run VC functions --%
function send_profile(profile)
116
   % writing profile to servo
Jesse Heckman's avatar
Jesse Heckman committed
117
   
118
   vs    = vs_servo;
Jesse Heckman's avatar
Jesse Heckman committed
119
   vs.write_profile(profile.v,profile.h);
120
   
Jesse Heckman's avatar
Jesse Heckman committed
121
122
123
124
   delete(vs);
end

function [sv,pv] = read_profile
125
126
127
   % read profile
   
   vs    = vs_servo;
Jesse Heckman's avatar
Jesse Heckman committed
128
129
130
   
   [sv.vertical,sv.horizontal] = vs.read_profile_sv;
   [pv.vertical,pv.horizontal] = vs.read_profile_pv;
131
   
Jesse Heckman's avatar
Jesse Heckman committed
132
133
134
   delete(vs);
end

Jesse Heckman's avatar
Jesse Heckman committed
135

Jesse Heckman's avatar
Jesse Heckman committed
136
137
138
139
140
141
142
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %