-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA00_initialCalib.m
More file actions
255 lines (196 loc) · 7.45 KB
/
A00_initialCalib.m
File metadata and controls
255 lines (196 loc) · 7.45 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
% HT-LMD - High-Throughput Learning, Memory, and Drug-Testing Platform for Small Aquatic Models
% Copyright (C) 2025 Gokul Rajan
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%%
% this script is to calibrate:
% 1) general: to calculate the midline of CS+ and CS-
% 2) general: quick check of LEDs
% 3) lag: delay calib between led and vis stim
% 4) lag: delay calib betn led and shock
% lagvis and lagshock are special checks done once in a while
% general is recommended to run before each experiment
%% Clear the workspace and the screen
sca;
close all;
clearvars;
Screen('Preference', 'VisualDebugLevel', 1);
%Screen('Preference', 'SkipSyncTests', 1); % may lead to some synch timimng issue;
%but can be used as long as the timimng is externally determined
%% initialise things here
% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);
% Get the screen numbers
%screens = Screen('Screens');
% Draw to the external screen if avaliable
screenNumber = 1; % forcing screen #1
% to project stim
% Define black and white
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
inc = white - grey;
% BG
BGFullLocation = 'C:\Users\orger\Desktop\Gokul\stim\rev1.png';
BGFullImage = imread(BGFullLocation);
% Open an on screen window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, 0.7);
% Screen('DrawTexture', window, BGFullTexture, [], [], 0);
% Screen('Flip', window);
%% ask for the protocol here %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
protocol = input('Which protocol do you want to run?','s');% choose protocol
if isempty(protocol)
protocol = 'cs';
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% setup arduino
ard = arduino('COM4', 'Uno'); % Initializes Arduino
% D9 for CS1 LED
% D10 for CS2 LED
% D11 for CSfull LED
% D12 for US LED
% D07 for shock
%% more initialization stuff
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Query the frame duration
ifi = Screen('GetFlipInterval', window);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
%%
% Here we load in an image from file.
csHalfLocation = ['C:\Users\orger\Desktop\Gokul\stim\cs1.png'];
csHalfImage = imread(csHalfLocation);
csFullLocation = ['C:\Users\orger\Desktop\Gokul\stim\csfull.png'];
csFullImage = imread(csFullLocation);
BGFullTexture = Screen('MakeTexture', window, BGFullImage);
%%
if (strcmp(protocol,'general'))
% Get the size of the image
[s1, s2, s3] = size(csHalfImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if s1 > screenYpixels || s2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Make the image into a texture
csHalfTexture = Screen('MakeTexture', window, csHalfImage);
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, csHalfTexture, [], [], 0);
% Bias check phase 2
writeDigitalPin(ard, 'D9', 1); % CS1 LED ON
% Flip to the screen
Screen('Flip', window);
% Wait for few seconds
WaitSecs(2);
% Now fill the screen blank
Screen('DrawTexture', window, BGFullTexture, [], [], 0);
writeDigitalPin(ard, 'D9', 0); % CS1 LED OFF
Screen('Flip', window);
WaitSecs(2);
disp('press any key to continue to half texture');
pause('on');
pause();
% Draw the image to the screen for a second time this time upside down and
% drawn onto our updated blue background
Screen('DrawTexture', window, csHalfTexture, [], [], 180);
writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
% Flip to the screen
Screen('Flip', window);
% Wait for one second
WaitSecs(2);
disp('press any key to proceed to check the LEDs');
pause('on');
pause();
writeDigitalPin(ard, 'D10', 0); % CS2 LED ON
WaitSecs(10);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%% check the LEDs
writeDigitalPin(ard, 'D09', 1); % CS1 LED ON
WaitSecs(5);
writeDigitalPin(ard, 'D09', 0); % CS1 LED OFF
writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
WaitSecs(5);
writeDigitalPin(ard, 'D10', 0); % CS2 LED OFF
writeDigitalPin(ard, 'D11', 1); % CSfull LED ON
WaitSecs(5);
writeDigitalPin(ard, 'D11', 0); % CSfull LED OFF
writeDigitalPin(ard, 'D12', 1); % US LED ON
WaitSecs(5);
writeDigitalPin(ard, 'D12', 0); % US LED OFF
writeDigitalPin(ard, 'D07', 1); % Shock ON
WaitSecs(5);
writeDigitalPin(ard, 'D07', 0); % Shock OFF
end
%% lagvis: check lag in visual stim and US delivery wrt to the LED proxy
if (strcmp(protocol,'lag'))
delay=10; % for arrival of US shock; all in secs
shock=2; % duration of the actual shock
% Make the image into a texture
csFullTexture = Screen('MakeTexture', window, csFullImage);
for tr=1:12
% Get the size of the image
[u1, u2, u3] = size(csFullImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if u1 > screenYpixels || u2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
%Screen('DrawTexture', window, csFullTexture, [], [], 0);
% Screen('FillRect', window, [0 0 0]);
% Screen('Flip', window);
WaitSecs(delay);
Screen('DrawTexture', window, csFullTexture, [], [], 0);
%Screen('FillRect', window, [1 1 1]);
writeDigitalPin(ard, 'D11', 1); % CSfull LED ON % MEASURE PIN11/ CS-FULL LED
Screen('Flip', window); % Flip to the screen % MEASURE ILLUMINACE Change of arena w/ a photodiode
%
% % Wait for few secs for the US arrive
WaitSecs(delay);
%
writeDigitalPin(ard, 'D12', 1); % US LED ON % MEASURE PIN12/ US LED
writeDigitalPin(ard, 'D07', 1); % Shock ON % % MEASURE shock at PIN6/ shock stim
WaitSecs(shock); % 2 secs of shock
writeDigitalPin(ard, 'D12', 0); % US LED OFF
writeDigitalPin(ard, 'D07', 0); % Shock OFF
%
WaitSecs(1); % wait for another sec and then switch off the vis stim
%
% % Now fill the screen blank
Screen('DrawTexture', window, BGFullTexture, [], [], 0);
writeDigitalPin(ard, 'D11', 0); % CSfull LED OFF
% Flip to the screen
Screen('Flip', window);
disp('press any key to repeat the stim for calibration');
pause('on');
pause();
end
end
%%
disp('press any key to exit the calibration');
pause('on');
pause();
% Clear the screen
sca;