16.01.2015 Views

Introduction to LabVIEW Control Design Toolkit by Finn Haugen ...

Introduction to LabVIEW Control Design Toolkit by Finn Haugen ...

Introduction to LabVIEW Control Design Toolkit by Finn Haugen ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Introduction</strong> <strong>to</strong><br />

<strong>LabVIEW</strong> <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> 1.0<br />

<strong>by</strong><br />

<strong>Finn</strong> <strong>Haugen</strong><br />

January 30, 2005<br />

Freeware!<br />

Contents:<br />

1 Preface<br />

2 The contents of the <strong>Control</strong> <strong>Design</strong> Palette<br />

3 Creating models<br />

3.1 Creating continuous-time (s-)transfer functions<br />

3.2 Creating discrete-time (z-)transfer functions<br />

3.3 Creating continuous-time state-space models<br />

3.4 Creating discrete-time state-space models<br />

3.5 Standard transfer functions<br />

3.6 PID controllers<br />

3.7 Writing models <strong>to</strong> file. Reading models from file<br />

3.8 Getting information about a model<br />

3.9 Converting <strong>Control</strong> <strong>Design</strong> models <strong>to</strong>/from Simulation Module models<br />

4 Connecting models<br />

4.1 Series connection<br />

4.2 Feedback connection<br />

5 Calculating transfer functions from state-space models<br />

6 Discretizing continuous-time models<br />

7 Simulation (time responses)<br />

8 Frequency response<br />

9 An application: <strong>Control</strong> system analysis and simulation<br />

1 Preface<br />

This document gives an introduction <strong>to</strong> the <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> version 2.0 for <strong>LabVIEW</strong><br />

7.1. (<strong>LabVIEW</strong> is produced <strong>by</strong> National Instruments.) It is assumed that you have basic<br />

knowledge about <strong>LabVIEW</strong> programming.<br />

The introduction is based on simple examples - all downloadable via hyperlinks. Only the basic<br />

functions are demonstrated. You can search for a function via the Help menu in <strong>LabVIEW</strong> or<br />

just browse for it on the <strong>Control</strong> <strong>Design</strong> palette in the Functions palette in <strong>LabVIEW</strong>. Chapter 2<br />

of this document list all functions available in the <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong>.<br />

Each function has several input parameters or arguments. You should always use Help (via<br />

right-clicking on the function block) <strong>to</strong> get information about these parameters before you use<br />

the function in your program.


The <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> was initially launched in Spring 2004. It expands <strong>LabVIEW</strong>'s<br />

capabilities for control system and dynamic system analysis and design considerably. The set of<br />

functions available is comparable with the <strong>Control</strong> System Toolbox in Matlab and the similar<br />

control system function category in Octave.<br />

Included in version 2.0 is the <strong>Control</strong> <strong>Design</strong> Assistant, which is an interactive <strong>to</strong>ol which can<br />

be used independent of <strong>LabVIEW</strong>, and without <strong>LabVIEW</strong> programming (you can however<br />

create <strong>LabVIEW</strong> code from your <strong>Control</strong> <strong>Design</strong> Assistant project). The <strong>Control</strong> <strong>Design</strong><br />

Assistant is available from the Start / Programs / National Instruments meny on your PC and<br />

from the Tools / <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> in <strong>LabVIEW</strong>.<br />

The VIs in the examples does not contain any while loops. Consequently, the VIs run just once.<br />

If you want a VI <strong>to</strong> run continuously with a well-defined time step between each while loop<br />

execution, possibly while you are adjusting some parameters, you can place the block diagram<br />

code in while loop.<br />

If you have comments or suggestions for this document please send them via e-mail <strong>to</strong> finn@<br />

techteach.no.<br />

In the text, CDT will be used as an abbreviation for <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong>.<br />

The date shown in the beginning of the document indicates the version of the document. The<br />

document may be updated any time. Changes from previous versions will be described in the<br />

Preface.<br />

2 The contents of the <strong>Control</strong> <strong>Design</strong> Palette<br />

Once the <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> is installed, the <strong>Control</strong> <strong>Design</strong> palette is available from the<br />

Functions palette. The <strong>Control</strong> <strong>Design</strong> palette is shown in the figure below.<br />

The <strong>Control</strong> <strong>Design</strong> palette<br />

Below is a list of functions (and possible subpalettes) on the <strong>Control</strong> <strong>Design</strong> palette. (It may be<br />

wise <strong>to</strong> just browse the list <strong>to</strong> get a quick impression of the possibilities.)<br />

The Model Construction palette, with the following functions and/or subpalettes:<br />

Construct State-Space Model<br />

