Create a Loop of Spreadsheet Cells

For certain applications, it may be necessary to repeat the actions of functions several times during a single acquisition and job execution. Constructing an application in this manner would necessitate hundreds, perhaps thousands, of spreadsheet cells to accomplish. However, In-Sight jobs can be constructed to use a loop of cells instead, saving programming space in the spreadsheet and creating more manageable blocks of spreadsheet cells.

The Clocked Data Storage functions, Repeat, RepeatUntil and StoreData, are used to group a selection of cells together and repeat their execution for a specific duration of time. For more information on Clocked Data Storage, see Clocked Data Storage Functions. For more information on Repeat and RepeatUntil, see Repeat and RepeatUntil. For more information on StoreData, see StoreData.

Example Overview

This topic covers how to utilize the Repeat, RepeatUntil and StoreData functions to construct loops - the repeated execution of spreadsheet cells for a specified duration. This example also demonstrates how to utilize other In-Sight Vision Tools, specifically the ExtractBlobs, SortBlobs and Caliper functions, to identify a feature of interest and inspect it for height and width tolerances. In addition, this application also utilizes a Custom View, which displays the graphical elements of the inspection, as well as statistical data about the pin connectors.

Application

Inspect pin connections for the proper height and width tolerances. After locating the position and counting the number of pin connectors, each pin connector is measured (in pixels) to verify that the pin connector is within the specified tolerance. By incorporating a loop of repeating cells, this job only requires less than 50 spreadsheet cells, whereas without incorporating a loop, the same job would require thousands of spreadsheet cells to program.

Load the Sample Application and Images

In a real-world application, you would be required to mount the In-Sight vision system, connect it and acquire images of your part or object. For the purposes of this example, a sample job and images are provided to simulate the application. To begin, you need to load the sample looping job and its accompanying images.

  1. Log on to your local emulator or In-Sight vision system.
  2. Select Open Job from the File Menu, and from the Open dialog, navigate to the Demo Connector Pin Inspection folder within the Looping folder of your In-Sight Explorer Spreadsheet Sample Jobs directory (for Windows 7/Windows 10: C:\Users\Public\Public Documents\Cognex\In-Sight\In-Sight Explorer x.x.x\Sample Jobs\Spreadsheet\Looping\Demo Connector Pin Inspection), and choose the "demo connector pin inspection.job" file.
  3. Once the job has been loaded, you need to load the corresponding sample images. Select Record/Playback Options from the Image Menu.
  4. The Record/Playback Options dialog should automatically open with the Playback tab presented; if not, click on the Playback tab.
  5. From the Playback Folder section, press the Browse button to launch the Browse for Folder dialog. Navigate to the Sample Jobs > Spreadsheet > Looping directory, and select the Demo Connector Pin Inspection folder. Press the OK button to continue.
  6. The Playback Folder should now display the directory that you specified, and the Image Count indicates the number of images in the directory. Press the OK button in the Record/Playback Options dialog to continue.

Count, Locate and Measure the Pin Connectors

The first step in this application is identifying and locating the pin connectors, which is accomplished by using the Blob Vision Tools, ExtractBlobs and SortBlobs. Beginning with the ExtractBlobs function, the image is inspected to determine the number (roughly 204 in each inspection) and position of each pin connector, followed by the SortBlobs function, which determines the location of each pin connector, relative to a fixture.

After the pin connectors have been counted and located, they are measured by the Caliper function to determine each pin connector's width and height (in pixels). Using the data returned by the Caliper function, spreadsheet logic is constructed to calculate whether or not the pin connector is within a 0.500 tolerance.

This section covers the following steps:

  1. Configuring the Blob Vision Tools

  2. Configuring the Horizontal and Vertical Caliper Edge Vision Tools

  3. Constructing the Spreadsheet Logic

    Tip: Enable Job Auditing to graphically display the cell dependencies within the job.

Configure the Blob Vision Tools

  1. Select the Blobs data structure returned by the ExtractBlobs function in cell A6 and double-click the cell to open the ExtractBlobs function's property sheet.
  2. The Region parameter is set to the entire image area, as their position varies from image to image and a fixture is not necessary (blob analysis is also one of the faster image processing techniques).
  3. The Number to Sort parameter is set to 500; to speed up the performance of the tool, lower the number to 250.
  4. For further performance enhancements, set the Color: Blob parameter to white, and the Color: Background parameter to black.
  5. Also set the Area Limit: Min parameter to 10, and the Area Limit: Max to 100. This prevents any extraneous object that may appear in the image from being classified as a pin connector.
  6. Press the OK button to close the ExtractBlobs property sheet.
  7. Next, select the Blobs data structure returned by the SortBlobs function in cell A7 and double-click the cell to open the SortBlobs function's property sheet.
  8. The Blobs parameter is set as an absolute reference to the Blobs data structure returned by the ExtractBlobs function in cell A6.
  9. Set the Number to Sort parameter to 250.
  10. The Sort By parameter is set to grid - X, then Y, from Fixture origin.
  11. Press the OK button to close the SortBlobs property sheet.

