labview - ide20.comide20.com/upload/modulelv/lesson02.pdf · labview lesson 2 pre-reqs/technical...

9
1 LabVIEW Lesson 2 Pre-reqs/Technical Skills Basic computer use Expectations Read lesson material Implement steps in software while reading through lesson material Complete quiz on Blackboard Submit completed assignment on Blackboard Attend help sessions as necessary Post comments on lesson web page Objectives/Measurables Learn basics of using LabVIEW, measured via Blackboard quiz score Lecture Topics Getting Started Basic Inserting Figures/Tables/Equations Assignment Table of Contents LabVIEW ........................................................................................................................................... 1 Lesson 1 ....................................................................................................................................................................................................... 1 Pre-reqs/Technical Skills ........................................................................................................................................................................... 1 Expectations..................................................................................................................................................................................................... 1 Objectives/Measurables ............................................................................................................................................................................. 1 Lecture Topics ................................................................................................................................................................................................. 1 Introduction............................................................................................................................................................................................... 1 Arrays ........................................................................................................................................................................................................... 2 Creating Arrays .............................................................................................................................................................................................. 2 Array Functions .............................................................................................................................................................................................. 3 Clusters ........................................................................................................................................................................................................ 4 Clusters vs. Arrays ......................................................................................................................................................................................... 5 Enumeration .............................................................................................................................................................................................. 5 Documentation ......................................................................................................................................................................................... 5 Creating Custom Controls .......................................................................................................................................................................... 6 Assignment ....................................................................................................................................... 8 Introduction Arrays group data elements of the same type. An array consists of elements and dimensions. Elements are the data that make up the array. A dimension is the length, height, or depth of an array. An array in LabVIEW can have one or more dimensions and as many as (2^31) 1 elements per dimension, memory permitting.

Upload: vuongdan

Post on 05-May-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

1

LabVIEW

Lesson 2

Pre-reqs/Technical Skills Basic computer use

Expectations Read lesson material

Implement steps in software while reading through lesson material

Complete quiz on Blackboard

Submit completed assignment on Blackboard

Attend help sessions as necessary

Post comments on lesson web page

Objectives/Measurables Learn basics of using LabVIEW, measured via Blackboard quiz score

Lecture Topics Getting Started

Basic

Inserting Figures/Tables/Equations

Assignment

Table of Contents

LabVIEW ........................................................................................................................................... 1 Lesson 1 ....................................................................................................................................................................................................... 1

Pre-reqs/Technical Skills ........................................................................................................................................................................... 1 Expectations ..................................................................................................................................................................................................... 1 Objectives/Measurables ............................................................................................................................................................................. 1 Lecture Topics ................................................................................................................................................................................................. 1

Introduction ............................................................................................................................................................................................... 1 Arrays ........................................................................................................................................................................................................... 2

Creating Arrays .............................................................................................................................................................................................. 2 Array Functions .............................................................................................................................................................................................. 3

Clusters ........................................................................................................................................................................................................ 4 Clusters vs. Arrays ......................................................................................................................................................................................... 5

Enumeration .............................................................................................................................................................................................. 5 Documentation ......................................................................................................................................................................................... 5

Creating Custom Controls .......................................................................................................................................................................... 6

Assignment ....................................................................................................................................... 8

Introduction Arrays group data elements of the same type. An array consists of elements and dimensions. Elements are the data that make up the array. A dimension is the length, height, or depth of an array. An array in LabVIEW can have one or more dimensions and as many as (2^31) – 1 elements per dimension, memory permitting.

2

Clusters group data elements of mixed types. Often the objects have a relationship with one another

from the perspective of the user or programmer (such as the student’s name [string], age [numeric],

and graduation status [boolean]).

An enum (short for enumeration) is a data type that pairs a number with a string (ie, months of the

year with the number 0-11). It appears as a string to you, and a number to computer.

The list of pairings is maintained as part of the data type (this is important when it comes to type

definitions and is different from a ring, which looks similar).

Arrays

Creating Arrays To create an array control or indicator, select an array on the Controls»Modern»Array, Matrix, and

Cluster palette, place it on the front panel, and drag a control or indicator into the array shell. If you

attempt to drag an invalid control or indicator such as an XY graph into the array shell, you are unable

to drop the control or indicator in the array shell. Once a valid item is placed in the array shell, the

array shell shrinks to fit around the control or indicator. Then drag the edge of the array to display

more elements.

Array shells are available on the front panel and block diagram, but you must insert an object in the

array shell before you use the array on the block diagram. Otherwise, the array terminal appears black

with an empty bracket.

Figure 1: Creating an Array

To add dimensions to an array one at a time, right-click the index display and select Add Dimension from the shortcut menu. You also can use the Positioning tool to resize the index display until you have as many dimensions as you want, hover over the bottom index and pull it down to add another dimension.

Figure 2: Index and Initialized Arrays

3

The index display tells you the index (location) of the element that is currently displayed in the box in

the upper right-hand corner of the array. Imagine the border of the array like a window into a giant

speadsheet of numbers, where the spreadsheet can slide around behind the window. The index will

tell you how much the spread sheet has slid around from its home position, where the window shows

the top left corner of the spreadsheet values. Therefore, the 1D array is hiding index 0 and possibly

other values at index 3 or more.

The index is zero-based, meaning it begins it counting with zero.

Uninitialized arrays will have a gray background and grayed-out numbers. If you have a value at index

1,1 in an array (which would be a 2x2 array), then column 3 will be uninitialized and all columns less

than 3 (0,1,2) must be initialized . Keep in mind an array is defined to be a 2x2 by the number of

rows/columns that are initialized, not just the number of columns and rows being displayed through

the “array window”.

Figure 3: Array Size and Dimension

To determine the size of a 1D array, count the number of initialized elements

To determine the size of a 2D array, count the number of initialized elements in a row and the number

of initialized elements in a column.

Array Functions There are many array functions; however, Figure 4 shows the ones that are often used. Use Context

Help to understand the different functions in the array palette.

4

Figure 4: Functions Palette and Description of a few functions

Clusters Clusters are created in a similar fashion to arrays: place a shell, then add object into the shell. Try

creating a cluster with different elements and data types inside the shell.

The terms bundle and cluster are closely related in LabVIEW.

Example: You use a bundle function to create a cluster. You use an unbundle function to extract the

parts of a cluster.

Bundle - Forms a cluster containing the given objects in the specified order.

Bundle by Name - Updates input cluster’s element values (the object must have an owned label).

*requires input cluster*

Unbundle - Splits a cluster into each of its individual elements by data type.

Unbundle by Name - Returns the cluster elements whose names you specify.

Two major difference between Unbundle/Bundle and Unbundle By Name/Bundle By Name: (1) “By

