labview & frc

93
LabVIEW & FRC BAA Fall Education Day 2015

Upload: haminh

Post on 02-Jan-2017

231 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: LabVIEW & FRC

LabVIEW & FRC

BAA Fall Education Day 2015

Page 2: LabVIEW & FRC

Who am I?

Jayesh Jariwala, P.E.

Univ of Delaware BChE ‘98

Process control engineer for 17+ years

Working at Applied Control Engineering, Inc

FRC Mentor for 6 years (Teams 1893 & 2528)

Page 3: LabVIEW & FRC

LabVIEW & FRC Outline

LabVIEW Environment

Programming Principles

Software Constructs / Structures

State Machines

Default robot and dashboard logic

Basic autonomous

Resources

Page 4: LabVIEW & FRC

FRC Control System: LabVIEW and roboRIO

• FIRST Robotics Competition: FIRST standardizes on NI CompactRIO hardware powered by NI LabVIEW software

Adoption of a Progressive Programming Platform

Page 5: LabVIEW & FRC

Role of the Controller

Autonomous

– Motor/actuator control

– Motion control

– Path control

– Object avoidance

Teleoperated

– Driver station input processing

– Telemetry back to console

– “Action” control

– Motion smoothing

Page 6: LabVIEW & FRC

Easy to Program

Programmable in C, Java, and LabVIEW

Wireless debugging

Laptop dashboard

Page 7: LabVIEW & FRC

Software Development Fundamentals

Page 8: LabVIEW & FRC

Software Development Method

1. Define the problem (scenario)

2. Design an algorithm and/or flowchart

3. Implement the design

4. Test and verify the implementation

5. Maintain and update the implementation

Page 9: LabVIEW & FRC

Define the Problem

Furnace Example

You need to design a furnace system to keep a building within a comfortable temperature range. For simplicity, the building has only a furnace and no air conditioning.

Page 10: LabVIEW & FRC

Design a Flowchart and/or Algorithm

Page 11: LabVIEW & FRC

Steps to Design a Flowchart

1. List all your inputs, outputs, and additional requirements

2. Define the possible states (nodes) and actions in each state

3. Define your state (node) transitions

4. Draw a flowchart linking the states (nodes)

Page 12: LabVIEW & FRC

Design a Flowchart—Furnace

This application has the following requirements:

• The interior temperature must remain within a set range: 70 –75 °F

• The heater turns on when the temperature is less than 70 °F and heat the room up until the temperature is 75 °F

• There is no AC to control

Page 13: LabVIEW & FRC

Example—Furnace

Transition/Decision

State and Action Related to State

Page 14: LabVIEW & FRC

Example (Advanced)—Coke Machine

This application has the following requirements:

• All Coke products are sold for 50 cents

• The machine accepts only nickels, dimes, and

quarters

• Exact change is not needed

• Change can be returned at any time during the

process of entering coins

• Only Coke is sold in machine (no buttons to select

other beverage)

Page 15: LabVIEW & FRC

Example (Advanced)—Coke Machine

Action Related to State

Transition

State

Page 16: LabVIEW & FRC

Example—Robot: Remote Control

This application has the following requirements:

• Robot must navigate a field with obstacles and

other robots and press a button that can be

reached only by an extendable arm

• There is a line on the course that marks a clear

path from the robot’s starting position to the

button’s location

• Manual/Teleoperated mode only

Page 17: LabVIEW & FRC

Example—Robot: Remote Control

Page 18: LabVIEW & FRC

Example—Robot: Autonomous

This application has the following requirements:

• Robot must navigate a field with obstacles and

other robots and press a button that can be

reached only by an extendable arm

• There is a line on the course that marks a clear

path from the robot’s starting position to the

button’s location

• Autonomous mode only

Page 19: LabVIEW & FRC
Page 20: LabVIEW & FRC

Introduction to NI LabVIEW

Page 21: LabVIEW & FRC

Compiled graphical development environment

Development time reduction of four to ten times

Tools to acquire, analyze, and present your data

What is LabVIEW? Laboratory Virtual Instrumentation Engineering Workbench

Page 22: LabVIEW & FRC

What is LabVIEW?

Speak G

– Graphical programming language

Go with the flow

– Dataflow programming

Easy writing

– Easy to learn

– Powerful debugging tools

Page 23: LabVIEW & FRC

Each VI has 2 windows

Front panel • User interface (UI)

– Controls = inputs – Indicators = outputs

Block diagram • Graphical code

– Data travels on wires from controls through functions to indicators

– Blocks execute by data flow

