Sunteți pe pagina 1din 239

Higher Institute for Applied Sciences and Technology (HIAST)

Control Department
Mechatronics – 5th year

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Road Map
LabView Basics Course
• Getting Started with LabVIEW Virtual Instruments.
• LabVIEW Data Type.
• Developing Modular Applications.
• LabVIEW Programming Structures.
• Arrays and Clusters.
• Storing Measurement Data.
• Charts & Graphs.
• DAQ SYSTEM.
• Connecting to External Devices.
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

Getting Started with


LabView Virtual
Instruments

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Getting Started with LabView
LabView is a system design platform and development environment for
a visual programming language from National Instruments.
LabView provides engineers and scientists with the tools needed to
create and deploy measurement and control systems.
LabView Everywhere
Sensor
Embedded
(FPGA)
Handheld
Wireless

Networked I/O

PC Boards

Industrial Computer (PXI)

Tektronix Open Windows


Oscilloscopes

PC, Mac, Linux, Sun

Workstation
Getting Started with LabView
LabView – Laboratory Virtual Instrument Engineering Workbench
is a graphical (visual) programming from National instruments (NI).
The purpose is automating the usage of processing and measuring equipment in any
laboratory setup.
C language Dataflow programming language

uses icons instead of lines of text to create programs


The graphical approach of LabVIEW allows non-programmers to build
programs by dragging and dropping virtual representations of lab
equipment with which they are already familiar.

Cross-platform
Getting Started with LabView
Graphical Programming for
Test, Measurement, and
Control
Benefits
• Rapid application
development with Express VIs
and easy-to-use graphical
environment
• Interactive measurement
assistants and powerful
redesigned DAQ interface for
connecting to all types of I/O.
• Allows creating stand-alone
executables.
• Included examples and the
documentation, makes it
simple to create small
applications .
Getting Started with LabView

• Called “Virtual Instruments” (VIs)


• Appearance and operation imitates actual
physical instruments

Without With
Getting Started with LabView

Supervision Industrial Control “SCADA”


Getting Started with LabView

Ethernet
extender

Programmable Logic
Pprogrammable logic Controller (PLC) controler ZELIO
( SCHNEIDER ELECTRIC)
monitoring using MODBUS/TCP protocol
Getting Started with LabView

Edge detection

Image acquisition and processing


Getting Started with LabView

Barcode reading

Image acquisition and processing


Getting Started with LabView
Getting Started with LabView
Getting Started with LabView
Getting Started with LabView
Getting Started with LabView
Front panel Block Diagram

Ctrl+E

Continuous run Block diagram toolbar Clean Up diagram


Pause

Run Stop
Reorder objects
Debugging features
Getting Started with LabView
Front panel Block Diagram
Controls palette

Tools palette
Getting Started with LabView
• LabView automatically selects the tool needed
• Available on the front panel and the block diagram
• A tool is a special operating mode of the mouse cursor
• Use the tools to operate and modify front panel and block diagram objects
• To show the tools palette, select Window » Show Tools Palette

Automatic Selection Tool

Operating Tool Scrolling Tool

Positioning/Resizing Tool Breakpoint Tool

Labeling Tool Probe Tool

Wiring Tool Color Copy Tool

Shortcut Menu Tool Coloring Tool


Getting Started with LabView

Front Panel
• Controls = Inputs
• Indicators = Outputs

Block Diagram
• Accompanying “program”
for front panel
• Components wired
together

20
Context Help
• To display the Context Help window, select
Help » Show Context Help, press the <Ctrl-H> keys,
or press the Show Context Help Window button in
the toolbar
• Move cursor over object
to display help

Simple/Detailed Context Help Lock Help More Help

21
Debugging Techniques
Finding Errors
Click on broken Run button. A window showing the
error appears
Execution Highlighting
Click on Execution Highlighting button; data flow is
animated using bubbles. Values are displayed on
wires.

22
Debugging Techniques
Probe
Right-click on wire and select probe and it shows
data as it flows through the wire segment
Breakpoints
Right-click on wire and select Set Breakpoint; pause
execution at the breakpoint.
Conditional Probe
Combination of a breakpoint and a probe. Right-click on
wire and select custom probe.

23
Debugging Techniques
Step Into, Over, and Out buttons for Single Stepping
Click on Step Into button to enable single stepping
Once Single Stepping has begun, the button steps
into nodes

Click on Step Over button to enable single stepping


