LabVIEW 2009

111
1 ECE 595K/ECE 495A LabVIEW Credits: 3(Class 2, Lab 3) Prerequisite: ECE 595K Graduate Standing ECE 495A Junior or Senior Standing Richard Gonzales Ofc P323, Ofc hrs: I am at PU all day TU & TR in my Ofc or a Lab Email: [email protected] Course Description: Theory and application of the graphical programming language LabVIEW in Data Acquisition, Control, Design, Analysis, Synthesis, Simulation, Instrumentation, and Engineering Problem Solutions: LabVIEW will also be used as a general purpose language to dot asks that have traditionally been done by languages such as C, MATLAB, SIMULINK, and EXCEL. Lab 3 hrs per week, Lecture 2 hrs per week Tu & Th 11:00 to 1:20 in P308..

Transcript of LabVIEW 2009

Page 1: LabVIEW 2009

11

ECE 595K/ECE 495A  LabVIEWCredits: 3(Class 2, Lab 3)Prerequisite:  ECE 595K Graduate Standing ECE 495A Junior or Senior Standing

Richard GonzalesOfc P323, Ofc hrs: I am at PU all day TU & TR in my Ofc or a Lab Email: [email protected]

Course Description: Theory and application of the graphicalprogramming language LabVIEW in Data Acquisition, Control, Design,

Analysis, Synthesis, Simulation, Instrumentation, and Engineering Problem Solutions:   LabVIEW will also be used as a general purpose language to dot asks that have traditionally been done by languages such as C, MATLAB, SIMULINK, and EXCEL. 

Lab 3 hrs per week, Lecture 2 hrs per weekTu & Th 11:00 to 1:20 in P308..

Page 2: LabVIEW 2009

22

Reference Texts:Labview 8 Student Edition, Robert Bishop, Prentice Hall, 2007LabVIEW for Everyone, Travis & Kring, Prentice Hall, 2008Introduction to Data Acquisition with LabVIEW, King, McGraw Hill, 2009Labview Graphical Programming, Johnson & Jennings, McGraw Hill, 2006The LabVIEW Style Book, Blumb, McGraw Hill, 2007

Course Grading:This is a relatively new experimental course, and the course grading and content may need to be modified as the course is developed. The current thinking is shown below. You will be kept informed of any changes implemented.

Tests & Quizzes .......................................25%Homework Exercises ...............................25%Laboratory Performance & Attendance....25%Project and/or Final Exam........................25%

Page 3: LabVIEW 2009

33

LabVIEW

Laboratory Virtual Instrument Engineering Workbench

Another and better name

Graphical Programming Language G (not text based)

It is a general purpose language like C, MATLAB, and others

It has Instrumentation and Display Capability

It is used for Simulation

It is used for Data Acquisition

It is used in Control Applications

Programs are called Virtual Instruments, VI’s

File names example: prog1.vi, xyz.vi, etc. The extension is vi

Page 4: LabVIEW 2009

44

Temperature Demo.vi Load from Demos Folder, Run and Discuss

Front Panel, Block DiagramCTRL T toggleIcon/Connector

Look at menus navigation, etc

Start LabVIEW and open a new vi

Visible pallet sets

1. Left click on Front Panel to get Controls Palette

2. Pin either the Classic or Modern Controls Palette

3. Left click on the Diagram Window to get the Functions Palette

4. Pin the Programming Palette

5. To get the Tools Palette click on View-Tools Palette

6. Look at different possible views of controls and Functions Palette

Page 5: LabVIEW 2009

55

Temperature Demo.vi cont 7. Left click on icons and others - look at menus

8. Run the program - discuss results

9. Blue integers, orange floating point

10.Try different inputs (Control values)

11. CTRL H Context Help

12. Nodes - program execution elements, Add, Subtract, subprograms.

13. Wires - data paths

14. Controls = Inputs

15. Indicators = Outputs

Page 6: LabVIEW 2009

66

Data Flow Programming.

A node can executed only when all the input data arrives at itsinput terminals. The node supplies data to all of its outputterminals when it finishes executing.

In contrast text based programs execute in the sequence they are written.

Load Arith-2.viHighlight execution and step through to demonstrate the dataFlow.

Page 7: LabVIEW 2009

77

Students Create some vi’s

1. Create a new vi Arith.vi Controls - numerical inputs A, B, and C Indicators - numerical Outputs Out 1, and Out 2 OUT1 = A + B OUT2 = (A+B) - B/C Build the vi shown below.

Page 8: LabVIEW 2009

88

Students Create some vi’s cont 2. Create Arith-2.vi Add a Boolean light to Arith.vi

The light should go on if A > to 3, and is otherwise off

Page 9: LabVIEW 2009

99

By convention, where possible, the data flow programmingdiagrams are constructed so that the flow is left to right.This results in the best readability. Note: Nodes also generally have their inputs on the left and outputs on the right.

Arith-2.vi Arith-2Poor.vi – Poorly done. Load, highlight execution, and run it

Page 10: LabVIEW 2009

Random number generation

Rand #.vi open and discuss

Page 11: LabVIEW 2009

Case.viopen and discuss

Page 12: LabVIEW 2009

3. Create Arith+Case.vi Add a True False Case to Arith-2.vi such that if A is not = 0 then

calculation is as before, but if A = 0 then OUT 1 = a random number between -5 and +6.8 (Span=11.8), and OUT 2 is unchanged.

Students Create some vi’s cont

Page 13: LabVIEW 2009

1313

Short list LabVIEW Shortcuts and some Notes

