Using Shared Variables on the NI Smart Camera in Vision Builder AI

Overview

Vision Builder AI is a configurable environment for machine vision allowing for image acquisition, processing, and results reporting all in a no-programming environment. As of version 3.5, shared variables are supported in Vision Builder AI, and allow for the communication with other pieces of hardware on the NI platform.

This tutorial will cover setting up shared variables between the NI Smart Camera and NI CompactRIO. These instructions will work for any setup involving a vision target running Vision Builder AI and a separate LabVIEW Real-Time target including cRIO, Compact Fieldpoint, and PC/PXI based systems.

Contents

Ethernet Connections

As stated above, we will connect the primary ports of both devices to a hub, switch, or router (depending on what you have available) to allow for communication to the development PC which should also be connected to this hub, switch, or router. 

Vision Builder AI - Host or Client?

The next thing to do is decide which piece of hardware (the Smart Camera or the CompactRIO) will be the host. Below we will cover both options. First we will discuss the Smart Camera (or any hardware device configured with Vision Builder AI) being the client and the other piece of hardware targeted by LabVIEW RT (in this case the NI cRIO-9074) being the host. In this case, the shared variable library will exist on the CompactRIO, and be accessed by the smart camera. The second setup will swap the host and client, and this document will discuss hosting shared variables within Vision Builder AI on a real-time host.


Option 1 - Using the Smart Camera as a Shared Variable Client

In this setup we'll use the NI CompactRIO as the shared variable host. We'll be running a LabVIEW project containing the shared variables hosted on the NI CompactRIO, and using Vision Builder AI running on the NI Smart Camera as a client for those shared variables.


A) Setting up the CompactRIO

The first step in hosting the shared variables on the CompactRIO is to create a new LabVIEW project. Add the CompactRIO to your project. 

Once this is done, you can set up your shared variables on the CompactRIO. The following document will walk you through this.

Using the LabVIEW Shared Variable

You should now have shared variables hosted on the CompactRIO that we can interact with from the NI Smart Camera. Three things to keep in mind are the IP address of your cRIO, the library name for the variables, and the variable name.

 

B) Setting up the Smart Camera

Shared variables are called two different things in Vision Builder AI, depending on where they are hosted. System Variables are hosted on the Vision Builder AI target. Network Variables are hosted on a separate target (in this case, the CompactRIO). 

In Vision Builder AI, you will want to first create an inspection (or open one of the included example inspections). For help with this, please view the NI Vision Builder for Automated Inspection Tutorial. This should get you through acquiring an image and doing some processing on it.

In the Additional Tools palette, there is a Set Variable step. This step is used for setting up variables for local use (called Inspection Variables), or the two types of shared variables discussed above. In this case, we'll be adding a new Network Variable. This variable can be found by selecting the browse button indicated below, and navigating to the shared variable hosted on the CompactRIO (this is where the IP address and variable name come in handy).

 

 

Option 2 - Hosting the Shared Variables on the Smart Camera

In this setup we'll use the NI CompactRIO as the shared variable client. We'll be running a LabVIEW project containing the shared variables hosted on the NI Smart Camera, and using Vision Builder AI running on the NI Smart Camera as a host for those shared variables (called System Variables in Vision Builder AI).


A) Setting up the Smart Camera

In Vision Builder AI, you still want to create an inspection first (or open one of the included example inspections). For help with this, please view the NI Vision Builder for Automated Inspection Tutorial, just like above. The inspection steps shouldn't differ, except for the Set Variable step.

In the Additional Tools palette, there is a Set Variable step. This step is used for setting up variables for local use (called Inspection Variables), or the two types of shared variables discussed above. In this case, we'll be adding a new System Variable. You can share anything from a diameter of an object you measured to a code read off of a part moving down a production line. 

The two bits of information you'll want to keep in mind are the IP address of the NI Smart camera, and the variable name you're going to target.


B) Setting up the CompactRIO

The first step in receiving the shared variables on the CompactRIO is to create a new LabVIEW project. Add the CompactRIO to your project. 

Once this is done, you can set up your LabVIEW project on the CompactRIO so that it's a client for the shared variables hosted on the NI Smart Camera. The following document will walk you through this.

Using the LabVIEW Shared Variable

You should be able to target the shared variables hosted on the NI Smart Camera just by browsing through the directory that has the IP address assigned to the camera.

Once these are set up, they can be read from and written to from anywhere in your LabVIEW application. 


Conclusion

As shown in this document, getting communication set up between a Vision Builder AI inspection and a LabVIEW project running on separate targets is an easy task that greatly simplifies integration of machine vision into any control or measurement application. Now, machine vision applications can be configured in Vision Builder AI, and only the pertinent data from the inspection can be sent across the network to other targets. This saves network bandwidth, cost of development, and makes trouble-shooting problems much quicker and easier.