• 검색 결과가 없습니다.

강의자료실 - 강의자료실

N/A
N/A
Protected

Academic year: 2021

Share "강의자료실 - 강의자료실"

Copied!
48
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

조선대학교 기계공학과

지능메카트로닉스 실험실

LabVIEW Basic

LabVIEW Graphical Development System

 Graphical Programming Environment  Compile code for multiple OS and devices  Useful in a broad range of applications

(2)

Applications of Virtual Instrument

• Design

– Signal and Image Processing – Embedded System Programming – Simulation and Prototyping – And more…

• Control

– Industrial Automatic Controls – Mechatronics and Robotics – And more…

• Tests and Measurements – Circuits and Electronics

– Measurements and Instrumentation – And more…

NI LabVIEW Robotics Starter Kit

NI sbRIO-9632 임베디드 컨트롤러LabVIEW Robotics, LabVIEW

Real-Time 및 LabVIEW FPGA 소프트웨어

초음파 센서, 엔코더, 모터, 배터리 및

충전기 포함

NI myRIO Mechatronics Kit

엔코더가 있는 2개의 DC 기어 모터H-bridge 드라이버가속도계3축 자이로적외선 근접 센서주변 광 센서초음파 거리 센서나침반Hobby 서보 모터

(3)

Section I - Hardware and LabVIEW Usage

A. Getting Data into your Computer • Data Acquisition Devices

– NI-DAQ

– Simulated Data Acquisition – Sound Card

B. LabVIEW Environment

• Front Panel / Block Diagram • Toolbar /Tools Palette

C. Components of a LabVIEW Application • Creating a VI

• Data Flow Execution D. Additional Help

• Finding Functions

• Tips for Working in LabVIEW

MAX

• MAX stands for Measurement & Automation Explorer. • MAX configures and organizes all your National Instruments

DAQ, PCI/PXI instruments, GPIB, IMAQ, IVI, Motion, VISA, and VXI devices.

• Used for configuring and testing devices.

Icon Found on Windows Desktop

(4)

Start » All Programs » National Instruments LabVIEW

Startup Screen:

»

Start from a Blank VI: New

» Blank VI

Start from an Example: Examples

» Find Examples…

LabVIEW 실행

Each VI has 2 Windows

Front Panel - User Interface (UI) – Controls  Inputs(입력) – Indicators  Outputs(출력)

Block Diagram - Graphical Code – 블록다이어그램

– 프런트패널과 항시 동반 – 순서도와 유사한 소스 코드

– 모든 컴포넌트(함수+객체)는 와이어링 됨

(5)

Controls Palette (

Controls

&

Indicators

)

(Place items on the Front Panel Window)

Indicator: Numeric Slide Control: Numeric Customize Palette View

Functions (and Structures) Palette

(Place items on the Block Diagram Window)

(6)

Tools Palette

(7)

Block Diagram Window Front Panel Window

Creating a VI

Input Terminals Output Terminal Boolean Control Graph Indicator

• But in most cases, look for a match in colors.

Controlshave an arrow on the right side and have a thick border.

Indicatorshave an arrow on the left and a thin border. • Logic rules apply to wiring in LabVIEW:

Each wire must have one (but only one) source (or control), and each wire may have multiple destinations (or indicators).

• Block diagram execution

– Dependent on the flow of data – Block diagram does NOT

execute right to left. • Node executes when data is

available to ALL input terminals. • Nodes supply data to all output

terminals when done.

(8)

Debugging Techniques

• Finding Errors

• Execution Highlighting

• Probes

Click on broken Run button.

Windowshowing error appears.

Click on Execution Highlighting button; data flow is animated using bubbles. Values are

displayed on wires.

Right-click on wireto display probe and it shows data as it flows through wire segment.

You can also select Probe tool from Tools palette and click on wire.

Context Help Window

• Help»Show Context Help, press the <Ctrl+H> keys

• Hover cursor over object to update window

Additional Help

– Right-Click on the VI icon

and choose Help, or

– Choose “Detailed Help.” on

the context help window

(9)

Tips for Working in LabVIEW

Keystroke Shortcuts

– <Ctrl+H> – Activate/Deactivate Context Help Window – <Ctrl+B> – Remove Broken Wires From Block Diagram – <Ctrl+E> – Toggle Between Front Panel and Block Diagram – <Ctrl+Z> – Undo (Also in Edit Menu)

Tools » Options… – Set Preferences in LabVIEW

File » VI Properties – Configure VI Appearance, Documentation, etc

.

Section II – Elements of Typical Programs

A. Loops • While Loop • For Loop • Wait Functions • Shift Register • Numeric Conversion B. Functions and SubVIs

• Types of Functions

• Modulizing Custom Functions (SubVI) • Functions Palette & Searching

C. Decision Making and File IO • Case Structure

(10)

Loops

Functions»Programming»Structures

• While Loops

– terminal counts iteration – Always runs at least once – Runs until stop condition is

met

• For Loops

– i terminal counts iterations – Run according to input N of

count terminal – i starts from 0

Drawing a Loop

1. Select the structure

2. Enclose code to be repeated

(11)

Select the Loop Condition

• Click the Conditional Terminal with the Operating tool to define when the loop stops

• Default: Stop if True

Iteration Terminal Conditional Terminal

Structure Tunnels

• Tunnels feed data into and out of structures.

• The tunnel is a block that appears on the border; the color of the block is related to the data type wired to the tunnel.

• When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel.

(12)

Wait Functions

Wait Until Next ms

Functions»Programming»Timing palette

가정된 소요시간

Wait Functions

Wait (ms)

Time Delay

Working the same way in both functions

(13)

Shift Register

• Available at left or right border of loop structures • Right-click the border and select Add Shift Register • Right terminal stores data on completion of iteration

• Left terminal provides stored data at beginning of next iteration

Before Loop Begins First Iteration Second Iteration Last Iteration Value ? Initial Value: 0

Additional Shift Register Elements

Latest value is passed to right terminal Right-click the left terminal to add new elements

Previous values are available at the left terminals

Right-click the border for a new shift register 1 loop ago 2 loops ago 3 loops ago

(14)

[피드백 노드]

• For 루프나 While 루프에서 노드나 노드 그룹의 출력을 그 노드나 노드 그룹의 입력으로 연결할 루프가 한 반복을 끝내면 데이터를 저장하고, 다음 반복의 루프에 그 값을 전 달 한다. • 화살표는 데이터 값이 어느 방향으로 와이어를 따라 흐르는지 나타냅니다. • 데이터 흐름 방향이 변경되는 경우 화살표는 자동으로 방향을 바꿉니다.

[시프트 레지스트]

• 이전 반복의 값을 루프를 통해 다음 반복으로 전달하고자 할 때 사용. • 루프 오른쪽의 터미널에는 윗방향 화살표가 있고, 반복이 끝날 때마다 데이터를 저장. • 레지스터의 오른쪽에 연결된 데이터를 다음 반복으로 전달. • 루프가 실행된 후에 루프의 오른쪽의 터미널 은 시프트 레지스터에 저장된 마지막 값을 반환.

Feedback Node

Uninitialized Shift Registers & Feedback Nodes

Run Once VI stops execution Run Again

Output = 8 Output = 4

(15)

Equivalent Presentation

Numeric Conversion

• Numerics default to double-precision (8 bytes) or long integer (4 bytes) • LabVIEW automatically converts to different representations

• For Loop count terminal always converts to a long integer • Red coercion dot on terminal indicates conversion

conversion mark

(16)

Numeric Conversion

• LabVIEW chooses the representation that uses more bits. • If the number of bits is the same,

LabVIEW chooses unsigned over signed. • To choose the representation,

right-click on the terminal and select “Representation”.

• When LabVIEW converts floating-point numerics to integers, it rounds to the nearest integer. LabVIEW rounds x.5 to the nearest even integer.

For example, LabVIEW rounds 2.5 to 2 and 3.5 to 4.

3 Types of Functions

Express VIs: interactive VIs with configurable dialog page (blue border)

Standard VIs: modularized VIs customized by wiring (customizable)

Functions: fundamental operating elements of LabVIEW; no front panel or block diagram (yellow) – building block

(17)

What Types of Functions are Available?

Input and Output

– Signal and Data Simulation

– Acquire and Generate Real Signals with DAQ – Instrument I/O Assistant (Serial & GPIB) – ActiveX for communication with other programs • Analysis

– Signal Processing – Statistics

– Advanced Math and Formulas – Continuous Time Solver • Storage

– File I/O

Searching for Controls, VIs, and Functions

• Palettes are filled with hundreds of VIs

• Press the search button to index the all VIs for text searching • Click and drag an item from the search window to the block diagram • Double-click an item to open the owning palette

(18)

Modularity in LabVIEW – SubVIs

Convert repeated functions and VIs with a single VI

Create SubVI

• Enclose area to be converted into a subVI. • Select Edit»Create SubVI from the Edit Menu.

(19)

Icon and Connector Pane

• Use this connector pane layout as a standard

• Top terminals are usually reserved for references, such as a file reference

• Bottom terminals are usually reserved for errorclusters

Icon and Connector Pane – Create Icon

• Create custom icons by right-clicking the icon in the upper right

corner of the front panel or block diagram and selecting Edit Iconor by double-clicking the icon

• You also can drag a graphic from anywhere in your file system and drop it on the icon

• Refer to the

Icon Art Glossaryat ni.com for standard graphics to use in a VI icon

(20)

LabVIEW Functions and SubVIs operate like

Functions in other languages

Function Pseudo Code

function average (in1, in2, out) {

out = (in1 + in2)/2.0; }

SubVI Block Diagram

Calling Program Pseudo Code main

{

average (in1, in2, pointavg) }

Calling VI Block Diagram

How Do I Make Decisions in LabVIEW?(1)

Case Structures

Functions » Programming » Structures » Case Structure

• Right-click the structure boarder to add or delete cases • Use the labeling tool to enter values in the selector

(a) (b)

(a) Boolean input: Simple if-then case

(b) Numeric input: if out of range, the default is chosen

• selector terminal에연결된 값에 따라 어떤 케이스가 실행되는지 결정하며, 그 값은boolean, string, integer, enumerated type 등이 됨

(21)

How Do I Make Decisions in LabVIEW?(2)

Select

Functions » Programming » Comparison » Select

• Depending on s, return a value wired to tfor true or ffor false

Communicating between loops

• Communicating between loops using data flow is not possible – The left loop will execute completely before the right loop

(22)

Local Variables

• Local Variables allow data to be passed between parallel loops. • A single control or indicator can be read or written to from more than

one location in the program

– Local Variables break the dataflow paradigm and should be used sparingly

Producer/Consumer Design Pattern

 File » New and navigate to VI » From Template » Frameworks » Design Patterns  Design pattern to share data between loops

(23)

State Machines(

응용분야: user interface/process testing

)

state(상태): 시간에 따라 변하는 객체값(시작, 상태전이, 끝)

static sequence: 수 많은 algorithm의 sequence dynamic sequence: 각 algorithm을 상태로 정의

① While Loop ② Shift Register: 다음 상태를 저장 ③ Case Structure: - 각각의 상태를 가지고, 내부 코드의 연산결과에 따라 다음상태가 결정됨 1 2 3

<Statechart Diagram for phone with Notation>

State Machines Transitions

 Several programming techniques exist for transitioning from state to state in LabVIEW using State Machines

① case structure: Default transition implies that after one state, another state always follows

② select function: Transitions between two potential states can be handled

(24)

File I/O

• File I/O – Allows recording or reading data in a file. • LabVIEW creates or uses the following file formats:

– Binary: underlying file format of all other file formats – ASCII: regular text files

– LVM: LabVIEW measurement data file(*.lvm), EXCEL format – TDM: created for NI products, binary format(*.tdm)

High Level File I/O Functions

• Easy to use

• High Level of abstraction

(25)

Programming Model (File I/O)

Open/ Create/ Replace File Read and/or Write to File Close File Check for Errors

- This same programming model applies to data acqusition,

instrument control, file I/O, and most other communication schemes. - In most instances, you will open the file or communication channel,

read and write multiple times, and then the communication will be closed or ended.

Spreadsheet Formatting

• Spreadsheet files are ASCII files with a certain formatting – Usually tabs between columns and end of line constants

between rows(CSV-format)

– LabVIEW includes VIs that perform this formatting or a string can be concatenated