or to step over nodes

Click on Step Out button to step out of nodes

24
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

Developing Modular
Applications

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Getting Started with LabView
Getting Started with LabView
Icon / Connector Pane
Creating Sub VIs
After you build a VI and create its icon and connector pane, you can use it in
another VI. A VI within another VI is called a subVI. A subVI corresponds
to a subroutine in text-based programming languages.
Creating Sub VIs

Front Panel Window:

Block Diagram Window:

٣٠
After building a VI, create its icon and connector pane, than it could be
used as a SUB-VI in another VI.

Step I:

Right-click in the icon and select Edit Icon, and draw a new desired Icon.
Step II: Creating the connector

Right-click in the icon and select Show Connector, and select a suitable connector
acording to the number of inputs and outputs.
Step III: Assign the connector terminals
Step IV: Save the file like C2Fconverter.vi

Then ,the newly created Sub-VI could be used as LIB-function by selecting


“Select a VI” in function palate in Block Diagram Window.
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Data Types
Prepared by: Eng. Al-Kayal Khaldoun
Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Wiring the Block Diagram
Scalar 1D Array 2D Array

Numeric

Boolean

String

Dynamic

36
LabView Data Types
Numeric Conversion
Data Types
Data Types
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Programming
Structures

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
The For Loop structure
The For Loop structure

Executes its subdiagram n


times, where n is the value
wired to the count (N) terminal.

The iteration (i) terminal


provides the current loop
iteration count, which ranges
from 0 to n-1.
The For Loop structure

Exercise:
Lets build a Second Timer using For Loop structure
which can count up to 60 sec.
The While Loop structure
The While Loop structure

Repeats the sub-diagram


inside it until the conditional
terminal.
The While Loop structure

Iteration Terminal Conditional Terminal


The While Loop structure
Example:
Lets build a Second Timer using While Loop structure
which can count Second while stop key not pressed.
The Loop Shift Registers
The Loop Shift Registers
The Loop Shift Registers
Example :
Calculate the following Series Sum
The Loop Shift Registers
Example of Multiple Shift Registers:
Feedback Nodes
• Appears automatically in a For Loop or While
Loop if you wire the output of a subVI,
function, or group of subVIs and functions to
the input of that same VI, function, or group.
• Stores data when the loop completes an
iteration, sends that value to the next iteration
of the loop, and transfers any data type
Feedback Nodes
• Wire from output to input
to automatically create a
feedback node
<OR>
• Place a feedback node from
the Functions»Structures
palette
The Case structure
The Case structure

Has one or more subdiagrams, or cases, exactly one of which executes


when the structure executes. The value wired to the selector terminal
determines which case to execute and can be Boolean, string, integer, or
enumerated type. Right-click the structure border to add or delete cases.
The Case structure
The Case structure
The Case structure
The Case structure
Example:
The Flat Sequence structure
The Flat Sequence structure
The Flat Sequence structure
Example:
The Flat Sequence structure
Example:
The Stacked Sequence structure
The Stacked Sequence structure

Consists of one or more subdiagrams, or frames, that execute sequentially.


Right-click the structure border to add and delete frames or to create
sequence locals to pass data between frames. Use the Stacked Sequence
structure to ensure a subdiagram executes before or after another
subdiagram.
The Stacked Sequence structure
The Stacked Sequence structure
The Stacked Sequence structure
Example:
To calculate the time required to execute
certain program or code
The Stacked Sequence structure
Example:
The Timing
The Timing
The Timing
The Formula Node
The Formula Node
A Formula Node in LabVIEW evaluates mathematical formulas and
expressions similar to C on the block diagram. In this way you may use
existing C code directly inside your LabVIEW code.

LabVIEW is a graphical programming language. So far we have learned how


to program algorithms in form of block diagrams. In some cases it is rather
difficult to write codes for algorithms with block diagrams. LabVIEW provides
a good tool, the Formula Node structure, to overcome this.

The Formula Node is a window in the block diagram where you can write
textual program code following the C-syntax. Using a Formula Node structure
for mathematical expressions is often more convenient than building the
expression using elementary blocks in the ordinary way in LabVIEW since it
is easier to write and maintain textual mathematical expressions than
drawing equivalent block diagram code.
The Formula Node
The Formula Node
Example:
The Formula Node
Homework
The Math Script Node
The Math Script Node
The MathScript Node implements similar functions to the Formula Node but
with the additional functionality of a full .m file compiler, making it useful as a
textual language for signal processing, analysis(MatLab).
The Math Script Node
The Event structure
An event is an asynchronous notification that something has occurred.
Events can originate from the user interface, external I/O, or other parts of the
program.
The Event structure can have multiple cases, each of which is a separate event-
handling routine.
The Event structure

