Upload
steven-ward
View
219
Download
0
Tags:
Embed Size (px)
Citation preview
LabVIEW Basics
Dustin Cruise
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
Topics Today
• LabVIEW Introduction• Getting Started Programming– Projects, VIs– Dataflow and execution control…
• Troubleshooting tools• Resources
LABVIEW INTRODUCTION
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.
GETTING STARTED PROGRAMINGVIs, variables, indicators, functions
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.
LabVIEW Block Diagram Example
• Startup
• Main Application
• Shutdown
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…
Quiz Time
• ‘I love LabVIEW’ is an example of a:– String– Double– Integer– Boolean
• How about 0.4234?
• See? This stuff is easy! Relax!
WHEN DO THINGS HAPPEN?Data flow and execution control
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.
Quiz
• What’s the order in which events will happen in the following code?
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!
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
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
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
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.
TROUBLESHOOTING TOOLS!
Problems we can have
• Bad algorithms
• Timing not behaving the way we’d like
• Race conditions
• Anything you can imagine
Diagnosing problems
• Probes
• Execution Highlighting
• PLOT PLOT PLOT PLOT PLOT PLOT– CHARTS ARE THE BEST! – KEY ADVANTAGE OF LABVIEW!
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!
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!
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
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