Skip to content

Commit 76a29a8

Browse files
committed
reward calibration check
1 parent 94cf13f commit 76a29a8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cortexlab/+hw/checkCalibration.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function c = checkCalibration()
2+
channel = 'rewardValve'; % The channel name of the reward controller
3+
rig = hw.devices; % Load the hardware file
4+
5+
% Fetch the reward control signal generator object
6+
rewardId = strcmp(rig.daqController.ChannelNames, channel);
7+
signalGen = rig.daqController.SignalGenerators(rewardID);
8+
% Fetch the most recent calibration
9+
[newestDate, I] = max([signalGen.Calibrations.dateTime]);
10+
lastCalibration = signalGen(rewardId).Calibrations(I);
11+
ul = [lastCalibration.volumeMicroLitres]; % Recorded volumes
12+
dt = [lastCalibration.durationSecs]; % Previous opening times
13+
14+
% Two specific volumes to test
15+
volumes = [2, 3];
16+
durations = arrayfun(@(x)interp1(ul, dt, x, 'pchip'), volumes);
17+
% OR two equally spaced points within the range
18+
durations = pick(linspace(dt(1), dt(end), 4), [2,3]);
19+
20+
% Run a quick calibration
21+
c = hw.calibrate(channel, rig.daqController, rig.scale, ...
22+
durations(1), ... % Min opening time
23+
durations(2), ... % Max opening time
24+
'settleWait', 1, ... % Set to 1 to trim test time
25+
'nPerT', 1, ... % Once per opening time
26+
'nVolumes', 2, ... % Pick the min and max opening times
27+
'delivPerSample', 200); % 100 fewer than usual
28+
29+
% Plot result over the previous calibration result
30+
figure('Color', 'w');
31+
plot(dt, ul, 'x-');
32+
hold on
33+
plot([c.durationSecs], [c.volumeMicroLitres], 'o');
34+
35+
% Set some labels, etc.
36+
xlabel('Duration (sec)');
37+
ylabel('Volume (\muL)');
38+
legend(["Previous calibration", "Measured deliveries"], 'Location', 'SouthEast')
39+
title(datestr(newestDate))

0 commit comments

Comments
 (0)