Write to Spreadsheet File: 1D or 2D arrays of numeric data  file with formated data.

(26)

Section III – Presenting your Results

A. Displaying Data on the Front Panel

• Controls and Indicators • Graphs and Charts • Loop Timing

B. Signal Processing

• MathScript • Arrays

• Clusters (eg. Class 및 struct와 유사)

Controls and Indicators

• Numeric Data

– Number input and display – Analog Sliders, Dials, and Gauges • Boolean Data

– Buttons and LEDs • Array & Matrix Data – Numeric Display – Chart

– Graph – XY Graph – Intensity Graph

– 3D graph: point, surface, and model

• Decorations – Tab Control – Arrows • Other

– Strings and text boxes – Picture/Image Display – ActiveX Controls

Express Controls Palette

(27)

Control & Indicator Properties

• Properties are characteristics or qualities about an object

• Properties can be found by right clicking on a Control or Indicator • Properties Include: – Size – Color – Plot Style – Plot color • Features include: – Cursors – Scaling

Charts

– Add 1 data point at a time with history

Waveform chart

• special numeric indicator that can display a history of values • Chart updates with each individual

point it receives

(28)

Graphs

– Display many data points at once

Waveform graph

• special numeric indicator that displays an array of data • Graph updates after all points have been collected • May be used in a loop if VI collects buffers of data

Functions » Express » Graph Indicators » Graph

Wiring to Charts

Single-Plot Chart Multiple-Plot Chart

Uniform X axis: X0= 0.0, ∆X = 1.0 Uniform X axis

you specify point spacing

Single-Plot Waveform Graphs

(29)

Multiple-Plot Waveform Graphs

Each row is a separate plot: X0 = 0 ∆X = 1 Each row is a separate plot: Bundle specifies point spacing of the X axis Hold “Ctrl” or Auto

• Non-uniform X axis

• Separate X and Y arrays

define data points

(30)

How Do I Time a Loop?

1. Loop Time Delay

– Configure the Time Delay Express VI for seconds to wait each iteration of the loop (works on For and While loops).

2. Timed Loops

– Configure special timed(multi-rate timing) While loop for desired dt.

Timed Loop Time Delay

Textual Math in LabVIEW

• Integrate existing scripts with LabVIEW for faster development • Interactive, easy-to-use, hands-on learning environment

• Develop algorithms, explore mathematical concepts, and analyze results using a single environment

• Freedom to choose the most effective syntax, whether graphical or textual within one VI

Supported Math Tools:

MathScript script node MathSoft software Mathematica software MATLAB®software

(31)

Math with the MathScript Node

• Implement equations textually in the interactive MathScript Node

• Input and Output variables created at the border by right-clicking

• Generally compatible with popular m-file script language (MATLAB)

• Terminate statements with a semicolon to disable immediate output

Programming » structures » MathScript

MathScript Window

• Interactively and rapidly develop and test algorithms • Share Scripts and Variables with the Node

• View /Modify Variable content in 1D, 2D, and 3D

Output Window Variable Workspace View/Modify Variable Contents m-file Script

(32)

• Collection of data elements that are of same type

• One or more dimensions, up to 2 elements per dimension

• Elements accessed by their index; first element is index 0

31

index

10-element array 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7

0 1 2 3 4 5 6 7 8 9

2D array

Five row by seven column array of 35 elements

0 1 2 3 4 5 6 0 1 2 3 4

Arrays

Creating an Array (Step 1 of 2)

Controls » Modern » Array, Matrix, and Cluster » Array • drag a control or indicator into the array shell

Drop it on the Front Panel.

(33)

Create an Array (Step 2 of 2)

1. Place an Array Shell.

2. Insert data type(“Numeric Control”) into the shell.

Add Dimension

for 2D arrays

Row Index

Column Index

1. Select Array Constant shell from the Array subpalette

2. Place the data object in the array shell

Creating Array Constants

(34)

67

Array Size

Initialize Array

Common Array Functions

Array Subset

68

The Build Array Function

Building a higher dimension array

Concatenate Inputs

(35)

69

The Index Array Function

Extracting an Element

Extracting an Element of a Row

Extracting a Row

• Function inputs can be of different types