Ctrl+H Opens Context Help WindowCtrl+E Toggle between Front Panel and Block DiagramCtrl+B Remove Broken WiresCtrl+Z Undo buttonCtrl+R Run VICtrl+F Find ObjectCtrl+W Close Active WindowCtrl+T Tiles the Front panel and Block Diagram

Ctrl Hold down after selecting object and drag away to make a copy of object Hold down while making a box in whitespace to make more room

Shift Hold down while using arrow keys to move an object fasterHold down and right click mouse button to bring up Tools Palette

Right-Click On any input or output to make controls/constants or indicators. On any control and go to Replace to change to

another type, and go to Properties to modify a specific item

Page 14: LabVIEW 2009

Short list LabVIEW Shortcuts and some Notes – cont

Tools —> Options Set Preferences in Labview

Instrument DriversDrivers available at ni.com/idnetInstall the instrument driver VI Library into LabVIEW 8.0\instr.lib directory. Access drivers from

Functions»Input»Instrument Drivers subpalette

NI Technical Support www.ni.com/support 1-866-275-6964

Drivers and Updates www.ni.com

Page 15: LabVIEW 2009

Creating SubVIs (Subroutines)

Any vi can be made into a SubVI just like any routine (program) can be

Made into a subroutine.

Method 1Arith.viOpen and discuss

To make Arith.vi into a SubVI, and give it a new name ArtihS.vi Load Arith.viEdit the Icon to identify the SubVI as ArithSOption – rename Controls and Indicators if desiredSelect the desired Connector (3 input, 2 output)Wire desired Controls and Indicators to the ConnectorSave the result as ArithS.vi

Note: I think that it is usually best use the SubVI’s name for the SubVI Icon.

Page 16: LabVIEW 2009

Creating SubVIs (subroutines) cont.

Method 2Open Arith+Case.vi

Select the same code that generates the SubVI ArithS.vi

Use Menu EDIT-Create SubVI to create the SubVI .Open the SubVI and edit the Icon as desired - ArithS.Rename the Controls and Indicators as desired.Save the result with the desired name – in this case ArithS.vi

Page 17: LabVIEW 2009

SubVIs cont.

Using SubVIs in a program. A SubVI can be used as many times as desired In a program.

Demonstrate using the SubVI ArithS.vi 2 times in a program namedUsingSubVI.vi where the 2 sets of inputs and outputs for the 2 SubVIsare::

Set 1. Inputs: A=X a control, B=3 a constant, and C=6 a constant. Outputs: Out1=Z an indicator and Out2=Out2 an indicator

Set 2. Inputs: A=6 a constant l, B=X a control, and C=Z the output from Set 1.

Outputs: Out1=XX an indicator and Out2 not used

Note: Load UsingSubVIIO.vi which contains the Controls, and Indicators as a starting point for the VI.

Page 18: LabVIEW 2009

Important! - Programming Success

1. A Step at a Time Build programs and subprogram in small steps testing each step thoroughly before adding the next step. Don’t go for broke with a big program!!

2. Divide and Conquer. Use Modular Programming techniques with SubVIs and Subprograms

Page 19: LabVIEW 2009

1919

LabVIEW Exercises 1. Write a VI to calculate the function: y = b^2-4*a*c

Make this VI into a SubVI Disc.vi with an appropriate icon and icon connect Inputs (controls) are a, b, and c,. The output (indicator) is y.

ab Disc yc2. Write a SubVI that calculated the roots of a quadratic equation using

the SubVI disc.vi from Exercise 1. The digital inputs to the VI should be the quadratic equation coefficients, and the outputs the roots of the quadratic equation. Note that the VI should be capable of dealing with both real and complex roots of the quadratic equation. Make this VI into a SubVI quad eq.vi with inputs a, b, and c, and outputs r1, i1, r2, and i2.

a r1 i1b quad eq r2c i2

Page 20: LabVIEW 2009

quad.vi - logic

Calculate Disc

Positive?

R1=(-b+sqrt(Disc))/(2*a)I1=0R2 =(-b-sqrt(Disc))/(2*a)I2=0

R1=-b/(2*a)I1=+sqrt(-Disc)/(2*a)R2=-b/(2*a)I2=-sqrt(-Disc))/(2*a)

YES

NO

Page 21: LabVIEW 2009

Exercise 2Open and discuss

