• 沒有找到結果。

儀表控制軟體與模擬

N/A
N/A
Protected

Academic year: 2022

Share "儀表控制軟體與模擬"

Copied!
48
0
0

加載中.... (立即查看全文)

全文

(1)

ni.com/training

美商國家儀器

台北市敦化南路二段216號12樓 ni.com/training

儀表控制軟體與模擬

授課人: 林俊宏 國立陽明大學 醫學工程博士 s5188@mail.ksu.edu.tw 06-2050521#3704

(2)

ni.com/training

虛擬儀控

(3)

ni.com/training

虛擬儀控軟體架構

測試及資料管理軟體

NI TestStand DIAdem

量測自動化服務軟體

LabVIEW

圖形化開發

應用開發環境

SignalExpress VI Logger Vision Builder AI

互動式工具

(4)

ni.com/training

超過 25,000 家公司採用

Fortune評比前 500 大製造業公司有90%以上使用NI產品

(5)

ni.com/training

LabVIEW

(6)

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

(7)

ni.com/training

Starting a VI

• Start new VI

7

(8)

ni.com/training

VI :構造

• 人機介面(Front Panel)

• 程式方塊圖(Block Diagram)

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

8

(9)

ni.com/training

VI Front Panel

• 人機介面(使用者介面)

• Control (Input)

• Indicator (Output)

9 Control Indicator

(10)

ni.com/training

VI Block Diagram

• 程式方塊圖(圖形化程式語言)

• Terminal(接點)

− Control & Indicator

• Constant(常數)

• Node(節點)

− SubVI(副程式)

− Function(函數)

− Structure(結構)

• Wire(接線)

10

control indicator

(11)

ni.com/training

VI Icon/Connector Pane

• 將VI使用為subVI時

• Icon: VI的圖示代表

• Connector Pane: VI的輸入與輸出

11

(12)

ni.com/training

Project Explorer

• 開發大型程式或專案

• 管理多個VI及subVI,將LabVIEW 與non-LabVIEW檔案包在一起

• Compile to EXE, DLL, Installer

• Deploy to PDA, FPGA, RT system

12

(13)

ni.com/training

Front Panel:

Front Panel Toolbar & Controls Palette

13 View » Controls

Palette

空白處按右鍵 控制面版

(14)

ni.com/training

Front Panel Controls & Indicators

14

Numeric Boolean

String

(15)

ni.com/training

Tools Palette

• 指定滑鼠游標的操作

15 工具面版

(16)

ni.com/training

練習 1.1:Clock (using Gauge)

16

(17)

ni.com/training

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

17

(18)

ni.com/training

Block Diagram:

Front Panel Toolbar & Functions Palette

18 函數面版

除錯工具

(19)

ni.com/training

Block Diagram-資料流

• Block Diagram(程式方塊圖)

− 資料流槪念

o由左而右執行

o所有Input到了才會執行

由左向右執行

(20)

ni.com/training

練習 1.3: 梯形面積計算

20

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

(21)

ni.com/training

Block Diagram:SubVI(副程式)

• VI

• 具有Front Panel與Block Diagram

• Icon & Connector Pane

• 內建 & 自創

• Express VI

• 功能較強大的內建VI

• 對話框

21

(22)

ni.com/training

Block Diagram:Wire(接線)

22

(23)

ni.com/training

更多資源

• ni.com

• Knowledge Base: http://ni.com/kb

• Forum: http://ni.com/taiwan/forum

• Forum: http://www.labviewpro.net

• support.taiwan@ni.com

• (02)2377-2222

23

(24)

ni.com/training

資料型別: Numeric & Boolean

• Numeric

Floating-Point

Integer

Complex

Boolean

開關型

− Switch (開關)

按鈕型

− Switch (開關)

− Latch (門鈴)

24

(25)

ni.com/training

練習 1.4:Mechanical Action

• Try to learn Mechanical Action from the example in LabVIEW

• Switch/Latch

• Pressed/Released

25

(26)

ni.com/training

練習 -樓梯燈控制

• 假設有兩層樓,樓上樓下分別有一個開關可控制樓 梯燈,請使用Switch When Pressed的型態來設計開關

,要注意樓上樓下都要能同時控制喔!

26

(27)

ni.com/training

While Loop

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

• 一定至少會執行一次

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

• 避免無窮迴圈

27

(28)

