© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 40 of 52
are two: the
“>”
does
get buffered. That’s five altogether, so we’re well within the eleven limit. As we
shall see in the next section, we can even include an acquisition command in the buffer.
Bagels and Bottles: Putting it All Together
Let’s integrate everything we’ve learned now into a real application. In this application, we’ve got bagels
passing by single-file atop a black conveyor belt. They are being lighted from above, so they will look
bright against a dark background. We want to record the outer diameter of each one. For this app, we
assume that the bagels are round and not oval. We also assume that there is a wide enough gap
between each pair of bagels that we will see it at least once. Finally, we assume that the conveyor spans
the entire field of view and that there are no crumbs on it to confuse the camera. (In real life, we would
have to question
every one
of these assumptions!) Here is the meat of the code that will do the work. As
with all previous examples, we must wrap it in the template given at the end of this chapter to be
complete:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
lft_edge VAR Byte
rgt_edge VAR Byte
max_dia VAR Byte
OWOUT owio, 1, [SETEXP, 30]
OWOUT owio, 0, [SETBIN, 128, 10, FIXED|LEVEL]
DO
OWOUT owio, 0, ["<", ACQBIN, FNDNXT|FWD|BRTEDG]
OWOUT owio, 0, [FNDNXT|BKWD|BRTEDG, ">"]
GOSUB Ready
OWOUT owio, 0, [DUMPADR, R 5]
OWIN owio, 2, [lft_edge, rgt_edge]
IF (rgt_edge) THEN
max_dia = rgt_edge - lf 1 MIN max_dia
ELSEIF (max_dia) THEN
DEBUG "Bagel diameter: ", DEC max_dia, CR
max_dia = 0
ENDIF
LOOP
Line numbers have been added to the left of the actual program so we can discuss each line here: