introducwon to labview
TRANSCRIPT
Introduc)on to LabVIEW
Hans-‐Pe6er Halvorsen, M.Sc.
Basic LabVIEW Programming
Na#onal Instruments is the vendor of LabVIEW
Na)onal Instruments creates both Hardware and So3ware
LabVIEW = Fun! Graphical Programming: • Very different from tradi)onal programming like
VB, C#, Maple, MATLAB, MathScript, etc. • It is more like a “drawing program” than a
Programming Language • This makes it easy to use for those who are not
programmers (or dont like programming J) • Excellent tool when using Hardware, when you
need to take Measurements (DAQ), etc. • It is fun and makes you very crea)ve!
LabVIEW Example
Property Nodes
Sequence Structure While Loop Sub VI
Case Structure Constants
Arrays
Stop Bu6on
Condi)on (When the loop shall end)
Local Variable Comment
Note! To do something with an object – Right-‐click on it
Hardware
cRIO
ZigBee
Vision System
Arduino
USB-‐6008
Wi-‐Fi DAQ
TC-‐01
NOx Sensor
Pt-‐100
Air Heater
Water Tank
LabVIEW Installa)on Download the sodware here: h6ps://lumen.ni.com/nicif/us/acadevallvdl/content.xhtml These are the main modules we use in the different courses at Telemark University College: • LabVIEW (LabVIEW Professional Development System 32-‐Bit: English) • LabVIEW MathScript RT Module • LabVIEW Control Design and Simula#on Module • LabVIEW PID and Fuzzy Logic Toolkit • LabVIEW System Iden#fica#on Toolkit • NI-‐DAQmx (Hardware Driver) Note! These packages are separate downloads! Make sure to download and install all of them! Select the Sodware in the “August 2013” column (LabVIEW 2013).
Note! The Serial Number is in Fronter!
LabVIEW Training
• LabVIEW Training for Students (Na)onal Instruments):
h6p://www.ni.com/academic/students/learn-‐labview/
• LabVIEW Course: h6p://home.hit.no/~hansha/?training=labview
LabVIEW Environment
Select File -‐> New VI (Ctrl + N) in order to start using LabVIEW
Students: Try this
This window appears when you start LabVIEW:
LabVIEW Environment Front Panel
Block Diagram
Create your User Interface/HMI here
Create your Code here
Switch between them: Ctrl + E
Students: Try this
Note! Both the Front Panel and the Block Diagram is stored in one single file. These files are called VIs (because the file extension is “.vi”). VI = Virtual Instruments
Controls and Func#ons Pale6e
Available from the Front Panel
Available from the Block Diagram
You create your User Interface Yo
u create you
r Cod
e
Right-‐click on the Front Panel
Right-‐click on
the Block Diagram
Students: Try this
You can “pin” them!
Customizing Controls and Func)ons Pale6es
Students: Do this for both the Controls PaleVe and the Func#ons PaleVe
Customizing LabVIEW IDE Select Tools ! Op#ons…
Students: Change the different op)ons according to how you want to use LabVIEW
Simple Example
Students: Try this simple example. Try “Minus”, “Divide” and “Mul)ply” as well.
Run the Program
Find these Controls and Indicators in the Controls Pale6e and place them on the Front Panel
Connect these together using the “Wiring tool” (your mouse)
Front Panel
Block Diagram
Controls Indicator
Controls vs.
Indicators
What is the difference?
Another Example Celcius to Fahrenheit
Students: Create the Front Panel and Block Diagram above
Front Panel
Block Diagram
Ctrl + B
While Loop
Students: Create this Example
While Loop
Block Diagram
Front Panel
Front Panel: Find these Controls in the Controls Pale6e and place them on the Front Panel with proper labels
Block Diagram: Find the While Loop in the Func)ons Pale6e and place it on the Block Diagram
Block Diagram: Connect these together using the “Wiring tool” (your mouse)
Run the Program
Purpose: A voltage signal [0-‐5V] from a DAQ device needs to be converted to the equivalent level values in a water tank [0-‐20cm]
Note! To do something with an object – Right-‐click on it
Plopng
Students: • Create this VI • Try out different op)ons on the Chart,
e.g. Autoscale, different Modes, Layout, Colors, etc. (Right-‐click on the Chart)
Purpose: This example simulates the Temperature in the Air Heater. The Temperature in the Air Heater should be between 20 and 50 degrees Celsius. We use the Random Generator in LabVIEW
Note! To do something with an object – Right-‐click on it
Charts vs. Graphs Chart: • Remembers history – New point added to end of plot
• Used inside a While Loop • One new point is added each )me Graph: • You plot all the data at once – typically an array with data
• Used outside a While Loop
Charts vs. Graphs -‐ Example
Students: Create this VI in order to see the difference between a Chart and a Graph
Note! To do something with an object – Right-‐click on it
Right-‐click on the border
SubVIs Input Output
(Control) (Indicator)
Icon that makes it easier to understand what the SubVI is doing
A SubVI is the same as a func)on or a method used in other languages
Students: Create this VI
Select Inputs and Outputs
Using SubVIs
SubVI (just drag it on the Block Diagram with your mouse)
Students: Create this VI
Project Explorer Similar to “Solu)ons Explorer” in Visual Studio. Keeps all your Files for a spesific project in one place.
It is recommended to use this when you create larger applica)ons that contains lots of VIs and other files, etc.
I need Help!! Ctrl + H When you use Ctrl + H, you may click on all kind of objects (both on Front Panel and Block Diagram) on the screen to get help, e.g., built-‐in func)ons
Ctrl + H
Spaghep Code – Bad Example1
Structure your code! Use SubVIs, Avoid Spaghep Code, Document your Code, etc.
Spaghep Code – Bad Example2
Structure your code! Use SubVIs, Avoid Spaghep Code, Document your Code, etc.
Make sure your code fits into your screen size – scrolling to see code is not good!
Good vs. Bad Code
Use SubVIs!!!
Avoid Spaghe[ Code!
The Flow should go from le3 to right
Make your code readable for others!
Short-‐Cuts
• There are no Short-‐Cuts if you want to learn LabVIEW! (except the few shown on the previous page J)
• Prac)ce, prac)ce and prac)ce!
LabVIEW Training: 1 -‐ LabVIEW Training for Students (Na)onal Instruments):
h6p://www.ni.com/academic/students/learn-‐labview/ 2 -‐ LabVIEW Course: h6p://home.hit.no/~hansha/?training=labview
Sorry!
Hans-‐PeVer Halvorsen, M.Sc. Telemark University College Faculty of Technology Department of Electrical Engineering, Informa#on Technology and Cyberne#cs
E-‐mail: [email protected] Blog: hVp://home.hit.no/~hansha/
29