Construct Transfer Function Model<br />

Construct Zero-Pole-Gain Model<br />

Construct Random Model<br />

Construct Special Model:<br />

First order with (or without) time delay<br />

Second order with (or without) time delay<br />

Delay Pade Approximation


PID Parallel<br />

PID Academic (parallel form)<br />

PID Serial<br />

Draw Transfer Function Equation (for displaying the transfer function nicely on the<br />

screen, as writing on paper)<br />

Draw Zero-Pole-Gain Equation<br />

Read Model From File<br />

Write Model From File<br />

Model Information palette (containing functions for setting and getting model<br />

information or properties)<br />

The Model Conversion palette, with the following functions:<br />

Convert <strong>to</strong> State-Space Model<br />

Convert <strong>to</strong> Transfer Function Model<br />

Convert <strong>to</strong> Zero-Pole-Gain Model<br />

Convert Delay with Pade Approximation<br />

Convert Delay <strong>to</strong> Poles at Origin<br />

Convert Continuous <strong>to</strong> Discrete (with various methods, e.g. Euler, Tustin, zero<br />

order hold)<br />

Convert Discrete <strong>to</strong> Discrete (changing the sampling interval)<br />

Convert Discrete <strong>to</strong> Continuous<br />

Convert <strong>Control</strong> <strong>Design</strong> <strong>to</strong> Simulation (converting models used in <strong>Control</strong> <strong>Design</strong><br />

Tookit for use in Simulation Module)<br />

Convert Simulation <strong>to</strong> <strong>Control</strong> <strong>Design</strong> (converting models used in Simulation<br />

Module for use in <strong>Control</strong> <strong>Design</strong> Tookit)<br />

The Model Interconnection palette, with the following functions and/or subpalettes:<br />

Serial<br />

Parallell<br />

Feedback<br />

Append<br />

Rational Polynomial palette with functions for combining polynomials<br />

The Model Reduction palette, with the following functions:<br />

Minimal Realization<br />

Model Order Reduction<br />

Minimal State Realization<br />

Remove IO (input or output) from Model<br />

Select IO (input or output) from Model<br />

The Time Response palette, with the following functions and/or subpalettes:<br />

Step Response (step input)<br />

Impulse Response (impulse input)<br />

Initial Response (response from initial state, with zero input)<br />

Linear Simulation (with user-defined input signal)<br />

Get Time Response Data<br />

The Frequency Response palette, with the following functions:<br />

Bode (calculating frequency response data and plotting the data in a Bode diagram)<br />

Nyquist<br />

Nichols<br />

Singular Values<br />

All Margins<br />

Gain and Phase Margin<br />

Evaluate at Frequency<br />

Bandwidth<br />

Get Frequency Response Data<br />

The Dynamic Characteristics palette, with the following functions:<br />

Root Locus<br />

Pole-Zero Map<br />

Damping Ratio and Natural Frequency<br />

DC Gain<br />

Stability


Norm<br />

Covariance Response<br />

Total Delay<br />

Distribute Delay<br />

Parametric Time Response<br />

The State Space Model Analysis palette, with the following functions:<br />

<strong>Control</strong>lability Matrix<br />

Observability Matrix<br />

Grammians<br />

Canonical State-Space Realization<br />

Balance State-Space Model (Diagonal)<br />

Balance State-Space Model (Grammians)<br />

<strong>Control</strong>lability Staircase<br />

Observability Staircase<br />

State Similarity Transform<br />

The State Feedback <strong>Design</strong> palette, with the following functions:<br />

Ackermann<br />

Pole Placement<br />

Linear Quadratic Regula<strong>to</strong>r<br />

Kalman Gain<br />

State Estima<strong>to</strong>r<br />

State-Space <strong>Control</strong>ler<br />

Augment Output with States<br />

3 Creating models<br />

3.1 Creating and displaying continuous-time (s-)transfer functions<br />

The Model Construction palette contains several functions for creating models. The resulting<br />

model is represented as a cluster. This cluster can be used as input argument <strong>to</strong> other functions,<br />

e.g. for simulation, frequency response analysis, etc.<br />

On the Model Construction palette there are also functions for displaying the transfer function<br />

nicely on the front panel.<br />

Example 3.1.1: Creating and displaying a continuous-time (s-)transfer function<br />

The VI shown below creates the following transfer function using the CD Construct Transfer<br />

Function Model function (CD means <strong>Control</strong> <strong>Design</strong>):<br />

H(s) = e -4s 3/(1+2s) = e -4s 3s 0 /(1s 0 +2s 1 )<br />

(a first order transfer function with gain 3, time constant 2, and time delay 4s). In the VI the CD<br />