Name” = label of elements visible (not just the data type. (2) Bundle By Name requires an input cluster

and updates, instead of creating a new cluster.

Bundle functions can be found in the Block Diagram, Functions>>Programing>>Cluster, Class, Variant.

Figure 5: Clusters and Bundles in the Block Diagram

Array Size: Returns the number of elements in each dimension of the array Index Array: Returns the value at the index you specify Initialize Array: Creates an initialized array of the dimension and data type you specify Build Array: Adds elements or dimensions to an array Search 1D Array: Returns the index of the value you specify; if not found, returns -1

5

Clusters vs. Arrays Clusters differ from arrays in that they are a fixed size

Clusters can contain mixed data types; arrays contain only one data type

Like an array, a cluster is either a control or an indicator and cannot contain a mixture of controls and

indicators

You can create a cluster of clusters, cluster of arrays, array of clusters, but NOT an array of arrays

Enumeration

Add an enum to your front panel, Controls>>Modern>>Ring & Enum.

To configure the enum by adding elements, right-click and select Edit Items… to bring up the Enum

Properties window in which you can add/delete/move items on the list

Figure 6: Enum Properties

Add all the months into your enum items. Notice that the digital display starts at zero not one.

Documentation

Figure 7: Front Panel Documentation

6

Caption: Front panel objects also can have captions. You can use captions instead of labels to localize a

VI without breaking the VI. Unlike a label, a caption does not affect the name of the object, and you

can use it as a more descriptive object label. The caption appears only in the front panel window.

If you assign the object to a connector pane terminal, the caption appears in a tip strip when you use

the Wiring tool to move the cursor over the terminal on the block diagram. The caption also appears

next to the terminal in the Context Help window if you move the cursor over the connector pane or VI

icon.

Descriptions of VIs and controls, indicators, and constants appear in the Context Help Window when

your cursor hovers over them.

A VI description is added by editing the VI Properties: Description field. You can get to VI Properties

through the File» VI Properties or by right-clicking on the VI icon and selecting VI Properties (in the

upper-right corner; not a subVI icon). A VI Properties window will appear like top image in this slide.

Select Documentation from the drop-down menu and enter your description.

A description for a control, indicator, or constant is created by right-clicking on the object and selecting

Properties from the short-cut menu. Click on the Documentation tab and enter the description. The

tip strip field is available here as well. Tip strips are short messages to help a user by popping up when

the cursor is over the object and the VI is running.

Figure 8: VI Properties window and Numeric Properties window

Block Diagram Comments, double click on a blank space to add text:

• Use to document algorithms that you use and add reference information

• Label structures to specify the main functionality

• Label long wires to identify their use/contents (right click on the wire Visible Items >> Label)

• Label constants to specify the nature of the constant

Creating Custom Controls In order to create a custom control or type def, you must right-click on an object on the FRONT PANEL.

Then go to Advanced >> Customize… to pull up the Control Editor window. In the Control Editor

Window you can add/remove things from a cluster, edit the items listed in an enum, change the color

of an LED, move increment/decrement arrows to the top/bottom of digital display instead of to the

side, and much more!

7

The tweezer button next to the drop-down takes you to low level editing where you can pull apart the

layers that create the object (ie, shadow, foreground, background, etc)

Figure 9: Front Panel right click and Control Editor Window

When you are ready to save your customization, you have three options, which are displayed in the

drop down box on the toolbar:

- Custom Control

- Type Definition

- Strict Type Definition

All 3 options create a *.ctl file, but behave differently. Depending on the option you choose, the file

created will typically be referred to as that option. For example, if you save as a type definition, it is

common to refer to that file as a type definition (or type def, for short).

Figure 11: drop down toolbar

8

Assignment Instructions: Please complete the following in one VI. Refer to the Front Panel screen shot in Figure 12 for

further guidance. Do not worry about small details such as labels, etc. Your VI does not have to be the same as

the screen shot.

If you have questions, please post comments on the homework on your university’s LabVIEW Workshop

website.

Part I: Arrays (5 points)

In Part One, the following array functions must all be used:

- Index Array

- Initialize Array

- Build Array

- Search 1D Array

1. Create a two-dimensional array of Booleans on the Front Panel. Create two numeric controls which

allow the user to select an element by entering a row and column. Display the chosen element using an

LED.

2. Using numeric controls A, B, and C, programmatically create a one-dimensional array with 5 elements.

The elements should be A, A, A, B, C.

3. Create a string control and a numeric indicator on the Front Panel. Allow the user to enter a color. The

numeric indicator should display the order of that color in the rainbow. The order of the rainbow is Red,

Orange, Yellow, Green, Blue, Indigo, Violet. For example, if the user types Yellow, the numeric indicator

should display 2.

Part II: Enums (2 points)

4. Create an enum with three items. Display the number which corresponds to the user’s selection in a

numeric indicator.

Part III: Clusters (3 points)

5. Create a cluster that displays the indicators from problems 1, 2, and 4 (an LED, an array, and a numeric

indicator). Hint: make sure that the order of the indicators in the cluster corresponds with the order of

the bundle function.

6. Create a cluster of a string, boolean, and numeric controls. Create indicators that display the user’s

inputs to the Boolean and numeric controls of the cluster.

9

Figure 12: Assignment Front Panel