LabVIEW Programs Are Called Virtual Instruments (VIs)

Page 24: LabVIEW & FRC

Controls Palette (Controls and Indicators)

Indicator:

Numeric Slide

Control:

Numeric

Customize Palette View

Page 25: LabVIEW & FRC

Functions (and Structures) Palette

(Place items on the Block Diagram Window)

Structure:

While Loop

Page 26: LabVIEW & FRC

Types of Functions (from the Functions Palette) Express VIs: Interactive VIs with configurable dialog page (blue border)

Standard VIs: Modularized VIs customized by wiring (customizable)

Functions: Fundamental operating elements of LabVIEW; no front panel or block diagram (yellow)

Page 27: LabVIEW & FRC

• Recommended: Automatic Selection Tool • Tools to operate and modify both front panel and block diagram objects

Operating Tool

Positioning/Resizing Tool

Labeling Tool

Wiring Tool

Automatic Selection Tool

Automatically chooses among the following tools:

Tools Palette

Page 28: LabVIEW & FRC

Run Button Continuous Run Button Abort Execution

Execution Highlighting Button

Additional Buttons on the Diagram Toolbar

Retain Wire Values Button

Step Function Buttons

Status Toolbar

Page 29: LabVIEW & FRC

Debugging Techniques • Finding Errors

• Execution Highlighting

• Probes

Click on broken Run button.

Window showing error appears.

Click on Execution Highlighting button; data flow is animated using bubbles. Values are displayed on wires.

Right-click on wire to display probe; it shows data as it flows through wire segment. You can also select the Probe tool from the Tools palette and click on the wire.

Page 30: LabVIEW & FRC

Context Help Window

Help»Show Context Help or press <Ctrl-H>

Hover cursor over object to update window

Additional Help

–Right-click on the VI icon and choose Help, or

–Choose “Detailed Help.” on the context help window

Page 31: LabVIEW & FRC

• Block diagram execution

– Dependent on the flow of data

– Block diagram does NOT execute left to right

• Node executes when data is available to ALL input terminals

• Nodes supply data to all output terminals when done

Dataflow Programming

Page 32: LabVIEW & FRC

Dataflow Programming

Page 33: LabVIEW & FRC

Data Types Found in LabVIEW

Page 34: LabVIEW & FRC

LabVIEW Shortcuts and Tools

<Ctrl-R>: Run the VI

<Ctrl-E>: Swap between front panel and block diagram

<Ctrl-H>: Turn on context help

<Ctrl-B>: Remove broken wires

<Ctrl-Z>: Undo

View»Navigation Window or Ctrl-Shift-N

Tools»CompactRIO Imaging Tool…

Tools»Setup Axis Camera

Tools»Options

Page 35: LabVIEW & FRC

Wires

• Transfer data between block diagram objects

• Wires are different colors, styles, and thicknesses, depending on data type

• A broken wire appears as a dashed black line with a red X in the middle

Block Diagram

Terminals

• Block Diagram appearance of front panel objects

• Entry & exit ports that exchange information between the front panel and block diagram

• Analogous to parameters and constants in text- based programming languages

Scalar 1D Array 2D Array

DBL Integer Numeric Numeric String

Page 36: LabVIEW & FRC

• Press <Ctrl>-B to delete all broken wires

• Right-click and select Clean Up Wire to reroute the wire

• Use the Clean Up Diagram tool to reroute multiple wires and objects to improve readability

• Select a section of your block diagram

• Click the Clean Up Diagram button on the block diagram toolbar (or <Ctrl>-U)

36

Block Diagram: Wiring Tips

Page 37: LabVIEW & FRC

Key LabVIEW Structures for FIRST

• Project Explorer

• Clusters

• Loops

• Case Structure

• Shift Registers

• Enums

• State Machines

Page 38: LabVIEW & FRC

Group and organize VIs

Manage hardware and I/O

Manage large LabVIEW applications

Manage VIs for multiple targets

Determine which code is running on laptop versus which code is running on CompactRIO hardware

(LabVIEW»Project»New)

LabVIEW Project

Robot Main.vi runs on the CompactRIO target since the VI falls under RT CompactRIO Target. Code under “My Computer” runs on the laptop.

You also can verify the program target by looking at the bottom left of the VI’s front panel .

Page 39: LabVIEW & FRC

Introduction to Clusters

Data structure that groups data together

Data may be of different types

Elements must be either all controls or all indicators

Thought of as wires bundled into a cable Easier to bundle wires together and pass around as a group rather than wire each individually

Order is important