Draw Transfer Function function displays the transfer function nicely in on the front panel<br />

(using a picture indica<strong>to</strong>r which can be created <strong>by</strong> right-clicking on the Equation output of the<br />

function).


Front panel and block diagram of create_tf_cont.vi.<br />

End of Example<br />

Note: If the time delay is zero, the Delay input argument of the CD Construct Transfer<br />

Function Model function can be unwired since the default value of the time delay is zero.<br />

Also note: The CD Construct Transfer Function Model function has an input parameter<br />

called Sampling Time. When creating continuous-time models this input must be either unwired<br />

(as in Example 3.1) or wired with value zero. If a non-zero sampling time is connected, a<br />

discrete-time transfer function will be created (with the numera<strong>to</strong>r and denomina<strong>to</strong>r coefficients<br />

as defined in the Numera<strong>to</strong>r and Denomina<strong>to</strong>r arrays). Cf. Section 3.2.<br />

3.2 Creating discrete-time (z-)transfer functions<br />

Example 3.2.1: Creating a discrete-time (z-)transfer function<br />

The VI shown below creates the following transfer function:<br />

H(z) = z -5 0.4/(-0.6+z) = z -5 0.4z 0 /(-0.6z 0 +1z 1 )<br />

with sampling time 0.1s. The fac<strong>to</strong>r z -5 represents a time delay of integer 5 samples (or time<br />

steps), not 5 seconds. (For the present transfer function, the time delay in seconds is 0.1*5 =<br />

0.5s.)<br />

Front panel and block diagram of create_tf_discrete.vi.<br />

End of Example<br />

3.3 Creating continuous-time state-space models<br />

Example 3.3.1: Creating a continuous-time state-space model


The VI shown below creates the following continuous-time state-space model using the CD<br />

Construct State-Space Model function:<br />

In the VI the matrices are represented <strong>by</strong> arrays. For all models (no matter the order or<br />

dimension of the system) these arrays are 2-dimensional arrays.<br />

End of Example<br />

Front panel and block diagram of create_cont_ss_model.vi.<br />

Note: The CD Construct State-Space Model function has an input parameter called Sampling<br />

Time. When creating continuous-time models this input must be either unwired (as in Example<br />

3.3) or wired with value zero. If a non-zero sampling time is connected, a discrete-time statespace<br />

model will be created (with the system matrices as defined <strong>by</strong> the 2-dimensional arrays A,<br />

B, C, and D).<br />

3.4 Creating discrete-time state-space models<br />

Example 3.4.1: Creating a discrete-time state-space model


The VI shown below creates the following discrete-time state-space model using the CD<br />

Construct State-Space Model function:<br />

x(k+1) = Ax(k) + Bu(k)<br />

y(k) = Cx(k) + Du(k)<br />

where the system matrices A, B, C, and D are as shown in the figure below. In the VI the<br />

matrices are represented <strong>by</strong> arrays. Note that the matrices are technically 2x2 matrices (arrays),<br />

although there may be only one row and/or column in the matrix.<br />

End of Example<br />

Front panel and block diagram of create_discrete_ss_model.vi.<br />

3.5 Standard transfer functions<br />

Several standard transfer functions are available:<br />

First order with (or without) time delay<br />

Second order with (or without) time delay<br />

Delay Pade Approximation<br />

Example 3.5.1: First order system with time delay<br />

The VI below creates a first order transfer function with gain 2, time constant 3 seconds and<br />

time delay 4 seconds.


Front panel and block diagram of first_order_with_time_delay.vi.<br />

End of Example<br />

3.6 PID controllers<br />

Several verions of PID controls are available as transfer functions:<br />

PID Academic:<br />

PID Parallel:<br />

PID Serial:<br />

Example 3.6.1: PID controller<br />

The VI shown below shows how <strong>to</strong> create and display an PID Academic controller (which is a<br />

standard parallel PID controller). (The derivative time is set <strong>to</strong> zero, so the controller is actually<br />

a PI controller.)


Front panel and block diagram of pid_controllers.vi.<br />

End of Example<br />

3.7 Writing models <strong>to</strong> file. Reading models from file<br />

Models can be written <strong>to</strong> a file, and later read from that file, using the CD Write Model <strong>to</strong> File<br />

and CD Read Model from File functions, respectively.<br />

Example 3.7.1: Writing a transfer function model <strong>to</strong> a file<br />

The VI shown below shows how <strong>to</strong> write a transfer function model <strong>to</strong> a file.<br />

Front panel and block diagram of file_write_model.vi.<br />

When the CD Write Model <strong>to</strong> File function is executed the usual Save File dialog window<br />

