Skip to content

Commit 0356894

Browse files
authored
Merge pull request #197 from cortex-lab/dev_errormessages
add informative error messages to water valve calibration code
2 parents 3eff565 + 81c9b1d commit 0356894

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

+hw/WeighingScale.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function init(obj)
5151
% Do nothing
5252
end
5353
end
54+
obj.tare(); % Tare the scale to ensure LastGrams is never empty
5455
end
5556

5657
function cleanup(obj)

+hw/calibrate.m

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
% 2013-01 CB created
1111

12+
13+
% Check that the scale is initialized
14+
if isempty(scales.Port) || isempty(scales.readGrams)
15+
error('Rigbox:hw:calibrate:noscales', 'Unable to communicate with scale. Scales object is not properly initialized')
16+
end
1217
% tMin = 30/1000;
1318
% tMax = 80/1000;
1419
interval = 0.1;
@@ -34,34 +39,41 @@
3439

3540
origParamsFun = signalGen.ParamsFun;
3641

37-
%deliver some just to get the scales to a new reading
42+
% deliver some just to check scales are registering changes
43+
fprintf('Checking the scale...\n');
44+
3845
signalGen.ParamsFun = @(sz) deal(sz(1), sz(3), 1/sum(sz(1:2)));
3946

47+
prevWeight = scales.readGrams;
48+
rewardController.command([tMax; interval; 50], 'foreground');
49+
pause(settleWait);
50+
newWeight = scales.readGrams;
51+
assert(newWeight > prevWeight + 0.02, ...
52+
'Rigbox:hw:calibrate:deadscale',...
53+
'Error: Scale is not registering changes in weight. Confirm scale is properly connected and that water is landing into the dish')
54+
55+
prevWeight = newWeight;
56+
fprintf('Initial scale reading is %.2fg\n', prevWeight);
57+
58+
startTime = GetSecs;
59+
fprintf('Deliveries will take approximately %.0f minute(s)\n', ceil(approxTime/60));
60+
4061
try
41-
% rewardController.deliverMultiple(tMax, interval, 50, true);
42-
rewardController.command([tMax; interval; 50], 'foreground');
43-
pause(settleWait);
44-
prevWeight = scales.readGrams; %now take initial reading
45-
fprintf('Initial scale reading is %.2fg\n', prevWeight);
46-
47-
startTime = GetSecs;
48-
fprintf('Deliveries will take approximately %.0f minute(s)\n', ceil(approxTime/60));
49-
50-
for j = 1:size(t,2)
51-
for i = 1:size(t,1)
52-
rewardController.command([t(i,j); interval; n(i,j)], 'foreground');
53-
% wait just a moment for drops to settle
54-
pause(settleWait);
55-
newWeight = scales.readGrams;
56-
dw(i,j) = newWeight - prevWeight;
57-
prevWeight = newWeight;
58-
ml = dw(i,j)/n(i,j);
59-
fprintf('Weight delta = %.2fg. Delivered %ful per %fms\n', dw(i,j), 1000*ml, 1000*t(i,j));
62+
for j = 1:size(t,2)
63+
for i = 1:size(t,1)
64+
rewardController.command([t(i,j); interval; n(i,j)], 'foreground');
65+
% wait just a moment for drops to settle
66+
pause(settleWait);
67+
newWeight = scales.readGrams;
68+
dw(i,j) = newWeight - prevWeight;
69+
prevWeight = newWeight;
70+
ml = dw(i,j)/n(i,j);
71+
fprintf('Weight delta = %.2fg. Delivered %ful per %fms\n', dw(i,j), 1000*ml, 1000*t(i,j));
72+
end
6073
end
61-
end
6274
catch ex
63-
signalGen.ParamsFun = origParamsFun;
64-
rethrow(ex)
75+
signalGen.ParamsFun = origParamsFun;
76+
rethrow(ex)
6577
end
6678
signalGen.ParamsFun = origParamsFun;
6779

@@ -74,8 +86,8 @@
7486
%from the data, make a measuredDelivery structure
7587
ul = 1000*mean(dw./n, 1);
7688
calibration = struct(...
77-
'durationSecs', num2cell(t(1,:)),...
78-
'volumeMicroLitres', num2cell(ul));
89+
'durationSecs', num2cell(t(1,:)),...
90+
'volumeMicroLitres', num2cell(ul));
7991
signalGen.Calibrations(end + 1).dateTime = now;
8092
signalGen.Calibrations(end).measuredDeliveries = calibration;
8193

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Starting after Rigbox 2.2.0, this file contains a curated, chronologically order
77
- Patch in alyx-matlab submodule 2019-07-25
88
- updated Signals performance test `993d906` 2019-07-19
99
- fixes to tests for the Alyx Panel `eb5e9b9` 2019-07-19
10+
- improvements to water expServer calibration function `dd0adb7` 2019-08-14
1011

1112
## [2.2.1](https://github.com/cortex-lab/Rigbox/releases/tag/v2.2.1) (Most Recent Stable Version)

0 commit comments

Comments
 (0)