Page 40: LabVIEW & FRC

Cluster Functions • In the Cluster & Variant subpalette of the Programming functions palette

• Can also be accessed by right-clicking the cluster terminal

(Terminal labels reflect data type)

Page 41: LabVIEW & FRC

Loops While Loop For Loop

Run until stop condition met Run N times

• Allow same piece of code to run multiple times

• Exit conditions different for each

Page 42: LabVIEW & FRC

1. Select the structure

2. Enclose code to be repeated

3. Drop or drag additional nodes and then wire

Drawing a Loop

Page 43: LabVIEW & FRC

1. Case Structures

2. Select

(a) (b)

(c)

How Do I Make Decisions in

LabVIEW?

Page 44: LabVIEW & FRC

Shift Register—Access Previous Loop Data

• Available at left or right border of loop structures

• Right-click the border and select Add Shift Register

• Right terminal stores data on completion of iteration

• Left terminal provides stored data at beginning of next iteration

Before Loop Begins

First Iteration

Second Iteration

Last Iteration

Value 3 Initial Value

Page 45: LabVIEW & FRC

Enum • An enum

represents a pair of values, a string, and a numeric, where the enum can be one of a defined list of values

Page 46: LabVIEW & FRC

Enum • Enum: enumerated

control, constant, or indicator

• Enums are useful because it is easier to manipulate numbers than strings on the block diagram

Page 47: LabVIEW & FRC

A state machine consists of a set of states and a transition function that maps to the next state

LabVIEW State Machine

While Loop

Case Structure Shift Register

Page 48: LabVIEW & FRC

A state machine consists of a set of states and a transition function that maps to the next state

LabVIEW State Machine

While Loop

Case Structure “Heater On” state shown.

Shift Register

Page 49: LabVIEW & FRC

Create SubVI Enclose area to be converted into a subVI

Select Edit»Create SubVI from the Edit menu

Page 50: LabVIEW & FRC

Connector Pane and Icon Viewer

Use this connector pane layout as a standard

Top terminals are usually reserved for file paths and references, such as a file reference

Bottom terminals are usually reserved for error clusters

Page 51: LabVIEW & FRC

Icon Viewer—Create an Icon

Create custom icons by right-clicking the icon in the upper-right corner of the front panel or block diagram and selecting Edit Icon or by double-clicking the icon

You also can drag a graphic from anywhere in your file system and drop it on the icon

Refer to the Icon Art Glossary at ni.com for standard graphics to use in a VI icon

Page 52: LabVIEW & FRC

How Do I Time a Loop? 1. Loop Time Delay

• Configure the Time Delay Express VI for a number of seconds to wait each iteration of the loop (works on For and While loops)

2. Timed Loops

Configure special-timed While Loop for desired dt

Timed Loop Time Delay

Page 53: LabVIEW & FRC

Charts—Add 1 Data Point at a Time With History

Waveform chart—Special numeric indicator that can display a history of values

Chart updates with each point it receives

Controls»Express»Graph Indicators»Chart

Page 54: LabVIEW & FRC

Graphs—Display Many Data Points at Once

Waveform graph—Special numeric indicator that displays an array of data

• Graph updates after all points have been collected

• May be used in a loop if the VI collects buffers of data

Controls»Express»Graph Indicators»Graph

Page 55: LabVIEW & FRC

• Loops can accumulate

arrays at their boundaries

with

auto-indexing

• For Loops auto-index by

default

• While Loops output only

the final value by default

• Right-click tunnel and

enable/disable auto-

indexing

Building Arrays With Loops (Auto-Indexing)

Wire becomes thicker

Wire remains the same size

Auto-Indexing Disabled

Auto-Indexing Enabled

Only one value (last iteration) is passed out of the loop

1D Array

0 1 2 3 4 5

5

Page 56: LabVIEW & FRC

Creating an Array (Step 1 of 2) From the Controls»Modern»Array, Matrix, and Cluster subpalette, select the Array icon.

Drop it on the front panel.

Page 57: LabVIEW & FRC

Create an Array (Step 2 of 2) 1. Place an array shell.

2. Insert data type into the shell (for example, numeric control).

Page 58: LabVIEW & FRC

Using Arrays and Clusters With Graphs

The waveform data type contains 3 pieces of data:

t0 = Start time

dt = Time between samples

Y = Array of Y magnitudes

You can create a waveform cluster in two ways:

Build Waveform (absolute time) Cluster (relative time)

Page 59: LabVIEW & FRC

Programming an FRC Robot

Page 60: LabVIEW & FRC

