12
TETRIX ® Mastery with LabVIEW Summary What is LabVIEW? LabVIEW is a graphical programming language. It allows code to be visually organized in comparison to traditional text-based programming. The LabVIEW programming language consists of many functions, inputs, and outputs, which are physically connected with wires to create a program. LabVIEW for LEGO ® MINDSTORMS ® has been specifically tailored to work with the LEGO MINDSTORMS NXT system, containing many functions specific to the device. This makes programming LEGO MINDSTORMS and TETRIX robots very straightforward in LabVIEW. LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program with the file extension .vi is a LabVIEW program file. What is the NXT Brick? The NXT Brick is a small computer which has three motor outputs, a display screen, four sensor inputs, and four buttons. This brick can store and execute programs files that have a .rxe extension. When LabVIEW compiles and sends a program to the robot, it is of this file type. The NXT Brick is built upon using LEGO MINDSTORMS and TETRIX ® elements to create a functioning robot that the user can program to complete a variety of tasks. Getting Started The Getting Started window is the first to appear when LabVIEW for LEGO MINDSTORMS starts. This window gives you the option to: To create a new robot project, click Create Program. In the window that opens, select the Robot Project template and under the Robot Project heading, select one of the configurations, or choose Blank Robot to make a unique robot configuration. For these lessons, the FTC Arm & Gripper Robot Project will be used. Introduction to LabVIEW™ Open existing programs. Create new programs. Find help. Complete LabVIEW challenges. Take LabVIEW tutorials. Open recent files. 1

Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Embed Size (px)

Citation preview

Page 1: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

What is LabVIEW?

LabVIEW is a graphical programming language. It allows code to be visually organized in comparison to traditional text-based programming. The LabVIEW programming language consists of many functions, inputs, and outputs, which are physically connected with wires to create a program.

LabVIEW for LEGO® MINDSTORMS® has been specifically tailored to work with the LEGO MINDSTORMS NXT system, containing many functions specific to the device. This makes programming LEGO MINDSTORMS and TETRIX robots very straightforward in LabVIEW.

LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program with the file extension .vi is a LabVIEW program file.

What is the NXT Brick?

The NXT Brick is a small computer which has three motor outputs, a display screen, four sensor inputs, and four buttons. This brick can store and execute programs files that have a .rxe extension. When LabVIEW compiles and sends a program to the robot, it is of this file type. The NXT Brick is built upon using LEGO MINDSTORMS and TETRIX® elements to create a functioning robot that the user can program to complete a variety of tasks.

Getting Started

The Getting Started window is the first to appear when LabVIEW for LEGO MINDSTORMS starts. This window gives you the option to:

To create a new robot project, click Create Program. In the window that opens, select the Robot Project template and under the Robot Project heading, select one of the configurations, or choose Blank Robot to make a unique robot configuration. For these lessons, the FTC Arm & Gripper Robot Project will be used.

Introduction to LabVIEW™

Open existing programs.

Create new programs.

Find help.Complete LabVIEW challenges.

Take LabVIEW tutorials.

Open recent files.

1

Page 2: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Click Create, give the Robot Project a name, and choose an appropriate directory in which to save it.

Robot Project Center

Once a new project is created, the Robot Project Center will appear. This is the robot project specific to the FTC Arm & Gripper Bot:

Introduction to LabVIEW™

Open the Schematic Editor.

Choose an NXT Brick to connect to.

Contains a link to the NXT Terminal, Data Viewer, and to more applications to choose from.

Create a new VI in the project.

Add an existing VI to the project.

View all VIs in the project.

Create a new Remote Configuration.

2

Page 3: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

Introduction to LabVIEW™

Connecting to the NXT Brick

It is important to be connected to the correct NXT in the Robot Project Center, as this cannot be changed in any VI that is opened. However, if this step is missed, the Robot Project Center window will remain open, and the connection can always be made at a later time. No program can run on the NXT until this has been completed.

To connect to an NXT Brick, first ensure that the brick is on and is either connected with a USB cable or has the Bluetooth™ both On and Visible. Next, select the correct brick from the Choose NXT menu. If it does not appear here, select the Find NXT… option.

To create a new program, click New VI and choose VI for NXT Target to target the program to the NXT Brick. If the correct option is not chosen, the correct function palettes may not be available once the blank VI opens.

Front Panel

The Front Panel is the grey window that appears. This is where controls and indicators are visible while a program runs. The Controls palette can be accessed by right-clicking anywhere on the front panel, and chosen controls can be dragged and placed in the necessary position. To be able to use controls and indicators on the front panel with the NXT Brick, the program must be run in Debug Mode to maintain communication with the brick throughout the execution of the program.

Controls are inputs, and Indicators are outputs, meaning that controls give values to a function, and indicators receive values from a function. Controls are therefore used to set certain values in a program, and indicators are used to display information received from the program.