Quadratic roots (-b+sqr(b^2 - 4*a*c)/(2*a)(-b- sqr(b^2 - 4*a*c)/(2*a)

Assignment due next period. Hand in:Exercise 2 on a 3 ½ floppy disk

File Folder name Exercise 2Contents:

Exercise 2.viDisc.viquad eq.vi

+ anything else needed

Page 22: LabVIEW 2009

2222

VI Examples

Learning LV8 examples from our text book in a Folder on the G drive

Demos Folder

ni.com web site

See Examples choice on LabVIEW welcome screen

Lots of other examples on line, and in many textbooks

Page 23: LabVIEW 2009

2323

Trouble shooting

Use quad eq.vi with its SubVI disc.vi to show some trouble shooting techniques

1. Show how to set default values on A, B, C (Say 1,2,3 or other)

2. Highlight Execution – run and look at data flow

3. Step thru the program

3. Show use of the Probe

4. Use the Stop to execute up to a point and then step thru.

Page 24: LabVIEW 2009

2424

Case Structures For more than just T, F case

demo Cases-3.vi Connect a numeric control to the boolean input, and instead of True False it becomes 0,1 then add as many cases as you want

Add other cases. There are 3 total in the Demo see be,low

Page 25: LabVIEW 2009

2525

While Loops

Open & Demo

WhileLoop.vi

Build a piece at a time

While - both with Stop if True & then change to Continue if True

Always executed once. Check for stop/continue is done after the loop execution.

add random #

add indicators inside and outside loop

add indexing and explain

add array indicator

Page 26: LabVIEW 2009

2626

While Loops with Shift RegistersDemo ShiftReg1.vi, Add initilization of the Shift register

Demo ShiftReg2.vi Sumation of iStep thru and show results

Page 27: LabVIEW 2009

2727

Demo ShiftReg3.viAdd feedback registersIi-1i-2etc

Page 28: LabVIEW 2009

Demo x^i.vi

Step thru and show results

Page 29: LabVIEW 2009

2929

Exercise 3. Write a SubVI e^x.vi to generate the function e^x , where x is a digital input, and e^x is a digital output. Use a Taylor series to generate the functionwith accuracy up to the nth place.

Taylor Series e^x = 1 +x^1/1! + x^2/2! + x^3/3! +x^4/4! +…

For example if n=5 the series should use terms up to and including the first one that is less than .00001 in absolute value). The SubVI should also output the value of y and the number of terms used.

The SubVI should output the value of e^x and the number of terms in the series.

Page 30: LabVIEW 2009

3030

Exercise 3 cont.Test your SubVI e^x.vi with Test e^x.vi - demo it.

Page 31: LabVIEW 2009

Important! - Programming Success

1. A Step at a Time Build programs and subprogram in small steps testing each step thoroughly before adding the next step. Don’t go for broke with a big program!!

2. Divide and Conquer. Use Modular Programming techniques with SubVIs and Subprograms

Load and demo Step at a Time with Exercise 3 - s1, s2, s3

Page 32: LabVIEW 2009

3232

Exercise 4. Write a SubVI Sin(x).vi to generate the function Sin(x) , where x is a digital input. Use a Taylor series to generate the function with accuracy up to the nth place.

Taylor Series Sin(x) = x - x^3/3! + x^5/5! - x^7/7! +…

For example if n=5 the series should use terms up to and including the first one that is less than the absolute value of .00001.

Write a test VI, TestSin(x).vi to test your Sin(x) SubVI.

Page 33: LabVIEW 2009

3333

Introduction to Graphing

Waveform Chart:

Open & Demo Charts.vi

Strip chart

Scope Chart

Sweep Chart

Exercise 5. Modify the above vi to display the SubVI Sin(x).vi of Homework Exercise 4 on a waveform chart. Let the value of X take on the values of the loop index I, and experiment with various delay values.

Page 34: LabVIEW 2009

3434

Demo Charts-1.viAdding chart signals. Replace the Bundle with a Build Array and note the difference.

Bundle yields two separate tracesBuild Array yields one trace, the sum of the two traces, because new data is appended to old

Stop

Page 35: LabVIEW 2009

3535

Waveform Graphs Build below a step at a time

Graphs-1.vi

Build array - note array sizes expanded with zeros to make both the same

Page 36: LabVIEW 2009

3636

Graphs with time. Graphs-2.vi

Page 37: LabVIEW 2009

3737

XY Graph XY Graph.vi. Inputs are X arrays & Y arrays

Delete pieces from XY Graph.vi and build back up in pieces in piecesIntroduce Express vi’s Build Express XY Graph is found on the Modern Graph PalletDynamic dataAdd cursor and make cursor free, use finger to move it around, and examine values on the curves

Page 38: LabVIEW 2009

3838

Exercise 6

Generate 100 random numbers in the range from +1 to -2, one number every 0.1 seconds. Also generate 100 values of 1.8sin10t, one value ot t every 0.1 seconds, ie, 0, .1, .2, .3 …

a) Display both the random numbers and the 1.8sin10t numbers on a single Waveform Chart as they are being generated, and experiment with the different display options and features. The objective is to learn all about Waveform Chart properties and features

b) Generate the above numbers and collect them in arrays. Display the arrays on a Waveform Graph verses the array index. Also display the arrays on a Waveform Graph verses time. Experiment with the different display options and features. The objective is to learn all about Waveform Graph properties and features

c) Display the array for the random numbers on the X axis, and the sin wave array on the y axis of an XY Graph. Experiment with the different display options and features. The objective is to learn all about XYGraph properties and features

Page 39: LabVIEW 2009

3939

Formula Node Formula Node-1.vi

If else exampleNote lower case if and else

Page 40: LabVIEW 2009

4040

Formula Node while loop example Formula Node-2.vi

Page 41: LabVIEW 2009

4141

Formula Node For Loop example Formula Node-3.vi ;

Page 42: LabVIEW 2009

4242

Some Formula Node Syntax Formula Node-4.vi floating-point-type:float, float32, float64integer-type: Int, int8, int16, int32, uInt8, uInt16, uInt32assignment-operators: = += –= *= /= >>= <<= &= ^= |= %= **=binary-operators: + – * / ^ != == > < >= <= && || & | % **

Formula Node with Arrays example Formula Node-4.vi Note i++ is short hand for i=i+1

Page 43: LabVIEW 2009

4343

Formula Node Do loopFormula Node-5.vi Bubble sort

1420

1420

1240

1204

1204

1024

1024

0124

0124

0124

0124

0124

0124

Page 44: LabVIEW 2009

4444

Exercise 7

Write a SubVI Roots.vi using a Formula Node to calculate the roots of a quadratic equation Ax^2+Bx+C.