ni.com/training

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

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

• 產生了多少個亂數?

28

(29)

ni.com/training

For Loop

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

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

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

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

29

(30)

ni.com/training

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

30

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

• 增加停止鍵功能

(31)

ni.com/training

迴圈特性

• 迴圈就像是輪盤一樣,有著下列的規則:

− 1.下好離手後,輪盤(迴圈)才開始轉。

− 2.輪盤沒停之前,不會知道中了幾號(迴圈沒停之前沒 有Output)。

(32)

ni.com/training

Tunnel

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

• 固定值

32

(33)

ni.com/training

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

(34)

ni.com/training

Wait & Wait Until Next ms Multiple

狀況一

狀況二

(35)

ni.com/training

Wait & Wait Until Next ms Multiple

等待時間 程式時間

100ms

50ms 100ms

50ms 100ms

50ms 情況一

等待時間 程式時間

100ms

120ms 100ms 情況二

120ms 100ms 120ms

等待時間 程式時間

100ms

50ms 100ms

50ms 100ms

50ms 情況一

等待時間 程式時間

100ms

120ms 100ms 情況二

120ms 100ms 120ms

(36)

ni.com/training

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

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

練習 1.7: 亂數產生 (Timing)

36

(37)

ni.com/training

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

37 0 0

0 1

1 2

2 3

3 4

(38)

ni.com/training

遞迴 (Iterative)資料:Shift Register

• 紀錄先前迴圈的資料

• 在迴圈左/右邊框按右鍵,Add Shift Register

• 可同時多個Shift Register

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

38 3

0 5

8

(39)

ni.com/training

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

• 初始值

39

VI stops execution Run Again Run Once

5 5

4 8

(40)

ni.com/training

練習 1.8:Fibonacci Sequence

40

• 1, 1, 2, 3, 5, 8, 13, 21, 34

• 每0.5秒產生一個

• 從8開始產生?

53

(41)

ni.com/training

繪製資料

• Waveform Chart(可記憶)

• 通常資料為scalar(亦可為vector)

• 每次新增加一個點

• 常置於迴圈中

• 可繪製一條或多條資料(Bundle)

• Waveform Graph(不可記憶)

• 資料必為vector

• 每次重新繪製資料

• 於迴圈中常配合Shift Register

• 可繪製一條或多條資料(2D-array)

• XY Graph(不可記憶)

• 資料為陣列數對(Bundle of array)

41

(42)

ni.com/training

Waveform Chart

• 清除歷史資料

• 按右鍵,Data Operations → Clear Chart

• 不同的更新模式

• Data Operations → Update mode

42

(43)

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

(44)

ni.com/training

Plotting Data

(45)

ni.com/training

練習 1.9: 比較各種 Waveform

45

• 產生一條斜率為1的直線(0,0)~(10,10)

• 用Waveform Chart做

• 用Waveform Graph做

• 用XY Graph做

(46)

ni.com/training

Case Structure

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

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

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

“?”可接受的格式

Boolean, Integer, String, Enum

46

(47)

ni.com/training

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

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

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

練習 1.10: 計算機

47

(48)

ni.com/training

練習:汽車模擬駕駛

汽車速度:0-200 km/Hr

引擎控制,可以決定速度,並且有±10%起伏 限速:130km/Hr

超速時:

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

亮燈

圖表: (Waveform Chart) 每秒更新約 25次

上下限為0-250km/Hr

48

參考文獻

相關文件

Step 3: : : :模擬環境設定 模擬環境設定 模擬環境設定 模擬環境設定、 、 、 、存檔與執行模擬 存檔與執行模擬

New: Overall correct % for each dimension in Maths and presented in a bar

Conversations Learning Journal Chart: Change & Strategic Thinking Date

Pursuant to the service agreement made between the Permanent Secretary for Education Incorporated (“Grantor”) and the Grantee in respect of each approved programme funded by the

Intelligent assessment technologies supports web based learning environment to provide students adaptive learning suggestions, give teachers hints to modify learning

Failure Mode and Effects Analysis (Failure Modes and Effects Analysis, FMEA) is used to analyze the product / system, the potential failure modes, identify potential trouble spots

在軟體的使用方面,使用 Simulink 來進行。Simulink 是一種分析與模擬動態

The scenarios fuzzy inference system is developed for effectively manage all the low-level sensors information and inductive high-level context scenarios based