appears. (If you have wired a file path <strong>to</strong> the File Path input of the function, this dialog window<br />

is not opened.) You can give the file any name (the file extension does not matter).<br />

End of Example<br />

A model can be read from a model file using the CD Read Model from File function.<br />

Example 3.7.2: Reading a transfer function model from a file<br />

The VI shown below shows how <strong>to</strong> read a transfer function model from a file. (The model is the<br />

same as in Example 3.7.1.)<br />

Front panel and block diagram of file_read_model.vi.<br />

When the CD Read Model from File function is executed a File dialog window appears. (If<br />

you have wired a file path <strong>to</strong> the File Path input of the function, this dialog window is not<br />

opened.)<br />

End of Example


3.8 Getting information about a model<br />

You can get various information about a model <strong>by</strong> using functions on the Create Model /<br />

Model Information subpalette.<br />

Example 3.8.1: Getting the numera<strong>to</strong>r and denomina<strong>to</strong>r coeffiecient arrays of a transfer function<br />

model<br />

The VI shown below shows how <strong>to</strong> get the numera<strong>to</strong>r and denomina<strong>to</strong>r coeffiecient arrays of a<br />

transfer function model using the CD Get Data from Model function.<br />

End of Example<br />

Front panel and block diagram of get_model_data.vi.<br />

3.9 Converting <strong>Control</strong> <strong>Design</strong> models <strong>to</strong>/from Simulation Module models<br />

You can use models created in <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> in a Simulation diagram in the <strong>LabVIEW</strong><br />

Simulation Module. However, it is then necessary <strong>to</strong> first convert the model <strong>by</strong> using the CD<br />

Convert <strong>Control</strong> <strong>Design</strong> <strong>to</strong> Simulation function.<br />

Example 3.9.1: Converting a <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> model <strong>to</strong> a Simulation Module model<br />

The VI shown below shows how <strong>to</strong> convert a transfer function model.<br />

End of Example<br />

Front panel and block diagram of convert_<strong>to</strong>_simmodule.vi.<br />

4 Connecting models<br />

The Model Interconnection palette contains several functions for connecting models. Series<br />

connection and a feedback connection of transfer functions are described in the following.


4.1 Series connection<br />

Example 4.1.1: Series connection of transfer function models<br />

The VI shown below shows how <strong>to</strong> get the resulting transfer function of two transfer functions<br />

connected in series using the CD Series function.<br />

End of Example<br />

4.2 Feedback connection<br />

Front panel and block diagram of serial_connection.vi.<br />

In models of feedback control systems, transfer functions are connected in a feedback loop. The<br />

resulting transfer function can be calculated using the CD Feedback function. This functions<br />

works for continuous-time models and for discrete-time models.<br />

Example 4.2.1: Feedback connection of continuous-time transfer function models<br />

The VI shown below shows how <strong>to</strong> get the resulting transfer function of two continuous-time<br />

transfer functions connected in a feedback loop.


Front panel and block diagram of feedback_connection.vi.<br />

End of Example<br />

Note: For continuous-time models, the CD Feedback function ignores a time delay included in<br />

any of the transfer functions in the feedback loop, that is, the resulting transfer function is<br />

derived assuming the time delays are zero. To actually include the time delay(s), use the CD<br />

Construct Special Model function with the option Delay (Pade Approx.) selected <strong>to</strong> create a<br />

rational transfer function representing (and approximating) the time delay. Then include this<br />

transfer function in the feedback loop using e.g. the CD Series function. This is demonstrated in<br />

Example 9.1.<br />

The following example shows how <strong>to</strong> connect discrete-time transfer functions including time<br />

delays in a feedback loop. It is necessary <strong>to</strong> convert the time delay part of a discrete-time model<br />

<strong>to</strong> poles at the origin using the CD Convert Delay <strong>to</strong> Poles at Origin function for the CD<br />

Feedback function <strong>to</strong> produce the correct transfer function of the combined feedback loop. This<br />

also applies <strong>to</strong> discrete-time transfer functions which have been derived <strong>by</strong> discretizing an<br />

original continuous-time transfer function, that is, you have <strong>to</strong> use the CD Convert Delay <strong>to</strong><br />

Poles at Origin function for the CD Feedback function <strong>to</strong> produce the correct result.<br />

Example 4.2.2: Feedback connection of discrete-time transfer function models including time<br />

delay<br />

In the VI shown below two discrete-time transfer functions are connected in a feedback loop.<br />

One of the transfer functions, H 2<br />

(z), contains a time delay of 2 samples, corresponding <strong>to</strong> 2<br />

poles at the origin of the z-plane.


End of Example<br />

