Example Code

Count Passed Inspections in Vision Builder AI

Code and Documents

Attachment

Download All

Description:

This example shows how the state diagram, user defined variables, and the calculator step can be used to output a Pass or Fail based on how many of the inspected images pass their individual inspections. This may be useful for applications which require inspecting a batch of parts with the goal being to pass or fail the entire batch.

Instructions:

1) Download the attached VBAI inspection and the folder of images to the same folder.

2) Open the inspection, and open the Simulate Acquisition step. Make sure that the image 0.jpg in the attached Images folder is selected as the image to inspect, with the box for Cycle Through Folder Images checked.

3) Double-click on the State Diagram to enter the state diagram view.

4) Select Operate >> Run Inspection Once

5) When it is finished, note the pass/fail state of the "Check Pass #" step. If the final number of Passed images is 20 or higher, this step will have a Pass state.

Inspect steps.png

Check and Reset steps.png

Inspection Steps:

1) Simulate image acquisition

2) Match a unique part of the image in the step "Match Color Pattern 1" to provide a basis for the coordinate system

3) The "Set Coordinate System" step uses the result of "Match Color Pattern 1" to set a new coordinate system

4) "Match LED" uses a color matching algorithm to search for an illuminated LED (the bottom left one). If not illuminated, no match is found and this step fails.

5) "Calculator 1" and "Set Variable 1" increment the user-defined variable "Num LED on" if the bottom left LED is illuminated. "Set Variable 1" increments the user-defined variable "iter count"

6) If "iter count" is greater than or equal to 40, the state diagram transitions from "Inspect" to "Check and Reset"

7) "Check Pass #" returns a pass if "Num LED on" is greater than or equal to 20

😎 "Reset Variables" resets all user-defined variables before ending the inspection

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors