Using Polymorphism with Clusters
Exercise 5-6 Cluster Scaling VI (Optional)
Objective: To build a VI that uses polymorphism with clusters.
This VI scales values stored in a cluster, where each component in the cluster has a different scale factor. In this exercise, assume that the voltages were measured from transducers that measure the pressure, flow rate, and temperature. The VI then scales these values to get the “actual” values present in the system.
Front Panel
1. Open the Cluster Scaling VI. The front panel is already built for you. Finish building the block diagram.
Block Diagram
2. Build the block diagram shown above. Make sure you apply the correct scale factors to each component in the raw data cluster.
3. Save and run the VI. Test several alternatives to ensure that the VI works properly.
4. Close the VI when you are finished.
End of Exercise 5-6
Summary, Tips, and Tricks
• An array is a collection of data elements of the same type. The data elements can be of any type, so you can create numeric, Boolean, string, or cluster arrays.
• Remember that the index value is zero-based so the index representing the first element of an array has a value of zero.
• If an array has no assigned data object, the array terminal will appear
black with an empty bracket.
• Creating an array on the front panel is a two-step process. First, place an
array shell, available on the Controls»Array & Cluster palette, on the
front panel. Then add the desired control or indicator to the shell. • There are many functions to manipulate arrays, such as Build Array and
Index Array, on the Array palette.
• In this lesson, you used array functions to work with only 1D arrays; however, the same functions work similarly with multidimensional arrays.
• Both the For Loop and While Loop can process and accumulate arrays at their borders. This is done by having auto-indexing enabled at the loop tunnels.
• By default, LabVIEW enables auto-indexing in For Loops and disables auto-indexing in While Loops.
• Polymorphism is the ability of a function to adjust to input data of
different data structures.
• Waveform graphs and XY graphs display data from arrays.
• Graphs have many unique features that you can use to customize your plot display. Right-click the graph or its components to access its different plotting options.
• You can display more than one plot on a graph by using the Build Array function, available on the Functions»Array palette, and by using Bundle for charts and XY Graphs. The graph automatically becomes a multiplot graph when you wire the array of outputs to the terminal. • A cluster is a data structure that groups data, even data of different types.
Objects in a cluster are either all controls or all indicators.
• If a VI has many front panel controls and indicators that you need to associate with terminals, you may want to group them into one or more clusters and use fewer terminals.
• Creating a cluster on the front panel or on the block diagram is a two-step process. First, create a cluster shell. Then place the components
• The Bundle and Bundle by Name functions are used to assemble clusters. The Unbundle and Unbundle by Name functions are used to disassemble clusters.
• You can use the polymorphic capabilities of LabVIEW functions with arrays and clusters.
• Try to place items in a cluster that logically or conceptually belong together.
• Use clusters to overcome the 24 terminal limitation on an icon and to group similar inputs and outputs together on a subVI. You can use this technique to group optional inputs on a subVI.
Additional Exercises
5-7 Build a VI that reverses the order of an array containing 100 random numbers. For example, array[0] becomes array[99], array[1] becomes array[98], and so on.
Hint: Use the Reverse 1D Array function, available on the Functions»Array palette, to reverse the array order. Name the VIReverse Random Array.vi.
5-8 Build a VI that first accumulates an array of temperature values using the Process Monitor VI, available on the Functions»User Libraries»Basics I Course palette. The array size is determined by a control on the front panel. Initialize an array, using the Initialize Array function, of the same size where all the values are equal to 10. Then add the two arrays, calculate the size of the final array, and extract the middle value from the final array. Display the
Temperature Array, the Initialized Array, the Final Array, and the Mid Value. Name the VIFind Mid Value.vi.
5-9 Build a VI that generates a 2D array of three rows by 10 columns containing random numbers. After generating the array, index each row and plot each row on its own graph. The front panel should contain three graphs. Name the VIExtract 2D Array.vi.
5-10 Build a VI that simulates the roll of a die with possible values 1–6 and keeps track of the number of times that the die rolls each value. The input is the number of times to roll the die, and the outputs include the number of times the die falls on each possible value. Do this using only one shift register. Name the VIDie Roller.vi.
5-11 Build a VI that generates a 1D array and then multiplies pairs of elements together, starting with elements 0 and 1, and outputs the resulting array. For example, the input array with values 1 23 10 5 7 11 results in the output array 23 50 77. Name the VIArray Pair
Multiplier.vi.
Hint: Use the Decimate 1D Array function, available on the Functions»Array palette.
Challenge