|
9 | 9 |
|
10 | 10 | % 2013-01 CB created |
11 | 11 |
|
| 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 |
12 | 17 | % tMin = 30/1000; |
13 | 18 | % tMax = 80/1000; |
14 | 19 | interval = 0.1; |
|
34 | 39 |
|
35 | 40 | origParamsFun = signalGen.ParamsFun; |
36 | 41 |
|
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 | + |
38 | 45 | signalGen.ParamsFun = @(sz) deal(sz(1), sz(3), 1/sum(sz(1:2))); |
39 | 46 |
|
| 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 | + |
40 | 61 | 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 |
60 | 73 | end |
61 | | - end |
62 | 74 | catch ex |
63 | | - signalGen.ParamsFun = origParamsFun; |
64 | | - rethrow(ex) |
| 75 | + signalGen.ParamsFun = origParamsFun; |
| 76 | + rethrow(ex) |
65 | 77 | end |
66 | 78 | signalGen.ParamsFun = origParamsFun; |
67 | 79 |
|
|
74 | 86 | %from the data, make a measuredDelivery structure |
75 | 87 | ul = 1000*mean(dw./n, 1); |
76 | 88 | calibration = struct(... |
77 | | - 'durationSecs', num2cell(t(1,:)),... |
78 | | - 'volumeMicroLitres', num2cell(ul)); |
| 89 | + 'durationSecs', num2cell(t(1,:)),... |
| 90 | + 'volumeMicroLitres', num2cell(ul)); |
79 | 91 | signalGen.Calibrations(end + 1).dateTime = now; |
80 | 92 | signalGen.Calibrations(end).measuredDeliveries = calibration; |
81 | 93 |
|
|
0 commit comments