Create Loops in Spreadsheet

For certain applications, it can be necessary to repeat the actions of some functions several times during a single acquisition and job execution. To achieve this, you can construct jobs using a loop of cells.

You can use the following Clocked Data Storage functions to create cell loops and manage their output:

The Repeat and RepeatUntil functions specify the range of cells in the loop and the number of repetitions. The RepeatUntil function also allows you to specify an exit condition for the loop to end before the specified maximum number of repetitions.

The StoreData function allows you to collect the data for each repetition in the loop. The PlotData function plots the graphics for each stored Data structure.

Example

In this example, the task is to inspect pin connections for the proper height tolerance. The job contains functions that locate the position of the pins and count the number of pin connectors. Each pin connector needs to be measured to verify that it is within the specified tolerance. Instead of creating individual functions for measuring each pin connector, you can create a loop of cells to simplify the Spreadsheet job.

This example demonstrates the following:

  • How to use the Repeat, RepeatUntil and StoreData functions to construct loops

  • How to use the ExtractBlobs, SortBlobs and Caliper functions to identify a feature of interest and inspect it for height and width tolerances

  • How to create a Custom View displaying the graphical elements of the inspection and statistical data about the pin connectors

This example uses a sample job and sample image set that is available on your local drive with your In-Sight installation in the following directory:

C:\ProgramData\Cognex\In-Sight\In-Sight\24.4.0\SampleJobs\Repeat

Load the Sample Application and Images

  1. Connect to your In-Sight vision system or emulator, and open Spreadsheet.

  2. Select Open Job from the File menu, and navigate to the directory where the sample job is installed.

  3. Open the demo connector pin inspection.jobx file.

  4. After the job loads, click on the Select the Record/Playback directory button in the bottom left corner of the Filmstrip.

  5. In the browsing dialog, select the directory where the sample job is installed to load the images contained by the directory into the Filmstrip.

Count, Locate, and Measure the Pin Connectors

The first step in this application is identifying and locating the pin connectors. The job achieves this by using the ExtractBlobs and SortBlobs functions. The ExtractBlobs function inspects the image to determine the number (roughly 204 in each inspection) and position of each pin connector. The SortBlobs function then determines the location of each pin connector, relative to a fixture.

After the Blob tools count and locate the pin connectors, the Caliper function determines the width and height of each pin connector in pixels. Using the Caliper function output, the job then puts the results through an InRange logic function to determine whether or not the pin connector is within a 0.500 tolerance.

The following procedure takes you through how the pin connector measurement section of the sample job is constructed:

Construct the Loop

Without loops, the process of counting, sorting and measuring all 204 pin connectors would require configuring 408 Caliper functions to account for both height and width, and a table returned by the SortBlobs function for all 204 found pin connectors with associated GetRow, GetCol and PlotLine functions. Looping greatly reduces the amount of space required to program the Spreadsheet, and also reduces the complexity and amount of time needed to construct.

Creating a loop involves storing the data for each iteration of the internal loop, and graphically representing the data of the accumulated inspections within the loop. During the inspection, the PlotLine function draws the edge output by the Caliper function, and a PlotString function creates an error message if necessary. In order to capture all of the graphical elements of the repeated inspections, a StoreData function is associated with each of the PlotLine and PlotString functions, and the StoreData functions are placed within the cells that constitute the loop.

In this example, the PlotLine function outputs its graphical data for each inspection into the StoreData function, which accumulates and stores the outputs for each pin connector. Without the StoreData function, only the last inspected pin connector would be displayed. At the end of the loop, the StoreData function outputs its accumulated data to a PlotData function, which generates the graphics from the accumulated loop.

The following procedure takes you through how the loop section of the sample job is constructed:

Display the Custom View

You can create a Custom View for operator interaction during the job run time. This functionality allows the operator to potentially adjust the Nominal Width or Height values, the Tolerance values, and whether or not certain results are visualized.

Using Controls functions such as EditInt and CheckBox functions allows operators to easily interact with the job at run time.

The following procedure takes you through how the Custom View of the sample job is constructed: