Overview:
The National Instruments LabVIEW graphical development environment helps create flexible and scalable design and control applications for your robot. With LabVIEW, you can:
1. Easily interface with input and output signals
2. Analyze data for meaningful information and advanced control
3. View and interpret results through intuitive displays and user interfaces.
In the field of robotic design, the LabVIEW graphical development environment provides a platform for dynamic system simulation and control design, real-time vision processing, and deployment to various execution targets, including your CompactRIO FRC controller.
The following exercise will provide you with an introduction to the tools and capabilities of LabVIEW. You will gain a general understanding of virtual instrumentation and how to implement code in LabVIEW. Skills include designing a user interface, using loop structures, and simple decision making in code.
Exercise 1: Introduction to LabVIEW
Expected Time to Complete: 10 minutes
Level of Difficulty: Beginner
Description:
LabVIEW programs are called virtual instruments, or VIs. In LabVIEW, you build a user interface, or front panel, with controls and indicators. After you build the user interface, you add code using VIs and structures to control the front panel objects. The block diagram contains this code.
Goal:
In the following exercise, you will build a VI that will add or subtract two numbers, depending on the user specification, and display the result. This exercise does
not use any hardware.
Implementation:
1) Launch LabVIEW
- Go to *Start*>>*Programs*>>National Instruments LabVIEW 8.5.
2) Open a New VI
- In the Getting Started Window, select Blank VI.

3) Add a Control to the Front Panel
- Right-click on the blank space of the front panel to display the Controls palette.
- Move the cursor over icons on the Controls palette to locate the Numeric Controls palette. Click the Knob control on the Numeric Controls palette.

- When you place the knob control on the front panel, its Label is highlighted. Name the numeric control Input A.
4) Repeat Step 3, this time, selecting a Vertical Pointer Slide. Name this control I+nput B+.

You will need to display the result of adding or subtracting these two numbers.
5) Place a Numeric Indicator on the Front Panel.
- Right-click to bring up the Controls Palette. Select Meter from the Numeric Controls palette and name it Result.
6) Change the Scaling of a Front Panel Object
- Double-click the 0 on the indicator and change it to -10.

You will need to specify whether to add or subtract Input A and Input B.
7) Add a Boolean Control to the Front Panel
- Right-click and navigate to the Boolean Controls palette. Select a Vertical Toggle Switch.

You can easily modify the appearance of front panel objects using the Positioning Tool, as shown below.
8) Change the size of a Front Panel object.
- Hover over the Vertical Toggle Switch until the Positioning Tool appears.

- Click on the Vertical Toggle Switch to select the front panel object. Drag the double-arrow-Positioning Tool to resize the Vertical Toggle Switch.

9) Change the labeling of a Front Panel Object.
- Right-click the Vertical Toggle Switch. In the fly-out menu, select Visible Items and uncheck Label.

- Create a floating label for the Vertical Toggle Switch by double-clicking anywhere on the Front Panel. Type Add and position this label at the top-right of the Vertical Toggle Switch. Repeat this step to place a Subtract label at the bottom-left of the Vertical Toggle Switch.

10) Increase the font of the Front Panel object labels.
- Select text using the Positioning Tool and Press <Ctrl+=> to incrementally increase font size.

11) Continue to use the Positioning Tool to edit and position the front panel objects. Your front panel should look something like that seen below.

12) Switch to the block diagram window
- Go to Window>>Show Block Diagram.
You will need a method of selecting between adding and subtracting Input A and Input B. You will use the Boolean Control to specify this in your code.
13) Place a Case Structure on the Block Diagram
- Right Click on the block diagram to reveal the Functions Palette. Hover the mouse to reveal the Structures Palette and select the Case Structure.

- Click and drag the cursor to place the Case Structure to left of the Boolean control on the block diagram.

In the Case Structure, only one subdiagram is visible at a time and the structure executes only one case at a time; an input value determines which subdiagram executes. The Case structure is similar to switch statements or if…then…else statements in text-based programming languages.
14) If the Boolean control is True, your code should add Input A and Input B. If False, your code should subtract Input B from Input A.
- Hover the cursor over the terminal of the Boolean control until the Wiring Tool appears. Wire the Boolean control to the input of the Case structure.

- Place an Add function from the Numeric palette in the Function palette in the True case subdiagram of the Case Structure.

- Wire the values from Input A and Input B through the left-hand side of the Case Structure to the inputs of the Add function.

- Wire the output of the Add function to the right-hand side of the Case structure.
- Click the case selector label at the top of the Case structure to show the False case subdiagram.

- Place a Subtract function in the False case subdiagram. Wire the values from Input A and Input B through the left-hand side of the Case Structure to the inputs of the Subtract function.

- Wire the output terminal from the Case structure to Result. Your block diagram should look something like as follows:

As you change the value of Input A and Input B, you want Result to update continuously.
Similar to a Do Loop or a Repeat-Until Loop in text-based programming languages, a While Loop executes a subdiagram until a condition occurs. Specifically, a While Loop executes the subdiagram until the conditional terminal receives a specific Boolean value. You will use a While Loop to update Result until the user specifies for the program to stop.
15) Repeat the add/subtract algorithm until the user selects to stop execution.
- Place a While Loop from the Structure Palette around the block diagram logic.

- Right-click the terminal on the Stop Condition in the bottom right corner of the While Loop and select Create Control.

- Your block diagram should now look as follows:

Testing
1) Display the front panel
- Switch to the front panel by pressing <Ctrl+e>. The front panel should now have the Stop button you created for your While Loop.
2) Run your VI and observe the program functionality.
- Click the Run button at the top of the screen. The arrow will change to indicate that the VI is running.

- Change the values of the front panel numeric controls and toggle the Boolean switch to change the behavior of the program.
- Observe the Result shown in the Meter indicator.
- Click stop to end the program.
- Close the VI when finished and do not save any files.
Very nice beginning example program.