Labview: Simulation Module User Manual
Labview: Simulation Module User Manual
TM
November 2005
371013C-01
Support
Worldwide Offices
Australia 1800 300 800, Austria 43 0 662 45 79 90 0, Belgium 32 0 2 757 00 20, Brazil 55 11 3262 3599,
Canada 800 433 3488, China 86 21 6555 7838, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00,
Finland 385 0 9 725 725 11, France 33 0 1 48 14 24 24, Germany 49 0 89 741 31 30, India 91 80 51190000,
Israel 972 0 3 6393737, Italy 39 02 413091, Japan 81 3 5472 2970, Korea 82 02 3451 3400,
Lebanon 961 0 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793, Netherlands 31 0 348 433 466,
New Zealand 0800 553 322, Norway 47 0 66 90 76 60, Poland 48 22 3390150, Portugal 351 210 311 210,
Russia 7 095 783 68 51, Singapore 1800 226 5886, Slovenia 386 3 425 4200, South Africa 27 0 11 805 8197,
Spain 34 91 640 0085, Sweden 46 0 8 587 895 00, Switzerland 41 56 200 51 51, Taiwan 886 02 2377 2222,
Thailand 662 278 6777, United Kingdom 44 0 1635 523545
For further support information, refer to the Technical Support and Professional Services appendix. To comment
on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter
the info code feedback.
Copyright
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying,
recording, storing in an information retrieval system, or translating, in whole or in part, without the prior written consent of National
Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright
and other intellectual property laws. Where NI software may be used to reproduce software or other materials belonging to others, you may
use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license or other legal
restriction.
Trademarks
National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section
on ni.com/legal for more information about National Instruments trademarks.
MATLAB®, Stateflow®, and Simulink® are the registered trademarks of The MathWorks, Inc. Further, other product and company names
mentioned herein are trademarks, registered trademarks, or trade names of their respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have no
agency, partnership, or joint-venture relationship with National Instruments.
Patents
For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software, the patents.txt file
on your CD, or ni.com/patents.
You are only permitted to use this product in accordance with the accompanying license agreement. All rights not expressly granted to you in
the license agreement accompanying the product are reserved to NI. Further, and without limiting the forgoing, no license or any right of any
kind (whether by express license, implied license, the doctrine of exhaustion or otherwise) is granted under any NI patents.
Chapter 1
Introduction to Simulation
Dynamic System Models ...............................................................................................1-2
Physical Models...............................................................................................1-2
Lumped versus Distributed Parameter Models.................................1-2
Linear versus Nonlinear Models .......................................................1-3
Time-Variant versus Time-Invariant Models ...................................1-3
Continuous versus Discrete Models..................................................1-3
Empirical Models ............................................................................................1-4
Linear Model Forms ........................................................................................1-4
Ordinary Differential Equation Solvers .........................................................................1-4
Rapid Control Prototyping and Hardware-in-the-Loop Configurations........................1-5
Chapter 2
Building Simulations
Using the Simulation Loop ............................................................................................2-1
Displaying Additional Inputs ..........................................................................2-2
Removing and Rearranging Inputs..................................................................2-2
Configuring Simulation Parameters...............................................................................2-3
Configuring Simulation Parameters Interactively ...........................................2-3
Configuring Simulation Parameters Programmatically...................................2-4
Using Simulation Functions...........................................................................................2-4
Defining Feedthrough Behavior and Feedback Cycles ...................................2-5
Changing Icon Styles.......................................................................................2-8
Configuring Simulation Functions ..................................................................2-8
Configuring Discrete Simulation Functions....................................................2-10
Stopping a Simulation Programmatically........................................................2-11
Placing LabVIEW VIs, Functions, and Structures on the
Simulation Diagram......................................................................................2-11
Chapter 3
Creating Simulation Subsystems
Creating and Running Subsystems................................................................................ 3-1
Creating Stand-Alone Subsystems.................................................................. 3-1
Running Subsystems within a Simulation Diagram ....................................... 3-3
Defining the Feedthrough Behavior of Subsystems...................................................... 3-4
Linearizing a Subsystem................................................................................................ 3-4
Linearizing a Subsystem Interactively ............................................................ 3-5
Linearizing a Subsystem Programmatically ................................................... 3-5
Trimming a Subsystem.................................................................................................. 3-7
Chapter 4
Executing Real-Time Applications
Determinism .................................................................................................................. 4-1
Case Study: Rapid Control Prototype and Hardware-in-the-Loop Configurations....... 4-2
Offline Simulation........................................................................................... 4-3
Rapid Control Prototype Configuration .......................................................... 4-3
Hardware-in-the-Loop Configuration ............................................................. 4-4
Executing Simulations on ETS Targets......................................................................... 4-5
Executing Simulations on RTX Targets........................................................................ 4-5
Chapter 5
Solving Ordinary Differential Equations
Simulation Discontinuities ............................................................................................ 5-2
ODE Solver Order and Simulation Accuracy ............................................................... 5-2
Variable Step-Size ODE Solvers versus Fixed Step-Size ODE Solvers....................... 5-3
Single-Step ODE Solvers versus Multi-Step ODE Solvers .......................................... 5-4
Stiff Problems................................................................................................................ 5-4
Simulation Module ODE Solvers.................................................................................. 5-5
Chapter 6
Optimizing Design Parameters
Constructing the Dynamic System Model .....................................................................6-3
Defining a Cost Function ...............................................................................................6-4
Defining Inequality Constraints.....................................................................................6-7
Defining Parameter Bounds...........................................................................................6-9
Defining Initial Parameter Values and a Mesh ..............................................................6-10
Executing the SQP Algorithm .......................................................................................6-11
Case Study: Designing a PID Controller for a Second-Order System ..........................6-12
Chapter 7
Using the Simulation Translator
Converting Models into LabVIEW Code ......................................................................7-1
Common Warnings ........................................................................................................7-2
Appendix A
Technical Support and Professional Services
Glossary
This manual contains information about the purpose of simulation and the
simulation process. This manual also describes how to use the LabVIEW
Simulation Module to simulate the behavior of a dynamic system.
Use this manual to learn how to use the Simulation Module in real-time
applications and how to use the Simulation Translator to convert model
(.mdl) files developed in The MathWorks, Inc. Simulink® simulation
environment into LabVIEW VIs. This manual also describes factors to
consider when you develop a model and factors to consider when you select
an ordinary differential equation (ODE) solver to use for a simulation.
This manual requires that you have a basic understanding of the LabVIEW
environment. If you are unfamiliar with LabVIEW, refer to the Getting
Started with LabVIEW manual before reading this manual.
Conventions
The following conventions appear in this manual:
» The » symbol leads you through nested menu items and dialog box options
to a final action. The sequence File»Page Setup»Options directs you to
pull down the File menu, select the Page Setup item, and select Options
from the last dialog box.
bold Bold text denotes items that you must select or click in the software, such
as menu items and dialog box options. Bold text also denotes parameter
names; dialog box names; and pages, sections, and components of dialog
boxes.
italic Italic text denotes variables, emphasis, or a cross reference. Italic text also
denotes text that is a placeholder for a word or value that you must supply.
monospace Text in this font denotes text or characters that you should enter from the
keyboard. This font is also used for the proper names of disk drives, paths,
directories, programs, subprograms, subroutines, device names, functions,
operations, variables, filenames, and extensions.
Related Documentation
The following documents contain information that you might find helpful
as you read this manual.
• LabVIEW Help
• LabVIEW Control Design Toolkit User Manual
• LabVIEW System Identification Toolkit User Manual
• LabVIEW Real-Time Module Help
• LabVIEW Execution Trace Toolkit User Guide
• NI-CAN Hardware and Software Manual
• NI-DAQmx Help
Control System
Sensors
Physical Models
The laws of physics define the physical model of a system. The following
sections describe various classifications and features of physical models.
1 Dorf, Richard C., and Robert H. Bishop. Modern Control Systems, 9th ed. Upper Saddle River, NJ: Prentice-Hall, Inc., 2001.
2 Franklin, Gene F., J. David Powell, and Abbas Emami-Naeini. Feedback Control of Dynamic Systems, 4th ed. Upper Saddle
River, NJ: Prentice Hall, 2002.
3 Franklin, Gene F., J. David Powell, and Michael L. Workman. Digital Control of Dynamic Systems, 3rd ed. Menlo Park, CA:
Addison Wesley Longman, Inc., 1998.
4 Nise, Norman S. Control Systems Engineering, 3rd ed. New York: John Wiley & Sons, Inc., 2000.
5 Ogata, Katsuhiko. Modern Control Engineering, 4th ed. Upper Saddle River, NJ: Prentice-Hall, Inc. 2001.
y1 = ƒ(x1)
y2 = ƒ(x2)
Y = ƒ(x1 + x2) = y1 + y2
Empirical Models
Empirical models use data gathered from experiments to define the
mathematical model of a system. To some degree, physical models are
empirical because you experimentally determine certain constants used to
develop the model. A variety of empirical modeling methods exist. One
method of empirical modeling uses tables of experimental data that
represent the system you want to model. Another method for developing
models uses system identification methods. System identification methods
use measured data to create differential or difference equation
representations that model the data. You can use System Identification
Toolkit to create models using system identification methods.
You can use the Simulation Module in conjunction with the LabVIEW
Control Design Toolkit, the LabVIEW Real-Time Module, and National
Instruments RT Series hardware to design and implement RCP and HIL
configurations. Refer to Chapter 4, Executing Real-Time Applications, for
more information about RCP and HIL configurations.
This chapter provides information about using the Simulation Loop and
Simulation functions to design, build, and configure simulations in
LabVIEW.
The Simulation Loop has two attached nodes. Use the Input Node of the
Simulation Loop to programmatically configure parameters of a
simulation. Refer to the Configuring Simulation Parameters
Programmatically section of this chapter for information about using the
Input Node to configure simulation parameters. Use the Output Node to
view any errors that occur during the Simulation Loop.
The second method you can use is adding individual inputs. To add the next
available input, right-click the Input Node and select Add Input from the
shortcut menu.
The third method you can use is displaying all the available inputs. To
display all the available inputs, right-click the Input Node and select Show
All Inputs from the shortcut menu.
The second method you can use is removing individual unwired inputs. To
remove the last unwired input on the Input Node, right-click the node and
select Remove Input from the shortcut menu.
You also can rearrange the order of unwired inputs on the Input Node.
Right-click an input and select Select Input from the shortcut menu to view
a list of inputs. The top half of this list contains the inputs currently
displayed on the Input Node. The input on which you right-clicked has a
checkmark by it. Select an input from the top half of the list to switch the
positions of the inputs. The bottom half of this list contains the inputs not
currently displayed on the Input Node. Select an input from the bottom half
of the list to replace the selected input with the input you select.
The Configure Simulation Parameters dialog box has two pages that
display different categories of parameters. You configure general
simulation parameters on the Simulation Parameters page. You configure
timing parameters on the Timing Parameters page. Refer to the LabVIEW
Help, available by selecting Help»Search the LabVIEW Help, for
information about the Configure Simulation Parameters dialog box.
Figure 2-2 shows how the gray boxes on the Input Node display any values
that you configure in the Configure Simulation Parameters dialog box.
Values that you configure programmatically do not have gray boxes.
You can use one or more Simulation functions and other LabVIEW
functions in a feedback cycle as long as at least one Simulation function
in the feedback cycle has indirect feedthrough behavior. The indirect
feedthrough function can start the data flow by executing the function
output at the current step before receiving an input from the cycle at the
current step. Therefore, the input at the current step and the output at the
current step must not depend on each other directly in at least one function
in the cycle.
has direct feedthrough to that output, the wire breaks. Figure 2-3 shows this
behavior.
Note The wires on the simulation diagram use arrows to indicate the direction of data
flow. These arrows help you identify feedback cycles on the simulation diagram by
showing data flow direction.
For other Simulation functions, the parameter values you specify determine
the feedthrough behavior. The following Simulation functions have
parameter-dependent feedthrough behavior:
• Transfer Function
• Zero-Pole-Gain
• State-Space
• Discrete Filter
• Discrete Integrator
• Discrete Transfer Function
• Discrete Zero-Pole-Gain
• Discrete State-Space
The Parameters section lists all the parameters that you can configure for
the Sine Signal function. When you select a parameter from the
Parameters section, the Parameter Information section displays a
control you can use to set the value of that parameter.
Use the Parameter source control to specify the source of the parameter
value. If you select Terminal, LabVIEW displays an input terminal for that
parameter on the simulation diagram, and you can wire values to this input
to configure the Simulation function. If you select Configuration Dialog
Box, LabVIEW removes that input from the simulation diagram. You then
must set the value for this parameter in the configuration dialog box.
The parameters you specify for a Simulation function are unique to that
function. If you create multiple instances of the same function, you can set
different parameter values for each instance.
Execution
Execution
Figure 2-6. How Period and Skew Affect a Discrete Simulation Function
xi x
---- – round ----i ≤ ε, i = 1, 2…n
z z
diagram. Refer to the SubVI Node Setup Dialog Box topic of the
LabVIEW Help for more information about configuring the behavior
of VIs on the simulation diagram. Refer to Chapter 5, Solving Ordinary
Differential Equations, for information about ODE solvers.
You define the size of MIMO models using the Inputs and Outputs text
boxes in the Model Dimensions section. If the model is state-space, you
also define the number of states using the States text box. The Model
Dimensions section is dimmed if you configure a SISO model because
SISO models have only one input and one output. Figure 2-7 shows a
sample configuration dialog box for a MIMO transfer function model.
The example in Figure 2-7 shows a model with two inputs and two outputs.
The Inputs and Outputs text boxes define these dimensions. The
Numerator and Denominator vectors define the coefficients of the
equation at the current input-output location. The Current Input and
Current Output text boxes define the current input-output location. The
Input-Output Model matrix also shows this location graphically with a
black square.
You can use the Model Conversion VIs in the Control Design Toolkit to
convert model forms and representations on the simulation diagram. For
example, you can wire a continuous controller model to the input of the
CD Convert Continuous to Discrete VI. Then, wire the output of this VI to
the input of a discrete Simulation function.
Refer to the Placing SubVIs on Block Diagrams topic of the LabVIEW Help
for information about placing subsystems within other VIs. Refer to the
Creating SubVIs topic of the LabVIEW Help for information about setting
up a connector pane. Refer to the Configuring Simulation Functions section
of Chapter 2, Building Simulations, for information about using the
configuration dialog box.
As you create the connector pane, consider the parameter requirements and
the initial value of each parameter. The default source for a subsystem
parameter depends on whether you specify that parameter as required,
recommended, or optional. The initial value for the parameter is the default
value of the parameter control.
Note When you create a subsystem using this method, the Simulation Module
automatically creates a connector pane and configuration dialog box for the simulation
subsystem. To launch this configuration dialog box, double-click the subsystem icon. To
edit the front panel or block diagram of the subsystem, right-click the subsystem icon and
select Open Subsystem from the shortcut menu.
subsystem as a stand-alone VI, you must open the subsystem and select
Operate»Configure Simulation Parameters or File»VI Properties from
the pull-down menu.
Linearizing a Subsystem
Linearizing a continuous nonlinear subsystem involves approximating the
behavior of the subsystem around an operating point. The operating point
is the set of the inputs and states of the subsystem. When you linearize a
subsystem, the result is a linear time-invariant (LTI) state-space model.
You can design a controller for LTI models using the LabVIEW Control
Design Toolkit. Refer to the Linear versus Nonlinear Models section of
Chapter 1, Introduction to Simulation, for information about linear and
nonlinear models.
Before you linearize a subsystem, you must choose the subsystem inputs
and outputs to include in the LTI model. If an input or output is constant,
you can exclude that input or output from the LTI model. You cannot
exclude a subsystem state from the LTI model.
You also can change the value of subsystem inputs and states. You cannot
change the value of subsystem outputs, because outputs are functions of the
inputs and states of the subsystem. However, you can trim a subsystem to
specify certain output conditions. Refer to the Trimming a Subsystem
section of this chapter for information about trimming a subsystem.
Note The default Parameter Type of each state, input, and output is Variable.
Note You can specify the subsystem to linearize using a Path or Reference to the
subsystem. Using a path to a subsystem causes the subsystem to load into memory every
time a VI accesses the subsystem. Using a reference to a subsystem ensures that the
subsystem loads into memory only once.
To obtain the parameter names or parameter values for a subsystem, use the
SIM Get Parameter Names VI or the SIM Get Parameter Value VI,
respectively. Refer to the LabVIEW Help for more information about the
Trim & Linearize VIs.
Trimming a Subsystem
Use the SIM Trim VI to trim a continuous simulation subsystem. Trimming
a subsystem involves searching for values of subsystem inputs and states
that satisfy any conditions you specify. By default, this VI trims a
subsystem to a steady state in which all state derivatives are zero. By
default, this VI does not specify any conditions and includes all inputs and
states in the search. You can use the SIM Query Subsystem VI and the SIM
Set Parameter Value VI to change the behavior of SIM Trim VI in the
following ways:
• Trim a subsystem to a transient state—Specify a non-zero Value for
one or more state derivatives. You also must set the Parameter Type
of these state derivatives to Fixed.
• Specify one or more state, input, and/or output
conditions—Specify a Value for one or more states, inputs, and/or
outputs. You also must set the Parameter Type of these states, inputs,
and/or outputs to Fixed.
For example, consider a car model car.vi that contains car position
as a state. The car model has a cruise-control system that must set the
position of the accelerator to maintain forward movement at a specified
velocity. You can specify the velocity of the car using the derivative of car
position. Figure 3-2 shows a LabVIEW block diagram that trims the car
model using a specified velocity of 60 miles per hour.
Note If the SIM Trim VI cannot satisfy all specified conditions, this VI returns the closest
values to the specified conditions.
Determinism
Running a simulation or controller in real time means that the simulation
time must equal the wall-clock time at each point at which the simulation
or controller interacts with the real world. Generally, these physical
interaction points correspond to the sampling points of the input and output
hardware. Thus, at each sampling time, the simulation time must equal the
wall-clock time.
All of the discrete ODE solvers have an inherently fixed time step size and
are inherently deterministic. Therefore, the discrete ODE solvers are
appropriate for real-time implementation. The Discrete Systems functions
use the discrete ODE solvers in their implementation. ODE solver
determinism is important only when you use continuous dynamic
functions, such as the Integrator, State-Space, Transfer Function, and
Zero-Pole-Gain functions.
Offline Simulation
The starting point is an offline simulation of the full dynamic system.
Offline systems are not connected to any hardware. The simulation
diagram in Figure 4-1 represents a simple control system. The system
contains a controller, a model of the plant, and a front panel control that
represents the set point or reference signal.
Hardware-in-the-Loop Configuration
A HIL configuration simulates the plant model when the plant model is
connected to a hardware controller. To convert an offline simulation to a
HIL configuration, remove the controller model from the simulation.
Replace the controller input with an output from a hardware device, and
replace the controller output with an input from a hardware device. The
result is a system similar to the RCP implementation, except with the
controller model, not the plant model, replaced with physical hardware
inputs and outputs.
When you follow this procedure, other tasks can to continue to execute
when the simulation is not scheduled to execute. Refer to the
LabVIEW Help for more information about using the LabVIEW Real-Time
Module for RTX Targets.
dy
------ = f ( t, y )
dt
y ( t0 ) = y0
A time step at time t + dt is a major time step of the ODE solver. All ODE
solvers might need to evaluate the simulation diagram multiple times
between major time steps to compute accurate values for time t + dt. A time
step at these intermediate evaluation times is a minor time step of the ODE
solver. Because LabVIEW indicators update only at major time steps, you
might notice data flowing through the simulation diagram several times
before LabVIEW updates the indicators and graphs.
Simulation Discontinuities
In general, the Simulation Module ODE solvers assume that all simulation
diagram signals and signal derivatives are continuous throughout any time
step. To get the most accurate solution possible, the ODE solver must stop
and restart whenever the solver encounters a discontinuity. Therefore, the
presence of many discontinuities in a simulation limits the maximum step
size that an ODE solver can take. The number of discontinuities influences
which ODE solver you choose.
1 Ascher, Uri M., and Linda R. Petzold. Computer Methods for Ordinary Differential Equations and Differential-Algebraic
Equations. Philadelphia: Society for Industrial and Applied Mathematics, 1998.
2 Shampine, Lawrence F. Numerical Solution of Ordinary Differential Equations. New York: Chapman & Hall, Inc., 1994.
As these examples show, high-order ODE solvers usually are more accurate
than low-order ODE solvers. In general, you can use fewer time steps and
larger step sizes with a high-order ODE solver to get the accuracy you need.
Using fewer time steps decreases the effects of round-off in the solution and
potentially reduces the amount of time needed to compute the solution.
Variable step-size ODE solvers can take small time steps when the
simulation variables vary rapidly and can take larger time steps when the
simulation variables vary slowly. This ability to change step sizes can
increase computational efficiency.
Stiff Problems
Certain problems, such as problems with transients that vary more quickly
than the problem solution, can be difficult to solve numerically. These
problems are stiff problems. When you solve stiff problems without a stiff
ODE solver, you might notice that variable step-size ODE solvers take
smaller and smaller time steps until the ODE solver can no longer make
progress on the simulation. You also might notice an inaccurate and rapidly
growing oscillatory solution no matter how small a step size you use. In this
situation, you can use a stiff ODE solver to get a more accurate solution.
For example, when designing a suspension system for a car, you must select
a stiffness constant for a spring and a damping constant for a dissipative
element. The goal is to find a parameter set that provides maximum
comfort. This optimal parameter set corresponds to a performance
measure, such as the average deviation of the passenger from a desired
height as the car travels down the road. You use parameter design to
determine this optimal parameter set while taking into account the
dynamics of the system and the expected operating conditions and
disturbances.
You can use several techniques to determine this parameter set. For some
problems, you might be able to compute the optimum analytically.
However, analytical solutions typically are difficult or impossible to
compute. In such cases, you can use numerical optimization instead. A
powerful and general purpose numerical optimization algorithm is
sequential quadratic programming (SQP). The SIM Optimal Design VI
uses this algorithm. This VI provides domain-specific functions you can
use to perform parameter optimization for design purposes. Specifically,
you can use this VI to determine optimal parameters from finite-horizon
time-domain dynamics simulations.
min ( J ( p ) )
hl ≤ H ( p ) ≤ hu
pl ≤ p ≤ pu
Designing a system using the SQP algorithm involves the following steps:
1. Constructing the dynamic system model and specifying the component
of that model for which you want to find optimal parameter values.
2. Defining a performance measure, also known as a cost function, you
want to minimize.
3. Defining any constraints on the dynamic system that any feasible
parameter values must satisfy.
4. Defining minimum and maximum values for each parameter.
5. Defining a set of initial parameter values and an initial parameters
mesh, which generates additional sets of initial parameter values.
6. Executing the SQP algorithm, using the information you specified in
steps 1 through 5, by running the SIM Optimal Design VI.
Note The cost function, inequality constraints, and component to optimize make up the
Problem Specification parameter of the SIM Optimal Design VI. For each option, you can
choose from pre-defined types or specify a customized version.
ru ry
Control Output
Feedforward Feedforward
Filter Filter
F2 G2
+ +
r Reference + u +
Controller Plant +
Filter y
C G1
F1 –
Sensor
S
F1, F2, C, G1, G2, and S consist of transfer functions and associated
information, such as delays and sampling time. You can use the
SIM Construct Default System VI to construct these transfer functions and
specify reference input signals r, ru, and ry . This VI returns the necessary
dynamic system information in the System Data output, which you then
can wire to the System Data input of the SIM Optimal Design VI. The
SIM Optimal Design VI then excites the system using the defined inputs
and obtains the time response.
Use the System response type parameter of the SIM Optimal Design VI to
specify if you want this VI to return optimal parameter values for C, F1, or
F2. By default, C is a parallel PID controller defined by the following
equation:
K KD s
U ( s ) = K P e + -----I + ---------------
s αs + 1
where α = 0.01, U is the control action, s is the Laplace variable, and KP,
KI, and KD are the proportional, integral, and derivative gains, respectively.
You also can define a custom type of system response data you want to
optimize by using VI templates. To access these templates, select File»New
from the pull-down menu to launch the New dialog box. Then select
VI»From Template»Simulation»Optimization Based Design from the
Create New tree. Double-click SIM System response (Modify
Controller Only).vit to modify only the structure of the controller.
Double-click SIM System response (General).vit to define a new
dynamic system structure.
If you define a new dynamic system structure, the block diagram code you
write must generate the output vector y and the time vector Time. The code
also must generate the control action vector u unless the optimization
problem does not require a control action. For example, if you use the
SIM Optimal Design VI to design the physical parameters of a mechanism,
you do not need to specify a control action. In this situation, ensure the cost
function and inequality constraints you specify do not take a control action
into account.
Use the Cost type parameter of the SIM Optimal Design VI to specify the
type of cost function you want this VI to minimize. The Simulation Module
includes the following types of cost functions:
• IE—A cost function that integrates the error.
• IAE—A cost function that integrates the absolute value of the error.
• ISE—A cost function that integrates the square of the error.
• ITAE—A cost function that integrates the time multiplied by the
absolute value of the error.
• ITE—A cost function that integrates the time multiplied by the error.
• ITSE—A cost function that integrates the time multiplied by the
square of the error.
• ISTE—A cost function that integrates the square of the time multiplied
by the square of the error.
• LQ—A linear quadratic cost function.
• Sum of Variances—A cost function based on the variance of the error
multiplied by the variance of the control action.
Refer to the SIM Optimal Design topic of the LabVIEW Help, available by
selecting Help»Search the LabVIEW Help from the pull-down menu, for
the equations of these cost functions.
You also can define a custom cost function using a VI template. To load this
template, in the New dialog box, select VI»From Template»Simulation»
Optimization Based Design»SIM Compute Cost.vit from the Create
New tree.
After you define these parameters, you can write LabVIEW block diagram
code to manipulate the parameters according to the cost function. For
example, the following equation defines the IE cost function.
T N
J IE = ∑∫ e i ( t ) dt ≅ ∑ ∑ ( ∆t ⋅ e ( n ) )
i
i 0 i n=0
where e(t) is the measured error, N is the total number of samples in the
time response, n is the current time response sample, and i is the index of
the current output.
Figure 6-2 shows the LabVIEW block diagram that represents this cost
function.
You can view the LabVIEW block diagrams of other cost functions in the
labview\vi.lib\addons\simulation\Optimization Based
Design\Cost\ directory.
Note The IE cost function in Figure 6-2 does not take the control action into account. In
this case, do not delete the u parameter from the block diagram. Deleting this parameter
breaks the connector pane structure on which the SIM Optimal Design VI depends.
Instead, leave the parameter unwired.
After you save the custom cost function as a VI, you must specify the
location of the custom function in the Problem Specification parameter of
the SIM Optimal Design VI. Select User defined for the Cost type
parameter and specify the path to the VI in the File path user defined
custom cost calculation path control.
Note Constraints add a great deal of complexity to the optimization problem. If possible,
minimize the number of constraints before executing the SQP algorithm. One strategy to
minimize the number of constraints involves first finding optimal values with no
constraints, then gradually adding constraints and determining the least amount of
constraints required for the dynamic system.
These envelopes are piecewise linear curves that specify the upper and
lower limits on a signal at all instants of simulation time. The SIM Optimal
Design VI then calculates H(p) as the minimum and maximum distance of
the time series points from these envelopes.
Note You can use the Graphically Specify Inequality Constraints VI, located in the
labview\examples\simulation\Optimization Based Design\Graphically
Specify Inequality Constraints\ directory, to draw the upper and lower
envelopes. This VI returns a set of points you then can wire to the Inequality Constraints
parameter.
A, B, C, and D are points that define the upper envelope UEi(t), and E, F,
G, and H are points that define the lower envelope LEi(t). The SIM Optimal
Design VI then constrains yi(t) to the following relationship:
LE i ( t ) < y i ( t ) < UE i ( t )
– ε < UC i < ∞
– ε < LC i < ∞
where ε = 1e–21.
You also can place constraints on the rate of change of control actions and
outputs. If at least five points are available, this VI computes these rates of
change using the following equation:
( t – 2h ) – 8f ( t – h ) + 8f ( t + h ) – f ( t + 2h )
f ( t ) = f------------------------------------------------------------------------------------------------------
·
12h
where t is the simulation time, h is the space between time steps, and f(t) is
an output or control action signal.
At boundaries, or if fewer than five points are available, this VI uses the
following equations instead:
(t + h) – f(t – h)
f ( t ) = f----------------------------------------
· · f(t + h) – f(t )
- or f ( t ) = --------------------------------
2h h
After you save the custom inequality constraint calculations as a VI, you
must specify the location of the custom function in the Problem
Specification parameter of the SIM Optimal Design VI. Select User
defined for the Inequality constraints type parameter and specify the path
to the VI in the File path user defined inequality constraints path control.
To mitigate this problem, you can execute the SQP algorithm several times,
using a different set of initial parameter values each time. If you use a large
enough range of initial parameter values within the given parameter space,
you can be relatively confident that the SQP algorithm finds the global
optimal values.
Each pattern has unique characteristics and strengths. For example, the
simplest possible option is the uniform grid, which generates a specified
number of equally-spaced locations in the parameter space. However, the
uniform random and quasirandom options often provide better coverage of
the parameter space while using a fewer number of points than the uniform
grid option. The random walk option biases the search to explore close to
the initial values but eventually explores a larger region of parameter space.
This option is useful if you think a particular parameter space contains the
optimal values and you want to focus on a certain region of that space, such
as the center.
The SQP algorithm takes as long to execute as the product of the number
of function evaluations and the run time of the simulation. If you specify
only one set of initial parameter values, the algorithm must solve, on
average, between 30 and 200 functions. The front panel of the SIM Optimal
Design VI includes a Current Data page that you can use to monitor the
progress of the algorithm as the VI runs. This page updates each time the
SQP algorithm executes from one set of initial parameter values.
The Optimal Design Parameters page of this VI also includes the Best
Parameters (Infeasible Constraints) and Best cost (Infeasible
Constraints) parameters. These parameters return optimal parameter
values and the associated cost function result with no constraints. This
information can be useful when revising the constraint envelopes.
If the dynamic system has constraints and the SQP algorithm does not
return feasible optimal values, try ensuring that the specified cost function
remains constant when parameter values are outside the feasible range.
This method helps you set reasonable parameter bounds. Additionally,
reducing system discontinuities helps the SQP algorithm execute precisely.
Figure 6-4. Block Diagram of the PID Design for Second Order Continuous System VI
1
G 1 ( s ) = -------------------------
-
2
s + 4s + 2
Figure 6-5 shows the System Matrices control that represents this
equation.
Note Notice in Figure 6-6 that r is the third element, or index number 2, of the Signal
Parameters Array. ru and ry correspond to the first and second elements of this array,
respectively. If you define a custom dynamic system, you also can define custom reference
signals beginning with the third element of this array.
The System response type parameter in Figure 6-7 shows this example
optimizes parameters for the controller C. The Inequality constraints type
parameter shows this example uses the default calculations for the
inequality constraint envelopes. The Cost type parameter shows this
example minimizes the linear quadratic (LQ) cost function. The following
equation shows this cost function.
T N
∫ ∑ ∆t ⋅ e ( n )Wu ( n )
T T
J LQ = e ( t )Wu ( t ) dt ≅
0 n=0
The Weights for cost function parameter in Figure 6-7 shows this example
uses the following weight matrix W:
W = 100 0
0 1
This weight matrix penalizes the control action but emphasizes that this
example minimizes the position error. W also reflects the difference in scale
between the control action range and the output range.
Figure 6-8 shows the Inequality Constraints parameter that defines the
inequality constraints envelopes.
Figure 6-8. Specifying Inequality Constraints on the Output and Control Action
The upper constraint envelope on the output is a line with points (0, 1.25)
and (10, 1.05). The lower constraint envelope on the output has points
(0, 0), (0, 1.5), and (10, 0.95). Figure 6-9 shows these envelopes.
Figure 6-8 also shows the constraints on the control action. The upper
constraint envelope is a line with points (0, 75) and (10, 20). The lower
constraint envelope is a line with points (0, –75) and (10, –25). Figure 6-10
shows these envelopes.
This example does not place inequality constraints on either the rate of
control action or the rate of output.
Figure 6-11 shows the parameter bounds this example uses for each gain
parameter of the PID controller.
Figure 6-11. Specifying Parameter Bounds for the Gain Parameters of the
PID Controller
These bounds form the parameter space in which this VI searches for
optimal values.
Figure 6-12 shows the initial parameter values this example uses. Each
element of this array corresponds to same element of the Parameter
Bounds array.
When you run this VI, the SQP algorithm executes once using the values
from the Initial Parameters parameter. The algorithm then executes two
more times, using the Initial Parameters Mesh parameter to generate two
sets of initial parameter values.
The first row of Figure 6-14 is the same as the values shown in Figure 6-12.
The second and third rows contain quasirandomly-generated locations
within the Parameter Bounds of each parameter.
Note The Array of Initial Parameters parameter is on the Debug Information page of
the SIM Optimal Design VI.
After the SQP algorithm executes, this VI returns all possible optimal
parameter values, as shown in Figure 6-15.
Of the parameter value sets shown in Figure 6-15, one set minimizes the
LQ cost function. The SIM Optimal Design VI returns this optimal set of
parameter values in the Design parameters array. Figure 6-16 shows this
array and the corresponding value of the cost function.
Therefore, the optimal gain values for KP, KI, and KD are 14.7257, 11.2553,
and 0.203472, respectively.
Note The Simulation Translator cannot convert diagrams developed with The
MathWorks, Inc. Stateflow® application software or other Simulink blocksets.
Common Warnings
If the Simulation Translator cannot find a value for a parameter in the .mdl
file it is converting, LabVIEW displays a warning. In these cases, the
Simulation Translator uses the default value of the parameter in the
corresponding LabVIEW function.
Note In some cases, the Simulation Translator cannot find a value for a parameter because
the parameter contains an expression instead of a constant value. If the MATLAB software
is installed on the computer, the Simulation Translator attempts to evaluate the MATLAB
software expressions in the .mdl file prior to converting the file. If the Simulation
Translator successfully evaluates the expression, the Simulation Translator uses the result
of that evaluation as the parameter value and does not produce a warning.
The Simulation Translator cannot fully convert all functions of every model
to LabVIEW block diagram code. If the Simulation Translator encounters
a block it cannot convert, you receive a warning. In these cases, the
Simulation Translator creates a placeholder simulation subsystem. You
must create a simulation subsystem using a LabVIEW VI to accomplish the
same functionality as the block to replace this placeholder simulation
subsystem. Refer to the Unsupported Blocks topic of the LabVIEW Help for
a list of the blocks the Simulation Translator cannot convert.
If you searched ni.com and could not find the answers you need, contact
your local office or NI corporate headquarters. Phone numbers for our
worldwide offices are listed at the front of this manual. You also can visit
the Worldwide Offices section of ni.com/niglobal to access the branch
office Web sites, which provide up-to-date contact information, support
phone numbers, email addresses, and current events.
B
BDF Backwards difference formula. Also known as Gear’s Method.
C
CGD Common Graph Description. The format the Simulation Translator uses to
store each system, subsystem, block, and line from a model developed in
The MathWorks, Inc. Simulink® simulation environment.
continuous model Dynamic system model used to represent real-world signals that vary
continuously with time. A continuous model is characterized by differential
equations.
D
direct feedthrough Relationship between a function input and a function output in which the
function uses the input at the current step to calculate the output at the
current step.
discrete model Dynamic system model used to represent signals that are sampled in time
at discrete intervals. A discrete model is characterized by difference
equations.
distributed parameter Physical model that can be described by partial differential equations.
model
E
empirical modeling Modeling technique in which you use experimental data to define a system
model.
F
feedback cycle Cycle in which data flow originates from an output of a function or
subsystem and terminates as an input of the same function or subsystem.
G
global error Maximum difference between the solution the function computes and the
exact solution.
H
HIL Hardware-in-the-loop. A simulation configuration in which you test
a controller implementation with a software model of the plant.
I
indirect feedthrough Relationship between a function input and a function output in which the
function does not use the input at the current step to compute the output at
the current step.
Input Node A collection of input terminals attached to the Simulation Loop. Use the
Input Node to configure simulation parameters programmatically.
L
linear model Model that obeys the principle of superposition.
local error Error introduced into the solution per time step.
M
major time step A time step evaluated at time t + dt.
minor time step A time step evaluated between major time steps.
multi-step ODE ODE solver that approximates the behavior of a model at time t + dt by
solver taking into account the behavior of the model at a number of previous time
steps.
N
nonlinear model Model that does not obey the principle of superposition.
O
ODE Ordinary differential equation.
order ODE solver characteristic that determines how much the error amount
changes when you vary the step size.
Output Node An output terminal on the Simulation Loop. Use the Output Node to view
any errors the simulation diagram generates.
P
PECE Predict-evaluate-correct-evaluate.
period The amount of time in which a discrete Simulation function must complete.
physical modeling Modeling technique in which you use the laws of physics to define a system
model.
R
RCP Rapid control prototype. A simulation configuration in which you test plant
hardware with a software model of the controller.
S
simulation diagram LabVIEW diagram that allows you to use Simulation functions within a
Simulation Loop or simulation subsystem. A simulation diagram, like other
LabVIEW diagrams, has the following semantic properties:
• The order of operations is not completely specified by the user.
• The order of operations is implied by data interdependencies.
• A function may only execute after all necessary inputs have become
available.
• Outputs are generated after a function completes execution.
Simulation Loop Loop that executes the simulation diagram over multiple time steps.
single-step ODE ODE solver that approximates the behavior of a model at time t + dt by
solver taking into account only the behavior of the model at time t.
skew The amount of time by which you want to delay the execution of a discrete
Simulation function.
stiff system System whose dynamics are described by widely varying time constants.
subsystem A section of a simulation diagram you represent with a single icon instead
of multiple Simulation functions and wires.
T
time step Interval from t to t + dt.
trim A procedure that searches for the values of states and inputs that produce
output and/or state derivative conditions you specify.
V
variable step-size ODE solver that adjusts the step size throughout the simulation to ensure
ODE solver that the per-step error remains at a given relative and absolute tolerance.