Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual...

28
Introducon to LabVIEW

Transcript of Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual...

Page 1: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Introduction to LabVIEW

Page 2: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

LabVIEW

• LabVIEW – Laboratory Virtual Instrument Engineering Workbench

• Graphical programming language that allows for instrument control, data acquisition, and pre/post processing of acquired data

LabVIEW works on a data flow model in which information within a LabVIEW program, called a virtual instrument (VI), flows from data sources to data sinks connected by wires. The data can be modified as it is passed from source to sink by other VIs. VIs consist of both a graphical user interface called the front panel and a code pipeline called the block diagram. These VIs tend to be much more complex considering that they can contain any number of internal or user created VIs.

Page 3: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Virtual instruments - cont.Consider a simplistic LabVIEW program which takes a single number from the user and multiplies it by 10. Analyzing such a program reveals the following data flow structure:

1. The user inputs a number (data source).

2. The program executes an addition VI taking the user's number and the number 10 as its inputs (data sink).

3. The addition VI returns the result of the addition operation (data source).

4. The result is displayed on the screen (data sink).

While this example is simplistic, it exemplifies how all LabVIEW VIs work. Data always flows from data sources to data sinks according to the block diagram, much like how water flows through a pipe.

Page 4: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

A VI has three main parts:

• The front panel: an interactive user interface of a VI, so named because it can simulates the front panel of a physical instrument.

• The block (or wiring) diagram: It is the VI’s source code, constructed in LabVIEW’s graphical programming language, It is the actual executable program.

• Icon/connector

Page 5: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Front Panel

Every user created VI has a front panel that contains the graphical interface with which a user interacts. The front panel can house various graphical objects ranging from simple buttons to complex graphs.

Various options are available for changing the look and feel of the objects on the front panel to match the needs of any application.

Page 6: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Block diagramNearly every VI has a block diagram containing some kind of program logic that serves to modify data as it flows from sources to sinks. The block diagram houses a pipeline structure of sources, sinks, VIs, and structures wired together in order to define this program logic. Most importantly, every data source and sink from the front panel has its analog source and sink on the block diagram.

This representation allows the input values from the user to be accessed from the block diagram. Likewise, new output values can be shown on the front panel by code executed in the block diagram.

Page 7: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

ControlsThe most common form of a data source in LabVIEW is a control. This element appears as some type of graphical element on the front panel of a VI that can receive input from a user or even another VI. As stated previously, any data source also has an analog symbol that appears on the block diagram so that its value can be read and used in the code pipeline. Controls make no exception to this rule.

Every control has an associated data type that determines what kind of data flows from it on the block diagram. Every data type also has an associated color shown on the block diagram.

Typical controls and their associated data types. In general, any control can be turned into an indicator and vice-versa.

Page 8: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Data typesDifferent data types are indicated with different colors.

• Floating point numbers (decimal numbers) are shown in orange color. The letters DBL on the icon is for double, which refers to floating point numbers with double precision, which expresses the numerical accuracy of the internal representation of the number in the computer. You can think of floating point numbers as decimal numbers.

• Integers are shown in blue color. One example is a numeric constant.

• Boolean data are shown in green color. The letters TF on the icon is for True/False, which are the two possible boolean (logical) values of the element. One example is the Stop terminal.

• Textual data are shown in pink color.

• Cluster data are shown in brown color. Clusters are multivariables. They contain one or more elements of possibly different data types.

Page 9: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

IndicatorsThe most common form of a data sink in LabVIEW is an indicator. This element appears as some type of graphical element on the front panel of a VI that can display output to a user or even another VI. As stated previously, any data sink in LabVIEW also has an analog symbol that appears on the block diagram so that its value can be updated in the code pipeline. Indicators make no exception to this rule.

Every indicator also has an associated data type that determines what kind of data can be written to it on the block diagram.

Typical indicators and their associated data types. In general, any control can be turned into an indicator and vice-versa.

The front panel and block diagram for the simple number plus ten example. It should be noted that the number control and answer indicator have their similarly named analogs on the block diagram.

Page 10: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

PalettesFront panel controls and indicators as well as block diagram VIs are available from a palettes visible depending on what window is currently active in the LabVIEW environment. These palettes have their contents separated into sub-categories containing controls, indicators, and VIs.

Typical top-level block diagram and front panel palettes.

Page 11: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

StructuresIn addition to controls, indicators, and VIs, the block diagram can also contain a number of programming structures that modify the sequence of data flow on the block diagram. These structures perform traditional functions like looping or case-selection, but many also provide services that have no clear counterparts in text based programming languages. LabVIEW currently supports six different structures -- while-loops, case structures, event structures, for-loops, sequence structures, and formula nodes.

Page 12: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

While-loopsOne of the most common structures encountered on a block diagram is the while-loop. Much like in text-based languages, the LabVIEW while-loop continually executes until a given boolean condition is met. Unlike in text-based languages, the LabVIEW while-loop contains its own loop counter that provides the current loop iteration starting at zero.

Three different ways of using a while-loop. The first loop continues forever because the loop conditional never becomes false. The second loop continues until a button on the front panel is pressed, sending a value of true to the loop conditional thereby stopping the loop. The third loop also continues forever, but also displays the current loop counter value in an indicator on the front panel. (It is important to note that these three loops will execute in parallel because their inputs are not dependent on each other.)

Page 13: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

While-loops - contThe while-loop is typically used in LabVIEW to continue some operation until either the user or some code event indicates that the operation should stop. Normally, some kind of millisecond delay is also inserted into the loop so that it doesn't occupy all of the computer's CPU time.