This, of course, should yield the same result of the earlier SubVI quad.vi.

A R1

B Roots I1

C R2

I2

Page 45: LabVIEW 2009

4545

Arrays

Build Array, Array Size

Array-1.vi

Index Array

Array-2.vi

Page 46: LabVIEW 2009

4646

Replace Array Subset: Array-3.vi

Array in determines size of the Array Result

Insert Into Array: Array-4.vi

Page 47: LabVIEW 2009

4747

Initialize Array, Array-5.vi

Examine all the other array operations in the Programming pallet

Exercise 8 Create a good example for one of the other array and email it to me at [email protected]. I will then email all of the examples back to everyone.

Page 48: LabVIEW 2009

4848

Polymorphism – dealing with arithmetic operations on arrays of different dimensions

Polymorphism.vi

Page 49: LabVIEW 2009

Indexing (again) with For and While Loops – Demo Indexing Loops.vi

Page 50: LabVIEW 2009

5050

Clusters: Creating Clusters for either indicators or controlsThe order (not the position) placed in the Cluster shell determined the order in the cluster.

Demo Clusters.vi

Page 51: LabVIEW 2009

5151

Local VariableA local variable can be created for any control or indicator.

Demo the Kitchen Timer.vi

Exercise 9 Note the problem with the Kitchen Timer: It can not be reset after it starts running. Fix this problem. Use the name Kitchen Timer-2.vi. Another local variable may prove useful.

Page 52: LabVIEW 2009

52

Exercise 10 Write a bubble sort sub vi: Sort-B.vi. that does the same sort asFormula Node-5.vi, but does not use the formula node and C code. LabVIEW For loops, While loops and other structures should be used. You may find that the use of a Local Variable will prove useful in order to set a DONE condition, and then to read, and to act on that condition.

Input Array [x] Sort-B

Sorted Array[y]

1420

1420

1240

1204

1204

1024

1024

0124

0124

0124

0124

0124

0124

Page 53: LabVIEW 2009

53

Exercise 10 cont Write a bubble sort sub vi: XY Sort-B.vi. that will sort [X], [Y] data pairs so that they are ordered pairs for increasing values of X. Test your SubVI with the [X], [Y] data pairs below:

[X]

[Y]

XY Sort-B

Sorted [X]

Sorted [Y]

Sorted [X] = -3.1 -1.2 0 1.2 3.9 5,0 6.3 7.5 10.1 12.6

Sorted [Y] = -1.9 2.1 6.7 3.1 -4.9 -8.1 4 1.9 -1.5 6

[X] = 3.9 12.6 6.3 0 -3.1 10.1 5,0 7.5 -1.2 1.2

[Y] = -4.9 6 4 6.7 -1.9 -1.5 -8.1 1.9 2.1 3.1

Page 54: LabVIEW 2009

54

Trapezoidal Integration lecture etc. on black board

y

x

x0, x1, x2, x3, …………

y0, y1, y2 ………

Etc

xi xi+1

yi+1

yi

Ai = ((yi+1+ yi)/2)*(xi+1 + xi)

Ai

Ai

A0 A1

A2

Page 55: LabVIEW 2009

55

Exercise 11 Write a SubVI (Trap I.vi) that will integrate a curve y(x) using trapezoidal integration. y(x) is described by [x], [y] data points, two arrays. The integral array [z] is the output of the SubVI, and is an array of values for the integral.

[x]

[y]

Write a test routine Exercise 11.vi to test the SubVI by integrating the curve described by the following data points.

(x,y) = (-3.1,-1.05), (-1.2,-2.51), (0,-3), (1.2,-2.91), (3,-2.43).(5,0), (6.3,2.42), (7.52,3.80), (10.1,4.67), (12.6,3.78),(14,2.78), (14.92,1.75), (16,1.30), (19.7,-.99), (21.5,-2.03)

Graph both y and z as a function of x on the same graph.

Trap I [z]

Page 56: LabVIEW 2009

56

Exercise 11.vi, testing the Trap I SubVI

Page 57: LabVIEW 2009

57

Interpolation Lecture summary

[X] = X0, X1, X2, x3, …XL

[Y] = Y0, Y1, Y2 ……… YL

Xi+1

Yi+1

Yi

Xa is in the range X0 to XLYa = Yi+1 – Yi)/(Xi+1-Xi)) (Xa-Xi) + YiPoint slope formula Y = mX + B

X

Y

Xi Xa

Ya Ya

Xa

X0

XL

Page 58: LabVIEW 2009

58

Interpolation Lecture summary

Out of range Xa<X0 or Xa>XL

[X] = X0, X1, X2, x3, …XL

[Y] = Y0, Y1, Y2 ……… YL

Xa>XLYa = (YL - YL-1)/(XL - XL-1)*(Xa-XL) + YL

Xa<X0Ya = (Y0+1 - Y0)/(X0+1 – X0)*(Xa-X0) + Y0

X

Y

Xa, Ya

XL, YL

X0, Y0

Xa, Ya

Page 59: LabVIEW 2009

59

[X]

[Y] Interp

Ya

Xa

i

m

Exercise 12Write a SubVI Interp.vi that does linear interpolation for array data points [X], [Y]. That is, for an input Xa the output Ya will be calculated, Outside of data range interpolation should take place, and the out of range magnitude M calculated and printed. The vi should also output the value of the index i, where Xi<=Xa<Xi+1. Note if Xa<=X0 the value of i should be 0, and if Xa>=XL the value of i is L-1

DemoTextInterp.vi

