190 likes | 202 Views
Learn about LabVIEW case structures and how to create an instrument for temperature conversion with selector switches. Utilize sub diagrams, handle data tunnels, and enhance user experience through different selectors and select functions. Dive into the Monte Carlo method to estimate pi in a class exercise.
E N D
CS320n –Visual Programming More LabVIEW Control Structures
What We Will Do Today • Learn about other LabVIEW control structures LabVIEW Control Structures
Case Structures • conditional execution • like a if – else in Alice or other languages • 2 or more sub diagrams • the diagram that executes is based on the input of a selector • Selector can be boolean, numeric, or a string LabVIEW Control Structures
Case Structure LabVIEW Control Structures
Case Structure Current Case Sub Diagram. Can only view one case at a time. Selector input. Will change based on data type of input: boolean, numeric String LabVIEW Control Structures
Case Structure Example • Create an instrument that can convert degrees F to degrees C or degrees C to degrees F • Must choose which conversion to make • use a switch on front panel to select which conversion to perform LabVIEW Control Structures
Block Diagram Choose sub diagram by clicking on increment / decrement arrows or clicking on the down arrow and selecting from the menu. LabVIEW Control Structures
Use Sub VIs • Add the C to F and F to C sub VIs to the block diagram LabVIEW Control Structures
Partial Block Diagram Problems with tunnels. If data comes out from one case outputs a value, all cases must have an output for that value. Not the same for input LabVIEW Control Structures
Completed Block Diagram LabVIEW Control Structures
Completed Front Panel LabVIEW Control Structures
One More Thing… • Any way to make instrument more user friendly than input label of “Temp In” and output label of “Converted Temp”? LabVIEW Control Structures
Different Selectors • In example selector was boolean • only two cases, true or false • selector can be numeric or string • control for numeric selector can be any numeric type but will get converted to int • for string and numeric selector many possible cases • right click on selector to add cases LabVIEW Control Structures
Select Function • simple alternative to if-else type case structure • a boolean input • if boolean is true pass on the value wired to t • if boolean is false pass on the value wired to f • can handle other data types LabVIEW Control Structures
Sequence Structure • In LabVIEW, execution is driven by data flow • when the input data is ready, functions execute • sometimes no way of telling which order things will execute • in most programming languages, flow of control is not driven by data, but is sequential based on order of statements in program LabVIEW Control Structures
Sequence Structure Flat Sequence structure with 2 more frames added. Frames execute in order. Alternative to Flat Sequence Structure is a Stacked Sequence Structure. Visually different in that only one frame visible at a time, but functionally equivalent. LabVIEW Control Structures
Class work • This exercise makes use of loops, but does not require case structures. • Monte Carlo method for determining Pi • pi is the ratio of the circumference of a circle to its diameter, no matter which circle you use to compute it. LabVIEW Control Structures
imagine a quarter of a unit circle. (radius = 1) pick points at random random value of x and y, between 0 and 1 use distance formula to determine if point is inside or outside circle square root of (x^2 + y^2) tally up points inside circle pick lot of points estimate of pi = 4 * (points inside / total number of points) Monte Carlo method 1,1 0,1 . outside . inside y 1,0 x LabVIEW Control Structures
Class work • write a LabVIEW program that picks random points to estimate pi. • Allow control for number of random points to pick • display resulting estimate of pi LabVIEW Control Structures