25
LabVIEW Basics Dustin Cruise

LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Embed Size (px)

Citation preview

Page 1: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

LabVIEW Basics

Dustin Cruise

Page 2: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Who is this guy?• Graduate Student in Mechanical Engineering

at Purdue University• Specialty Areas: Combustion

Control Systems• I work in a lab burning things and

using lasers• I use LabVIEW a lot in my research• Sensors• Actuators• Data Acquisition and Analysis• Image Capture and Machine Vision

Page 3: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Topics Today

• LabVIEW Introduction• Getting Started Programming– Projects, VIs– Dataflow and execution control…

• Troubleshooting tools• Resources

Page 4: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

LABVIEW INTRODUCTION

Page 5: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Virtual Instruments

• LabVIEW is a programming language! It is a full-fledged programming language, unlike many graphical “languages” which are not really complete.

• Historically, LabVIEW was designed by National Instruments to make life easier for engineers and scientists wanting to put together instrumentation– Advantage over other software is built-in analysis tools

• It is meant to be easy to use…– But you can’t program it exactly like C or other more

traditional languages. It is a Dataflow, not a procedural language.

Page 6: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

GETTING STARTED PROGRAMINGVIs, variables, indicators, functions

Page 7: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Project Tree and Virtual Instruments

• Project Tree– Organizes and links VIs to hardware

• Components of a VI:– Front panel:

• You can put “indicators” and “controls” here• Super useful! Buttons, LEDs, graphs, dials, anything you want!• Caution though: charts can require a lot of processor and

memory

– Block diagram:• Computational stuff goes here. This is the “code” part! Where

the magic happens.

Page 8: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

LabVIEW Block Diagram Example

• Startup

• Main Application

• Shutdown

Page 9: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Variables/Signals

• Variables/signals – people will use these terms interchangeably– Travel on wires– Basic types:

• Boolean – True or False (green wire)• Numeric (integer) – negative or positive, ie -4, -25535, +5390584

(blue wire)• Double – decimal number, like 0.3423423, 65.0232 (orange wire)• String – array of characters that travel together, like a word or

sentence…i.e. ‘this is a string’ (pink wire)

– More types:• Just wait! We’ll get there…

Page 10: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Quiz Time

• ‘I love LabVIEW’ is an example of a:– String– Double– Integer– Boolean

• How about 0.4234?

• See? This stuff is easy! Relax!

Page 11: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

WHEN DO THINGS HAPPEN?Data flow and execution control

Page 12: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Dataflow

• Things happen in order…sort of.

• But what’s the order when you just have things strung together?

• Sometimes, it is hard to tell. Let’s talk about the rules with a little demonstration.

Page 13: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Quiz

• What’s the order in which events will happen in the following code?

Page 14: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Execution Control

• While Loops– Loop until condition is met

• For Loops– Loop a number of times

• Timing a VI– Waits/delays– Timed loops USE FOR TIME CRITICAL THINGS

LIKE CONTROL LOOPS!

Page 15: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Execution Control

• Case Statements– Use these to switch between possible code

branches; i.e. do this or this other thing based on the value of a switch

• Boolean operations– Logic operations

Page 16: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Relating Data

• Arrays– All of same type, traveling together– Multiple dimensions possible

• Clusters– Multiple types bundled together– Can address by signal name

• Type Definitions– Kinda like object oriented programming…not going to cover it

very much here, but it can be useful

Page 17: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Modularity

• SubVIs are super helpful in keeping code clean.– Simple example

• Be careful that you know how they will behave…especially when you put loops in SubVIs.– Stay organized, add descriptions

Page 18: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Some tricky questions

• What about…parallel loops?– This can be hairy.

• What can help?– Simple example with local variables to stop two

parallel loops.– Local variables help you when everything is on the

same block diagram…handy.– Global variables are used when running multiple

VIs; different block diagrams.

Page 19: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

TROUBLESHOOTING TOOLS!

Page 20: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Problems we can have

• Bad algorithms

• Timing not behaving the way we’d like

• Race conditions

• Anything you can imagine

Page 21: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Diagnosing problems

• Probes

• Execution Highlighting

• PLOT PLOT PLOT PLOT PLOT PLOT– CHARTS ARE THE BEST! – KEY ADVANTAGE OF LABVIEW!

Page 22: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Designing code to avoid problems

• Use simplest code problem to accomplish a task– THINK ABOUT THE CODE BEFORE YOU START

PROGRAMMING!– Flowcharts/pseudocode not always the best…due

to Dataflow you sometimes want to work backwards!

– Practice on simple examples!

Page 23: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Dealing with Timing Problems

• Since LabVIEW is a implicitly and unavoidably multithreaded language, embrace it! It is super fun!– Hint:• Use Queues and Error Clusters to control execution

timing.• What are these?

• Use advanced code structures like state machines!

Page 24: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

How to learn LabVIEW

• The secret to learning LabVIEW… is doing LabVIEW.

• Build a library of examples as you come across them– Most likely, what you’re trying to do has already

been done before– Try to explain what each piece of an example VI

does. It doesn’t work to just glance over• Get familiar with resources

Page 25: LabVIEW Basics Dustin Cruise. Who is this guy? Graduate Student in Mechanical Engineering at Purdue University Specialty Areas: Combustion Control Systems

Resources

• FIRST’s getting started documentation that comes with the control system (available online as well)– Search for FRC LabVIEW NI and lots of things come up.

• FRCmastery.com• NI Examples found in Help menu• NI.com• Effective LabVIEW Programming, Thomas J. Bress