The Event structure includes a Timeout event, which allows you to control
when the Timeout event executes.

The Timeout terminal at the top left corner of the Event structure, specifies
the number of milliseconds to wait for an event before timing out.

The default is -1 ,indicating never to time out.


The Event structure
The Event structure
The Event structure
Exercise 1:
Build a program that shows a massage box when pressing a key, using
polling, and event driven technique.
Polling Technique :
Without events, the block diagram must poll the state of front panel objects
in a loop, checking to see if any change has occurred.
Event Programming Technique:
Exercise 2:

Build a program that shows the mouse x-y


coordinate when moving over the window,
using event driven technique.
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Arrays
Prepared by: Eng. Al-Kayal Khaldoun
Kaldoun.kayal@hiast.edu.sy
Damascus 2013
LabView Arrays
LabView Arrays

Remember that you must assign a data object to the empty array shell
before using the array on the block diagram. If you do not assign a data
object, the array terminal will appear black with an empty bracket.
LabView Arrays
Creating Array Constants in The Block Diagram
Creating Array Constants in The Block Diagram
Array Controls and Indicators
1. Select the Array shell from the Controls 2. Place data object inside shell
palette

Add Dimension
for 2D arrays
Array Functions
Common Array Functions

Array Size

Initialize Array
Array Functions
Common Array Functions

Array Subset
The Build Array Function

Appending an element

Concatenate Inputs

Building a higher dimension array default


The Index Array Function

Extracting an Element

Extracting a Row

Extracting an Element of a Row


Array Polymorphism
Function inputs can be of different types
All LabVIEW arithmetic functions are polymorphic

Combination Result

Scalar + Scalar Scalar

Array + Scalar Array

Array + Array Array

Array + Array Array


Exercise
Construct a virtual thermometer accomplished with a white noise.
Store the reading for a specific period of time in an array.
Processes the stored data, determine the mean value ,Standard
deviation, max and min values.
Exercise
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Clusters
Prepared by: Eng. Al-Kayal Khaldoun
Kaldoun.kayal@hiast.edu.sy
Damascus 2013
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
Clusters
Cluster Functions - Bundle
Cluster Functions – Bundle By Name
Cluster Functions - Unbundle
Cluster Functions – Unbundle By Name
Cluster to Array Conversion
Error Cluster
Use the error in and error out clusters in each VI you
use or build to handle errors in the VI.
The error clusters located on the Controls »Array &
Cluster palette include the components of information
shown
Error Cluster Details
• Status is a Boolean value that reports
TRUE if an error occurred. Most VIs,
functions, and structures that accept
Boolean data also recognize this
parameter.
• Code is a signed 32-bit integer that
identifies the error numerically. A non-
zero error code coupled with a status
of FALSE signals a warning rather than
a fatal error.
• Source is a string that identifies where
the error occurred.
Error Handling with Clusters
• LabView does not handle errors automatically. In LabView,
you can make these error handling decisions on the block
diagram of the VI.
• Error handling in LabView follows the dataflow model. Just
as data flow through a VI, so can error information.
• Wire the error information from the beginning of the VI to
the end.

Error Cluster
Simple Error Handler
Use the Simple Error Handler to handle the error at the end of
the execution flow.

The Simple Error Handler is located on the Functions»All


Functions»Time and Dialog palette. Wire the error cluster to
the Error In (no error) input.
Using While Loops for Error Handling
You can wire an error cluster to the conditional
terminal of a While Loop to stop the iteration of the
While Loop.
Only the TRUE or FALSE value of the status
parameter of the error cluster is passed to the
terminal.
When an error occurs, the
While Loop stops.
Exercise
Construct a virtual thermometer accomplished with a white noise.
Store the reading for a specific period of time in an array.
Processes the stored data, determine the mean value ,Standard
deviation, max and min values, use cluster when delivering for indications.
Exercise
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Strings
Prepared by: Eng. Al-Kayal Khaldoun Damascus 2013
Strings
A string is a sequence of characters (ASCII)
String Display Modes
Normal display code display

Password display

