Skip to content

Commit d5dc9d7

Browse files
committed
Added input args
1 parent 76a29a8 commit d5dc9d7

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

+hw/calibrate.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
function calibration = calibrate(channel, rewardController, scales, tMin, tMax, varargin)
22
%HW.CALIBRATE Performs measured reward deliveries for calibration
33
% This function is used by srv.expServer to return a water calibration.
4-
% It still requires some scales to be attached to the computer.
4+
% It still requires some scales to be attached to the computer. The
5+
% resulting calibration data are returned and also appended to the
6+
% rewardController 'Calibrations' property.
57
%
68
% Inputs:
79
% channel (char) - the name of the channel to use. Must match one of
@@ -26,6 +28,10 @@
2628
% settleWait (double) - time in seconds to wait between delivering
2729
% sample and recording a new weight. Gives the scale reading time to
2830
% stabalize. Default 2 seconds.
31+
%
32+
% Output:
33+
% calibration (struct): An 1xnVolumes structure with the fields
34+
% 'durationSecs' and 'volumeMicroLitres'.
2935
%
3036
% TODO: Sanitize and integrate into HW.REWARDVALVECONTROL
3137
%

cortexlab/+hw/checkCalibration.m

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
1-
function c = checkCalibration()
2-
channel = 'rewardValve'; % The channel name of the reward controller
1+
function c = checkValveCalibration(channelName, volumes)
2+
% HW.CHECKVALVECALIBRATION Check two volumes along calibration plot
3+
% This function is used to plot the measured volumes at two points along
4+
% the last recorded calibration curve. This can be used to easily check
5+
% whether the calibration is still accurate.
6+
%
7+
% Inputs (Optional):
8+
% channelName (char): The name of the reward valve channel to check.
9+
% The channel name must be associated with a hw.RewardValveControl
10+
% object in the rig's hw.DaqController object. Default 'rewardValve'.
11+
% volumes (numerical): A 2-element array of volumes to check. Default
12+
% is to pick two evenly spaced volumes within the calibration range.
13+
%
14+
% Ouput:
15+
% c (struct): The measured volumes corresponding to the opening times.
16+
%
17+
% Examples:
18+
% % Plot two measured volumes again the previous calibration data
19+
% hw.checkRewardValveCalibration();
20+
%
21+
% % Check by how much the deliveries have changed for some given volumes
22+
% volumes = [2 3]; % Check 2 and 3ul deliveries
23+
% c = hw.checkRewardValveCalibration('rewardValve', volumes);
24+
% dV = diff([c.volumeMicroLitres; volumes])
25+
%
26+
% See also hw.calibrate, hw.RewardValveControl
27+
28+
% The default channel name of the reward controller
29+
if nargin < 1, channelName = 'rewardValve'; end
330
rig = hw.devices; % Load the hardware file
431

532
% Fetch the reward control signal generator object
6-
rewardId = strcmp(rig.daqController.ChannelNames, channel);
33+
rewardId = strcmp(rig.daqController.ChannelNames, channelName);
734
signalGen = rig.daqController.SignalGenerators(rewardID);
835
% Fetch the most recent calibration
936
[newestDate, I] = max([signalGen.Calibrations.dateTime]);
1037
lastCalibration = signalGen(rewardId).Calibrations(I);
1138
ul = [lastCalibration.volumeMicroLitres]; % Recorded volumes
1239
dt = [lastCalibration.durationSecs]; % Previous opening times
1340

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]);
41+
if nargin > 1
42+
% User provided two specific volumes to test
43+
assert(isnumeric(volumes) && numel(volumes) == 2, ...
44+
'Rigbox:hw:checkCalibration:volumesIncorrect', ...
45+
'volumes must be a two element numerical array')
46+
% Interpolate previous calibration data to find opening times
47+
durations = arrayfun(@(x)interp1(ul, dt, x, 'pchip'), volumes);
48+
else
49+
% Otherwise pick two equally spaced points within the calibration range
50+
durations = pick(linspace(dt(1), dt(end), 4), 2:3);
51+
end
1952

2053
% Run a quick calibration
21-
c = hw.calibrate(channel, rig.daqController, rig.scale, ...
54+
c = hw.calibrate(channelName, rig.daqController, rig.scale, ...
2255
durations(1), ... % Min opening time
2356
durations(2), ... % Max opening time
2457
'settleWait', 1, ... % Set to 1 to trim test time

0 commit comments

Comments
 (0)