LabVIEW Introduction Alan Jennings Programming in general The Data: MATLAB, C, Java • Variables, stack LabVIEW, Simulink, FPGA • Connections (wires) – 1 Output, – Many inputs Excel • Predefined by cells 3/28/2012 Programming comparison 2 Programming in general The 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 Programming in general Structure: Order of execution MATLAB, C, Java, Excel • Sequential: Line after line • Routing commands –Loops, conditional, break, goto, LabVIEW, • As data is available • Loops Simulink, FPGA • Blocks with inputs and outputs – FPGA physically simultaneous – Simulink numerically simultaneous 3/28/2012 Programming comparison 4 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 • Inputs: – Number, – File names, 3/28/2012 Front Panel Array, Matrix Categories LabVIEW Components 6 • Inputs: – Binary 3/28/2012 Front Panel More Numeric LabVIEW Components 7 Icons: little to no description • • • • Function Blocks Icons Blocks Default values Using Context help Hover over icons, blocks or wires to see what it is and the different signals 3/28/2012 LabVIEW Components Blocks expand to show all possible signals 8 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 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 see 3/28/2012 LabVIEW Components 10 Ex: Finding Largest Value • Generate Data • Compare each value to current best 3/28/2012 Programming Examples 11 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 Generate Data 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Ex: Finding Largest Value Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test 1 2 3 4 5 6 4 3 3/28/2012 Programming Examples 13 Generate Data Ex: Finding Largest Value These are controlled by the front panel 3/28/2012 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test Programming Examples 14 Generate Data Ex: Finding Largest Value 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test 3/28/2012 Programming Examples 15 Generate Data Ex: Finding Largest Value 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Compare each value to current best To pull of individual values, convert to an array 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test Other blocks may require other formats 3/28/2012 Programming Examples 16 Generate Data Ex: Finding Largest Value 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test Pull the 0 index as the initial condition Use it to initialize feedback block 3/28/2012 Programming Examples 17 Generate Data 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Ex: Finding Largest Value Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test Indexed (pulls each value) Non-Indexed (returns last) Non-Indexed 3/28/2012 Programming Examples 18 Generate Data Ex: Finding Largest Value 1. Set standard deviation and number of samples 2. Use Gaussian generation block 3. Convert data type Compare each value to current best 4. Initialize the current largest value 5. Use `for’ loop to index over signal 6. Change selection based on logic test Flow if current largest is largest 3/28/2012 Flow if current value is largest Programming Examples 19 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 Ex: Approximating Human Control • TankControl.vi • Simple Tank Control (loss proportion to height) 3/28/2012 Programming Examples 21 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 Ex: Approximating Human Control • Doesn’t Work! • Zeros for linear fit first time • Troubleshooting planar fit error 3/28/2012 Programming Examples 23 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 I didn’t say the graphs looked good. Sequence loop separates activation Data Type conversions to use graphics Need to separate the array and bundle x & y as pairs 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
© Copyright 2026 Paperzz