Configure the Horizontal and Vertical Caliper Edge Vision Tools

  1. Select the Edges data structure returned by the Caliper function in cell G13 (the Caliper Horizontal) and double-click the cell to open the Caliper function's property sheet.
  2. The Fixture parameter is set as an absolute reference to cells E13 and F13, which are the results output by the SortBlobs function of the pin connector's Row and Column pixel coordinates, and the GetLoopCount function, which determines which indexed pin connector to inspect based on its position in the loop.
  3. The Region parameter is configured around the bottom-right pin connector's width.
  4. The Edge Mode parameter is set to Edge Pair, with the first edge being the left-hand side of the pin connector, and the second edge being the right-hand side of the pin connector.
  5. The Edge Distance parameter is set to 9, the maximum pixel distance of the width of the pin connector.
  6. Press the OK button to close the horizontal Caliper function's property sheet.
  7. Next, select the Edges data structure returned by the Caliper function in cell L13 (the Caliper Vertical) and double-click the cell to open the Caliper function's property sheet.
  8. The Fixture parameter is also set as an absolute reference to cells E13 and F13, which are the results output by the SortBlobs function of the pin connector's Row and Column pixel coordinates, and the GetLoopCount function, which determines which indexed pin connector to inspect based on its position in the loop.
  9. The Region parameter is configured around the bottom-right pin connector's height.
  10. The Edge Mode parameter is set to Edge Pair, with the first edge being the top of the pin connector, and the second edge being the bottom of the pin connector.
  11. The Edge Distance parameter is set to 8, the maximum pixel distance of the height of the pin connector.
  12. Press the OK button to close the horizontal Caliper function's property sheet.

Construct the Spreadsheet Logic

  1. For each of the Caliper functions, the GetEdgeDistance function is used to extract the distance between edge pairs returned by the Caliper function.
  2. The InRange function is used to calculate whether or not the distance returned by the GetEdgeDistance function is within the ranges defined by the EditInt functions defining the Nominal Width, Height and Tolerance in the Custom View controls section of the spreadsheet.
  3. The Stringf function is used to output a text string containing a floating point value, constructed to only display two decimal places.
  4. Two PlotLine functions are used to draw the found edges returned by the Caliper functions, and a PlotString function is used to draw defect information, if necessary, output by the Stringf function.

Construct the Loop