Block Diagram

The Block Diagram is where the code for the program is placed. To access the block diagram from the front panel, either choose Show Block Diagram from the Window menu, or press Ctrl-E on the keyboard. The toolbar at the top of the block diagram (also visible on the front panel) is used to control the program.

The Functions palette can be accessed by right-clicking the block diagram. This is where all the functions necessary to create a program reside. Functions can be chosen and placed anywhere on the block diagram.

Functions

Each function has terminals that connect to other functions with wires. Generally, inputs are located on the left side of the function and outputs are on the right. Some inputs are on the top of the function, such is the case with motor and sensor functions.

Inputs to functions are often set as constants. A constant is a number set before the program executes which does not change at any point during the program. To create a constant for any function input terminal, right-click the terminal and select Create >> Constant.

Wiring

When building code, it is helpful to keep all wires connecting functions clean and organized. Wires can be moved easily by clicking and dragging them or by clicking and then using the arrow keys on the keyboard to move them.

Also note that differences in the appearance of wires represent the different types of data they carry:

• A blue wire passes an integer value.• An orange wire passes a numeric value (containing a decimal).• A green wire passes a Boolean value (TRUE or FALSE).• A pink wire passes a string value (words and letters).• A thick wire passes an array of values.

Palettes

Important sub-palettes that will be used to program NXT robots include NXT I/O and TETRIX®, which are found in the functions palette.

3

Page 4: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Introduction to LabVIEW™

Context Help

This very useful tool in LabVIEW™ can be accessed by going to the Help menu and selecting Show Context Help, or by pressing Ctrl-H. When a function is hovered over, a labelled diagram, brief description, and a link to more detailed information about that function is displayed. The diagram shows what is required for each input and output for that function. Any input that is bold in the diagram is a required input.

Deploying Code

The toolbar at the top of the block diagram or front panel is used to control and run programs.

Run

This button compiles the code, sends it to the NXT Brick, and runs the code on the NXT immediately, but does not maintain the connection between the brick and the computer while the code is executing.

Deploy

This button compiles the code and sends it to the NXT Brick, but does not run the program.

Debug

This button compiles the code, sends it to the NXT Brick, and runs the code on the NXT immediately while maintaining the connection between the brick and the computer throughout the execution of the program. When using controls on the front panel to control a robot, Debug Mode must be used.

Errors

If there are any problems with your code, the Run button at the top will appear as a broken arrow. If this is clicked, a list of errors will appear in a new window.

4

Page 5: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

Summary Programming Guide

Introduction:

In this guide, basic programming concepts within the LabVIEW™ for LEGO® MINDSTORMS® programming language will be reviewed. The FTC Arm & Gripper Bot will be programmed to respond to sensors, and make decisions based on sensor input. Basic motor and servo movement and the use of controls and indicators will also be explored.

Getting Started:

1. Open the Robot Project Center and click Create Program. Under Templates, select Robot Project, and under Robot Project, select FTC Arm & Gripper. Click Create.

2. Select Programs from the Robot Files menu, then click New VI on the right side of the window and choose the VI for NXT Target option. Name this VI when prompted, and click Create. A blank VI will open.

Reading Sensors:

3. Begin the program by placing a function to read the touch sensor on the block diagram.

a. Select the Read Sensor function from the NXT I/O sub-palette and place it on the block diagram.

b. From the polymorphic selector at the bottom of the function, select Read Touch >> Pressed.

c. Create a constant for the Port terminal, and set it to the correct port number. For the FTC Arm & Gripper Bot, this should be set to Port 4.

5

Page 6: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Summary Programming Guide

Using a While Loop

4. In order for the robot to continually check the touch sensor, instead of checking it just once and ending the program, create a While Loop around the touch sensor. This will cause the code contained to execute repeatedly, until a certain condition is met.

a. From the NXT Programming sub-palette, under Structures, choose While Loop.

b. Drag the loop around the existing code.

Using a Case Structure:

5. Place a Case structure beside the Read Touch function to make a decision based on the status of the touch sensor.

a. From the NXT Programming sub-palette, under Structures, choose Case structure.

6

Page 7: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

Summary Programming Guide

b. Drag the mouse to create space within the Case structure.

c. Wire the Yes/No terminal of the Read Touch function into the Case selector of the Case structure.

Moving the Servos:

6. Inside the True case of the Case structure, build code to make the robot’s arm and gripper servos to go to positions 255 and 100, respectively.

a. From NXT Robotics under TETRIX®, choose the TETRIX Move Servos function.

b. Place this function within the Case structure.

7

Page 8: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Summary Programming Guide