• All LabVIEW arithmetic functions are polymorphic(not matrix arithmetic)

Scalar + Scalar Array + Scalar Combination Result Scalar Array Array Array + Array Array + Array Array

Polymorphism

(36)

• For / While Loops can accumulate arrays at their boundaries with auto-indexing

• For Loops auto-index by default

• While Loops output only the

final valueby default

Right-click tunneland enable/disable auto-indexing

Building Arrays with Loops (Auto-Indexing)

Wire becomes thicker

Wire remains the same size

Auto-Indexing Disabled Auto-Indexing Enabled

Only one value (last iteration) is passed out of the loop 1D Array

0 1 2 3 4 5

5

tunnel

• Inner loop creates column elements • Outer loop stacks them into rows

Creating 2D Arrays

1D Array 0 1 2 3 4 5

(37)

Introduction to Clusters

• Data structure that groups data together

• Data may be of different types

• Analogous to struct in C

Elements must be either

all controls

or

all indicators

• Thought of as wires bundled into a cable

• Order is important

Creating a Cluster

(38)

Creating Cluster Constants

1. Select Cluster Constant shell from the Cluster subpalette

2. Place objects in the Cluster shell

Cluster Order

• Elements have a logical order (start with 0)

• To change order, right-click the border and select Reorder Controls in Cluster...

(39)

Cluster Functions - Bundle

• In the Cluster & Variant subpalette of the Programming palette • Can also be accessed by right-clicking the cluster terminal

Bundle

(Terminal labels reflect data type)

Bundle By Name –update specificcluster object

Cluster Functions - Unbundle

(40)

Using Arrays and Clusters with Graphs

The Waveform Datatype contains 3 pieces of

data:

• t0 = Start Time

• dt = Time between Samples • Y = Array of Y magnitudes

Two ways to create a Waveform Cluster:

Build Waveform (absolute time) Cluster (relative time)

(41)
(42)
(43)
(44)
(45)
(46)

CASE STRUCTURE

If…then…else

콜라판매 자판기

50원, 100원 및 500원 동전을 사용할 수 있으며, 500원하는 콜라판매 자판기 프로그램개발(design patternState Machines)

 statechart diagram 작성: 동전투입, 제품구입, 환불 등의동사기반으로 상태전이가 발생

 EVENT Structure : 대기 응답대기, case구조와 유사하게 작성됨  Enum(열거형 데이터): 정의한 데이터중 하나를 선택할 때 활용됨  Type definition(타입정의)

– .ctl파일이 생성됨

(47)

내용 정리

• 변수 - 컨트롤(입력), 인디케이터(출력) • 배열변수 • 상수 • 수식연산 • 논리연산 • 비교연산 • while loop • for loop • 시간지연 • 상태머신 • 파일저장

APPENDIX 1 - 컨트롤, 인디케이터의 데이터 타입

•정수형(I64, I32, I16, I8)

•부호없는 정수형(U64, U32, U16, U8) •실수형(EXT, DBL, SGL)

(48)

참조

관련 문서

systemic circulation, in the right ventricle and oxygenated blood from the lungs, or pulmonary circulation, in the left ventricle, as in birds and mammals.. Two vessels,

Unique members represent the cumulative number of members that have borrowed on the SoFi platform or opened a financial services account through SoFi Money, SoFi Invest, SoFi

**In matches where Round 3 requires a drill to be done on the Right side for half the round and Left side for the other half of the round, there will be a 10 second

Pentad geopotential height at the 200 hPa for pre heavy rain phase (left), heavy rain phase (middle) and their difference of heavy rain phase minus pre heavy (right).. Units

core exercise program showed not only increasing peak torque of the right leg, left leg in Hip Extension of exercise group but also increasing peak torque of the right leg, left

Select: Skin surface (Target of intersection, white border on upper figure) Click: [GO] (in the lower right side of modeling window). Select: original and duplicated curves

In the change of physical strength, The exercise group showed statistically significant differences in muscle strength(right), muscle strength(left),

Figure 14 Shift of Fabry-Pérot fringe pattern (left) and quenching PL spectra (right) of Cu(II)-TMEDA catalyst coated PPS under the exposure of TEP vapors... Figure