Hex display
String Functions
String Length

Concatenate Strings
(spaces here)
String Functions
String Subset

Match Pattern
Converting Numerics to Strings
Using Build Text
Converting Numerics to Strings
Using Format Into String function
Exercise

Lets build the following control using the Format into String function.
Converting Strings to Numerics
Using Scan From String function
Exercise
Exercise
Search and Replace String
Search and Replace String
Exercise:
Search and Replace String
Review Exercise

Lets build a virtual


calculator ,using
the LabView
functions that we
have studied up till
now.
Review Exercise
Review Exercise
Step 1:
• Add event case for all numeric keys {0,1,2,3,4,5,6,7,8,9}.
• Use the CtRef node for obtaining the key text, using Application Control
Palette > Property Node > Boolean Text > Text
• Join the last entered key code accumulated in the shift register with
current using concatenated strings toll.
Review Exercise
Review Exercise
Step 2:
• Add new event case for the point key { . }.
• Check if any point has already been dialed.
• Join the last entered key code accumulated in the shift register with
current point using concatenated strings toll.
Review Exercise
Step 3:

• Add new event case for the Clear key { C }.


Review Exercise
Step 4:
• Add new event case for the Math operation keys { + , - , x , / }.
• Convert the accumulated in the shift register string into a float number.
• Store the float number (First Operand) into second shift register as a
float number.
• Store the math operation key text { + , - , x , / } into third shift register
Review Exercise
Step 5:
• Add new event case for the execution key { = }.
• Convert the accumulated in the shift register string into a float number and
use it as a second operand.
• Perform an appropriate math operation according to the stored operation
code in the third shift register using the case structure.
• Convert the operation result into string using the Format Into String function.
Homework 2

Extend the
previous example
to be able to
calculate more
functions as shown
right.
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
File I/O
Prepared by: Eng. Al-Kayal Khaldoun Damascus 2013
LabView File I/O
File I/O Programming Model -
Intermediate
Open/ Read
Close Check for
Create/ and/or
File Errors
Replace File Write to File
Write To Text File
Write To Text File
Example:
Read From Text File
Read From Text File
Example:
Formatting a Spreadsheet String
• Spreadsheets are popular tools for data handling and analysis
• There are many formats for spreadsheet data. One of the most popular
is tab-delimited:
– Columns are separated by a tab character
– Rows are separated by an end-of-line character

A spreadsheet yields:

Tab End of Line


Formatting a Spreadsheet String
Formatting a Spreadsheet String
Example:
Formatting a Spreadsheet String
Formatting a Spreadsheet String
Formatting a Spreadsheet String
Write To Spreadsheet File
Write to Spreadsheet File (text file)
Write to Spreadsheet File (text file)

Build 2D Array Write to Spreadsheet


Read from Spreadsheet File
Read Spreadsheet File (text file)
Read Spreadsheet File (text file)
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
Charts & Graphs
Prepared by: Eng. Al-Kayal Khaldoun
Kaldoun.kayal@hiast.edu.sy
Damascus 2013
LabView Charts & Graphs
LabView Charts & Graphs Type
Waveform Charts Example
Waveform Graphs Example
Waveform Graphs Example
Waveform XY Graphs Example
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

LabView
DAQ SYSTEM

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy Damascus 2013
What is DAQ System
Sensors (Transducers)
DAQ Properties
DAQ Systems
NI USB-6008
NI USB-6009
NI USB 6008/6009 Block Diagram
NI USB 6008/6009
NI USB 6008/6009
NI USB 6008/6009
Terminal Assignments
NI USB 6008/6009
Analog Input
Analog Input Configurations
Differential Connection (DIFF)
Referenced Single Ended (RSE) Connection
Taking Differential Measurements
Analog Output
How to use DAQ NI-USB 6009
Configuration Using DAQ Assistant
Select Acquire Signals
Configuration Using DAQ Assistant
Acquire Signals
Acquire Signals
Finish Acquire Signals
Generate Signals
Example of Using DAQ (NI USB-6009)

Construct a testing
device for drawing
Diode Current / Voltage
characteristic ,using
DAQ system (NI USB-
6009)
Save measurements in
file.
Example of Using DAQ (NI USB-6009)
Terminal Assignments
Example of Using DAQ (NI USB-6009)
Example of Using DAQ (NI USB-6009)
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

Connecting to External
Devices

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Serial Communication

 Popular means of communication between