c. Create a constant for the servo motors by right-clicking the Servos terminal, and selecting Create Constant. Expand the constant that appears by pressing the down arrow below the unselected motor. From the drop-down menu, choose Gripper for the first constant and Arm for the second.

d. Create constants wired into the Position 1 and Position 2 terminals. Set the Position 1 constant to 100 and the Position 2 constant to 255. This will move to the Gripper servo to a position of 100 and the Arm to a position of 255, when the touch sensor is in the pressed state.

7. Create a wait function to allow half a second for them to get into position before continuing the program.

a. From the NXT I/O sub-palette, choose Wait For.

b. Place the Wait function next to the TETRIX® Move Servos function, inside the Case structure. From the polymorphic selector, choose Wait For Time >> msec.

8

Page 9: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

Summary Programming Guide

c. Create a constant set to 500 wired to the Time terminal of the wait function. This will instruct the robot to wait for 500 milliseconds, or half a second.

Reading the Ultrasonic Sensor:

8. Build the code which will stop the While Loop when the ultrasonic sensor reads a value of less than 10 cm, signalling that an object is directly in front of the sensor. Since there is no code outside the While Loop, when the loop is terminated, the program will end.

a. Place a Read Sensor block next to the Case structure, and choose Read Ultrasonic from the polymorphic selector.

b. Create a constant in the Port terminal set to Port 2.

c. From the NXT Programming sub-palette, under Comparison, choose Less?.

9

Page 10: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Summary Programming Guide

d. Place the Less? function next to the Read Ultrasonic function, and wire the Distance output terminal into the top terminal, labelled x, of the Less? function.

e. Create a constant wired to the bottom terminal, labelled y, of the Less? function. Wire the output of the Less? function to the Loop Condition terminal of the While Loop.

Complete the Code:

9. Wire the NXT Terminals of each NXT function to ensure the tasks are carried out in the correct sequence. Ensure to wire through both cases of the Case structure.

Modify the Code:

Move the DC Motors in Place of the Servos:

1. Create a TETRIX® Move DC Motors function by selecting it from the TETRIX palette in NXT Programming.

2. Create a constant wired to the Motor terminal. Expand the constant and set the motors to Right Wheel and Left Wheel.

10

Page 11: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

TETRIX® Mastery with LabVIEW™Summary

Summary Programming Guide

3. Create constants wired to the Power/Speed 1 and Power/Speed 2 terminals. This will be the drive motor power. If the robot is to go straight forward or straight backward, one constant can be wired into both terminals, as the right and left motors will need to have the same power.

4. It is important to remember that the TETRIX DC Motors do not turn off until they receive a command to do so. For this rea-son, any time a TETRIX Move DC Motors command is used, a TETRIX Stop DC Motors command should also be incorpo-rated into the program. The motor constants are wired to the same position in both functions. Note that the same motor constants can be used for both functions to save space.

Create a Control and Indicator:

• To control a value in the program manually from the Front Panel, a control must be added. A control is added to a function in the place of a constant.

• To view a value in the program on the Front Panel, an indicator must be added. An indicator is wired to the output of a function.

1. Add a numeric control by right-clicking the Front Panel and selecting one of the control options in the Numeric palette. For this exercise, one of the slider options is recommended. Notice that a new function also appears on the block diagram when this control is placed on the front panel. Note that the control can be renamed by clicking the current name and typ-ing a new one.

Notice that the control has DBL at the bottom of the icon that appears on the block diagram. This shows the representation of the value stored, in this case, a double precision representation. This can be changed to a different type of representa-tion by right-clicking the icon on the block diagram or the control on the front panel, and selecting one of the options under Representation.

2. Add a Numeric Indicator on the Front Panel from the top row of the Numeric palette. This displays values that are passed to it. Notice that another new function appears on the block diagram. Place this function just to the right of the control, leav-ing a little space in between to place one more function.

Notice that the control has an arrow on the right side of the function, and the indicator has an arrow on the left. This is because a control only has an out put terminal, and an indicator only has an input.

11

Page 12: Introduction to LabVIEW™ - TETRIX Robotics · LabVIEW programs are saved as a VI, which stands for Virtual Instrument. Programs made in LabVIEW are often referred to as VIs. A program

Summary TETRIX® Mastery with LabVIEW™

Summary Programming Guide

3. If the control was directly wired to the indicator and the program run, the indicator would simply read the value the control has been set to. Place an Add function between the control and indicator. Connect the output of the control to one of the inputs of the add function, and the output of the add function to the input of the indicator. Create a constant for the other input terminal of the Add function, and set it to a value. The indicator on the front panel will now display the result of the control added to the constant that has been set when the program is run.

4. To change the range of the control, right-click it on either the block diagram or the front panel and choose the Properties option. Select the Scale tab at the top. The range can be changed in the Scale Range section of the window. Click OK to apply the changes.

12