Advanced LabVIEW Topics 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 Advanced Code Structures – State Machines – Multiple/Parallel Loops Passing Data – Queues – Notifiers – Local Variables Resources
Everything in One Giant Loop Can’t run at different rates. Not all tasks need to be run every loop execution – Some may only run when there is an user input, or hardware trigger Split tasks into multiple loops
Standard Design Patterns for Splitting Tasks State Machines Parallel Loops – Master/Slave – Producer/Consumer – User Interface Event Handler
STATE MACHINES
State Machine Basics “States” are events independent from another – Start, Stop – Start Drive Fwd Turn Left Move Arm Move Arm Stop State Machine consists of a While Loop, Case Structure, Shift Register, and Transition Code – Each case defines a “state” of the machine – At end of current state, decide next state to go to; stay or go to different state
State Diagram
State Machine Example Case Structure States Transitions Event driven
PARALLEL LOOPS
Parallel Loops Multiple or Parallel Loops for multiple tasks where timing is important – Each loop has their own bit of processor – One loop can have higher priority for processor over another – Loops can run at different rates Will need to pass data between loops
Master/Slave One as Master, others as slaves. Master controls all the slave loops. Slaves must take less time than Master so data is not lost Good for: – Responding to user interface while also collecting data
Master/Slave Example Data passed with shared variable in this case
Producer / Consumer Separates tasks between: – Tasks producing data – Tasks consuming data Uses queues to pass data Good example of use:
Producer/Consumer Example Data passed with shared variable in this case
Queues, Notifiers, and Variable Queues when wanting all data Notifiers when only most current data – Don’t buffer data, so overwriting is an issue Variables – Local Available to all of VI – Global Available to all Vis – Shared
Diagnosing problems Probes Execution Highlighting PLOT PLOT PLOT PLOT PLOT PLOT – CHARTS ARE THE BEST! – KEY ADVANTAGE OF LABVIEW!
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
Examples State machine – Help, State Machine fundamentals Master Slave Producer consumer Queues, Local Variables – Disc 2, Queues vs Local Variables – Help, Simple Queues Notifiers – Help, Simple Notifiers