computer and peripheral device
 Data sent one bit at a time across the cable
 Used for low transfer rates or long distances
 Only a cable is needed since most computers
have at least one available serial port
RS-232 equipment PC Serial
Port

RS-232 Cable
Serial Communication

• RS-232
– DCE or DTE configurations Our application configuration
 Baud rate : 9600 bit per s
– 9-pin or 25-pin
 Data bits : 8 bits
• RS-422
 Parity : no parity
– DCE or DTE
 Stop bits : 1
– 8-pin
 Flow control : no
• RS-485
– Multidrop
Serial Communication

Serial palette will allows to:

•Configure
•Open
•Read / write
•Close

Serial communication
How to configure & open communication

VISA Configure Serial Port


Initializes the serial port specified by VISA
resource name to the specified settings.
Serial Communication
How to Read Write Serial Data
How to Read Write Serial Data
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

Building SCADA System in


LabView Environment

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Building SCADA System in LabView Environment

Supervisory Control And Data Acquisition (SCADA)


Building SCADA System in LabView Environment

while (1)
{
if(start==TRUE)
{
A=read_adc(0);
B=read_adc(1);
C=read_adc(2);
D=read_adc(3);
E=PINC;

printf("A%4dB%4dC%4dD%4dE%4dF%4d",A,B,C,D,E);
delay_ms(50);
}
};
Building SCADA System in LabView Environment

// USART Receiver interrupt service routine


interrupt [USART_RXC] void
usart_rx_isr(void)
{ if (data=‘v'){Led0= Low;F&=0xfe;}
char status,data; if (data==‘x'){Led1= Low;F&=0xfd;}
status=UCSRA; if (data==‘z'){Led2= Low;F&=0xfb;}
data=UDR; if (data==‘s'){Led3= Low;F&=0xf7;}
if (data=='o')start = TRUE; if (data==‘w'){Led4= Low;F&=0xef;}
if (data=='n')start = FALSE; if (data==‘q'){Led5= Low;F&=0xdf;}
if (data='1'){Led0= Hi;F|=0x01;} if (data==‘u'){Led6= Low;F&=0xbf;}
if (data=='2'){Led1= Hi;F|=0x02;} if (data==‘p'){Led7= Low;F&=0x7f;}
if (data=='3'){Led2= Hi;F|=0x04;} }
if (data=='4'){Led3= Hi;F|=0x08;}
if (data=='5'){Led4= Hi;F|=0x10;}
if (data=='6'){Led5= Hi;F|=0x20;}
if (data=='7'){Led6= Hi;F|=0x40;}
if (data=='8'){Led7= Hi;F|=0x80;}
Building SCADA System in LabView Environment
Phase I : Building Communication Interface
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Building SCADA System in LabView Environment
Phase II : Implementing the SCADA Control
Building SCADA System in LabView Environment
Higher Institute for Applied Sciences and Technology (HIAST)
Control Department - Mechatronics – 5th year

Final assignment

Prepared by: Eng. Al-Kayal Khaldoun


Kaldoun.kayal@hiast.edu.sy
Damascus 2013
Final assignment
Final assignment
Suppose we have three perpendicular accelerometers strapped down on a
moving vehicle, which has fixed orientation with respect to our coordinate
frame XYZ.
Lets consider the first analog output as forward accelerometer, the
second analog output as lateral accelerometer, and the third analog
output as vertical accelerometer.
We should consider that, the meddle value of each analog output is zero,
in order to have positive and negative accelerations.
Final assignment

Do the following obligations:

1- Store the last n measurement of each analog sensor in an array to be


updated every coming measurement ,organizing a scrolling window on the
last n measurement (n=10 could be adjusted).

2- Process the arrays data ,and exclude abnormal values.

3- Calculate the mean values for each array and consider it as an


accelerometer raw data.
Final assignment

4- Convert the row data using the accelerometer scale factor.


where

5- Compensate the bias error for each accelerometer.


where

6- Compensate the misalignment errors between three accelerometers.


where
misalignment error between Ax,Ay = 1.1 m Rad
misalignment error between Ax,Az = -3.2 m Rad
misalignment error between Ay,Az = 1.6 m Rad
Final assignment

7- Calculate the liner speed along each axis, by integrating accelerometers


reading.

8- Calculate the vehicle position along each axis, by integrating speed


reading.

9- Display above calculated values in appropriate interface.

S-ar putea să vă placă și