Understanding Robot Main.vi

Page 61: LabVIEW & FRC

Robot Main Block Diagram

SubVIs

Case Structure

While Loop

Sequence Structure

Global Variables Controls (From Front Panel)

Page 62: LabVIEW & FRC

Robot Main—Flowchart View

Page 63: LabVIEW & FRC

Begin.vi

Its purpose is to initialize and define all of the motors, sensors, I/O, and other items connected to your robot.

Every time you use a device, you must initialize/open it in the Begin VI and give it a name.

(Also in Finish.VI later)

Page 64: LabVIEW & FRC

The green Booleans control the orientation of the motors.

The two blue enums correspond to the PWM output ports on the robot.

Motor Configuration (Within Begin.vi)

Page 65: LabVIEW & FRC

Motor Reference Registry Set (Within Begin.VI)

The pink string refers to the refnum name given to the device. Here “Left and Right Motors” will be called later in the program to access these Jaguar motor controllers.

The Drive Reference Registry Set VI sets a reference into a registry so that other VIs can call the reference.

Page 66: LabVIEW & FRC

TeleOp.vi

To view Teleop.vi in Robot Main, select Teleop Enabled in the case structure.

It is called each time a teleop driver station packet is received and robot is enabled.

Teleop is the subVI that contains the code that you can use to drive the robot with the joystick. You can program Teleop code in this subVI.

Page 67: LabVIEW & FRC

Autonomous Independent.vi

The Autonomous Independent.vi is automatically started when the autonomous mode begins and automatically ended when the autonomous mode ends.

This is where the code executed during autonomous mode is contained.

Page 68: LabVIEW & FRC

Autonomous Independent.vi

In the default code, there are three While Loops. These loops turn the robot right, turn the robot left, and stop the robot, respectively.

The data is wired sequentially from one loop to another. It is important to note that the code runs in the same sequence as it is wired. The second While Loop does not run until the first loop is finished.

Page 69: LabVIEW & FRC

Finish.vi

Finish SubVI is called before exiting, so you can save data, clean up I/O, and so on.

If a new device (for example, a joystick) was added to Begin VI, you must close this device in Finish VI.

Page 70: LabVIEW & FRC

Close Motor Reference (Within Finish VI)

To close a motor reference, use a Drive Reference Get VI and a Drive Reference Close VI.

Follow a similar structure for other devices such as joysticks, cameras, and so on.

Page 71: LabVIEW & FRC

LabVIEW FRC Installation Shortcuts

When you install LabVIEW on your computer, you are going to find four different icons:

• FRC LabVIEW Icon

– Opens the LabVIEW program

• FRC cRIO Imaging Tool

– Opens the cRIO Imaging Tool, which sets the cRIO IP address and updates the firmware image

• FRC Driver Station Icon

– Opens the Driver Station, which handles the communication between the computer and the robot

• Setup Axis Camera

– Opens the Setup Axis Camera tool, which is used for configuring the axis camera

Page 72: LabVIEW & FRC

Getting Started

When you open the LabVIEW program, a Getting Started Window pops up.

Getting started tutorials for FRC are provided on the right side of the Getting Started Window. The tutorials include plenty of useful information.

To start a new FRC LabVIEW project, click FRC cRIO Robot Project on the left side of the window.

Page 73: LabVIEW & FRC

Create New FRC Robot Project

Here, you can change

– Project name

– Project location

– cRIO IP address

Page 74: LabVIEW & FRC

Project Explorer The Project Explorer opens after creating the new FRC robot project

You can use the Project Explorer Window to create and edit LabVIEW projects

All code included in the FRC robot project default template is listed under the Items tab

To start modifying the robot code, expand RT CompactRIO Target and double-click Robot Main.vi

Page 75: LabVIEW & FRC

Robot Main.VI

Page 76: LabVIEW & FRC

Deploying Code to Robot

You can run the Arcade Drive with the default FRC robot code provided

Always run the RobotMain.vi

To deploy the code to the CompactRIO target, click Run in the top left corner.

Stage 1 Stage 2 Stage 3 develop download deploy

Page 77: LabVIEW & FRC

FRC Driver Station

Before running the Arcade Drive using the default FRC robot code, you need to open the FRC Driver Station.

The FRC Driver Station handles the communication between the computer and the robot.

When the lights of the Communications, Robot Code, and the Stop Button turn green, the robot is ready to run.

Select Teleoperated and then click Enable to start the robot.

Page 78: LabVIEW & FRC

Adding Joystick Controls

Done within Teleop SubVI

