© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 41 of 52
Line
Description
1-3
Some variables that aren’t included in the template are defined here. You’re already familiar with
lft_edge
and
rgt_edge
. The variable
max_dia
is used to keep track of the largest diameter
seen so far on a particular bagel.
5 Exposure time is set to 30.
6
Binary acquisition parameters are set: Threshold = 128; Hysteresis = 10; Threshold is fixed
instead of floating, and comparisons are done on the level instead of a window.
8
Once the basic parameters have been established, they don’t change. The real work can now
commence within a
DO
loop.
9
Here, we buffer the plain binary acquire command, and the command that looks for the first
dark-to-bright edge. Notice that we just use
FNDNXT
here, without the
Begin
and
End
limits.
This is because we’re scanning the entire field of view. When a new image is acquired, these
limits are automatically reset to
1
and
255
, respectively.
10
Continuing with the buffering, we include the command that looks for the same kind of edge, but
coming in from the right. We also end the buffering, which starts the whole chain of commands
executing.
11
Here, we wait for all the commands to finish executing. When they do, the image will have been
acquired, and both edges will have been located – all with only four bytes in the buffer.
12
Now we’re ready to read the results, so start reading from location
R 5
. This is
because the
ACQBIN
is buffered along with the finds, and it always adds five bytes to the
results buffer, thus pushing the find results five bytes higher.
13 Read the positions of the left and right edges.
14 If we found the right edge, the left edge is there, too.
15
The current diameter is
rgt_edge – lf 1
. If that’s greater than the maximum diameter
seen so far on this bagel, make it the maximum diameter, using the
MIN
operator.
16
If we didn’t see an edge, we’re between bagels, and if
max_dia
is non-zero, one has
just
gone
past that we haven’t recorded yet.
17 So tell the world what we just saw.
18 Reset
max_dia
to zero, so it’s ready for the next bagel.
20 And back for another scan.
So that’s it: a complete inspection-and-reporting program in 20 lines of code. But let’s take it one step
further. One technique where buffering really shines is when it’s combined with externally-triggered
exposures. This makes it possible to buffer an entire acquisition-and-analysis sequence
and to begin
execution immediately
. But nothing will happen until a falling edge on
P3
is detected, whereupon the
driver firmware springs into action by itself, “snaps the picture”, and does the analysis. All the PBASIC
program has to do is call
Ready
when
it’s
ready, to see if new results are available. In fact, if further
processing of the results read from the firmware is required, we can even “arm” the firmware ahead of
that processing, in order to overlap processing one image with acquiring the next.
To demonstrate this technique, we’re going to change the mission slightly. Instead of looking for each
bagel’s maximum width, we’re going to measure each one to compute the overall area covered by the
bagel, including the hole. For measurement consistency, we’ve installed an encoder on our hypothetical
conveyor that issues a pulse every quarter inch of travel. So, if we measure the overall width of each
bagel every quarter of an inch of travel and accumulate the sum of those widths, we will have measured
its area once it has passed.