Front panel and block diagram of feedback_connection_discrete.vi.<br />

5 Calculating transfer functions from state-space models<br />

The CD Convert <strong>to</strong> Transfer Function Model function converts continuous-time and discretetime<br />

state-space models <strong>to</strong> transfer function models. The resulting transfer function model is<br />

actually a MIMO (multiple input multiple output) transfer function, i.e. a transfer function<br />

matrix. To get a particular SISO (single input single output) transfer function from this MIMO<br />

transfer function you must apply the CD Get Data from Model function. This is illustrated in<br />

the following example. This example is about a continuous-time model, but the same functions<br />

are used for discrete-time models.<br />

Example 5.1: Calculating transfer function from state-space model<br />

The VI shown below shows how <strong>to</strong> get the SISO transfer function from input u <strong>to</strong> output y from<br />

the state-space model


dx/dt = Ax + Bu<br />

y = Cx + Du<br />

where the system matrices are as shown on the VI front panel below.<br />

Front panel and block diagram of convert_ss_<strong>to</strong>_tf.vi.<br />

Note that the indexing of the rows and the columns start with indices 0, i.e. the first row has<br />

index 0, and the first column has index 0.<br />

End of Example<br />

6 Discretizing continuous-time models<br />

The following example illustrates how <strong>to</strong> discretize a continuous-time transfer function using<br />

the CD Convert Continuous <strong>to</strong> Discrete function. The same function can be used <strong>to</strong> discretize<br />

state-space models. Converting a model the opposite way - from discrete-time <strong>to</strong> continuoustime<br />

- is done in a similar way using the CD Convert Discrete <strong>to</strong> Continuous function.<br />

Example 6.1: Discretizing a continuous-time transfer function<br />

The VI shown below shows how <strong>to</strong> do the discretization using the ZOH method (zero order<br />

hold) with sampling time 0.2s. The original transfer function contains a time delay of 1 second.<br />

This time delay is represented in the discrete-time transfer function <strong>by</strong> the fac<strong>to</strong>r z -5 (since<br />

5*0.2s = 1s).


Front panel and block diagram of convert_cont_<strong>to</strong>_discrete.vi.<br />

End of Example<br />

7 Simulation (time responses)<br />

The Time Response palette contains several simulation functions for simulating step response,<br />

impulse response, arbitrary input response, and initial state response. The following example<br />

shows how <strong>to</strong> simulate the step response.<br />

The simulations are run as a "batch" simulation, being completed as fast as the PC allows. If<br />

you want a real-time simulation, i.e. the simulation develops along a real time axis, you can use<br />

<strong>LabVIEW</strong> Simulation Module. Models created in the <strong>Control</strong> <strong>Design</strong> <strong>Toolkit</strong> can be used in the<br />

Simulation Module <strong>by</strong> using the models conversion functions demonstrated in Chapter 3.10.<br />

Example 7.1: Simulation of the step response of a continuous-time transfer function<br />

The VI shown below simulates the step response of the following transfer function:<br />

H(s) = 3/(1+2s)


Front panel and block diagram of step_response_tf_model.vi.<br />

CD Step Response simulates with a unity step (amplitude 1) at the model input.<br />

The graph indica<strong>to</strong>r can be created <strong>by</strong> right-clicking on the Step Response Graph output of the<br />

CD Step Response function.<br />

End of Example<br />

8 Frequency response<br />

The Frequency Response palette contains several functions for generating and plotting<br />

frequency response data - for continuous-time as well as discrete-time models.<br />

Example 8.1: Frequency response of a continuous-time transfer function


Front panel and block diagram of frequency_response.vi.<br />

End of Example<br />

9 An application: Analysis and simulation of control system<br />

Example 9.1: <strong>Control</strong> system analysis and simulation<br />

The VI shown below shows how <strong>to</strong> analyze and simulate a feedback control system. The block<br />

diagram code is put inside a while loop with cycle time 100ms <strong>to</strong> make the program run<br />

continuously. The controller is a PID Academic controller (which has parallel form) with the<br />

following transfer function, H c<br />

(s):


A Pade approximation is used <strong>to</strong> represent the time delay of the process because the CD<br />

Feedback function works correctly only if there are only rational transfer functions in the<br />

feedback loop.


Front panel and block diagram of controlsys_analysis.vi.<br />

End of Example<br />

More free stuff from TechTeach:<br />

KYBSIM - free simula<strong>to</strong>rs, ready <strong>to</strong> run!<br />

<strong>Introduction</strong> <strong>to</strong> <strong>LabVIEW</strong> Simulation Module<br />

<strong>Introduction</strong> <strong>to</strong> discrete-time signals and systems

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!