Without the ability to construct a loop of spreadsheet cells, the process of counting, sorting and measuring all 204 pin connectors would require configuring 408 Caliper functions (one for height and one for 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 an error message is created by an PlotString function, 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.

This section covers the following steps:

  1. Configuring the PlotLine, PlotString and StoreData Functions

  2. Configuring the Repeat and GetLoopCount Functions

  3. Configuring the PlotData Function

    Tip: Enable Job Auditing to graphically display the cell dependencies within the job.

Configure the PlotLine, PlotString and StoreData Functions

  1. Select the Plot data structure returned by the PlotLine function in cell J13 (the Caliper Horizontal) and double-click the cell to open the PlotLine function's property sheet.
  2. The Line parameter has been constructed with dynamic arguments inside the Row and Column coordinates, using GetRow and GetCol Edges Vision Data Access functions to extract the edge data from the Caliper function and graphically draw the horizontal edge of the pin connector.
  3. The Color parameter has also been constructed with a dynamic argument, though much simpler. This parameter's argument uses the result output into cell I13, which alternates between 0 and 1 based on the results of the Caliper function (0 for no edge and 1 for an edge), to determine if the color displayed is red or green.
  4. The Show parameter is an absolute cell reference to cell J1, which is a CheckBox function that controls whether or not the line should be displayed by the Custom View.
  5. Each of the additional PlotLine and PlotString functions for the Horizontal and Vertical Calipers are constructed in the same manner.
  6. Select the Data data structure returned by the StoreData function in cell K13 (the Caliper Horizontal) and double-click the cell to open the StoreData function's property sheet.
  7. The Event parameter is an absolute cell reference to the Image data structure in cell A0 (containing the AcquireImage function). Thus the function will execute every time an image is acquired.
  8. The Data parameter is a cell reference to the Plot data structure returned by the PlotLine function in cell J13, and the StoreData function will capture all of the graphical display data output by the PlotLine function during the execution of the loop.
  9. The Number of Steps parameter is an absolute cell reference to the GetNFound Blobs Vision Data Access function in cell D6, which extracts the total number of blobs found from the ExtractBlobs function. This number determines how many times the StoreData function should accumulate data.
  10. Each of the additional StoreData functions for the Horizontal and Vertical Calipers are constructed in the same manner.
  11. Finally, select the Plot data structure returned by the PlotCircle function in cell R13 and double-click the cell to open the PlotCircle function's property sheet. This function will be used to draw a circle over any pin connectors that fail.
  12. The Circle parameter has been constructed with dynamic arguments inside the Row and Column coordinates, using the two GetRow and GetCol Edges Vision Data Access functions to extract the edge data from the Caliper function, divided by two, to extrapolate the Row/Column coordinates of the circle to be drawn (if necessary).
  13. The Show parameter uses a dynamic argument utilizing two Mathematics functions to determine whether or not the circle should be drawn.
  14. Select the Data data structure returned by the StoreData function in cell S13; this StoreData function is configured to capture the data output by the PlotCircle function in cell R13.

Configure the Repeat and GetLoopCount Functions

  1. Select the Loop data structure returned by the Repeat function in cell B13; the Repeat function is configured directly in the cell or formula bar on the Job Edit toolbar. With the Loop data structure selected, the formula for the Repeat function is visible in the formula bar on the Job Edit toolbar.
  2. The Event parameter is an absolute cell reference to the Image data structure in cell A0 (containing the AcquireImage function). Thus the function will execute every time an image is acquired.
  3. The Iterations to Repeat parameter is an absolute cell reference to GetNFound Blobs Vision Data Access function in cell D6, which extracts the total number of blobs found from the ExtractBlobs function. This number determines how many times the functions should execute.
  4. The Cells to Repeat parameter is configured to encapsulate the cells from D13 to S15.
  5. Select the GetLoopCount function contained in cell D13. This function keeps a count of the loop and determines which indexed pin connector is being inspected.
  6. The "Blob Results" output in cells E13 (GetRow) and F13 (GetCol) are constructed to reference the SortBlobs function for their position, and the GetLoopCount function for their index.

Configure the PlotData Functions

  1. Select the Plot data structure returned by the PlotData function in cell A19 and double-click the cell to open the PlotData function's property sheet.
  2. The Data parameter is set as a relative reference to the Data data structure returned by the StoreData function in cell K13. The PlotData function will construct the graphical display based on the data stored in the StoreData function.
  3. Each of the StoreData functions contained in the loop have an associated PlotData function to draw the graphics accumulated during the loop.

Display the Custom View

A Custom View display has been created for operator interaction during the job's runtime. This functionality allows the operator to potentially adjust the Nominal Width or Height values, the Tolerance values, and whether or not certain results are drawn or displayed.

Utilizing Controls Functions, such as EditInt and CheckBox functions, allows operators to easily interact with the job at runtime.

This section covers the following steps:

  1. Configuring the Controls in the Custom View

  2. Configuring the Custom View Display

    Tip: Enable Job Auditing to graphically display the cell dependencies within the job. For more information, see Job Auditing.

Configure the Controls Functions for the Custom View

  1. Select the EditInt function in cell G1.
  2. This EditInt function, as well as the EditInt functions in cells G2, H1 and H2, is used as an input for the InRange functions in cells in I13 and N13. These Controls functions are used to calculate whether or not the distance returned by the GetEdgeDistance function is within tolerance.
  3. Select the CheckBox function in cell J1.
  4. This CheckBox function is used as an input to the PlotLine functions in cells J13 and J14. This Controls function is used to determine whether or not the horizontal results of the Caliper function are displayed.
  5. Select the CheckBox function in cell J2.
  6. This CheckBox function is used as an input to the PlotLine functions in cells O13 and O14. This Controls function is used to determine whether or not the vertical results of the Caliper function are displayed.
  7. Select the CheckBox function in cell N1.
  8. This CheckBox function is used as an input to the PlotCircle function in cell R13. This Controls function is used to determine whether or not to display a red circle over defective pin connectors.
  9. Select the CheckBox function in cell N2.
  10. This CheckBox function is used as an input to the PlotString functions in cells J15 and O15. This Control is used to determine whether or not to display the value of the Caliper function as a numeric text string.

Configure the Custom View Display

  1. From the Edit menu, select Custom View Settings, which will launch the Custom View Settings dialog.
  2. The Cell Range is defined to encompass the Controls functions described in the Configuring the Controls Functions for the Custom View section.
  3. Press the Move/Resize button to enter interactive graphics mode to position where the Controls functions will reside in the image.
  4. Press the OK button to close the Custom View Settings dialog.
  5. From the View menu, select Custom View to display the Custom View user interface. This is the user interface that the operator will interact with during the job's runtime.
  6. To simulate runtime, from the Record/Playback toolbar, press the Play button. This will initiate the playback of the images in the Playback Folder, simulating the job's execution during runtime.