Commit 13d27f9b authored by Jesse Heckman's avatar Jesse Heckman
Browse files

organized runExp core vPrime

parent d4141c5b
......@@ -270,9 +270,11 @@ end
function path = datapath(path)
if nargin == 0; path = []; end
if isempty(path) || ~exist(path)
if isunix
if ismac % MAC (personal // NO VC, NO TDT)
path = '/Users/jjheckman/Documents/Data/PhD/Experiment/VC';
else
elseif isunix && ~ismac % LINUX (public // VC, NO TDT)
path = 'C:/VC/DATA';
elseif ispc % WINDOWS (public // VC, TDT)
path = 'C:/VC/DATA';
end
end
......
......@@ -7,7 +7,7 @@ function D = pb_vCreateSignal(N, dur, SR, freq, type, varargin)
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
dshow = pb_keyval('dshow',varargin,'false');
dshow = pb_keyval('dshow',varargin,false);
D(N) = struct;
for i=1:N
......
function cnt = pb_vInitialize(h, initialize)
% PB_VREADYEXP(h,initialize)
%
% PB_VREADYEXP() interacts with GUI during check in/out experiment.
%
% See also PB_VRUNEXP
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if initialize; initialize = 'off'; else; initialize = 'on'; end
set(h.buttonClose, 'Enable', initialize) % avoid closing GUI during executing run function
set(h.buttonRun, 'Enable', initialize)
set(h.buttonLoad, 'Enable', initialize)
if strcmp(initialize,'off')
% Ready feedback plots
axes(h.signals); cla;
axes(h.eTrace); cla; h.eTrace.YLim = [0 300]; h.eTrace.XLim = [0 2.5];
axes(h.hTrace); cla; h.hTrace.YLim = [0 300]; h.hTrace.XLim = [0 2.5];
else
disp([newline newline 'Experiment finished!']);
end
if nargout == 1; cnt = 0; end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_vInitialize(h, initialize)
% PB_VREADYEXP()
%
% PB_VREADYEXP() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
set(h.buttonClose, 'Enable', ~initialize) % avoid closing GUI during executing run function
set(h.buttonRun, 'Enable', ~initialize)
set(h.buttonLoad, 'Enable', ~initialize)
if initialize
% Ready feedback plots
axes(h.signals); cla;
axes(h.eTrace); cla; h.eTrace.YLim = [0 300]; h.eTrace.XLim = [0 2.5];
axes(h.hTrace); cla; h.hTrace.YLim = [0 300]; h.hTrace.XLim = [0 2.5];
else
disp([newline newline 'Experiment finished!']);
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [Dat,profile,dur] = pb_vSignalVC(h,block,iBlock)
% PB_VSIGNALVC()
%
% PB_VSIGNALVC() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% READ SIGNAL PARAMETERS
signal(1) = block(iBlock).signal.ver;
signal(2) = block(iBlock).signal.hor;
signal = pb_vSafety(signal);
%% CREATE BASIC SIGNAL
vSignal = pb_vCreateSignal(1, signal(1).duration, 10, .1, signal(1).type);
hSignal = pb_vCreateSignal(1, signal(2).duration, 10, .1, signal(2).type);
%% FINALIZE SIGNAL
Dat.v.x = vSignal.x .* signal(1).amplitude;
profile.v = Dat.v.x;
Dat.v.t = (0:1:length(Dat.v.x)-1)/10;
Dat.h.x = hSignal.x .* signal(2).amplitude; profile.h = Dat.h.x;
Dat.h.t = (0:1:length(Dat.h.x)-1)/10;
Dat.v.amplitude = signal(1).amplitude;
Dat.h.amplitude = signal(2).amplitude;
dur = max([signal(1).duration signal(2).duration])+5; % add 5 extra seconds for delay of the system
%% FEEDBACK GUI
updateBlock(h,iBlock,signal);
axes(h.signals); cla; hold on;
h.signals.YLim = [-50 50];
plot(Dat.v.t,Dat.v.x,'k');
plot(Dat.h.t,Dat.h.x,'b');
end
function updateBlock(h, iBlock, signal)
% Updates the block information to the GUI
bn = pb_sentenceCase(num2str(iBlock,'%03d')); % count block
set(h.Bn,'string',bn);
vs = ['V = ' pb_sentenceCase(signal(1).type) ... % VC stim
', H = ' pb_sentenceCase(signal(2).type)];
set(h.Vs,'string',vs);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_vTraces(h)
% PB_VTRACES()
%
% PB_VTRACES() ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
%% PLOT TRACES
% head trace
axes(h.hTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
% eye trace
axes(h.eTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
%% HIGHLIGHT CURRENT
te = pb_fobj(h.eTrace,'Type','Line');
th = pb_fobj(h.hTrace,'Type','Line');
col = pb_selectcolor(10,5);
for iT = 1:length(th)
switch iT
case length(th)
th(iT).Color = col(10,:);
te(iT).Color = col(10,:);
otherwise
th(iT).Color = col(1,:);
te(iT).Color = col(1,:);
end
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -11,119 +11,68 @@ function pb_vRunExp(expinfo,h)
%% INITIALIZE
% load & read experiment
[block, cfg] = pb_vReadExp(expinfo.expfile); % struct
[block, cfg] = pb_vReadExp(expinfo.expfile);
cnt = pb_vInitialize(h,true);
nblocks = cfg.Blocks;
nTotTrials = cfg.Trials;
cnt = 0;
bDat(nblocks) = struct; % pre-allocate data for speed
bDat(nblocks) = struct('v',[],'h',[]); % pre-allocate data for speed
tDat(nTotTrials) = struct;
set(h.buttonClose, 'Enable', 'off') % avoid closing GUI during executing run function
set(h.buttonRun, 'Enable', 'off')
set(h.buttonLoad, 'Enable', 'off')
% Ready feedback plots
axes(h.signals); cla;
axes(h.eTrace); cla; h.eTrace.YLim = [0 300]; h.eTrace.XLim = [0 2.5];
axes(h.hTrace); cla; h.hTrace.YLim = [0 300]; h.hTrace.XLim = [0 2.5];
%% BODY
% Iterate experiment
pause(2);
for iBlock = 1:nblocks
% Runs blocks of trials with a vestibular condition
nTrials = length(block(iBlock).trial);
%% RUN CHAIR
% read signals
signal(1) = block(iBlock).signal.ver;
signal(2) = block(iBlock).signal.hor;
signal = pb_vSafety(signal);
% run chair
bDat(iBlock).signal = pb_vRunVC(signal);
%% PLOT SIGNALS
% set axis and plot signals
axes(h.signals); cla; hold on;
h.signals.YLim = [-50 50];
nTrials = length(block(iBlock).trial);
[bDat(iBlock),profile,dur] = pb_vSignalVC(h,block,iBlock); % reads, checks, creates & plots vestibular signals
plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'k');
plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'b');
updateBlock(h,iBlock,signal);
%% 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
for iTrial = 1:nTrials
% Runs all trials within one block
cnt = cnt+1;
updateTrial(h, iTrial, cnt, nTotTrials, tDat);
updateTrial(h, iTrial, cnt, nTotTrials);
pb_vClearTrial(cnt,iBlock,iTrial);
pb_vRecordData(expinfo,cnt);
%pb_vRunTrial(experiment(iTrial));
%pb_vFeedbackGUI();
pb_vTraces(h);
pause(1);
%% PLOT TRACES
% head trace
axes(h.hTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
% eye trace
axes(h.eTrace); hold on;
ws = 20; b = (1/ws)*ones(1,ws); a = 1;
x = 0:.05:2.5;
y = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
y = filter(b,a,y) .* tukeywin(length(x),1)';
plot(x,y);
% highlight active traces
te = pb_fobj(h.eTrace,'Type','Line');
th = pb_fobj(h.hTrace,'Type','Line');
col = pb_selectcolor(10,5);
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);
for iT = 1:length(th)
switch iT
case length(th)
th(iT).Color = col(10,:);
te(iT).Color = col(10,:);
otherwise
th(iT).Color = col(1,:);
te(iT).Color = col(1,:);
end
end
[sv,pv] = read_profile;
Dat.sv = sv;
Dat.pv = pv;
end
pause(1)
end
%% CHECK OUT
disp([newline newline 'Experiment finished!'])
set(h.buttonClose, 'Enable', 'on');
set(h.buttonRun, 'Enable', 'on');
set(h.buttonLoad, 'Enable', 'on');
pb_vInitialize(h,false);
end
function updateBlock(h, iBlock, signal)
% Updates the block information to the GUI
bn = pb_sentenceCase(num2str(iBlock,'%03d')); % count block
set(h.Bn,'string',bn);
vs = ['V = ' pb_sentenceCase(signal(1).type) ... % VC stim
', H = ' pb_sentenceCase(signal(2).type)];
set(h.Vs,'string',vs);
end
function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
function updateTrial(h, iTrial, cnt, nTotTrials)
% Updates the trial information to the GUI
h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials']; % counting title
......@@ -132,6 +81,24 @@ function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
set(h.Tn,'string',tn)
end
%-- 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
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment