28
LabVIEW Introduction Alan Jennings

LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Embed Size (px)

Citation preview

Page 1: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

LabVIEW Introduction

Alan Jennings

Page 2: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Programming in general

The Data:MATLAB, C, Java• Variables, stackLabVIEW, Simulink, FPGA• Connections (wires)

– 1 Output, – Many inputs

Excel• Predefined by cells

3/28/2012 Programming comparison 2

Page 3: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Programming in generalThe Instructions: Inputs and outputs

MATLAB, C, Java, Excel• function, operator, method• [m,b]= linearfit(x, 3*x+4)LabVIEW, Simulink, FPGA• Blocks with inputs and

outputs

3/28/2012 Programming comparison 3

Page 4: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Programming in generalStructure: Order of executionMATLAB, C, Java, Excel• Sequential: Line after line• Routing commands

–Loops, conditional, break, goto, LabVIEW, • As data is available• LoopsSimulink, FPGA• Blocks with inputs and outputs

–FPGA physically simultaneous–Simulink numerically simultaneous

3/28/2012 Programming comparison 4

Page 5: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Setting up a LabVIEW Program

• Front Panel– Controls: how the user controls the program– Indicators: Displaying results – Function Wiring

for using your VI’s by other VI’s• Block Diagram– Data: All controls and indicators, Also constants – Doing something: Add functions– Control what happens: Add structure

3/28/2012 LabVIEW Components 5

Page 6: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Front Panel• Inputs: – Number, Array, Matrix

3/28/2012 LabVIEW Components 6

– File names, Categories

Page 7: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Front Panel• Inputs: – Binary More Numeric

3/28/2012 LabVIEW Components 7

Page 8: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Function Blocks• Icons • Blocks• Default values• Using Context help

3/28/2012 LabVIEW Components 8

Blocks expand to show all possible signals

Icons: little to no description

Hover over icons, blocks or wires to see what it is and the different signals

Page 9: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Loops• For Loop – Indexing over arrays

• While Loop– Wait for an event to stop

(such as user or trigger)– Feedback block

• Sequence loops– Specify execution order– Important for local variables

• Case loops– Conditional Execution

3/28/2012 LabVIEW Components 9

Page 10: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Data Types

• Waveforms– Values, to, Sample frequency

• Arrays (column)• 2d Arrays • Clusters (similar to structures)• Objects (typical for controlling DAQ’s, etc)• Easiest thing to do is use the port and create

constant to see3/28/2012 LabVIEW Components 10

Page 11: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest Value

• Generate Data• Compare each value to current best

3/28/2012 Programming Examples 11

Page 12: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest Value

• Generate Data– Use Gaussian generation block• Set standard deviation and number of samples

– Convert data type

• Compare each value to current best– Initialize the current largest value– Use `for’ loop to index over signal– Change selection based on logic test

3/28/2012 Programming Examples 12

Page 13: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest ValueGenerate Data

1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

3/28/2012 Programming Examples 13

12 3 4

3

5

4

6

Page 14: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest ValueGenerate Data

1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

3/28/2012 Programming Examples 14

These are controlled by the front panel

Page 15: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest ValueGenerate Data

1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

3/28/2012 Programming Examples 15

Page 16: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest ValueGenerate Data

1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

3/28/2012 Programming Examples 16

To pull of individual values, convert to an array

Other blocks may require other formats

Page 17: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest Value

3/28/2012 Programming Examples 17

Pull the 0 index as the initial condition

Use it to initialize feedback block

Generate Data1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

Page 18: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest Value

3/28/2012 Programming Examples 18

Indexed (pulls each value)

Non-Indexed

Non-Indexed (returns last)

Generate Data1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

Page 19: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Finding Largest Value

3/28/2012 Programming Examples 19

Flow if current largest is largest Flow if current value is largest

Generate Data1. Set standard deviation and number of samples2. Use Gaussian generation block3. Convert data type

Compare each value to current best4. Initialize the current largest value5. Use `for’ loop to index over signal6. Change selection based on logic test

Page 20: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Approximating Human Control

• Dynamic System• Generate disturbance, – Or possibly tracking path

• Find the command as function of error and its derivative

• Do linear fit to find average gain values• Find how well the gains describe behavior

3/28/2012 Programming Examples 20

Page 21: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Approximating Human Control• TankControl.vi• Simple Tank Control (loss proportion to height)

3/28/2012 Programming Examples 21

Page 22: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Approximating Human Control• TankControl_2.vi• Include maximum time• Do linear estimation of control policy• Use local variables

3/28/2012 Programming Examples 22

Page 23: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Approximating Human Control

• Doesn’t Work!• Zeros for linear fit

first time• Troubleshooting

planar fit error

3/28/2012 Programming Examples 23

Page 24: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Ex: Approximating Human Control• TankControl_3.vi• Add 2D and 3D graphs• Add control for set point• Add start button

3/28/2012 Programming Examples 24

Page 25: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

I didn’t say the graphs looked good. I didn’t say the graphs looked good.

Page 26: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Sequence loop separates activationSequence loop separates activation

Page 27: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Data Type conversions to use graphicsData Type conversions to use graphics

Need to separate the array and bundle x & y as pairsNeed to separate the array and bundle x & y as pairs

Page 28: LabVIEW Introduction Alan Jennings. Programming in general The Data: MATLAB, C, Java Variables, stack LabVIEW, Simulink, FPGA Connections (wires) – 1

Other Program Challenges

• Programming Problems:• Finding prime numbers• Binary to dec converter• tausiq.wordpress.com/2009/07/27/push-ups-with-blaze/

• Rock, paper, scissor tournament• Currency Converter• Verifying 8 Queens

3/28/2012 Programming comparison 28