Page 60: LabVIEW 2009

DemoTextInterp.vi

Page 61: LabVIEW 2009

61

Write a vi, Exercise 12.vi, to test InterpM.vi and Interp.vi using the [x], [y] data of Exercise 11, and the following test values for [xa].

[Xa] = [-5, -3.1 -2.03, -1.49, 6.3, 9.8, 11.5, 17.62, 19.7, 21.5, and 23.4].Test other data array inputs.

X]

[Y] InterpM

[Ya]

[Xa]

[i]

[m]

Exercise 12 cont. Write a SubVI InterpM.vi that does linear interpolation for a array of data [X], [Y] points, and for an array of input values [Xa]. That is, interpolation for the elements of an input array [Xa] an interpolated output array [Ya] will be calculated. Also an array [i], and an out of range magnitude array [m.] will be calculated.

Page 62: LabVIEW 2009

Exercise 12 – Demo TestInterp&InterpM.vi,

Page 63: LabVIEW 2009

Select 1.viA 3 bit binary array selector

Page 64: LabVIEW 2009

64

Select 2.vi another selector

Select 2.vi

Page 65: LabVIEW 2009

65

Integration from xa to xb, lecture etc on blackboard, Calculate the Integral of a curve from xa to xb using original data where possible.

y

x

Note xa and xb are not required to be data points.

Given, xa, xb, and

x0, x1, x2, x3, …………

y0, y1, y2 ………

xb

Ai

A0 A1

A2

xa Ai+1

Page 66: LabVIEW 2009

66

Exercise 13Write a SubVI NewD.vi with inputs [x], [y], xa, and xb. The outputs of the SubVI aremodified arrays [xn], and [yn], which are new set of data point arrays from the low limit xa to the high limit xb. The original data points are to be used except at the end points xa and xb. Thus, interpolation will be necessary and your sub vi Interp.vi will be needed. Also consider error checking for invalid input values etc.

Write a vi TestNewD.vi that calculates an array [z] which is equal to the integral of a curve defined by arrays [xn] and [yn] above. TestNewD.vi logically will thus include the SubVIs Trap I.vi, NewD.vi, and Interp.vi. The integral is to be from a low limit of xa to a high limit of xb. The output results [z], vs the [xn] should be graphed over the range from xa to xb. Use the data of Exercise 11, and test your vi for xa = -4.9, xb = 11.5, and xa = 3.1, xb = 10.5. Also test for other alues for xa &, xb. Check the results to make sure the vi is working properly.

[x]

[y] NewD [yn]xa

xb

[xn] = [xa, xi, xi+1, …., xb]

error

Page 67: LabVIEW 2009

67

TestNewD.vi. Run it also for for various values of xa, and xb

Page 68: LabVIEW 2009

68

Integration from Xa to Xb using new points equally spaced, Calculate the Integral of a curve from Xa to Xb using new points equally spaced by inc.

y

x

Note xa and xb are not necessarly data points.

Given, Xa, Xb, and inc, the desired increment, and data

x0, x1, x2, x3, …………

y0, y1, y2 ………

calculate [xn] = [xa, xa + inc, xa + 2*inc +…………..xb] etc Black board lecture

xbA0

A2

xa

Page 69: LabVIEW 2009

69

Exercise 14Write a SubVI NewD2.vi with inputs [x], [y], Xa, and Xb. The outputs of the SubVI are modified arrays [Xn], and [Yn], which are new set of data point arrays equally spaced by inc from the low limit Xa to Xi<=Xb. That is [Xn]=[Xa, Xa+inc, Xa+2*inc, ….Xb] Thus, interpolation will be necessary. Also consider error checking.

Write a vi Exercise 14.vi that calculates an array [z] which is equal to the integral of a curve defined by arrays [x] and [y]. Exercise 13.vi logically will include the SubVIs Trap I.vi, NewD.vi, and Interp.vi and possibly InterpM.vi. The integral is to be from a low limit of xa to a high limit of xb. The output results [z], vs the [xn] should be graphed over the range from xa to xb. Use the data of Exercise 11, and test your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb = 10.5, and inc=1 and also test it for other values for xa &, xb. Check the results to make sure the vi is working properly.

[x][y]

NewD2 [Yn]xaxb

[Xn]

errorinc

Page 70: LabVIEW 2009

Demo SubVI, xa inc xb.vi: given [x] xa, inc, & xb, create [xa, xa+inc, xa+2*inc………xb ]

Page 71: LabVIEW 2009

71

TestNewD2.vi: Testing NewD2.vi

Page 72: LabVIEW 2009

72

Curve Fitting, Blackboard lecture first on polynomial curve fitting then:

Demo CurveFit-1.vi, and CurveFit-2.vi & use experiment with different polynomialOrders.

Page 73: LabVIEW 2009

73

Curve fit with lots of points: Demo CurveFit-3.vi, with different orders from demo folder

Page 74: LabVIEW 2009

74

Blackboard Lecture on polynomial Integration

Page 75: LabVIEW 2009

75

Exercise 15, Polynomial IntegrationWrite a SubVI to evaluate the integral of a polynomial c0 + c1*x =+ c2x^2 + …Start by writing the SubVI PolyInt 1 Point.vi with input data [c (poly coef)], and x to do the evaluation of the integrated polynomial c0*x/1 + c1*x^2/2 + c2* x^3/3 + c3*x^4/4 + … ……… The output of the SubVI z is the integrted polynomial evaluated at one value of x (1 point).

