forked from fyhamoeba/IncageMapCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacMan_CageLab.m
More file actions
101 lines (88 loc) · 3.3 KB
/
PacMan_CageLab.m
File metadata and controls
101 lines (88 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function PacMan_CageLab(opts)
disp(opts);
% PACMAN_CAGELAB - Run the PacMan Cage Lab experiment,
% opts are the settings from the GUI
% legacy code uses globals :-( TODO - refactor away globals!
global mapname SubjectName Left
%% =========================== initial config for PTB
PsychDefaultSetup(2);
%% =========================== ALF file paths
% we use alyxManager to identify the proper save path
% ALF file paths compatible with Alyx database
% https://int-brain-lab.github.io/ONE/alf_intro.html
if isfield(opts,'alyx') && isa(opts.alyx,'alyxManager'); opts.alyx.checkPaths; end
if isfield(opts,'savePath')
opts.alyx.paths.savedData = opt.savePath;
else
opts.savePath = opts.alyx.paths.savedData;
end
opts.alyx.checkPaths; % ensure paths are correct on the local machine
[opts.alyxPath, opts.sessionID, opts.dateID, opts.ALFName] = opts.alyx.getALF(...
opts.session.subjectName, opts.session.labName, true);
opts.dataName = [opts.alyxPath filesep 'matlab.raw.pacman.' opts.ALFName '.mat'];
%% =========================== Set up other paths
% additional paths, diary is saved to ALF path too
opts.rootPath = fileparts(mfilename("fullpath"));
if ~isfield(opts,'mapPath') || ~exist(opts.mapPath,'dir')
opts.mapPath = [opts.rootPath filesep 'Maps'];
end
opts.diaryPath = [opts.alyxPath filesep '_matlab_diary.pacman.' opts.ALFName '.log'];
diary(opts.diaryPath);
fprintf("\n===>>> PacMan Task Starting...\n");
disp(opts);
fprintf("\n===>>> PacMan Task ALF path: %s\n",opts.alyxPath);
%% =========================== force resolution
if opts.forceResolution
Screen('Resolution',opts.screen,1920,1080,60);
disp(Screen('Resolution',opts.screen));
end
%% =========================== hardware initialisation
if opts.audio
%we use audio manager as it stops conflicts with PTB tasks.
opts.aM = audioManager('device', opts.audioDevice,...
'fileName',fullfile(opts.rootPath, 'explode.mp3'),...
'volumeLevel', opts.audioVolume);
setup(opts.aM);
loadSamples(opts.aM);
if opts.audioBeeps; opts.aM.beep(3000,0.1,opts.audioVolume); end
else
opts.aM = audioManager('silentMode', true);
end
if opts.reward
opts.water = PTBSimia.pumpManager(false); % false = real pump
else
opts.water = PTBSimia.pumpManager(true); % true = dummy pump
end
opts.broadcast = matmoteGO.broadcast;
opts.status = matmoteGO.status(); % initialize experiment status object
[~,hname] = system('hostname');
hname = strip(hname);
if isempty(hname); hname = 'unknown'; end
opts.hostname = hname;
%% =========================== messaging setup
if ~opts.remote
opts.zmq = [];
end
%% =========================== keyboard setup
Priority(0);
ListenChar(0); %ListenChar(-1); %2=capture all keystrokes
RestrictKeysForKbCheck([]);
clear PsychHID; % clear any previous keyboard events
clear KbCheck; % clear any previous keyboard events
%% =========================== other initialisations
SubjectName = opts.session.subjectName; % comes from CageLab GUI
Left = 0;
if ~isfield(opts,'mapName') || isempty(opts.mapName)
opts.mapName = "GenerateRandomMap_1_oneWay_random";
end
[~,opts.mapName,~] = fileparts(opts.mapName); % remove .m
mapname = opts.mapName;
%% =========================== the current main function
try
main_2025(opts);
catch ME
try opts.status.updateStatusToStopped(); end
sca;
rethrow(ME)
end
end