48
ni.com/training 美商國家儀器 台北市敦化南路二段21612ni.com/training 儀表控制軟體與模擬 授課人: 林俊宏 國立陽明大學 醫學工程博士 [email protected] 06-2050521#3704

LabVIEW Data Acquisition and Signal Conditioning Courseeportfolio.lib.ksu.edu.tw/user/4/9/4980K010/repository/LabVIEW.pdf · What is LabVIEW? • Laboratory Virtual Instrument Engineering

  • Upload
    others

  • View
    9

  • Download
    5

Embed Size (px)

Citation preview

ni.com/training

美商國家儀器台北市敦化南路二段216號12樓

ni.com/training

儀表控制軟體與模擬

授課人: 林俊宏

國立陽明大學醫學工程博士

[email protected]#3704

ni.com/training

虛擬儀控

ni.com/training

虛擬儀控軟體架構

測試及資料管理軟體NI TestStand , DIAdem

量測自動化服務軟體

LabVIEW圖形化開發

應用開發環境

SignalExpressVI Logger

Vision Builder AI

互動式工具

ni.com/training

超過 25,000 家公司採用Fortune評比前 500 大製造業公司有90%以上使用NI產品

ni.com/training

LabVIEW

ni.com/training

What is LabVIEW?

• Laboratory Virtual Instrument Engineering Workbench

• 圖形化程式語言(G語言)

• LabVIEW的程式:VIs (Virtual Instruments)

• 易於資料擷取、分析、呈現 Acquire, Analyze and Present

• 最新版本:2010

• 支援多核心版本:8.5 or later

6

ni.com/training

Starting a VI

• Start new VI

7

ni.com/training

VI:構造

• 人機介面(Front Panel)

• 程式方塊圖(Block Diagram)

• 圖示/連接器面板(Icon/Connector Pane)

8

ni.com/training

VI:Front Panel

• 人機介面(使用者介面)• Control (Input)• Indicator (Output)

9

Control Indicator

ni.com/training

VI:Block Diagram

• 程式方塊圖(圖形化程式語言)• Terminal(接點)− Control & Indicator

• Constant(常數)• Node(節點)− SubVI(副程式)− Function(函數)− Structure(結構)

• Wire(接線)

10

controlindicator

ni.com/training

VI:Icon/Connector Pane• 將VI使用為subVI時• Icon: VI的圖示代表• Connector Pane: VI的輸入與輸出

11

ni.com/training

Project Explorer• 開發大型程式或專案• 管理多個VI及subVI,將LabVIEW

與non-LabVIEW檔案包在一起• Compile to EXE, DLL, Installer• Deploy to PDA, FPGA, RT

system

12

ni.com/training

Front Panel:Front Panel Toolbar & Controls Palette

13

View » Controls Palette或空白處按右鍵

控制面版

ni.com/training

Front Panel:Controls & Indicators

14

Numeric Boolean

String

ni.com/training

Tools Palette• 指定滑鼠游標的操作

15

工具面版

ni.com/training

練習1.1:Clock (using Gauge)

16

ni.com/training

練習1.2:熟悉如何建立Front Panel

17

ni.com/training

Block Diagram:Front Panel Toolbar & Functions Palette

18

函數面版

除錯工具

ni.com/training

Block Diagram-資料流

• Block Diagram(程式方塊圖)− 資料流槪念o由左而右執行o所有Input到了才會執行

由左向右執行

ni.com/training

練習1.3:梯形面積計算

20

• 公式: (上底+下底) × 高 ÷ 2 =梯形面積

ni.com/training

Block Diagram:SubVI(副程式)• VI• 具有Front Panel與Block Diagram• Icon & Connector Pane• 內建 & 自創

• Express VI• 功能較強大的內建VI• 對話框

21

ni.com/training

Block Diagram:Wire(接線)

22

ni.com/training

更多資源

• ni.com• Knowledge Base: http://ni.com/kb• Forum: http://ni.com/taiwan/forum• Forum: http://www.labviewpro.net

[email protected]

• (02)2377-2222

23

ni.com/training

資料型別:Numeric & Boolean

• Numeric• Floating-Point• Integer• Complex

• Boolean• 開關型

− Switch (開關)

• 按鈕型− Switch (開關)− Latch (門鈴)

24

ni.com/training

練習1.4:Mechanical Action

• Try to learn Mechanical Action from the example in LabVIEW

• Switch/Latch• Pressed/Released

25

ni.com/training

練習-樓梯燈控制• 假設有兩層樓,樓上樓下分別有一個開關可控制樓

梯燈,請使用Switch When Pressed的型態來設計開關,要注意樓上樓下都要能同時控制喔!

26

ni.com/training