The Drive Reference Get VI gets the reference and passes it to the Arcade Drive VI

The Joystick Reference Get VI gets the reference and sends it to Joystick Get VI

The Joystick Get VI gets the user input value of the joystick axes and sends out a cluster

The cluster is unbundled using the Unbundle by Name function to get the values of the x and y axes; values are sent to the Arcade Drive VI

Page 79: LabVIEW & FRC

Adding Joystick Controls

The Joystick Get VI outputs the values of the buttons as a Button cluster.

To access data in a cluster, you need to insert an Unbundle by Name function.

To do this, right-click on the block diagram and click the Cluster, Class & Variant palette. Then click Unbundle by Name and wire this up to the button output of the Joystick Get VI.

Page 80: LabVIEW & FRC

FRC Robot Exercise 2: Add Joystick Controls

Tasks • Modify code in Teleop SubVI • Add joystick button to momentarily stop

motors • Implement decision making with case

structure • Extract value from cluster read from

joystick

Page 81: LabVIEW & FRC

Adding Joystick Controls

In the False Case (when Button 1 is not pressed), the motors should keep running.

In the True Case (when Button 1 is pressed), the motors should stop. Therefore, the x- and y-axis values should be zero.

Page 82: LabVIEW & FRC

Adding a New Device

Every time you add a device, you must initialize/open it in the Begin VI and give it a name.

If a new device (for example, a motor or joystick) was added to Begin VI, you must also close this device in Finish VI.

The device can then be communicated to in Teleop or Autonomous SubVIs.

Note: In the last exercise, we didn’t need to initialize or finish the joystick device when adding a button since this was already done in the template provided.

Page 83: LabVIEW & FRC

FRC Robot Exercise 3: Add a Servo Motor

Tasks • Initialize the new servo motor by

modifying Begin SubVI • Modify the Teleop SubVI to use the

joystick to move the new servo motor • Modify the Finish SubVI to close the

reference of the new servo motor

Page 84: LabVIEW & FRC

Adding a Servo Motor The value of the y-axis ranges from –1 to 1, and the range of the servo angle is from 0 to 170 degrees.

Hence the formula is (User Input + 1) * 85 = Servo Angle

Page 85: LabVIEW & FRC

FRC Robot Exercise 4: Add a Digital Input as Limit Switch

Tasks • Initialize the new limit switch using digital

input by modifying Begin SubVI • Modify the Teleop SubVI to read the digital

input to monitor if the switch has been pressed

• Modify the Finish SubVI to close the reference of the digital line for the limit switch

BONUS: Modify the code to use both the limit switch on the robot and the joystick button to stop the robot.

Page 86: LabVIEW & FRC

Adding a Digital Line for a Limit Switch Remember: Code is inverted on the limit switch. When it is pressed (or closed), the output value is False. When the

limit switch is not pressed (open), the output value is True.

Page 87: LabVIEW & FRC

Adding a Digital Line for a Limit Switch BONUS: Use a Boolean OR to use either the joystick button or the limit switch.

Page 88: LabVIEW & FRC

Additional Resources and Next Steps

Page 89: LabVIEW & FRC

Ensuring Success

• ni.com/first

• Ask support questions— monitored by applications engineers

• Access training materials and tech documentation

• Interact with other teams and mentors

Join the NI FIRST Community online

Page 90: LabVIEW & FRC

Additional Resources NI Academic Web and Student Corner

– ni.com/academic

Connexions: Full LabVIEW Training Course

– cnx.rice.edu

– Or search for “LabVIEW basics”

LabVIEW Certification

– LabVIEW Fundamentals Exam (free on ni.com/academic)

– Certified LabVIEW Associate Developer Exam (industry-recognized certification)

Get your own copy of the LabVIEW Student Edition

– ni.com/academic

National Instruments FIRST Website

– ni.com/first By Robert H. Bishop

Published by Prentice Hall

Page 91: LabVIEW & FRC

Your Next Step…

Take the Free LabVIEW Fundamentals Exam at ni.com/academic

Visit NI’s FRC Website and Network with Other FIRST Participants

ni.com/first

Visit the FRC Website and Learn About Other Resources and Program Specifics

usfirst.org

Page 92: LabVIEW & FRC

• www.ni.com/duke

• Additional introductory detail

• Videos showing some cool applications of LabVIEW

• www.k12lab.com

• Examples, videos, lesson plans

• www.ni.com/first

• Software updates, online training material

Resources

Page 93: LabVIEW & FRC

LabVIEW & FRC

Thanks for attending!!