|
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 |
3 | 30 | rig = hw.devices; % Load the hardware file |
4 | 31 |
|
5 | 32 | % Fetch the reward control signal generator object |
6 | | -rewardId = strcmp(rig.daqController.ChannelNames, channel); |
| 33 | +rewardId = strcmp(rig.daqController.ChannelNames, channelName); |
7 | 34 | signalGen = rig.daqController.SignalGenerators(rewardID); |
8 | 35 | % Fetch the most recent calibration |
9 | 36 | [newestDate, I] = max([signalGen.Calibrations.dateTime]); |
10 | 37 | lastCalibration = signalGen(rewardId).Calibrations(I); |
11 | 38 | ul = [lastCalibration.volumeMicroLitres]; % Recorded volumes |
12 | 39 | dt = [lastCalibration.durationSecs]; % Previous opening times |
13 | 40 |
|
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 |
19 | 52 |
|
20 | 53 | % Run a quick calibration |
21 | | -c = hw.calibrate(channel, rig.daqController, rig.scale, ... |
| 54 | +c = hw.calibrate(channelName, rig.daqController, rig.scale, ... |
22 | 55 | durations(1), ... % Min opening time |
23 | 56 | durations(2), ... % Max opening time |
24 | 57 | 'settleWait', 1, ... % Set to 1 to trim test time |
|
0 commit comments