While Loop• i 從 0 開始,每一圈增加 1

• 一定至少會執行一次

• 必須提供停止條件(或繼續條件)

• 避免無窮迴圈

27

ni.com/training

練習1.5:亂數產生(While-loop)

• 程式不斷產生出0~1之間的亂數,當使用者按下停止鍵後停止

• 產生了多少個亂數?

28

ni.com/training

For Loop• i 從 0 開始,每一圈增加 1

• 總共執行N次(最後的 i =N-1)

• 亦可提供停止條件(或繼續條件)

• 通常知道迴圈執行次數,用For loop;未知迴圈執行次數(由其他條件來決定),用While loop

29

ni.com/training

練習1.6:亂數產生(For-loop)

30

• 將上一個練習改為用For做,得到第1,000,000個亂數時停止

• 增加停止鍵功能

ni.com/training

迴圈特性• 迴圈就像是輪盤一樣,有著下列的規則:− 1.下好離手後,輪盤(迴圈)才開始轉。− 2.輪盤沒停之前,不會知道中了幾號(迴圈沒停之前沒

有Output)。

ni.com/training

Tunnel• 資料進出結構(For-loop和While-loop等)的出入口

• 固定值

32

ni.com/training

為什麼程式連續執行時需要進行時間控制呢?

ni.com/training

Wait & Wait Until Next ms Multiple

狀況一

狀況二

ni.com/training

Wait & Wait Until Next ms Multiple

等待時間

程式時間

100ms50ms

100ms50ms

100ms50ms

情況一

等待時間

程式時間

100ms120ms

100ms情況二

120ms100ms

120ms

等待時間

程式時間

100ms50ms

100ms50ms

100ms50ms

情況一

等待時間

程式時間

100ms120ms

100ms情況二

120ms100ms

120ms

ni.com/training

• 每秒產生一個0~1之間的亂數,並畫在Chart上

• 如何修改使得產生的時間越來越慢?

練習1.7:亂數產生(Timing)

36

ni.com/training

什麼是Shift Register(移位暫存器)

37

0 00 11 22 33 4

ni.com/training

遞迴(Iterative)資料:Shift Register• 紀錄先前迴圈的資料• 在迴圈左/右邊框按右鍵,Add Shift Register• 可同時多個Shift Register

• 紀錄先前多次迴圈的資料(Shift Register上按Add Element)

38

3

50

8

ni.com/training

遞迴(Iterative)資料:Shift Register(cont.)

• 初始值

39

VI stops execution Run AgainRun Once

55

84

ni.com/training

練習1.8:Fibonacci Sequence

40

• 1, 1, 2, 3, 5, 8, 13, 21, 34• 每0.5秒產生一個

• 從8開始產生?

53

ni.com/training

繪製資料

• Waveform Chart(可記憶)• 通常資料為scalar(亦可為vector)• 每次新增加一個點• 常置於迴圈中• 可繪製一條或多條資料(Bundle)• Waveform Graph(不可記憶)• 資料必為vector• 每次重新繪製資料• 於迴圈中常配合Shift Register• 可繪製一條或多條資料(2D-array)• XY Graph(不可記憶)• 資料為陣列數對(Bundle of array)

41

ni.com/training

Waveform Chart

• 清除歷史資料• 按右鍵,Data Operations → Clear Chart

• 不同的更新模式• Data Operations → Update mode

42

ni.com/training

Chart Update Modes• Right-click the chart and select Advanced»Update Mode

from the shortcut menu• Strip chart is the default update mode• Scope chart and Sweep chart modes display plots

significantly faster than the strip chart mode

ni.com/training

Plotting Data

ni.com/training

練習1.9:比較各種Waveform

45

• 產生一條斜率為1的直線(0,0)~(10,10)• 用Waveform Chart做• 用Waveform Graph做• 用XY Graph做

ni.com/training

Case Structure• 面對不同的情況,要讓程式做不同的動作

• 一次只有一種可能(只能進入其中一個case)

• 不一定每個case都要使用輸入資料,但若有輸出,則必須為每個case定義各自的輸出

• “?”可接受的格式• Boolean, Integer, String, Enum

46

ni.com/training

• 使用者可以選擇「加」、「減」、「乘」或「除」

• 若發生「除以零」的情形,則答案顯示出「999」

• 設定使用者只能輸入整數,且第二個數只能為0~100的整數

練習1.10:計算機

47

ni.com/training

練習:汽車模擬駕駛汽車速度:0-200 km/Hr

引擎控制,可以決定速度,並且有±10%起伏

限速:130km/Hr

超速時:警示文字:「林先生,您已經超速囉!」亮燈

圖表: (Waveform Chart)每秒更新約 25次上下限為0-250km/Hr

48