introducwon to labview

29
Introduc)on to LabVIEW HansPe6er Halvorsen, M.Sc. Basic LabVIEW Programming

Upload: phamthuy

Post on 02-Jan-2017

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IntroducWon to LabVIEW

Introduc)on  to  LabVIEW  

Hans-­‐Pe6er  Halvorsen,  M.Sc.  

Basic  LabVIEW  Programming  

Page 2: IntroducWon to LabVIEW

Na#onal  Instruments  is  the  vendor  of  LabVIEW  

Na)onal  Instruments  creates  both  Hardware  and  So3ware  

Page 3: IntroducWon to LabVIEW

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!  

Page 4: IntroducWon to LabVIEW

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  

Page 5: IntroducWon to LabVIEW

Hardware  

cRIO  

ZigBee  

Vision  System  

Arduino  

USB-­‐6008  

Wi-­‐Fi  DAQ  

TC-­‐01  

NOx  Sensor  

Pt-­‐100  

Air  Heater  

Water  Tank  

Page 6: IntroducWon to LabVIEW

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!  

Page 7: IntroducWon to LabVIEW

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    

 

Page 8: IntroducWon to 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:  

Page 9: IntroducWon to 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    

Page 10: IntroducWon to LabVIEW

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!  

Page 11: IntroducWon to LabVIEW

Customizing  Controls  and  Func)ons  Pale6es  

Students:  Do  this  for  both  the  Controls  PaleVe  and  the  Func#ons  PaleVe  

Page 12: IntroducWon to LabVIEW

Customizing  LabVIEW  IDE  Select  Tools  !  Op#ons…  

Students:  Change  the  different  op)ons  according  to  how  you  want  to  use  LabVIEW  

Page 13: IntroducWon to 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?  

Page 14: IntroducWon to LabVIEW

Another  Example  Celcius  to  Fahrenheit  

Students:  Create  the  Front  Panel  and  Block  Diagram  above  

Front  Panel  

Block  Diagram  

Page 15: IntroducWon to LabVIEW

Ctrl  +  B  

Page 16: IntroducWon to LabVIEW

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  

Page 17: IntroducWon to LabVIEW

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  

Page 18: IntroducWon to LabVIEW

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    

Page 19: IntroducWon to LabVIEW

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  

Page 20: IntroducWon to LabVIEW

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  

Page 21: IntroducWon to LabVIEW

Using  SubVIs  

SubVI  (just  drag  it  on  the  Block  Diagram  with  your  mouse)  

Students:  Create  this  VI  

Page 22: IntroducWon to LabVIEW

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.    

Page 23: IntroducWon to LabVIEW

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  

Page 24: IntroducWon to LabVIEW

Spaghep  Code  –  Bad  Example1  

Structure  your  code!  Use  SubVIs,  Avoid  Spaghep  Code,  Document  your  Code,  etc.  

Page 25: IntroducWon to LabVIEW

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!  

Page 26: IntroducWon to LabVIEW

Good  vs.  Bad  Code  

Use  SubVIs!!!  

Avoid  Spaghe[  Code!  

The  Flow  should  go  from  le3  to  right  

Make  your  code  readable  for  others!  

Page 27: IntroducWon to LabVIEW

Short-­‐Cuts  

Page 28: IntroducWon to LabVIEW

•  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!  

Page 29: IntroducWon to LabVIEW

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