Then write PolyInt.vi with array data inputs [c (poly coef)], xa, inc, and xb. The output of the SubVI is the integral array, [z]. [z] is the integral from xa to xb evaluated at each [x2] array point, where [x2]=[xa, xa+inc, xa+2*inc, xa + 3*inc,…. …xb]. This routine will logically use the SubVI PolyInt 1 Point.vi.

Write a vi Exercise 15.vi to test PolyInt.vi, PolyInt 1 Point.vi and calculate the array [z], which is equal to the integral at the data points [x2] of a curve defined by arrays [x] and [y]. Plot the results and fully test the vi’s. Use the data of Exercise 11, and test your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb = 10.5, and inc=1 and also test it for other values for xa &, xb. Experiment with different polynomial fit order. Check the results to make sure the vi is working properly.

[c (poly coef)]PolyInt1 Point

x

z

error

PolyIntxa

xb

[z]

errorinc

[x2]

[c (poly coef)]

Page 76: LabVIEW 2009

76

Exercise 15, Polynomial Integration test resultsDemonstrate this vi

Page 77: LabVIEW 2009

Submit your Exercises on 3.5 floppy disk

1. Print your name on the outside of the 3.5 floppy.

2. Submit all completed exercises. Save complete folders with all SubVIs needed for each exercise in the folder, eg, Exercise 1 Folder, etc.

Lecture on Least square error curve fitting - RegressionHand out & discuss Regression.doc

Page 78: LabVIEW 2009

78

Linear Algebraic EquationsDemo Lin Alg.vi.

Page 79: LabVIEW 2009

79

Exercise 16, Write a SubVI Poly LSE Fit.vi to determine the polynomial coefficients for a least square error fit of data points [x], [y] using the regression technique. This SubVI should be basically the same as the LabVIEW LSE routine

Write a vi, Exercise 16.vi, to test Poly LSE Fit.vi. Use the [x], [y] data of Exercise 11, and compare your results with the LabVIEW LSE routine, and Check the to make sure the vi is working properly.

[x] Poly LSE Fit

[y]

error

[c (poly coef)]

Order

[y] Best fit

mse

Page 80: LabVIEW 2009

Exercise 16.vi

Page 81: LabVIEW 2009

81

Course Project, Paper, and Presentation

A few Project IdeasData AcquisitionGauss Jordan linear equation solverFast Fourier TransformSerial CommunicationsActive XGPIBInstrument ControlProperty NodesEvent-Driven ProgrammingReport GenerationSignal GenerationSignal analysisSignal ProcessingMathScriptMaster Slave loop techniquesInternet resources and examplesI/O file handlingDigital FilteringDigital image processingVideo image processing3 dimension graphingEvent handling – mouse & keyboard Anything that contributes new knowledge, examples & etc.

Page 82: LabVIEW 2009

82

ScheduleProject Selection Due November 4 with a brief written abstract of what you plan to do.

Final Project Abstract and all Exercises are Due November 20 on your 3.5 diskFinal Abstract FormatTitle:_____________Name:____________Brief description less than 100 words

Project Paper And Programs Are Due November 25Put everything on your disk in a folder named PROJECT and give it to me on 11/25. In addition give me a printed copy of the project paper.

Project Oral PresentationsNovember 25 Wajahat Asfar

Hui WangGuoheng Chen

December 2 Ning XuXiao Guo

December 4 Xiaohan XuMan Xu

Page 83: LabVIEW 2009

83

Euhlers Technique, Differential Equations

Blackboard lecture on first order differential equationse

Page 84: LabVIEW 2009

84

F(X,Y) Euh 1.vi

DE Euh 1.vi, demo this

Page 85: LabVIEW 2009

85

Blackboard lecture and hand outs on Euhler’s technique for an nth order differential equations.

Exercise 17, Write a SubVI Euh M.vi that uses Euhler’s method to solve a set of 1st order differential equations. Note, also a SubVI F(X,Y) Euh M.vi will be needed for the function describing the differential equation

Write a VI, TestEuh M.vi, to test Euh,M.vi, and F(X,Y) Euh M.vi for the differential equation Y’’’ + 5Y’’ + 8Y’+6Y= 3. Check the to make sure the VI is working properly.

X0

Euh MXl[Y]

[Y]0

[X]DXX

F(X,Y) Euh M

Y

[F(X,[Y])]

Page 86: LabVIEW 2009

86

Exercise 17.vi, demo this.

Page 87: LabVIEW 2009

87

Exercise 18Exercise 18The RocketThe Rocket

This is a hypothetical This is a hypothetical LabVIEW Design Exercise. LabVIEW Design Exercise. A weather and pollution data A weather and pollution data gathering rocket containing gathering rocket containing delicate instrumentation and delicate instrumentation and photographic equipment is photographic equipment is being developed. The being developed. The rocket, using a solid rocket rocket, using a solid rocket fuel, is to be launched from fuel, is to be launched from the ground. It is expected the ground. It is expected to reach an altitude of to reach an altitude of about 1 mile, and then about 1 mile, and then return to earth under the return to earth under the influence of gravity. A influence of gravity. A free body diagram showing free body diagram showing the forces acting on the the forces acting on the rocket is shown.rocket is shown.

eennggiinnee tthhrruusstt iinn llbbss TT == --115566**ddww((tt))//ddtt,, wwhheerree ww iitt tthhee ffuueell wweeiigghhtt llbbss

aaiirr ddrraagg KK((yy))**ddyy//ddtt**||ddyy//ddtt||llbbss

ffoorrccee ooff ggrraavviittyy mm((tt))gg llbbss,, wwhheerree gg == 3322..22 fftt//sseecc22

mmaassss ooff rroocckkeett wwiitthh aa ffuullll llooaadd ooff ffuueell aatt tt==00 iiss 99..5566 sslluuggss ((wweeiigghhtt == 330077..88 llbbss)) yy((tt))

Page 88: LabVIEW 2009

88

As fuel is burned a thrust force is created which is As fuel is burned a thrust force is created which is proportional to the rate of fuel consumption. Laboratory proportional to the rate of fuel consumption. Laboratory data from dynamometer tests shows the rate of fuel data from dynamometer tests shows the rate of fuel consumption Vs time. Data points are provided showing consumption Vs time. Data points are provided showing consumption in lbs per second Vs time for the 9 second consumption in lbs per second Vs time for the 9 second solid fuel burn cycle in the file -DWDT.VI. solid fuel burn cycle in the file -DWDT.VI.

The air friction function K(y) varies with altitude. As The air friction function K(y) varies with altitude. As altitude increases the air gets thinner and the friction altitude increases the air gets thinner and the friction multiplying factor decreases. The data file K(y)Data.vi is multiplying factor decreases. The data file K(y)Data.vi is provided. provided.

As fuel burns the rocket mass decreases. This and the As fuel burns the rocket mass decreases. This and the nonlinear drag force result in a nonlinear system of nonlinear drag force result in a nonlinear system of differential equations which do not lend themselves to differential equations which do not lend themselves to analytical solution, and thus a numerical digital solution analytical solution, and thus a numerical digital solution may be the only way to investigate this design problem. may be the only way to investigate this design problem. Various simplifying assumptions have been made, such as a Various simplifying assumptions have been made, such as a constant gravitational force and the air density force constant gravitational force and the air density force function. An analysis of the free body diagram followsfunction. An analysis of the free body diagram follows::

Page 89: LabVIEW 2009

Note that for t > 9 seconds mNote that for t > 9 seconds m’’ = 0, T = 0. = 0, T = 0.

Applying NewtonApplying Newton’’s Laws for the free body diagram yields:s Laws for the free body diagram yields:d(mv)/dt = T - 32.2m d(mv)/dt = T - 32.2m –– K(y)dy/dt|dy/dt| K(y)dy/dt|dy/dt| note that d(mv)dt = mdv/dt + vdm/dtnote that d(mv)dt = mdv/dt + vdm/dt

and since v = dy/dt thus,and since v = dy/dt thus,

mdmd22y/dty/dt2 2 + dy/dt*dm/dt = T - 32.2m + dy/dt*dm/dt = T - 32.2m –– K(y)dy/dt|dy/dt|, K(y)dy/dt|dy/dt|,

oror

dd22y/dty/dt22 = 1/m(T - 32.2m = 1/m(T - 32.2m –– K(y)dy/dt|dy/dt| - dy/dt*dm/dt) K(y)dy/dt|dy/dt| - dy/dt*dm/dt)

This equation is now converted to a set of 1st order This equation is now converted to a set of 1st order differential equations.differential equations. letting Yletting Y00 = y, and Y = y, and Y11 = dy/dt and using prime (‘) to denote = dy/dt and using prime (‘) to denote

differentiation (d/dt) yields the following state equations:differentiation (d/dt) yields the following state equations:

YY00’= F0 = Y’= F0 = Y11

YY11’= F1 = (T - 32.2m – K(Y’= F1 = (T - 32.2m – K(Y00)Y)Y11|Y|Y11| - m’Y| - m’Y11)/m)/m

Page 90: LabVIEW 2009

90

Analyze and investigate the rocket flight using LabVIEW. Analyze and investigate the rocket flight using LabVIEW. Your solution should include the following: Your solution should include the following: 1.1. Data points and a graph of the position (y),Data points and a graph of the position (y), velocity (yvelocity (y’’), and), and acceleration (yacceleration (y’’’’) Vs time. ) Vs time. 2.2. Determine the time and magnitude of the maximumDetermine the time and magnitude of the maximum height, velocity and acceleration of the rocket.height, velocity and acceleration of the rocket.3. How fast is it traveling when it hits the ground? 3. How fast is it traveling when it hits the ground? 4. What is the average velocity for the entire flight? 4. What is the average velocity for the entire flight? 5. How long is the flight from the time it leaves the5. How long is the flight from the time it leaves the ground until itground until it returns. returns.

You will need to include a provision at launch time so You will need to include a provision at launch time so that the height of the rocket does not go negative that the height of the rocket does not go negative (below the earth), because at t=0, and until some time (below the earth), because at t=0, and until some time tt11 the solid fuel thrust force is less than the force of the solid fuel thrust force is less than the force of

gravity. This will accelerate the rocket in the -y gravity. This will accelerate the rocket in the -y direction. In reality the launch pad would prevent this direction. In reality the launch pad would prevent this from happening. from happening.

Page 91: LabVIEW 2009

91

Your solution should be modular with appropriate SubVIs. For Your solution should be modular with appropriate SubVIs. For the SubVI F(X,Y) Euh M.vi the following two vis will be needed.the SubVI F(X,Y) Euh M.vi the following two vis will be needed.

Time Data

mm’TTime

m’ rate of change Rocket mass slugs/sec

m Rocket Mass Slugs

Fuel Rate Data

K(y) K(y)y

Interpolation and trapezoidal integration are appropriate for the fuel data to calculate m, m’ and T. For the air friction function K(y), a polynomial curve fit is preferred because of the nature of the data given.