A while-loop that will stop when the loop iterator passes 1000 or when the user presses the stop button. A loop delay is also used to ensure that the loop operation doesn't occupy all of the CPU time.

Page 14: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

While-loops - contNearly all structures in LabVIEW, including while-loops, can have inputs and outputs. Wires that pass into and out of while-loops form small connection points called tunnels on the structure. Various, powerful options are available for shaping data flowing through tunnels, ie. shift registers.

Input and output loop tunnels. The while loops takes a numeric value through an input tunnel and multiplies it times its current iteration value. When the loop is stopped, the value of the last multiplication is passed through an output tunnel and displayed in another indicator.

Page 15: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Case structuresAnother common structure encountered in LabVIEW is the case structure. Like in text-based languages, the case structure executes a block of code based on the value of a certain variable. In LabVIEW, a case selector located on the case structure is wired to a data source. The value fed into the case selector determines what case executes. Only one case is shown at a time, but the visible case can be cycled by clicking on the arrows to the left or the right of the case name.

The use of a case structure as a simple Boolean if-statement. If the two numbers entered by the user add to zero, then a string message is displayed on the front panel saying so. If the two numbers do not add to zero, then a string message is displayed stating that they do not. The false case of the case structure is not shown.

Page 16: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

For-loopsAnother common looping structure encountered on a block diagram is the for-loop. Much like in text-based languages, the LabVIEW for-loop continually executes until a given count is reached. Unlike in text-based languages, the LabVIEW for-loop can only step towards the final count by increasing the loop counter by one each iteration. To make larger steps or to step in the negative direction, while-loops with shift registers must be used.

For-loop counter. The loop runs from zero to ninety-nine and increases the loop counter by one each iteration.

Page 17: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Formula NodesA Formula Node is a box where you enter algebraic formulas directly into the Block Diagram. It is useful when an equation is complicated or has many variables. Below is an example of how you would implement y = x^2 + x + 1 with regular block diagram nodes:

It is much easier to use the Formula Node. Below is an example:

Page 18: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

ClustersCluster data types are somewhat unique to LabVIEW and act as containers capable of storing a number of variables of different data types. In the simplest sense, clusters can be thought of as a group of data values that are bundled together to form a more complex, and often more meaningful, data type. From an object oriented perspective, clusters can be thought of as primitive objects with a number of properties without any methods to acts on them.

A cluster with a number of elements. This cluster can be thought of representing a set of properties of a college course that can flow as a single object through the wires on the block diagram.

Page 19: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Clusters - contA number of operations exist for clusters, the most important of which are the bundling and unbundling operations. Individual pieces of data flowing through different wires can be bundled together to form a cluster that flows through a single wire. Likewise, a cluster flowing through a single wire can be unbundled so that its elements can flow through their own wires.

Cluster bundling and unbundling. The person cluster is unbundled to reveal its elements so that the age element can be increased by one. The data is then bundled again to create a new cluster with the updated values. Notice that the cluster elements are given by name here.

Page 20: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Clusters - contClustering is commonly used for two purposes. First, clusters help to logically group related data values together, thus supporting the object oriented idea of encapsulation. Second, clusters help to minimize the number of wires on the block diagram that flow into VIs. If clusters did not exist, VIs with cluster inputs would have to receive all of their data through separate wires leading to drastic decreases in readability.

Page 21: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

• Advanced VIs:– Motion

– Vision

Page 22: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

NI 7358 Motion controller

• The NI 7358 controller is a combination of servo and stepper motor controller for PXI, Compact PCI, and PCI bus computers.

• Fully-programmable motion control for up to eight independent axes of motion.

• Coordinated motion is supported through multi-dimensional coordinate spaces.

• Each axis provides dedicated motion I/O for limit and home switches and additional I/O for general-purpose functions.

• The external motion and digital I/O connectors on the NI 7358 controller are high-density, 68-pin female VHDCI connectors.

Page 23: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

NI UMI -7774

• NI UMI -7774 is a 4-Axis Universal Motion Interface as seen in Figure

Page 24: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

MID-7604 Power Drive

• MID-7604 stepper and servo motor power drives provide reliable, easy-to-connect drive solutions for all NI motion controllers as seen in Figure I.2.

• 4-axis stepper power drive, 1.4 A per axis

• Host PC bus power monitoring/shutdown

• Power supply, driver, heat sink, and cooling

Page 25: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

LabVIEW based Control Scheme

25

Motor Control Hardware Configuration

Four Stepper Motors (X, Y, Z and Tool feed) in ECSMM Set-up

Motion Controller

Universal Motion Interface

Integrated Stepper Driver

Snap shot of ‘Soft’ control panelSnapshot of control program lay out

•Table Speed (TS),•Tool Feed,• and Direction

Page 26: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

LabVIEW based Control Station

26

NI 7604 Driver Board

Power Supply for Control Circuit

Power SupplyFor Motors

Snapshot of the display of contoured machining path followed by the x-y stage

Page 27: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

Block diagram of experimental set-up

LabVIEW : Acronym for Laboratory Virtual Instrumentation Engineering Workbench

NI UMI 7774 is a 4-Axis Universal Motion Interface. MID 7604 motor power drive

27

Page 28: Introduction to LabVIEW · Introduction to LabVIEW. LabVIEW • LabVIEW – Laboratory Virtual Instrument Engineering Workbench • Graphical programming language that allows for

• Reference: ni.com