NI Vision Builder For Automated Inspection Development Toolkit Tutorial
NI Vision Builder For Automated Inspection Development Toolkit Tutorial
Support Worldwide Technical Support and Product Information ni.com National Instruments Corporate Headquarters 11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100 Worldwide Offices Australia 1800 300 800, Austria 43 662 457990-0, Belgium 32 (0) 2 757 0020, Brazil 55 11 3262 3599, Canada 800 433 3488, China 86 21 5050 9800, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 358 (0) 9 725 72511, France 01 57 66 24 24, Germany 49 89 7413130, India 91 80 41190000, Israel 972 3 6393737, Italy 39 02 41309277, Japan 0120-527196, Korea 82 02 3451 3400, Lebanon 961 (0) 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793, Netherlands 31 (0) 348 433 466, New Zealand 0800 553 322, Norway 47 (0) 66 90 76 60, Poland 48 22 328 90 10, Portugal 351 210 311 210, Russia 7 495 783 6851, Singapore 1800 226 5886, Slovenia 386 3 425 42 00, South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 (0) 8 587 895 00, Switzerland 41 56 2005151, Taiwan 886 02 2377 2222, Thailand 662 278 6777, Turkey 90 212 279 3031, United Kingdom 44 (0) 1635 523545 For further support information, refer to the Technical Support and Professional Services appendix. To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback. 20032009 National Instruments Corporation. All rights reserved.
Important Information
Warranty
The media on which you receive National Instruments software are warranted not to fail to execute programming instructions, due to defects in materials and workmanship, for a period of 90 days from date of shipment, as evidenced by receipts or other documentation. National Instruments will, at its option, repair or replace software media that do not execute programming instructions if National Instruments receives notice of such defects during the warranty period. National Instruments does not warrant that the operation of the software shall be uninterrupted or error free. A Return Material Authorization (RMA) number must be obtained from the factory and clearly marked on the outside of the package before any equipment will be accepted for warranty work. National Instruments will pay the shipping costs of returning to the owner parts which are covered by warranty. National Instruments believes that the information in this document is accurate. The document has been carefully reviewed for technical accuracy. In the event that technical or typographical errors exist, National Instruments reserves the right to make changes to subsequent editions of this document without prior notice to holders of this edition. The reader should consult National Instruments if errors are suspected. In no event shall National Instruments be liable for any damages arising out of or related to this document or the information contained in it. EXCEPT AS SPECIFIED HEREIN, NATIONAL INSTRUMENTS MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. CUSTOMERS RIGHT TO RECOVER DAMAGES CAUSED BY FAULT OR NEGLIGENCE ON THE PART OF NATIONAL INSTRUMENTS SHALL BE LIMITED TO THE AMOUNT THERETOFORE PAID BY THE CUSTOMER. NATIONAL INSTRUMENTS WILL NOT BE LIABLE FOR DAMAGES RESULTING FROM LOSS OF DATA, PROFITS, USE OF PRODUCTS, OR INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. This limitation of the liability of National Instruments will apply regardless of the form of action, whether in contract or tort, including negligence. Any action against National Instruments must be brought within one year after the cause of action accrues. National Instruments shall not be liable for any delay in performance due to causes beyond its reasonable control. The warranty provided herein does not cover damages, defects, malfunctions, or service failures caused by owners failure to follow the National Instruments installation, operation, or maintenance instructions; owners modification of the product; owners abuse, misuse, or negligent acts; and power failure or surges, fire, flood, accident, actions of third parties, or other events outside reasonable control.
Copyright
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying, recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National Instruments Corporation. National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license or other legal restriction.
Trademarks
National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section on ni.com/legal for more information about National Instruments trademarks. Other product and company names mentioned herein are trademarks or trade names of their respective companies. Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have no agency, partnership, or joint-venture relationship with National Instruments.
Patents
For patents covering National Instruments products/technology, refer to the appropriate location: HelpPatents in your software, the patents.txt file on your media, or the National Instruments Patent Notice at ni.com/patents.
Contents
About This Manual
Conventions ...................................................................................................................ix Related Documentation..................................................................................................x
Contents
vi
ni.com
Contents
vii
Note
The Vision Builder AI Development Toolkit is designed for advanced LabVIEW users who have experience developing LabVIEW applications with the NI Vision Development Module.
Conventions
The following conventions appear in this manual: The symbol leads you through nested menu items and dialog box options to a final action. The sequence FilePage SetupOptions directs you to pull down the File menu, select the Page Setup item, and select Options from the last dialog box. This icon denotes a tip, which alerts you to advisory information. This icon denotes a note, which alerts you to important information. bold Bold text denotes items that you must select or click in the software, such as menu items and dialog box options. Bold text also denotes parameter names. Italic text denotes variables, emphasis, a cross-reference, or an introduction to a key concept. Italic text also denotes text that is a placeholder for a word or value that you must supply. Text in this font denotes text or characters that you should enter from the keyboard, sections of code, programming examples, and syntax examples. This font is also used for the proper names of disk drives, paths, directories, programs, subprograms, subroutines, device names, functions, operations, variables, filenames, and extensions.
ix NI Vision Builder AI Development Toolkit Tutorial
italic
monospace
The name of a step that you created with the Vision Builder AI Development Toolkit.
<Vision Builder AI> The location to which you installed Vision Builder AI.
Related Documentation
The following documents contain information that you may find helpful as you read this manual: NI Vision Concepts HelpDescribes the basic concepts of image analysis, image processing, and machine vision. This document also contains in-depth discussions about imaging functions for advanced users. The NI Vision Concepts Help is available by selecting StartAll ProgramsNational InstrumentsVision Builder AI DocumentationNI Vision Concepts Help from the Start menu. NI Vision Builder for Automated Inspection: Configuration HelpContains information about using the Vision Builder for Automated Inspection Configuration Interface to create a machine vision application. The NI Vision Builder for Automated Inspection: Configuration Help is available by selecting StartAll Programs National InstrumentsVision Builder AIDocumentationVision Builder AI Configuration Interface Help from the Start menu. NI Vision Builder for Automated Inspection: Inspection HelpContains information about running applications created with Vision Builder AI Inspection Interface. The NI Vision Builder for Automated Inspection: Inspection Help is available by selecting StartAll ProgramsNational InstrumentsVision Builder AI DocumentationVision Builder AI Inspection Interface Help from the Start menu. NI Vision Builder for Automated Inspection TutorialDescribes Vision Builder for Automated Inspection and provides step-by-step instructions for solving common visual inspection tasks, such as inspection, gauging, part presence, guidance, and counting. The NI Vision Builder for Automated Inspection Tutorial is available by selecting StartAll ProgramsNational InstrumentsVision Builder AIDocumentationVision Builder AI Tutorial from the Start menu.
ni.com
NI Vision for LabVIEW HelpContains reference information about NI Vision for LabVIEW palettes and VIs. This help file also guides you through tasks, from setting up your imaging system to taking measurements. If the NI Vision Development Module is installed the NI Vision for LabVIEW Help is available by selecting HelpNI Vision for LabVIEW Help from the LabVIEW interface. NI Developer ZoneVisit ni.com/zone for the latest example programs, tutorials, technical presentations, and a community area where you can share ideas, questions, and source code with developers around the world.
xi
This chapter introduces the Vision Builder for Automated Inspection (Vision Builder AI) Development Toolkit. This chapter also contains the system requirements and installation instructions for the Vision Builder AI Development Toolkit.
Introduction
The Vision Builder AI Development Toolkit features a wizard and an application program interface (API) to create custom steps for use in any Vision Builder AI inspection.
Note
This toolkit is designed for advanced LabVIEW users who have experience developing LabVIEW applications with the NI Vision Development Module. A custom step processes an image according to parameters or limits, which may be defined by the user, and produces results. You can create custom steps to provide functionality that is not already included in Vision Builder AI. For example, you can develop a custom step that drives a camera or other hardware not currently supported in Vision Builder AI. You also can create a custom step to include a customized image processing algorithm.
Note
The Vision Builder AI Development Toolkit does not support the creation of acquisition steps for remote targets, such as the NI 17xx Smart Camera, NI CVS-1450 Series Compact Vision System, or NI EVS-1460 Series Embedded Vision System. You can distribute custom steps with the executable version of Vision Builder AI, to provide end users with a customized Vision Builder AI package.
1-1
Chapter 1
System Requirements
Table 1-1 includes minimum system requirements for the Vision Builder AI Development Toolkit:
Table 1-1. Minimum System Requirements
Minimum Processor Memory Display Pentium III, Celeron 866 MHz, or equivalent processor 256 MB RAM 1,024 768 resolution video adapter with a 16-bit display Microsoft Windows Vista/XP/2000 Microsoft Internet Explorer 5.0 or later 10 MB LabVIEW 8.5.1
Recommended Pentium 4/M or equivalent 512 MB RAM 1,024 768 resolution video adapter with a 24-bit or 32-bit display
NI Vision Development Module 2009* NI Vision Acquisition Software 2009 LabVIEW 8.5.1 Real-Time Module
The NI Vision Development Module is required to develop custom image processing steps. The NI Vision Acquisition Software is required to deploy custom image processing steps to remote targets.
The LabVIEW Real-Time Module is required to develop custom steps for remote targets. The Vision Builder AI Development Toolkit does not support the creation of acquisition steps for remote targets.
1-2
ni.com
Chapter 1
Installation Instructions
Complete the following steps to install the Vision Builder AI Development Toolkit.
Note
You must install LabVIEW before installing the Vision Builder AI Development Toolkit. To install the Vision Builder AI Development Toolkit on a Windows system, you must be logged in with administrator privileges. 1. 2. 3. In the feature tree for Vision Builder AI, select Development Toolkit and select Install this feature to the local drive. Click Next. Follow the setup instructions on your screen.
Note
You must install LabVIEW before installing the Vision Builder AI Development Toolkit. 1. 2. 3. 4. 5. 6. Open the Windows Add or Remove Programs utility, located on the Control Panel. Select National Instruments Software, then click Change. Select NI Vision Builder AI and click Modify. In the feature tree for Vision Builder AI, select Development Toolkit and select Install this feature to the local drive. Click Next. Follow the setup instructions on your screen.
1-3
Chapter 1
5. 6.
The Import Vision Builder AI 3.6 Step wizard creates the following files in the <Vision Builder AI 2009>\UserPlugins folder:
59 <Custom Step Name>.llbSource code for the custom step
Launch LabVIEW. Select FileOpen on the LabVIEW toolbar. Navigate to the <Vision Builder AI 3.6>\UserPlugins folder, select the LLB of the custom step created for Vision Builder AI 3.6, and click OK. Select the XControl (.xctl) file and click OK. LabVIEW opens the XControl. Select FileSave As. Select the Rename option. Click Continue.
5. 6. 7. 8.
1-4
ni.com
Chapter 1
9.
Navigate to the <Vision Builder AI 2009>\UserPlugins folder, select the LLB of the custom step created for Vision Builder AI 2009, and click OK.
10. Click OK to save the XControl. 11. Close the XControl, and click Dont Save - All when prompted to save changes. 12. Close LabVIEW. The XControl still links to the custom step created for Vision Builder AI 3.6. To link the XControl to the custom step created for Vision Builder AI 2009, complete the following steps: 1. 2. 3. Navigate to the <Vision Builder AI 3.6>\UserPlugins folder and delete the custom step created for Vision Builder AI 3.6. Launch LabVIEW. Navigate to the <Vision Builder AI 2009>\UserPlugins folder, select the LLB of the custom step created for Vision Builder AI 2009, and click OK. Select the XControl (.xctl) file, then click OK. A dialog box indicates that the XControl is no longer linked to the custom step for Vision Builder AI 3.6. Click OK. Select FileSave All. Close the XControl. Close LabVIEW. Navigate to the <Vision Builder AI 3.6>\UserPlugins folder, and rename the backup copy of the custom step for Vision Builder AI 3.6 to the original step name.
4. 5. 6. 7. 8. 9.
The XControl in the custom step for Vision Builder AI 2009 functions properly.
1-5
This chapter describes the components of a custom step created with the Vision Builder AI Development Toolkit.
Tip
Examine other templates to help determine how to modify your custom step. For example, if you want to create a custom step that combines image processing and creating image masks, use the Simple Processing template to create the custom step, then refer to the Coordinate System template for ideas about how to implement image mask creation.
2-1
Chapter 2
custom step, as well as several utility VIs that you can use as you modify your custom step. If you create helper VIs or controls for your custom step, save them in this LLB. Refer to the Source Code VIs section for more information about the source code VIs stored in the custom step LLB.
<Custom Step Name>.tifIcon for the custom step. Modify this
file to change the icon for the custom step. Do not change the file extension or dimensions of the icon. To deploy a custom step, you must save the custom step for distribution. Refer to the Distributing The Custom Step section of Chapter 3, Creating a Custom Image Processing Step, for more information about deploying custom steps.
All VIs VI
The All VIs VI is not designed to be executed. The block diagram of the All VIs VI provides a project window that contains the VIs that you can modify or use in your custom step. The block diagram of this VI is divided into the following sections: Set Up GlobalContains the <Custom Step Name> - Init Globals VI. Refer to the Init Globals VI section for more information about this VI. The Init Globals VI is connected to a string indicator to ensure that the All VIs VI has no errors. This string indicator serves no other purpose. Custom VIsThis section contains the VIs you must modify customize the behavior of your custom step. Refer to the User Interface VI section and the User Programming VI section for more information about custom VIs.
2-2
ni.com
Chapter 2
Utility VIsThis section contains utility VIs that you can call within the source VIs to perform specific functions, such as displaying an image in the main Vision Builder AI window. You cannot modify these VIs. Refer to the Utility VIs section for more information about utility VIs. Dynamic VIsThis section is designed to contain any VIs that you call dynamically. Place any VIs that you call dynamically within a source VI in this section to ensure that the VI is saved correctly when you build the custom step for distribution.
Init Globals VI
The Init Globals VI allows you to specify the following properties for a custom step: The name and description of the step that appear in Vision Builder AI. The version of the custom step. The tools palette tab that contains the custom step in Vision Builder AI. The region where the user interface for the custom step appears in Vision Builder AI. Whether the custom step can be used in product selection mode. The path to a help file that you create for the custom step. Refer to Appendix B, Creating Documentation for the Custom Step, for information about creating help for the custom step. The default ROI tool for the step, the ROI tools supported by the custom step, the names of the available ROI tools, and the display of previously created ROIs. The image file types supported by the custom step.
For detailed information about the parameters in the Init Globals VI that you can set to specify the properties of your custom step, refer to Appendix A, Controls and Indicators Used in Source Code VIs.
Note
When you modify the controls and indicators in the Init Globals VI, you must make the new values the default for the control or indicator and save the changes. To make the current values the default for a control or indicator, select EditMake Current Values Default, and save the VI.
2-3
Chapter 2
Parameters Control
This is the type definition for the parameters used by the custom step. Type definitions link all the instances of a custom control or indicator to a saved custom control or indicator file. You can update all instances of a parameter by editing the <Custom Step Name> - parameters.ctl file, which allows you to easily use the same controls and indicators in multiple source code VIs.
Tip If you have multiple parameters, place them inside a cluster. By bundling several data elements into a single cluster data structure, you eliminate wire clutter on the block diagram and reduce the number of VI connector pane terminals required to handle parameter data.
User Interface VI
The front panel of the User Interface VI is the interface the user sees when configuring the custom step. The User Interface VI allows the user to modify step parameters, and can compare data from the User Programming VI with user-defined parameters to indicate the step status. The User Interface VI is executed when a user selects the custom step from the Vision Builder AI Inspection Steps palette or when the user opens a step already inserted in the script to edit parameters.
Note
Do not resize the tab control on the user interface or change its position. Changing the tab control on the custom step user interface might move the user interface controls and indicators to a position that the user cannot access.
Tip
To display the user interface of the custom step in the main window of Vision Builder AI, open the Init Globals VI and select Main Window from the Region list.
User Programming VI
The User Programming VI performs image processing, and can return image processing results. The front panel is never displayed, so it does not have to be modified. Do not modify the connector pane of this VI. The Vision Builder AI engine sets the value of the Setup variant control, which contains the setup parameters defined by the user in the user interface. Use the Variant To Data VI to access this data. Use the same data structure that you used to package the data in User Interface VI. To ensure that you use the same data type, always use the Parameters control type definition with the Variant to Data VI.
2-4
ni.com
Chapter 2
The User Programming VI operates in one of the three following modes: SetupExecuted once when the user opens an inspection that contains the custom step or inserts the custom step in the script. Use this mode to perform any one-time initialization routines, such as reading a pattern matching template or initializing a data acquisition (DAQ) or image acquisition device. ExecutionExecuted each time the step is called within the Vision Builder AI inspection. This mode performs the main function of the custom step. CleanupExecuted when the user closes an inspection or when the step is removed from the script. Use this mode to dispose of any resources allocated in the Setup mode.
Utility VIs
Utility VIs perform tasks that are commonly necessary in Vision Builder AI steps. These VIs can be accessed from the All VIs block diagram, but not all utility VIs are included with every type of custom step. The utility VIs are located at <Vision Builder AI>\Plugins\ Common SDK VIs.llb.
2-5
Chapter 2
The input to the VBAI CoordSys Name Utility VI is a coordinate system identified by the coordinate system name that the user selected from the user interface. The VBAI CoordSys Name Utility VI returns a unique ID for the coordinate system, along with the coordinate system data. The unique coordinate system ID ensures that the correct coordinate system is selected, even when the coordinate system is renamed.
2-6
ni.com
Chapter 2
2-7
Chapter 2
Figure 2-1. Dataflow between the User Interface, User Programming, and Utility VIs
The User Interface VI is called when the user inserts the custom step into a script, or opens the custom step to edit its configuration. The front panel of the User Interface VI is the interface that the user sees when configuring the custom step. If the user validates a custom step by clicking OK in the user interface of the custom step, Vision Builder AI automatically calls the setup and execution modes of the User Programming VI and inserts the step in the script.
Note
When developing the User Interface VI, ensure that you call the User Programming VI in setup mode to perform any initialization before you call the execution mode of the User Programming VI. When the step executes, the Vision Builder AI engine sets the image and the Previous Measurements array, and sets the Setup variant to the value previously set in User Interface VI. In execution mode, the User Programming VI accesses the data from the User Interface VI, then processes the image and produces results. When the user closes the script, the Vision Builder AI engine calls the cleanup mode of the User Programming VI. Figure 2-1 illustrates the sequence of the setup, execution, and cleanup modes of the User Programming VI.
2-8
ni.com
Chapter 2
Examples
Complete the following steps to view a block diagram that shows the event structure that handles the OK button in the user interface of the custom step: 1. 2. 3. 4. 5. Create a custom step using the Simple Processing Step template. Open the User Interface VI. View the block diagram. Select frame 3 of the sequence structure. Select event case 3 of the event structure. In this event case, the step uses the VBAI Check Unique Step Name utility VI to verify that the step name is valid before it allows the step to exit.
Complete the following steps to view a block diagram that shows the relationship between the User Interface VI and the User Programming VI: 1. 2. 3. 4. 5. Create a custom step using the Processing Step that Logs Measurements template. Open the User Interface VI. View the block diagram. Select frame 3 of the sequence structure. Select event case 0 of the event structure. In this event case, the step compares the Pass/Fail Data returned from the User Programming VI to the Pass/Fail Conditions set by the user in the user interface, then updates the Step Status indicator based on the comparison results. The step also uses the VBAI Display in Main Window utility VI to update the main window of Vision Builder AI with the processed image returned by the User Programming VI.
Setup Variant
The Setup variant stores the parameters of the step. If the step requests more than one parameter, bundle the parameters in a cluster, and use the To Variant VI to store the parameters in the variant. Use the Variant to Data VI to retrieve these parameters in the User Programming VI. Complete the following steps to view a block diagram that shows the relationship between the step parameters and the Variant to Data VI: 1. 2. Create a custom step using the Simple Processing Step template. Open the User Interface VI.
2-9
Chapter 2
3. 4. 5.
View the block diagram. Select frame 1 of the sequence structure. Select the True case of the case structure. The True case executes if the user edits the step, and updates the user interface with values stored in the Setup in variant.
Process ID
When the user creates an instance of a custom step, the Vision Builder AI engine provides the step instance with a Process ID, which is a string that uniquely identifies the custom step. The Process ID differentiates multiple instances of the same step. Use the Process ID to allocate resources to a specific instance of a custom step. For example, you can pass a Process ID to the IMAQ Create VI to allocate a unique image for an instance of a custom step. The IMAQ Create VI is installed as part of the NI Vision Development Module or NI Vision Acquisition Software.
Tip
The VBAI Resource Manager utility VI is designed to help you create, get, and deallocate step specific resources. Refer to the Utility VIs section for more information about the VBAI Resource Manager VI.
Tip
You can use a variable to pass information between the different modes of the VI. If the values of the variable change between multiple instances of the same custom VI, the variable is overwritten with the latest value.
Save any global variables created in the 59 <Custom Step Name>.llb with the step name as the prefix, followed by a dash. For example, if you created a variable called MyGlobal for a step you named Image Processing, save the global variable as Image Processing - MyGlobal.vi.
2-10
ni.com
This chapter introduces concepts required to create custom steps for Vision Builder AI. Follow the instructions in this chapter to complete the following tasks:
Note
Generate a custom step from a template using the Create Custom Step Wizard Modify the custom step to perform an image threshold Debug the custom step Save the custom step for deployment
This tutorial requires the NI Vision Development Module in addition to the minimum system requirements of the Vision Builder AI Development Toolkit.
3-1
Chapter 3
4.
Enter This step performs a manual threshold as the Description for the custom step. The description is displayed next to the step name in the Vision Builder AI Inspection Steps palette. Click Next. In the Templates list select Simple Processing Step. A simple processing step processes an input image and returns pass/fail information. Refer to the Types of Custom Steps section of Chapter 2, Understanding Custom Steps, for information about each custom step template. Click Next and verify the setup information. Close all open VIs to ensure that the custom step is created successfully. Click Finish to create the custom step. The Create Custom Step wizard opens the Manual Threshold - All VIs VI block diagram. This VI provides a project window that contains the VIs that you can modify for the custom step. Refer to the Source Code VIs section of Chapter 2, Understanding Custom Steps, for information about the All VIs VI.
5. 6.
7. 8. 9.
3-2
ni.com
Chapter 3
Note
The custom step is not available in Vision Builder AI until you save it for distribution. National Instruments recommends that you debug the custom step before you save it for distribution. Refer to the Debugging the Custom Step section for information about debugging custom steps.
3-3
Chapter 3
Modify the block diagram of the User Interface VI to set default values for the threshold range
Note
Do not resize the tab control on the user interface or change its position. Changing the tab control on the custom step user interface might move the user interface controls and indicators to a position that the user cannot access.
5. 6.
a.
b.
3-4
ni.com
Chapter 3
b. c. d. e. f. 7.
Add a cluster to the front panel. Label the cluster Threshold Range. Add a numeric control to the cluster. Label the numeric control
Minimum Value.
Add another numeric control to the cluster. Label the numeric control Maximum Value, as illustrated in Figure 3-2b. Select FileSave to save the type definition. Select FileClose to close the type definition.
Position the type definition cluster so that the Minimum Value and Maximum Value controls are visible, as illustrated in Figure 3-3.
Tip
Set the color of the cluster background and border to transparent to hide the cluster on the user interface. To change the cluster color to transparent, select ViewTools Palette, and select the Set Color tool. Right-click the cluster background or border to open the color picker, and Select the T box in the upper right corner of the color picker.
3-5
Chapter 3
8. 9.
Relabel the Kernel cluster as Threshold Range. Select FileSave to save the User Interface VI.
The user interface now contains two numeric controls that allow the user to specify the range for the image threshold.
4.
5. 6.
Select FileSave to save the User Interface VI. Select FileClose to close the User Interface VI.
When the user adds the custom step to an inspection in Vision Builder AI, the User Interface VI initializes the Maximum Value control to 90.
3-6
ni.com
Chapter 3
6.
3-7
Chapter 3
a.
The Execution case of the case structure contains a broken wire that connects the Variant to Data VI and the IMAQ Convolute VI. Delete the broken wire. Replace the IMAQ Convolute VI with the IMAQ Threshold VI. Verify that the Image control is wired to the Image Src input of the IMAQ Threshold VI. Verify that Image Dst Out output of the IMAQ Threshold VI is connected to the Image out indicator. Wire the data output from the Variant to Data VI to the Range input of the IMAQ Threshold VI. Create a numeric constant with a value of 255 and wire it to the Replace Value input of the IMAQ Threshold VI.
b. c. d. e. f. 7. 8.
Select FileSave to save the User Programming VI. Select FileClose to close the User Programming VI.
Note
When you modify the controls and indicators in the Init Globals VI, you must make the new values the default for the control or indicator and save the changes. 5. Select FileSave to save the Init Globals VI.
3-8
ni.com
Chapter 3
3-9
Chapter 3
Note
You must open Vision Builder AI from LabVIEW to test a custom step that has not been saved for distribution. Refer to the Distributing The Custom Step section for information about saving custom steps for use with the Vision Builder AI executable. 3. 4. Click Configure Inspection to open the Vision Builder AI Configuration interface. Add a Simulate Acquisition step to the inspection. Select
<Vision Builder AI>\DemoImg\Tutorial 1\Image 01.jpg
as the source image. Because the Manual Threshold custom step operates on an image, you must acquire an image to test the custom step. 5. Add the Manual Threshold custom step to the inspection. By default, custom steps are located on the Use Additional Tools palette. If you did not modify the custom step icon, the custom step displays the default custom step icon. 6. When you open the custom step, Vision Builder AI operates in debugging mode. The front panel of the User Interface VI for the custom step opens in LabVIEW. The front panel of the User Interface VI may open behind the Vision Builder AI window. Open the User Interface VI by clicking the VI window in the taskbar. When the custom step is added to the inspection, the main window displays the output image from the Manual Threshold custom step. Figure 3-6 illustrates the output image from the custom step. White pixels indicate values within the threshold range.
3-10
ni.com
Chapter 3
7. 8.
Modify the Minimum Value and Maximum Value, and observe the changes made to the image in the main window of Vision Builder AI. Press <Ctrl-E> or select WindowShow Block Diagram to open the block diagram and begin debugging the custom step. Standard LabVIEW debugging tools are available to debug the custom step. Select the appropriate debugging options and breakpoints to debug the custom step.
9.
Exit debugging mode by clicking Abort Execution in the LabVIEW toolbar, by clicking Cancel in the custom step User Interface VI front panel, or by clicking the Exit button in Vision Builder AI.
3-11
Chapter 3
The Save Your Custom Step for Distribution wizard builds 59 Manual Threshold.bin in the <Vision Builder AI>\ UserPlugins folder. To distribute the custom step, install 59 Manual Threshold.bin and the corresponding .tif file to the <Vision Builder AI>\UserPlugins folder on the vision inspection system.
3-12
ni.com
This chapter introduces concepts required to create a custom step that performs pass/fail analysis. Complete the steps in this chapter to modify the custom step that you created in Chapter 3, Creating a Custom Image Processing Step, to perform the following functions: Log a measurementThe modified step calculates the percentage of the image that is removed by an image threshold. The percentage is logged and made available to subsequent steps. Set a limit conditionThe modified step compares the logged percentage against a minimum threshold percentage specified through the user interface. Based on the results of the comparison, the step indicates whether the image under inspection passes or fails.
Note Refer to the Processing Step that Logs Measurements template as you proceed with this tutorial. Use the Processing Step that Logs Measurements template to create new custom steps that perform pass/fail analysis. Note
This tutorial requires the NI Vision Development Module in addition to the minimum system requirements of the Vision Builder AI Developers Toolkit.
4-1
Chapter 4
5.
Select the Existing custom step you previously created option. Figure 4-1 illustrates the correct option.
6. 7. 8. 9.
Click Next. Select Manual Threshold from the Existing Custom Steps Previously Created list. Click Next and verify the setup information. Close all open VIs to ensure that the custom step is created successfully. Click Finish to create the custom step. The Create Custom Step wizard opens the Manual Threshold Pass Fail - All VIs VI. This VI provides a project window that contains the VIs you can modify for the custom step. Refer to the Source Code VIs section of Chapter 2, Understanding Custom Steps, for information about the VIs that make up a custom step.
Note
The custom step is not available in Vision Builder AI until you save it for distribution. National Instruments recommends that you debug the custom step before you save it for distribution. Refer to the Debugging the Custom Step section for information about debugging custom steps.
4-2
ni.com
Chapter 4
Select the Manual Threshold Pass Fail - All VIs.vi and click OK.
Logging Measurements
Follow the steps in this section to modify the User Programming VI to perform the following functions: Calculate the percentage of the image that is removed by an image threshold Store the thresholded percentage to the Measurements array so that other steps can access the value Log the thresholded percentage so that Vision Builder AI can compare the value with the limits specified by the user in the user interface
4-3
Chapter 4
4. 5. 6.
Navigate to the No Error case of the case structure. Navigate to the Execution case of the case structure within the No Error case. Complete the following steps to modify the block diagram to calculate the percentage of the image removed by the image threshold, as shown in Figure 4-2:
a. b. c. d. e. f. g. h. i. j. 7.
Place an IMAQ Histograph VI inside the execution case of the case structure. Wire the Image Dst Out output of the IMAQ Threshold VI to the Image input of the IMAQ Histograph VI. Place a Divide function inside the case structure. Connect the Mean Value output of the IMAQ Histograph VI to the x input of the Divide function. Create a numeric constant with a value of 255 and wire it to the y input of the Divide function. Place a Multiply function inside the Execution case of the case structure. Connect the x/y output of the Divide function to the x input of the Multiply function. Create a numeric constant with a value of 100 and wire it to the y input of the Multiply function. Place a To Double Precision Float function inside the case structure. Connect the x/y output of the Divide function to the number input of the To Double Precision Float function.
Select FileSave.
4-4
ni.com
Chapter 4
The output of the To Double Precision Float function provides the percentage of the image removed by the threshold.
1. 2. 3. 4. 5. 6. 7. 8.
With the User Programming VI block diagram open, navigate to the Execution case of the case structure within the No Error case. Place a Flatten To String function inside the case structure. Connect the double precision float output of the To Double Precision Float function to the anything input of the Flatten To String Function. Place an Bundle By Name function inside the case structure. Connect the data string output of the Flatten To String function to the element 0 input of the Bundle By Name function. Right-click the block diagram and select Select a VI. Navigate to <Vision Builder AI>\Plugins\Common SDK VIs.llb, select VBAI SDK - Result.ctl, and click OK. Place the cluster inside the case structure. The cluster contains four elements. ValueThe result value, in the form of a flattened string. Vision Builder AI results can be of type double, Boolean, or string. The Value element must be the flattened string of the result. TypeThe type of the result. NameThe name of the result. UnitThe unit of measure that corresponds to the result.
4-5
Chapter 4
9.
Click the Type enum and select Numeric from the list.
10. Enter Threshold Percentage as the value for the Name string. 11. Connect the cluster to the input cluster input of the Bundle By Name function. 12. Place a Build Array function inside the case structure. 13. Connect the output cluster output of the Bundle By Name function to the element 0 input of the Build Array function. 14. Locate the Measurements array that is inside the case structure. Connect the appended array output of the Build Array function to the Measurements array. 15. Select FileSave. The percentage of the image removed by the threshold is stored in the Measurements array as Threshold Percentage.
Note
You can log additional results by adding more elements to the array.
4-6
ni.com
Chapter 4
Complete the following steps to modify the block diagram to store the thresholded percentage to the Pass/Fail Data array, as shown in Figure 4-4:
Figure 4-4. Storing the Threshold Percentage in the Pass/Fail Data Array
1. 2. 3. 4.
Tip
With the User Programming VI block diagram open, navigate to the Execution case of the case structure within the No Error case. Place an Array constant inside the Execution case of the case structure. Place a String constant inside the array. Enter Percent = %d as the string text.
To automatically resize a string constant, right-click the string and select Size To Text. 5. 6. 7. 8. 9. Expand the array vertically to create another string element. Enter Condition Not Met as the string text for the string element. Place a Bundle function inside the case structure. Wire the double precision float output of the To Double Precision Float function to the element 0 input of the Bundle function. Wire the string array to the element 1 input of the Bundle function.
10. Place a Build Array function inside the case structure. 11. Connect the output cluster output of the Bundle function to the element 0 input of the Build Array function.
4-7
Chapter 4
12. Locate the Pass/Fail Data array that is inside the case structure. Connect the appended array output of the Build Array function to the Pass/Fail Data array. 13. Select FileSave to save the User Programming VI. 14. Select FileClose to close the User Programming VI. The percentage of the image removed by the threshold is stored in the Pass/Fail Data array and returned to the User Interface VI so that the step can perform pass/fail analysis and update the step status.
Note
The Pass/Fail Data array must have the same number of elements as the Pass/Fail Condition out array found in the User Interface VI. Each element of the Pass/Fail Data array is compared to a condition specified in the Pass/Fail Condition out array.
Open the All VIs VI. Double-click the User Interface VI to open it.
Do not resize the tab control on the user interface or change its position. Changing the tab control on the custom step user interface might move the user interface controls and indicators to a position that the user cannot access. 3. 4. 5. Select the Limits tab. Right-click the front panel and select Select a Control. Navigate to <Vision Builder AI>\Plugins\Common SDK VIs.llb, select VBAI SDK - Pass Fail Condition.ctl, and click OK. The Pass/Fail Condition control is a type definition that includes the controls necessary to enable and perform pass/fail analysis.
4-8
ni.com
Chapter 4
6.
Place the Pass/Fail Condition control on the Limits tab, as illustrated in Figure 4-5.
7. 8. 9.
Right-click the Used Boolean and select Visible ItemsCaption. Enter Enable Pass/Fail Analysis as the caption text. Right-click the Value 1 control and select Visible ItemsCaption. Enter Maximum Threshold Percentage as the caption text. The Pass/Fail Condition cluster contains controls that the user should never modify. Resize the Pass/Fail Condition cluster to hide the Value 2 and Function controls, as illustrated in Figure 4-6.
4-9
Chapter 4
10. Select FileSave. The user interface now contains controls that allow the user to enable pass/fail analysis, and to specify a limit condition for pass/fail analysis.
4-10
ni.com
Chapter 4
Complete the following steps to modify the User Interface VI block diagram to initialize the pass/fail controls with default values: 1. 2. With the User Interface VI front panel open, select the Limits tab. Right-click the Pass/Fail Condition cluster and select FindTerminal. LabVIEW highlights the Pass/Fail Condition control on the User Interface block diagram. Move the Pass/Fail Condition control outside of the stacked sequence structure. Do not delete this control. Select frame 1 of the stacked sequence structure. Locate the case structure within frame 1 and select the False case. The false case specifies default values for the control. Complete the following steps to build the block diagram shown in Figure 4-7:
3. 4.
5.
a. b. c. d. e. 6.
Place a local variable outside the right side of the case structure. Click the local variable and select Pass/Fail Condition from the list. Right-click the Pass/Fail Condition variable and select CreateConstant. Place the constant inside the case structure. Wire the constant to the Pass/Fail Condition variable.
Select FileSave.
When the user adds the custom step to an inspection in Vision Builder AI, the User Interface VI initializes the pass/fail controls to the values specified in the constant.
4-11
Chapter 4
a. b. c. d.
Place the Pass/Fail Condition control inside the case structure. Place a Build Array function inside the case structure. Wire the Pass/Fail Condition control to the input of the Build Array function. Disconnect the Pass/Fail Conditions in array from the Pass/Fail Conditions out array. Move the Pass/Fail Conditions in array outside of the stacked sequence structure. Do not delete this array. Wire the output of the Build Array function to the Pass/Fail Conditions out array.
e.
4-12
ni.com
Chapter 4
When the user saves the step, the values from the Pass/Fail Condition control are stored in the Pass/Fail Conditions out array. When the user edits the step, the Vision Builder AI engine passes the values stored in the Pass/Fail Conditions out array to the Pass/Fail Conditions in array. Use the Pass/Fail Conditions in array to initialize values for the pass/fail controls on the Limits tab.
a. b. c. d. 4.
Place the Pass/Fail Conditions in control inside the case structure in frame 1. Place an Index Array function inside the case structure. Wire the Pass/Fail Conditions in control to the array input of the Index Array function. Wire the element output of the Index Array function to the Pass/Fail Condition variable.
Select FileSave.
4-13
Chapter 4
When the user edits the step, the User Interface VI initializes the pass/fail controls to the values specified in the Pass/Fail Conditions in array.
Disconnect the Event Data Node from the To Variant function. Because event case 0 now handles multiple events, you must modify the source code that handles changes to the threshold range controls. Place a local variable inside the event structure. Click the local variable and select Threshold Range from the list. Right-click the Threshold Range variable and select Change To Read.
5. 6. 7.
4-14
ni.com
Chapter 4
8.
Wire the Threshold Range variable to the anything input of the To Variant function. Figure 4-10 illustrates the modified event structure.
9.
1. 2. 3.
National Instruments Corporation
With the User Interface VI block diagram open, select frame 3 of the stacked sequence structure. Locate the event structure within frame 3 and select event case 0. Place a local variable inside the event structure.
4-15 NI Vision Builder AI Development Toolkit Tutorial
Chapter 4
4. 5. 6. 7. 8. 9.
Click the local variable and select Pass/Fail Condition from the list. Right-click the Pass/Fail Condition variable and select Change to Read. Place a Build Array function inside the event structure. Wire the Pass/Fail Condition variable to the element 0 input of the Build Array function. Open the All VIs VI block diagram and locate the VBAI Decision Maker (Float) VI. Copy the VBAI Decision Maker (Float) VI into the event structure of the User Interface VI. The VBAI Decision Maker (Float) VI compares results from User Programming VI against the limit conditions specified by the user in the User Interface VI to determine whether the step result conditions are met.
10. Wire the output of the Build Array function to the Pass/Fail Condition input of the VBAI Decision Maker (Float) VI. 11. Wire the Pass/Fail Data output of the Manual Threshold Pass Fail User Programming VI to the Pass/Fail Data input of the VBAI Decision Maker (Float) VI. 12. Delete the Boolean constant that is wired to the Step Status indicator. 13. Wire the Pass/Fail Flag output of the VBAI Decision Maker (Float) VI to the Step Status indicator. 14. Select FileSave to save the User Interface VI.
4-16
ni.com
Chapter 4
5.
Place a numeric indicator on the Limits tab. Label the numeric indicator Threshold Percentage as illustrated in Figure 4-12.
6. 7. 8.
Right-click the Threshold Percentage indicator and select Properties. In the Appearance tab, select the Disabled option. Click OK to close the properties dialog box. Press <Ctrl-E> or select WindowShow Block Diagram to return to the block diagram.
4-17
Chapter 4
9.
Complete the following steps to build the block diagram show in Figure 4-13:
a. b.
Place an Index Array function inside the event structure. Wire the Measurements output of the Manual Threshold Pass Fail - User Programming VI to the array input of the Index Array function. Place an Unbundle By Name function inside the event structure. Wire the element output of the Index Array function to the Unbundle By Name function. Place an Unflatten From String function inside the event structure. Wire the Value output of the Unbundle By Name function to the binary string input of the Unflatten From String function. Place a Numeric constant inside the event structure and wire it to the type input of the Unflatten From String function. Right-click the Numeric constant and select RepresentationDouble Precision. Wire the value output of the Unflatten From String function to the Threshold Percentage indicator. Figure 4-13 illustrates the complete block diagram.
c. d. e. f. g. h. i.
10. Select FileSave to save the User Interface VI. 11. Select FileClose to close the User Interface VI. The Manual Threshold Pass Fail step is complete.
4-18
ni.com
Chapter 4
Launch LabVIEW.
You must configure LabVIEW before debugging a custom step. Refer to the Configuring LabVIEW to Debug Custom Steps section of Chapter 3, Creating a Custom Image Processing Step, for more information about configuring LabVIEW. 2. Select ToolsVision Builder AITest Your Custom Step in Vision Builder AI to launch Vision Builder AI and test the step.
Note
You must open Vision Builder AI from LabVIEW to test a custom step that has not been saved for distribution. Refer to the Distributing The Custom Step section of Chapter 3, Creating a Custom Image Processing Step, for information about saving custom steps for use with the Vision Builder AI executable. 3. 4. Click Configure Inspection to open the Vision Builder AI Configuration interface. Add a Simulate Acquisition step to the acquisition. Because the Manual Threshold Pass Fail custom step operates on an image, you must acquire an image to test the custom step. Add the Manual Threshold Pass Fail custom step to the inspection. By default, custom steps are located on the Use Additional Tools palette. If you did not modify the custom step icon, the custom step displays the default custom step icon. 6. When you open the custom step, Vision Builder AI operates in debugging mode. The front panel of the User Interface VI for the custom step opens in LabVIEW. The front panel of the User Interface VI may open behind the Vision Builder AI window. Open the User Interface VI by clicking the VI window in the taskbar. Complete the following steps to debug the custom step: a. b. c. Select the Limits tab of the Manual Threshold Pass Fail custom step. Locate the Thresholded Percentage indicator and note the value. Select the Enable Pass/Fail Analysis checkbox. Note that the Step Status indicator changes to FAIL. The step fails because the thresholded percentage exceeds the specified maximum threshold percentage value of 0.
5.
7.
4-19
Chapter 4
d. e. f.
Enter 20 as the value for the Maximum Threshold Percentage control. Note that the Step Status indicator changes to PASS. Select the Settings tab. Enter 200 as the value for the Maximum Value control. Note that the Step Status indicator changes to FAIL because the thresholded percentage once again exceeds the minimum required threshold percentage. Click OK to add the step to the inspection, then edit the step to verify that the controls initialize to the correct values.
g.
When you are satisfied with the performance of the step, save the step for distribution. Refer to the Distributing The Custom Step section of Chapter 3, Creating a Custom Image Processing Step, for more information about saving custom steps for distribution.
4-20
ni.com
Complete the steps in this chapter to modify the custom step that you created in Chapter 4, Logging Measurement and Setting Limit Conditions, so that the user can select measurement results from previous steps as threshold range values. You can use the Measurements indicator in the Execution mode of the User Programming VI to log double, Boolean, and string measurements of the custom step for use in subsequent steps. For more information about the Measurements indicator, refer to the User Programming VI Parameters section of Appendix A, Controls and Indicators Used in Source Code VIs.
Note
This tutorial requires the NI Vision Development Module in addition to the minimum system requirements of the Vision Builder AI Developers Toolkit.
5-1
Chapter 5
The Create Custom Step wizard opens the Manual Threshold Previous Measurements - All VIs VI. This VI provides a project window that contains the VIs you can modify for the custom step.
Note
The custom step is not available in Vision Builder AI until you save it for distribution. National Instruments recommends that you debug the custom step before you save it for distribution. Refer to the Debugging the Custom Step section for information about debugging custom steps.
5-2
ni.com
Chapter 5
Note
Do not resize the tab control on the user interface or change its position. Changing the tab control on the custom step user interface might move the user interface controls and indicators to a position that the user cannot access. 4. 5. 6. Right-click the Threshold Range cluster and select Open Type Def to open the Parameters control. Expand the size of the Parameters control window and the Threshold Range cluster. Complete the following steps to build the front panel shown in Figure 5-1:
a. b. c. d. e.
Right-click the front panel and select Select a Control. Navigate to <Vision Builder AI>\Plugins\Common SDK VIs.llb, select IVB Measure ID.ctl, and click OK. Place the control inside the Threshold Range cluster. Label the control Minimum Value Result. Select the Minimum Value Result cluster. Select EditCopy to copy the cluster.
5-3
Chapter 5
f. g. 7. 8.
Click the background of the Threshold Range cluster, then select EditPaste to paste a copy of the Minimum Value Result cluster. Label the new cluster Maximum Value Result.
Select FileSave to save the type definition. Select FileClose to close the type definition.
With the User Interface VI front panel open, select the Settings tab. Expand the User Interface VI front panel window.
Do not resize the tab control on the user interface or change its position. Changing the tab control on the custom step user interface might move the user interface controls and indicators to a position that the user cannot access.
5-4
ni.com
Chapter 5
3.
Move the Threshold Range cluster off of the tab control, as illustrated in Figure 5-2:
5-5
Chapter 5
4.
Complete the following steps to build the front panel shown in Figure 5-3:
a. b. c. d. 5. 6.
Add a system ring to the Settings tab. Label the system ring Minimum Value Source. Add a system ring to the Settings tab. Label the system ring Maximum Value Source. Add a system spin control to the Settings tab. Label the system spin control Minimum Value (Constant). Add a system spin control to the Settings tab. Label the system spin control Maximum Value (Constant).
Press <Ctrl-E> or select WindowShow Block Diagram to show the block diagram. Move the Minimum Value Source, Minimum Value (Constant), Maximum Value Source, and Maximum Value (Constant) controls outside the stacked sequence structure. Select FileSave.
5-6 ni.com
7.
Chapter 5
a. b.
Locate the Previous Measurements array. Move the Previous Measurements array to the top of the stacked sequence structure. Open the All VIs VI block diagram and locate the VBAI SDK Populate Result Ring VI. The VBAI SDK - Populate Result Ring VI loops through the results returned by previous steps in the inspection and returns a list of results and corresponding GUIDs of the selected data type. The default data type is numeric.
c. d.
Copy the VBAI SDK - Populate Result Ring VI into the stacked sequence structure of the User Interface VI. Wire the Previous Measurements array to the Previous Measurements input of the VBAI SDK - Populate Results Ring VI. Right-click the Minimum Value Source ring control and select CreateProperty NodeStrings[]. Place the Minimum Value Source property node inside the stacked sequence structure. Select the Minimum Value Source property node and select Change to Write. Right-click the Maximum Value Source ring control and select CreateProperty NodeStrings[].
e. f. g. h.
5-7
Chapter 5
i. j. k.
Place the Maximum Value Source property node inside the stacked sequence structure. Select the Maximum Value Source property node and select Change to Write. Wire the Previous Measurement Names output of the VBAI SDK - Populate Results Ring VI to the Strings[] input of the Minimum Value Source and Maximum Value Source property nodes. Right-click the border of the stacked sequence structure and select Add Sequence Local.
l.
m. Place a free label next to the sequence local, outside the stacked sequence structure. Enter Previous Measurement IDs as the label text. n. 3. Wire the Measurement IDs output of the VBAI SDK - Populate Results Ring VI to the sequence local.
Select FileSave.
5-8
ni.com
Chapter 5
3.
Complete the following steps to build the block diagram shown in Figure 5-5:
Figure 5-5. Initializing the Previous Measurement Controls with Default Values
a. b. c. d. e. f. g. h. i. j.
Place an Unbundle By Name function inside the case structure. Wire the Parameters.ctl cluster to the input of the Unbundle By Name structure. Expand the Unbundle By Name function so that two elements are visible. Right-click the Minimum Value (Constant) control and select CreateLocal Variable. Place the Minimum Value (Constant) variable inside the stacked sequence structure. Wire the Minimum Value output of the Unbundle By Name function to the input of the Minimum Value (Constant) variable. Right-click the Maximum Value (Constant) control and select CreateLocal Variable. Place the Maximum Value (Constant) variable inside the stacked sequence structure. Wire the Maximum Value output of the Unbundle By Name function to the input of the Maximum Value (Constant) variable. Locate the Threshold Range property node to the right of the case structure. Right-click the Threshold Range property node and select Link toPaneTab ControlMinimum Value Source.
5-9
Chapter 5
k. l.
Right-click the Maximum Value Source control and select CreateLocal Variable. Place the Maximum Value variable inside the stacked sequence structure. Wire the numeric constant to the Minimum Value Source property node and the Maximum Value Source variable.
Select FileSave.
When the user adds the custom step to an inspection in Vision Builder AI, the User Interface VI initializes the Minimum Value Constant and Maximum Value Constant controls to default values. The User Interface VI initializes the Minimum Value Source and Maximum Value Source ring structures to a value of 0, which corresponds to a selection of the constant values as the source values.
5-10
ni.com
Chapter 5
3.
Complete the following steps to build the block diagram shown in Figure 5-6:
Figure 5-6. Initializing the Previous Measurement Controls with Existing Values
a. b. c. d. e. f. g. h.
Place an Unbundle By Name function inside the case structure. Wire the data output of the Variant To Data function to the input of the Unbundle By Name structure. Expand the Unbundle By Name function so that four elements are visible. Wire the Minimum Value output of the Unbundle By Name function to the Minimum Value (Constant) variable. Wire the Maximum Value output of the Unbundle By Name function to the Maximum Value (Constant) variable. Place a Search 1D Array function inside the case structure. Wire the Previous Measurement IDs sequence local to the 1D array input of the Search 1D Array function. Wire the Minimum Value Result output of the Unbundle By Name function to the element input of the Search 1D Array function. Place a Less Than 0? function inside the case structure. Wire the index of elements output of the Search 1D Array function to the x input of the Less Than 0? function. Place a Select function inside the case structure. Wire the x < 0? output of the Less Than 0? function to the s input of the Select function.
i. j. k. l.
5-11
Chapter 5
m. Place a numeric constant inside the case structure. n. o. p. q. r. s. Wire the numeric constant to the t input of the Select function. Wire the index of elements output of the Search 1D Array function to the f input of the Select function. Wire the s? t:f output of the Select function to the Minimum Value Source property node. Place a Search 1D Array function inside the case structure. Wire the Previous Measurement IDs sequence local to the 1D array input of the Search 1D Array function. Wire the Maximum Value Result output of the Unbundle By Name function to the element input of the Search 1D Array function. Place a Less Than 0? function inside the case structure. Wire the index of elements output of the Search 1D Array function to the x input of the Less Than 0? function. Place a Select function inside the case structure.
t. u. v.
w. Wire the x < 0? output of the Less Than 0? function to the s input of the Select function. x. y. z. 4. Wire the numeric constant to the t input of the Select function. Wire the index of elements output of the Search 1D Array function to the f input of the Select function. Wire the s? t:f output of the Select function to the Maximum Value Source variable.
Select FileSave.
When the user edits the step, the Vision Builder AI engine passes that values stored in the Setup out array to the Setup in array. The User Interface VI initializes the previous measurement controls to the values specified in the Setup in array. The User Interface VI uses the Search 1D Array functions to verify that the values stored for the Minimum Value Source and Maximum Value Source ring structures correspond to the Measurement IDs of available measurements. If the search function returns an index with a negative value, then the measurement is missing and the corresponding ring structure is initialized to a value of 0.
5-12
ni.com
Chapter 5
3.
b. c. d. e. f. g. h. i. j. k. l. n. o. p. 4.
m. Click the blue plus button next to the Event Specifiers list.
Place a Bundle By Name function inside the event structure. Expand the Bundle By Name function to display four elements.
5-13
Chapter 5
5.
Complete the following steps to configure the Bundle By Name function as illustrated in Figure 5-7:
a.
Locate the Threshold Range variable. Disconnect the Threshold Range variable from the To Variant function and move the Threshold Range variable to the right of the Bundle By Name function. Right-click the Threshold Range Variable and select CreateConstant. Wire the constant to the input cluster input of the Bundle By Name function. Click element 0 of the Bundle By Name function and select Minimum Value ResultAll Elements. Click element 1 of the Bundle By Name function and select Minimum Value. Click element 2 of the Bundle By Name function and select Maximum Value ResultAll Elements. Click element 3 of the Bundle By Name function and select Maximum Value.
b. c. d. e. f. g.
5-14
ni.com
Chapter 5
6.
Complete the following steps to build the block diagram illustrated in Figure 5-7: a. b. c. d. e. f. g. h. i. j. k. l. Move the Minimum Value Source control inside the event structure. Place an Index Array function inside the event structure. Wire the Minimum Value Source control to the index input of the Index Array function. Wire the Previous Measurement IDs sequence local to the array input of the Index Array functions. Wire the element output of the Index Array function to the Minimum Value Result input of the Bundle function. Move the Minimum Value (Constant) control inside the event structure. Wire the Minimum Value (Constant) control to the Minimum Value input of the Bundle function. Move the Maximum Value Source control inside the event structure. Place an Index Array function inside the event structure. Wire the Maximum Value Source control to the index input of the Index Array function. Wire the Previous Measurement IDs sequence local to the array input of the Index Array functions. Wire the element output of the Index Array function to the Maximum Value Result input of the Bundle function.
m. Move the Maximum Value (Constant) control inside the event structure. n. o. p. q. 7. Wire the Maximum Value (Constant) control to the Maximum Value input of the Bundle function. Right-click the Threshold Range variable and select Change to Write. Wire the output cluster output of the Bundle By Name function to the Threshold Range variable. Wire the output cluster output of the Bundle function to the anything input of the To Variant function.
Select FileSave.
5-15
Chapter 5
When the user clicks the Run Once button, the User Interface VI updates the property nodes for the Minimum Value (Constant) control and triggers the User Programming VI.
5-16
ni.com
Chapter 5
6.
Complete the following steps to build the block diagram illustrated in Figure 5-8:
a. b.
Delete the broken wire. Place an Unbundle By Name function inside the case structure. Expand the Unbundle By Name function so that four elements are visible. Wire the data output of the Variant To Data function to the input cluster input of the Unbundle By Name function. Open the All VIs VI block diagram and locate the VBAI SDK Get Result VI. Place a VBAI SDK Get Result VI inside the case structure. Wire the Minimum Value Result output of the Unbundle By Name function to the Measure ID input of the VBAI SDK Get Result VI.
c. d. e. f.
5-17
Chapter 5
g. h. i. j. k. l.
Place an Unbundle By Name function inside the case structure. Wire the Result Value output of the VBAI SDK Get Result VI to the input cluster input of the Unbundle By Name function. Place a Select function inside the case structure. Wire the Result Available output of the VBAI SDK Get Result VI to the s input of the Select function. Wire the Numeric output of the Unbundle By Name function to the t input of the Select function. Wire the Minimum Value output of the Unbundle By Name function to the f input of the Select function. Wire the s?t:f output of the Select function to the element 0 input of the Bundle function. Place a VBAI SDK Get Result VI inside the case structure. Wire the Maximum Value Result output of the Unbundle By Name function to the Measure ID input of the VBAI SDK Get Result VI. Place an Unbundle By Name function inside the case structure. Wire the Result Value output of the VBAI SDK Get Result VI to the input cluster input of the Unbundle By Name function. Place a Select function inside the case structure. Wire the Result Available output of the VBAI SDK Get Result VI to the s input of the Select function. Wire the Numeric output of the Unbundle By Name function to the t input of the Select function. Wire the Maximum Value output of the Unbundle By Name function to the f input of the Select function.
q. r. s. t. u. v.
w. Wire the s?t:f output of the Select function to the element 1 input of the Bundle function. x. 7. 8. Wire the output cluster output of the Bundle function to the Range input of the IMAQ Threshold VI.
Select FileSave to save the User Programming VI. Select FileClose to close the User Programming VI.
The User Programming VI uses the VBAI SDK Get Result VI to verify that the GUID for the measurement specified by the user contains a valid numeric value. If the GUID contains a valid numeric value, the User Programming VI performs the image threshold using the measurement
5-18
ni.com
Chapter 5
value stored in the GUID. If the GUID does not contain a valid numeric value, the User Programming VI uses the value of the corresponding constant.
Launch LabVIEW.
You must configure LabVIEW before debugging a custom step. Refer to the Configuring LabVIEW to Debug Custom Steps section of Chapter 3, Creating a Custom Image Processing Step, for more information about configuring LabVIEW. 2. Select ToolsVision Builder AITest Your Custom Step in Vision Builder AI to launch Vision Builder AI and test the step.
Note
You must open Vision Builder AI from LabVIEW to test a custom step that has not been saved for distribution. Refer to the Distributing The Custom Step section of Chapter 3, Creating a Custom Image Processing Step, for information about saving custom steps for use with the Vision Builder AI executable. 3. 4. Open the Vision Builder AI Configuration interface. Add a Simulate Acquisition step to the acquisition. Because the Manual Threshold Previous Measurements custom step operates on an image, you must acquire an image to test the custom step. Add a Calculator step to the acquisition. You will use result measurements from the Calculator step to test whether the Manual Threshold Previous Measurements custom step correctly handles previous measurements. Complete the following steps to configure the Calculator step: a. The calculator setup wizard launches when you add a Calculator step to the inspection. In the calculator setup wizard, click Next twice so that the Output Results list appears. Click Add New Output Result. Enter Minimum Value as the Name for the output result. Click Add New Output Result. Enter Maximum Value as the Name for the output result. Click Finish. Click Show Functions Palette.
5.
b. c. d. e. f. g.
5-19
Chapter 5
h. i. j. 6.
Wire a Boolean constant to the Step Result indicator. Wire a numeric constant to the Minimum Value indicator. Enter 30 as the value for the numeric constant. Wire a numeric constant to the Maximum Value indicator. Enter 120 as the value for the numeric constant.
Add the Manual Threshold Previous Results custom step to the inspection. By default, custom steps are located on the Use Additional Tools palette. If you did not modify the custom step icon, the custom step displays the default custom step icon.
7.
When you open the custom step, Vision Builder AI operates in debugging mode. The front panel of the User Interface VI for the custom step opens in LabVIEW. The front panel of the User Interface VI may open behind the Vision Builder AI window. Open the User Interface VI by clicking the VI window in the taskbar. Select the Settings tab. Select Calculator 1 - Minimum Value from the Minimum Value Source list.
8. 9.
10. Select Calculator 1 - Maximum Value from the Maximum Value Source list. The main window displays the output image from the Manual Threshold Previous Measurements custom step, which reflects the threshold range specified by the previous measurements from the Calculator step. 11. Click OK. 12. Double-click the Calculator step in the inspection to edit it. 13. Enter 50 as the value of the numeric constant wired to the Minimum Value indicator. 14. Enter 100 as the value of the numeric constant wired to the Maximum Value indicator. 15. Click OK.
5-20
ni.com
Chapter 5
16. Select the Manual Threshold Previous Measurements step in the inspection. The main window displays the output image from the Manual Threshold Previous Measurements custom step, which reflects the threshold range specified by the modified previous measurements from the Calculator step. 17. When you are satisfied with the performance of the step, save the step for distribution. Refer to the Distributing The Custom Step section of Chapter 3, Creating a Custom Image Processing Step, for more information about saving custom steps for distribution.
5-21
This section contains detailed descriptions of the controls and indicators that appear in the source code VIs of a custom step.
Element Local Name Description Version Tab Location Region Use in Product Select Context Help
Description Name of the step as it appears in Vision Builder AI. Descriptive text that appears next to the custom step in the Vision Builder AI tools palette. String to help keep track of the custom step version. To check the version, the developer must read the variable. Tab of the Vision Builder AI Inspection Tools palette where the custom step is located. Region where the user interface for the custom step appears. Specifies whether the custom step is available in the Product Select state. File path to a custom compiled HTML help file. Refer to Appendix B, Creating Documentation for the Custom Step, for information about creating help for the custom step. Available ROI tools. A green LED indicates that the tool appears in the toolbar. A red LED indicates that the tool does not appear in the toolbar. Display name for each of the available ROI tools. This element is useful if you need to localize ROI tool names. Default ROI tool for the custom step.
ROI Tools and Image Support Localized ROI Tool Name Default Tool
A-1
Appendix A
Description Show/hide previously created ROIs in the Region of Interest control on the User Interface VI front panel. Image types supported by the custom step. A green LED indicates that the image type is supported by the step. A red LED indicates that the image type is not supported. An error will occur if the user attempts to apply the step to an unsupported image type. The Supported Image Types control does not appear in the Simulate Acquisition Step.
Note
When you modify the controls and indicators in the Init Globals VI, you must make the new values the default for the control or indicator and save the changes. To make the current values the default for a control or indicator, select EditMake Current Values Default, and save the VI.
A-2
ni.com
Appendix A
Edit Mode
ROI Event
A-3
Appendix A
A-4
ni.com
Appendix A
Table A-3 lists the indicators that return data from the User Interface VI.
Table A-3. User Interface VI Indicators
Description Name the user entered for the step. Variant that contains the parameters of the step. If the step requires more than one parameter, bundle the parameters in a cluster, and use the To Variant VI to package the parameters in the variant. Pass/fail conditions of the custom step. The constant ROI to be saved. If a programmable ROI was selected, the ROI will be saved automatically.
A-5
Appendix A
Controls Image
Description Processed image from the previous step in the inspection. Tip: This control is used only in Execution mode.
Unique ID provided from the Vision Builder AI engine. Parameters the user sets in the XXXX - User Interface VI. Use the Variant To Data VI to extract the values stored in this variant. The mode of the VI. The constant ROI to be saved. The array contains the following elements: Global RectangleContains the coordinates of the bounding rectangle. ContoursEach of the individual shapes that define an ROI.
A-6
ni.com
Appendix A
Table A-5 lists the indicators that return data from the User Programming VI.
Table A-5. User Programming VI Indicators
Description Processed image to be provided to the next step in the script. If you are not processing the image, you must still connect Image In to Image Out to ensure that the other steps in the script receive the image. The Image Out control is used only in Execution mode. Measurements created by the step, which can be passed to subsequent steps. The Measurements control is used only in Execution mode. This cluster contains the following elements: ValueFlattened string of the Measurements value. You can store measurements only in the following three LabVIEW data types: double, Boolean, and string. If you choose a double, Value must be the flattened string of a double. If you choose Pass Fail or Boolean for the Type element, Value must be the flattened string of a Boolean. If you choose ID or String in the Type element, Value must be the flattened string of a LabVIEW string. Use the Flatten to String VI to flatten your chosen value type to a string. TypeData type of the data. NameMeasurement name. UnitMeasurement unit.
Measurements
Pass/Fail Data
Pass/fail data that the Decision Maker VI uses to make the pass/fail decision for the step. The Pass/Fail Data control is used only in Execution mode. The Pass/Fail Data array must contain the same number of elements as the Pass/Fail Conditions out indicator on the user interface. The Decision Maker VI applies the pass/fail condition information from the user interface to the pass/fail condition information of the XXXX - User Programming VI. Pass/Fail DataNumber that the Decision Maker VI compares to the pass/fail condition information from the user interface. The Vision Builder AI engine compares the Pass/Fail Data number to Value 1 and Value 2 of the Pass/Fail Condition out cluster of the XXXX - User Interface VI. The engine bases this comparison on the function specified in Pass/Fail Condition out. Fail StringStrings that are displayed in the script window of the user interface when a step fails.
A-7
Appendix A
Description/Data Type Flattened string of a double, Boolean, or string. To create this parameter, use the Flatten to String VI to flatten the data to a string. One of the following predefined Vision Builder AI types: Pass FailDo not use. X Position (Pix)Use this double to log an x-coordinate point. Y Position (Pix)Use this double to log a y-coordinate point. X Position (World)Do not use. Vision Builder AI automatically creates the Real World coordinates of points if the image is calibrated. Y Position (World)Do not use. Vision Builder AI automatically creates the Real World coordinates of points if the image is calibrated. ScoreDouble Distance (Pix)Double Distance (World)Double AngleDouble StraightnessDouble Radius (Pix)Double Radius (World)Double RoundnessDouble Average IntensityDouble Std Dev IntensityDouble Minimum IntensityDouble Maximum IntensityDouble # of HolesDouble BooleanBoolean NumericDouble StringString Area (Pix)Double Area (World)Double Percentage of AreaDouble IDString # of MatchesDouble # of ObjectsDouble # of EdgesDouble OrientationDouble Aspect RatioDouble
A-8
ni.com
You may want to provide documentation for the custom step so that the users can access information about how to use the step. To add HTML documentation for the custom step, you must create HTML documentation for the custom step, then compile your HTML documentation into a help file and modify the Init Globals VI to call the help file for the custom step.
B-1
Appendix B
For information about creating compiled HTML help, refer to Help for HTML Help, which is available from the Help menu in HTML Help Workshop.
B-2
ni.com
Appendix B
If you add at least one file to the Context Help array, make sure all three elements of the array are populated, duplicating the file name if necessary. If you add a file name to one element and leave one or more of the remaining elements blank, Vision Builder AI displays an error indicating that a page was not found for the tabs that are represented by the blank elements. For example, if you created an HTML file that covers configuring the custom step and you add that file name to the first element in Context Help but leave the other two elements blank, the Control Descriptions and FAQs tabs in Vision Builder AI display an error indicating a page was not found for the custom step. 6. 7. 8. 9. Select EditMake Current Values Default. Save and close the VI. Select ToolsVision Builder AITest Your Custom Step in Vision Builder AI. Navigate to the appropriate tab and click the custom step to view the newly added documentation.
B-3
Visit the following sections of the award-winning National Instruments Web site at ni.com for technical support and professional services: SupportTechnical support at ni.com/support includes the following resources: Self-Help Technical ResourcesFor answers and solutions, visit ni.com/support for software drivers and updates, a searchable KnowledgeBase, product manuals, step-by-step troubleshooting wizards, thousands of example programs, tutorials, application notes, instrument drivers, and so on. Registered users also receive access to the NI Discussion Forums at ni.com/forums. NI Applications Engineers make sure every question submitted online receives an answer. Standard Service Program MembershipThis program entitles members to direct access to NI Applications Engineers via phone and email for one-to-one technical support as well as exclusive access to on demand training modules via the Services Resource Center. NI offers complementary membership for a full year after purchase, after which you may renew to continue your benefits. For information about other technical support options in your area, visit ni.com/services, or contact your local office at ni.com/contact. Training and CertificationVisit ni.com/training for self-paced training, eLearning virtual classrooms, interactive CDs, and Certification program information. You also can register for instructor-led, hands-on courses at locations around the world. System IntegrationIf you have time constraints, limited in-house technical resources, or other project challenges, National Instruments Alliance Partner members can help. To learn more, call your local NI office or visit ni.com/alliance.
C-1
Appendix C
If you searched ni.com and could not find the answers you need, contact your local office or NI corporate headquarters. Phone numbers for our worldwide offices are listed at the front of this manual. You also can visit the Worldwide Offices section of ni.com/niglobal to access the branch office Web sites, which provide up-to-date contact information, support phone numbers, email addresses, and current events.
C-2
ni.com