T Rocket EngineThrust

Page 92: LabVIEW 2009

92

Logical extensions to this design problem are:Logical extensions to this design problem are:

1. Jettison the fuel section of the rocket after the fuel is used up. This 1. Jettison the fuel section of the rocket after the fuel is used up. This would reduce the mass and effect the final altitude, and/or amount of would reduce the mass and effect the final altitude, and/or amount of fuel required. Say that the fuel shell that can be discarded is 1 slug, and fuel required. Say that the fuel shell that can be discarded is 1 slug, and it could be jettisoned 1 second after the fuel is used up. it could be jettisoned 1 second after the fuel is used up.

2. The use of a parachute to be deployed at a prescribed altitude in order to 2. The use of a parachute to be deployed at a prescribed altitude in order to soften the landing, and protect the payload. The parachute could create soften the landing, and protect the payload. The parachute could create an additional air drag force that would increase with time during an additional air drag force that would increase with time during deployment from 0 to a maximum value of kp*dy/dt*|dy/dt|. Maybe a deployment from 0 to a maximum value of kp*dy/dt*|dy/dt|. Maybe a reasonable deployment algorithm might be linear increase in kp from 0 reasonable deployment algorithm might be linear increase in kp from 0 to .0876 in 1 second. to .0876 in 1 second.

3. The effects (max velocity, acceleration, height etc,) resulting from 3. The effects (max velocity, acceleration, height etc,) resulting from different solid fuel burning rate schedules with the same initial amount different solid fuel burning rate schedules with the same initial amount fuel. fuel.

4.4. Investigate the effects of gravitational changes that occur with altitude.Investigate the effects of gravitational changes that occur with altitude.

Do a demo of the Solution Exercise 18Do a demo of the Solution Exercise 18

Page 93: LabVIEW 2009

93

File I/O and Strings Demo theseFile I/O and Strings Demo these

File I/O 1.vi File I/O 1.vi Create Path, and write time &Create Path, and write time &Date to a Text FileDate to a Text File

File I/O 2.vi File I/O 2.vi Create a file with time date Create a file with time date as file name & write a numerical as file name & write a numerical Value converted to ASCII to the fileValue converted to ASCII to the file

Page 94: LabVIEW 2009

94

File I/O 3.vi: File I/O 3.vi: File Path, Headers, Write to a Text File, File Path, Headers, Write to a Text File, Write to aWrite to a Excel File, and Write to aExcel File, and Write to a a a binary File binary File Data Acquisition DAQ Data Acquisition DAQ Demo thisDemo this

Page 95: LabVIEW 2009

95

File I/O 4.vi: File I/O 4.vi: Read 1d String Data from a Text File Read 1d String Data from a Text File and convert to Numerical 1d Data and convert to Numerical 1d Data Array. Data Acquisition DAQ - Array. Data Acquisition DAQ - Demo thisDemo this

Page 96: LabVIEW 2009

96

File I/O 5.vi: File I/O 5.vi: Read Data from a Binary File and convert to Numerical Read Data from a Binary File and convert to Numerical 2d Array Data. Data Acquisition DAQ - 2d Array Data. Data Acquisition DAQ - Demo thisDemo this

Page 97: LabVIEW 2009

97

Exercise 19Study File IO 1.vi, File IO 2.vi, File IO 3.vi, File IO 4.vi, and File IO 5.vi …. for a full understanding.Write a SubVI String to Numbers.vi that will convert multiple lines of an ascii string of numbers to a numerical array. The vi should handle String data representing by both 1 and 2 dimensional data. The data string format is tab separated for each row, and rows are separated by a carriage return. Fully test the SubVI with Exercise 19.vi – Sample below.

Array 1d String to Numbers

StringArray 2d

Page 98: LabVIEW 2009

98

DAQ1.vi DemoData acquisition, analog in using DAQ Assistant, 1 Sample, 8 Channels, on Demand, 10 ms loop time = acquire rate, Channel 2 Selected for acquired samples and graphing

Page 99: LabVIEW 2009

99

DAQ2.vi DemoData acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels, at 10HZ (10 ms sample rate), Channel 2 Selected for acquired samples and graphing

Page 100: LabVIEW 2009

100

DAQ3.vi DemoData acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels, at 10HZ (10 ms sample rate) , Time & channel results saved in an EXCEL spread sheet and graphed.

Page 101: LabVIEW 2009

101

DAQ4.vi DemoData acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels, at 10HZ (10 ms sample rate) , time added to data, results saved every .1 sec as it is acquired in a text file.

Page 102: LabVIEW 2009

102

DAQ5.vi Demo Data acquisitionDigital InputDigital OutputAnalog Out - DAC

Page 103: LabVIEW 2009

103

Data Buffer Window.vi DemoArray In has new Add Array appended to it array resized, and oldest data is discarded yielding Array OUT – a moving window

1 2 3 4 5 6 7 8 9 10

Page 104: LabVIEW 2009

104

DAQ6.vi Demo Master – Slave Analog in DAQ

Page 105: LabVIEW 2009

DAQ Signals.vi Demo A DAQ Signal simulator for 5 channels with sin, square wave, and random signals of variable frequency, amplitude and offset

TimeInput

Page 106: LabVIEW 2009

FFT.vi Demo Fast Fourier Transform

Page 107: LabVIEW 2009

107

Demo vis in Mouse Examples Folder

Page 108: LabVIEW 2009

108

Page 109: LabVIEW 2009

109

Page 110: LabVIEW 2009

110

Page 111: LabVIEW 2009

111