Intro To LV in 3 Hours For Control and Sim
Intro To LV in 3 Hours For Control and Sim
in 3 Hours
for Control Design and Simulation
1
+_ s
Virtual Instrumentation
For more than 25 years, National Instruments has revolutionized the way engineers and scientists in
industry, government, and academia approach measurement and automation. Leveraging PCs and
commercial technologies, virtual instrumentation increases productivity and lowers costs for test, control,
and design applications through easy-to-integrate software, such as NI LabVIEW, and modular
measurement and control hardware for PXI, PCI, USB, and Ethernet.
With virtual instrumentation, engineers use graphical programming software to create user-defined
solutions that meet their specific needs, which is a great alternative to proprietary, fixed functionality
traditional instruments. Additionally, virtual instrumentation capitalizes on the ever-increasing performance
of personal computers. For example, in test, measurement, and control, engineers have used virtual
instrumentation to downsize automated test equipment (ATE) while experiencing up to a 10 times increase
in productivity gains at a fraction of the cost of traditional instrument solutions. Last year 25,000 companies
in 90 countries invested in more than 6 million virtual instrumentation channels from National Instruments.
Flight Control
Precision Machine Control
Process Control
Control Applications
When discussing control systems, we are actually referring to a large range
of applications. Probably even larger than you have suspected. First of all,
control systems are commonly found in industrial environments. For
example, consider an oil refinery with process control systems that
continually manufacture and produce oil. The control system used for
processing may consist of a Programmable Logic Controller (PLC) executing
a PID algorithm, or a Distribute Control System (DCS) for a larger process
control. In this case, the control system is used to manufacture a product.
A control system can also be part of an end product being manufactured.
This has been seen primarily in the automotive and aerospace industries with
electronic control units and flight control systems. However, control systems
are now finding their way into other end products such as precision motor
controllers for computer hard drives and white goods like washing machines.
While control systems used to manufacture a product often stem from
established control strategies such as PID control, control systems
embedded in end products often use new and innovative control strategies.
The tools and techniques used to develop and embed control systems in
end-products has evolved to include model-based design tools. However,
manufacturing control engineers are also beginning to adopt these tools and
techniques to develop more advanced control systems.
Startup Screen:
Start from a Blank VI:
New » Blank VI
or
Start from an Example:
Examples » Find
Examples…
LabVIEW
LabVIEW is a graphical programming language that uses icons instead of lines of text to create
applications. In contrast to text-based programming languages, where instructions determine program
execution, LabVIEW uses dataflow programming, where the flow of data determines execution order.
You can purchase several add-on software toolkits for developing specialized applications. All the
toolkits integrate seamlessly in LabVIEW. Refer to the National Instruments Web site for more
information about these toolkits.
LabVIEW also includes several wizards to help you quickly configure your DAQ devices and
computer-based instruments and build applications.
LabVIEW Example Finder
LabVIEW includes hundreds of example VIs you can use and incorporate into VIs that you create. In
addition to the example VIs that ship with LabVIEW, you also can access hundreds of example VIs on
the NI Developer Zone (zone.ni.com). You can modify an example VI to fit an application, or you can
copy and paste from one or more examples into a VI that you create.
Block Diagram
Front Panel
Indicator:
Gauge
Use the Controls palette to place controls and indicators on the front panel. The Controls palette is available
only on the front panel. To view the palette, right-click on an open area in the front panel. Alternatively, select
Window » Show Controls Palette. Tack down the Controls palette by clicking the pushpin on the top left corner
of the palette.
Structure:
While Loop
Use the Functions palette to build the block diagram. The Functions palette is available only on the block
diagram. To view the palette, select Window»Show Functions Palette. You also can display the Functions
palette by right-clicking an open area on the block diagram. Tack down the Functions palette by clicking the
pushpin on the top left corner of the palette.
Numeric Numeric
Controls Indicator
When you create an object on the Front Panel, a terminal will be created on the Block Diagram. These terminals
give you access to the Front Panel objects from the Block Diagram code.
Each terminal contains useful information about the Front Panel object it corresponds to. For example, the color
and symbols provide information about the data type. For example: The dynamic data type is a polymorphic data
type represented by dark blue terminals. Boolean terminals are green with TF lettering.
In general, blue terminals should wire to blue terminals, green to green, and so on. This is not a hard-and-fast
rule; LabVIEW will allow a user to connect a blue terminal (dynamic data) to an orange terminal (fractional value),
for example. But in most cases, look for a match in colors.
Controls have an arrow on the right side and have a thick border. Indicators have an arrow on the left and a thin
border. Logic rules apply to wiring in LabVIEW: Each wire must have one (but only one) source (or control), and
each wire may have multiple destinations (or indicators).
Operating Tool
Positioning/Resizing Tool
Labeling Tool
Wiring Tool
If automatic tool selection is enabled and you move the cursor over objects on the front panel or block diagram,
LabVIEW automatically selects the corresponding tool from the Tools palette. Toggle automatic tool selection by
clicking the Automatic Tool Selection button in the Tools palette.
Use the Operating tool to change the values of a control or select the text within a control.
Use the Positioning tool to select, move, or resize objects. The Positioning tool changes shape when it moves
over a corner of a resizable object.
Use the Labeling tool to edit text and create free labels. The Labeling tool changes to a cursor when you create
free labels.
Use the Wiring tool to wire objects together on the block diagram.
Other important tools:
Run Button
Abort Execution
Additional Buttons on
the Diagram Toolbar
• Click the Run button to run the VI. While the VI runs, the Run button appears with a black arrow
if the VI is a top-level VI, meaning it has no callers and therefore is not a subVI.
• Click the Continuous Run button to run the VI until you abort or pause it. You also can click the
button again to disable continuous running.
• While the VI runs, the Abort Execution button appears. Click this button to stop the VI
immediately.
Note: Avoid using the Abort Execution button to stop a VI. Either let the VI complete its data
flow or design a method to stop the VI programmatically. By doing so, the VI is at a known state.
For example, place a button on the front panel that stops the VI when you click it.
• Click the Pause button to pause a running VI. When you click the Pause button, LabVIEW
highlights on the block diagram the location where you paused execution. Click the Pause
button again to continue running the VI.
• Select the Text Settings pull-down menu to change the font settings for the VI, including size,
style, and color.
• Select the Align Objects pull-down menu to align objects along axes, including vertical, top
edge, left, and so on.
• Select the Distribute Objects pull-down menu to space objects evenly, including gaps,
compression, and so on.
• Select the Resize Objects pull-down menu to change the width and height of front panel
objects.
LabVIEW follows a dataflow model for running VIs. A block diagram node executes when all
its inputs are available. When a node completes execution, it supplies data to its output
terminals and passes the output data to the next node in the dataflow path. Visual Basic,
C++, JAVA, and most other text-based programming languages follow a control flow model of
program execution. In control flow, the sequential order of program elements determines the
execution order of a program.
Consider the block diagram above. It adds two numbers and then multiplies by 2 from the
result of the addition. In this case, the block diagram executes from left to right, not because
the objects are placed in that order, but because one of the inputs of the Multiply function is
not valid until the Add function has finished executing and passed the data to the Multiply
function. Remember that a node executes only when data are available at all of its input
terminals, and it supplies data to its output terminals only when it finishes execution. In the
second piece of code, the Simulate Signal Express VI receives input from the controls and
passes its result to the Graph.
You may consider the add-multiply and the simulate signal code to co-exist on the same
block diagram in parallel. This means that they will both begin executing at the same time and
run independent of one another. If the computer running this code had multiple processors,
these two pieces of code could run independent of one another (each on its own processor)
without any additional coding.
Additional Help
– Right-Click on the VI icon
and choose Help, or
– Choose “Detailed Help.” on
the context help window
The Context Help window displays basic information about LabVIEW objects when you
move the cursor over each object. Objects with context help information include VIs,
functions, constants, structures, palettes, properties, methods, events, and dialog box
components.
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
Connections displayed in Context Help:
Required – bold
Recommended – normal
Optional – dimmed
Additional Help
• VI, Function, & How-To Help is also available.
– Help» VI, Function, & How-To Help
– Right-click the VI icon and choose Help, or
– Choose “Detailed Help.” on the context help window.
• LabVIEW Help – reference style help
– Help»Search the LabVIEW Help…
Overview
With the release of National Instruments LabVIEW 8, you have new freedom to choose the most effective
syntax for technical computing, whether you are developing algorithms, exploring DSP concepts, or analyzing
results. You can instrument your scripts and develop algorithms on the block diagram by interacting with
popular third-party math tools such as The MathWorks Inc. MATLAB software, Mathematica, Maple, Mathcad,
IDL and Xmath. Use of these math tools with LabVIEW is achieved in a variety of ways depending on the
vendor as listed below:
In LabVIEW 8, you can combine the intuitive LabVIEW graphical dataflow programming with MathScript, a
math-oriented textual programming language that is generally compatible with popular m-file script language.
(Functions»Programming»
Structures»MathScript)
The MathScript Node enhances LabVIEW by adding a native text-based language for
mathematical algorithm implementation in the graphical programming environment. M-file
scripts you’ve written and saved from the MathScript window can be opened and used in the
MathScript node. M-file scripts you created in other math software will generally run as well.
The MathScript allows you to pick the syntax you are most comfortable with to solve the
problem. Equations can be instrumented with the MathScript Node for parameter exploration,
simulation, or deployment in a final application.
View/Modify
Variable Contents
User Commands
m-file Script
(LabVIEW»Tools»MathScript Window)
The MathScript Window provides an interactive environment where equations can be prototyped and
calculations can be made. The MathScript Window and Node share a common syntax and global
variables making the move from prototype to implementation seamless. The data preview pane
provides a convenient way to view variable data as numbers, graphically, or audibly (with soundcard
support).
Help for MathScript
Help for the environment can be accessed using the Mathscript Interactive Environment Window. Type
Help in the command window for an introduction to MathScript help. Help followed by a function will
display help specific to that function.
Features of the interactive MathScript Window:
• Prototype equations and formulas through the command Window
• Easily access function help by typing Help <function> in the Command Window
• Select a variable to display its data in the Preview Pane and even listen to the result
• Write, Save, Load, and Run m-files using the Script tab
• Share data between the MathScript Node in LabVIEW and the MathScript Window using Global
Variables
• Advanced plotting features and image export features
End of Exercise
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
In this case, the model of the system is derived from the physical model
(using physics). An alternative would be to measure system response to
stimulus and derive a model with LabVIEW System Identification Toolkit.
Transfer function is the mathematical relationship between the output of the control system i.e. the
plant and its input. Generally represented by the Laplace transform of the output of the system or plant
divided by the Laplace transform of the plant’s input under the zero initial condition. We can also
represent transfer function by Z-Transform.
The input and the output of a transfer function can be either mechanical or electrical parameters, in
this case our system is motor, and the input to the system is voltage and the output from the
system is angular velocity.
We can derive a transfer function of the physical model by using physics equations i.e. equations of
motion, and so on; or can be estimated using tools like LabVIEW System Identification Toolkit.
5. where : Td = 0
Brushes
Drive Shaft
6. (substitute in Electrical eqn)
Encoder
7. Ω
= m
Vm Inertial Mass
The model for the DC motor is derived from the electrical and mechanical characteristics of the
system. The input to the motor is voltage (Vm), and the output from the motor is angular velocity (ωm).
The transfer function that defines the motor model is the ratio between the Laplace transforms of the
input and output:
(Ωm/Vm)=km/(Rm*Jeq*s+km2)
Where:
km = Motor back-EMF constant (V/(rad/s))
Rm = Motor armature resistance (Ohms)
Jeq = Equivalent moment of inertia (kg*m2) (Assume that Jeq=Jm(Motor armature moment of inertia))
This transfer function makes up the Plant model that will be used throughout the exercises in this
course. The Plant model will be used to design a Controller model, which can then be tested with the
actual motor.
Use the Model Construction VIs to graphically create linear system models and modify the properties of a
system model. You also can use the Model Construction VIs to save a system model to a file, read a
system model from a file, or obtain a visual representation of a model.
The first step in working with the Control Design toolkit is inputting a model to work with. The Control
Design Toolkit can work with Transfer Function (TF), State Space (SS), and Zero Pole Gain (ZPK)
models. The model itself is stored as a cluster which can be passed from VI to VI to perform multiple
operations on a single model.
Models can be constructed using a text-based language with the Control Design MathScript functions. Use the
MathScript Node to define a region on the block diagram for textual programming. MathScript can work with
Transfer Function (TF), State Space (SS), and Zero Pole Gain (ZPK) models. The cluster containing the model
information produced by the MathScript Node has the same form as the cluster produced by the Model
Construction VIs, allowing for interchangeable use of textual and graphical programming.
Exercise 1a:
1. Build the VI block diagram.
Open a blank VI and save it as Exercise_1a.vi from the Getting Started
screen.
Switch to the block diagram (<Ctrl+E>).
Place the CD Construct Transfer Function Model.vi on the block diagram. From
the functions palette, select Addons»Control Design»Model Construction»CD
Construct Transfer Function Model.vi and place it on the block diagram.
From the drop-down menu select Single-Input Single-Output (Symbolic).
Right-click the Symbolic Numerator input terminal of the CD Construct
Transfer Function Model.vi and select Create»Control from the shortcut menu.
Right-click the Symbolic Denominator input terminal of the CD Construct
Transfer Function Model.vi and select Create»Control from the shortcut menu.
Right-click the Variables input terminal of the CD Construct Transfer Function
Model.vi and select Create»Control from the shortcut menu.
Place the CD Draw Transfer Function Equation.vi on the block diagram. From
the functions palette, select Addons»Control Design»Model Construction»
CD Draw Transfer Function Equation.vi and place it on the block diagram.
From the drop-down menu select Transfer Function.
Wire the Transfer Function Model output terminal of the CD Construct
Transfer Function Model.vi to the Transfer Function Model input terminal of
the CD Draw Transfer Function Equation.vi.
Right-click the Equation output terminal of the CD Draw Transfer Function
Equation.vi and select Create»Indicator from the shortcut menu.
Double-click the label of the picture indicator, and rename it Plant
Equation.
Save the VI.
SymbolicDenominator
K^2 J*Rm
Variables
Name Value
K 0.028
Rm 3.3
J 9.64E-06
Make the control values default. Select Edit » Make Selected Values Default.
Run the VI. Observe the transfer function drawn in the picture indicator. This
transfer function will be used in future exercises.
Save the VI.
End of Exercise 1a
Exercise 1b:
1. Build the VI block diagram.
Open a blank VI and save it as Exercise_1b.vi from the Getting Started
screen.
Switch to the block diagram (<Ctrl+E>).
Place a MathScript Node on the block diagram. Right-click to open the functions
palette and select Programming»Structures»MathScript Node.
Enter the following code inside the MathScript Node:
%Motor Model
num = [K];
den = [J*Rm K^2];
sys = tf(num,den);
Right-click on the left border of the MathScript Node and select Add Input.
Enter K as input. Right-click the input terminal of the K variable and select
Create»Control from the shortcut menu.
Right-click on the left border of the MathScript Node and select Add Input.
Enter Rm as input. Right-click the input terminal of the Rm variable and select
Create»Control from the shortcut menu.
Right-click on the left border of the MathScript Node and select Add Input.
Enter J as input. Right-click the input terminal of the J variable and select
Create»Control from the shortcut menu.
Right-click on the right border of the MathScript Node and select Add Output.
Enter plant as output. Right-click on plant and select Choose Data
Type»Add-ons»TF object.
Make the control values default. Select Edit » Make Selected Values Default.
Run the VI. Observe the transfer function drawn in the picture indicator. This
transfer function will be used in future exercises.
Save the VI.
End of Exercise 1b
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
A common control system consists of a controller model and a plant model. The output of the controller is sent
to the plant. In a closed loop system, the output of the plant is subtracted from the input (set point) of the
system, producing an error value, which acts as the controller input. This is known as feedback.
3. Integrator: 1/s
• The integrator is used to convert the output from the motor plant (angular velocity) to have units
consistent with the setpoint of the system (angular position).
PID controller provides the excitation for the plant; the gains Kp, Kd and Ki PID controller is set to control the
overall system behavior.
“e” represents the tracking error, which is the difference between the desired output and the actual output. This
error signal (e) will be sent to the PID controller; the controller then computes the proportional, the derivative and
the integral of this error signal. The output of the PID controller is now fed into the plant, which generate another
output and new error is calculated. This error is once again fed back to the PID controller and process is
repeated.
A proportional controller (Kp) will have the effect of reducing the rise time and steady-state error. A derivative
control (Kd) will have the effect of increasing the stability of the system, reducing the overshoot, and improving
the transient response and an integral control (Ki) will have the effect of eliminating the steady-state error,
reduces rise time, but increases settling time.
PID
The CD Construct PID Model VI creates a PID controller model in the form of a transfer function. This
is a polymorphic VI, with options for PID Parallel, PID Academic, and PID Series models. In this
course, the PID Parallel model is used. The following equation is used in the PID Parallel Model:
Series: A B
A +
Parallel:
+
B
+
A
Feedback: -
System models can be interconnected with the LabVIEW Control Design Toolkit either graphically or textually.
Graphical interconnections can created with LabVIEW VIs from the Model Interconnection palette. The same
interconnections can be created textually within a MathScript node with the textual Control Design functions.
The different types of model interconnection include Series, Parallel, and Feedback connections. Each function
has two input models and one output model.
•Create a Series model graphically with the CD Series VI, or textually with the Series() function.
•Create a Parallel model graphically with the CD Parallel VI, or textually with the Parallel() function.
•Create a Feedback model graphically with the CD Feedback VI, or textually with the Feedback() function.
These different forms of interconnections are often used together to create complete control systems by
combining controllers and plants with feedback.
• Types of interconnection:
– Series
– Parallel
– Feedback
– Append
The Control Design MathScript functions include model interconnection functions. The connect functions will create an
output model equivalent to the interconnected input models.
Control Design models can be interconnected graphically, as well as textually. The Model Interconnection VIs
will create an output model equivalent to the interconnected input models.
The Time Response VIs can be used to create generic linear simulations and time
domain plots for step inputs, impulse inputs, and initial condition responses. Results
can be graphed, or parametric data about the linear simulations can be displayed.
CD Root Locus: Used to plot the Evans plot or trajectory of closed-loop poles of a
single-input single-output (SISO) system as the feedback gain varies from zero to
infinity.
CD Bode: Produces the Bode magnitude and Bode phase plots of the system
model on an XY graph.
CD Nyquist: Produces the Nyquist plot of the input system for which this VI plots
the imaginary part of the frequency response against its real part.
CD Pole-Zero Map: Plots the poles and zeros of a system model on an XY graph
that represents a complex plane.
Exercise 2:
1. Open a blank VI from the Getting Started screen. Save the VI as Exercise 2.vi.
2. Go to the block diagram (<Ctrl+E>) and place a while loop down. Right-click to open
the functions palette and select Programming»Structures»While Loop. Click and drag
on the block diagram to make the while loop the correct size.
3. Place the CD Construct PID Model.vi on the block diagram. From the functions palette,
select Addons»Control Design»Model Construction»CD Construct PID Model.vi
and place it on the block diagram. From the drop-down menu select PID Parallel.
4. Right-click the Kc input terminal of the CD Construct PID Model.vi and select
Create»Control from the shortcut menu.
5. Right-click the Ki input terminal of the CD Construct PID Model.vi and select
Create»Control from the shortcut menu.
6. Right-click the Kd input terminal of the CD Construct PID Model.vi and select
Create»Control from the shortcut menu.
7. Right-click the High Frequency Time Constant [s] (Tf) input terminal of the CD
Construct PID Model.vi and select Create»Constant from the shortcut menu.
8. Place the CD Series.vi on the block diagram. From the functions palette, select
Addons»Control Design»Model Construction»CD Series.vi and place it on the block
diagram. From the drop-down menu select Transfer Function and Transfer Function.
9. Wire the Transfer Function Model output terminal of the CD Construct PID Model.vi
to the Model 1 input terminal of the CD Series.vi.
10. Place the CD Feedback.vi on the block diagram. From the functions palette, select
Addons»Control Design»Model Construction»CD Feedback.vi and place it on the
block diagram. From the drop-down menu select Transfer Function and Transfer
Function.
End of Exercise 2
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
The National Instruments LabVIEW Simulation Module integrates dynamic system simulation into the LabVIEW
environment. As a module, the Simulation Module adds new functionality to core LabVIEW. The simulation loop
can model linear, nonlinear, discrete, and continuous plant or control systems in block diagram form. Create
models from blocks such as integrator, derivative, and transfer function blocks, and then add graphs and
controls to test out the models. Alternatively, you can import models developed in the NI LabVIEW Control
Design Toolkit or NI LabVIEW System Identification Toolkit. The interactive nature of the LabVIEW tools allow
you to modify parameters while logging the results of the simulation. Models built with the simulation node can
also seamlessly download to a real-time target with the LabVIEW Real-Time Module for control prototyping and
hardware-in-the-loop (HIL) simulation.
The simulation loop is the core component of the Simulation Module. It is an “upgraded” version of the while
loop which integrates powerful differential equation solvers, internal or external timing features, and cross-
platform capabilities. With the Simulation Module, continuous time systems can be run in the discrete digital
world. The loop consists of three main parts:
Input node (Left)- allows simulation parameters to be programmatically defined. By default, these
parameters are static and can be configured by double-clicking the input node. This node can be expanded
by clicking on the bottom border of the node to “grab” the handle and dragging down to show additional
parameters.
Main loop – The system to be simulated is placed here.
Output node (Right) – returns any errors that may have happened in the loop, such as an improper transfer
function.
Configuring a Simulation
There are many parameters that can be configured for a given simulation loop.
Simulation Parameters Tab
Simulation Time – Specifies for what period of “simulation time” how long the simulation should run. This time
doesn’t necessarily dictate the computation time of the simulation. See Timing Parameters below.
Solver Method – Specifices what Ordinary Differential Equation ODE) solver is used to solve integral and differential
type blocks in the simulation. A wide variety of solvers are available.
Time Step and Tolerance – These settings control the window of time steps used by LabVIEW. Typically, the
default settings will suffice, but adjust them if necessary.
Discrete Time – While the Default Auto Discrete Time option will typically work for most simulations, you can force
LabVIEW to use a specific step size here.
Timing Parameters Tab
Timing – The software timing option is always used when performing simulations. This will solve the equation as
fast as the CPU can. To observe a simulation run in “real time”, disable the software timing option and set the
timing parameters below.
Loop Timing Source – When implementing a simulation in hardware, change the loop timing source to an available
hardware timing. This option can be used to sync the simulation execution with an external time source, such as the
operating system clock or even a Data Acquisition board’s clock.
Loop Timing Parameters – These options control how the loop executes with respect to the selected timing source.
For more detailed information on these options, consult the LabVIEW help by clicking the Help button.
Place simulation loops in your diagram by selecting them from the Simulation Palette in the Functions palette:
When selected, the mouse cursor becomes a special pointer that you use to enclose the section of code you
want to repeat.
Click the mouse button to define the top-left corner, click the mouse button again at the bottom-right corner,
and the Simulation Loop boundary is created around the selected code.
Drag or drop additional blocks or functions in the Simulation Loop if needed.
Simulations can utilize a wide variety of signals sources. Simulated signals are useful for characterizing system
response and testing corner cases. Chirps provide a useful frequency sweep, and pulses provide good step
response information. The indexer is useful for using a predetermined arbitrary signal, and can interpolate
between samples for better resolution.
Once the simulation is confirmed, a real world signal can be substituted for the simulation signal. In this
configuration, the simulation is now performing calculations based on actual data and is very good for testing the
system before controlling the output.
The Simulation Time Waveform chart is a special numeric indicator that displays one or more plots. The waveform
chart is located on the Functions » Control Design & Simulation » Simulation » Graph Utilities » SimTime
Waveform palette. Waveform charts can display single or multiple plots. The following front panel shows an
example of a multi-plot waveform chart.
You can change the min and max values of either the x or y axis by double clicking on the value with the labeling
tool and typing the new value. Similarly, you can change the label of the axis. You can also right click the plot
legend and change the style, shape, and color of the trace that is displayed on the chart.
Km 1
+_ PID J eq Rm s + K m
2
s
Exercise 3:
1. Open Exercise 2.vi.
2. Save the VI as Exercise 3.vi.
3. Go to the block diagram and remove the While Loop. Right-click the edge of the
loop and choose Remove While Loop so that the code inside the loop does not
get deleted.
4. Change the controls connected to the MathScript Node into constants.
Right-click the K control and choose Change to Constant. Set the
constant to 0.028.
Right-click the Rm control and choose Change to Constant. Set the
constant to 3.3.
Right-click the J control and choose Change to Constant. Set the
constant to 9.64E-6.
7. Remove everything from the block diagram except for the MathScript Node, the
constants wired into the MathScript Node, Kc, Ki, and Kd.
End of Exercise 3
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
Nonlinearities cause ideal models and controllers to behave different than expected in the real world.
Sources of nonlinearities include saturation, noise, and friction, which cannot be accounted for with a
linear system model. The Simulation Module can analyze nonlinear models, allowing us to simulate
non-ideal behavior before deployment.
Kc = 10
Ki = 0
Kd = 1
In this example, a PID controller model is created with the Control Design toolkit. The PID parameters
are tuned so that the step response of the system is very close to ideal. The controller model is then
used in the Simulation Module with the same PID parameters, where a saturation nonlinearity is
introduced. The nonlinearity represents the maximum and minimum voltage (24V, -24V) that can be
supplied to the motor. The introduction of this saturation changes the behavior of the system so that it
has a far less ideal behavior. This real world constraint of saturation must now be accounted for, and
the PID controller parameters need to be readjusted to give a better step response while staying
within the constraints dictated by the nonlinearity.
Simulation
• Introduce Impairments and Nonlinearities
• Verify Performance
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plots build intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI (Linear Time Invariant) analysis found in the Control Design Toolkit. The
Simulation Module allows nonlinearities to be represented in the model. Voltage limits can be
modeled using the Saturation block. Other nonlinear behaviors can be written in LabVIEW,
MathScritp, and the LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
Km 1
+_ PID J eq Rm s + K m
2
s
Exercise 4:
1. Open Exercise 3.vi.
2. Save the VI as Exercise 4.vi.
3. Go to the front panel and place down a Slide Switch control. Right-click and
select Boolean»Slide Switch
4. Label the Slide Switch Input Mode.
5. Double-click on empty space to the left of Input Mode to create a free label. Type
“Manual (Dial)” inside this free label.
6. Double-click on empty space to the right of Input Mode to create another free
label. Type “Pulse Train” inside this free label.
7. Place a dial on the front panel. Right-click and select Numeric»Dial.
8. Label the Dial Input Angle.
9. Place a stop button on the front panel. Right-click and select Boolean» Stop
Button.
10. Go to the block diagram.
11. Double-click the block on the top-left of the Simulation Loop. In the Configure
Simulation Parameters window, set Final Time to “Inf”.
12. Right-click the Step Signal VI and select Replace» Programming» Comparison»
Select
13. Right-click Input Angle (rad) and select Create» Control.
14. Label this new control Output Angle (rad).
15. Right-click Output Angle (rad) and select Change to Indicator.
End of Exercise 4
The controller can be optimized by fully understanding the plant. This understanding comes from
analysis done in the LabVIEW Control Design Toolkit. Specialized graphs, such as Bode, root-locus,
and Nyquist plot, builds intuition of how the plant will behave. Further analysis using these plots with
an open loop system with the controller allow stability and other characteristics to be calculated. In
this way, we use Control Design to optimize the parameters, in our case the gains P, I, and D. Graphs
in the time domain, such as the step response, provide immediate feedback on the ideal behavior of
the system, such as rise time, overshoot, settling time, and steady-state error.
We then use the Simulation Module to validate these parameters under real world constraints. One
prime example is the maximum and minimum voltage and current available to be supplied to the
motor. The voltage limits of the motor define the linear range of operation. Outside of that range, the
motor might be damaged or become unpredictable. This is an example of nonlinear behavior, which
cannot be modeled using LTI analysis found in the Control Design Toolkit. The Simulation Module
allows nonlinearities to be represented in the model. Voltage limits can be modeled using the
Saturation block. Other nonlinear behaviors can be written in LabVIEW, MathScript, and the
LabVIEW Formula Node, and integrated into the model as a Sub VI.
The optimization process usually includes several iterations between Control Design and Simulation to
achieve the desired performance of the system.
Once a control system is designed with the Control Design Toolkit and the Simulation Module, the algorithm can
be deployed to control a real physical system. The deployed algorithm can be run on a desktop PC or a Real
Time system.
Running a control system on a desktop PC involves simply replacing the plant model with hardware input and
output functions. The system can then be run in LabVIEW just as with the simulated system. One example
would be to replace the transfer function representing the plant in the Simulation loop with NI-DAQmx input and
output VIs. The DAQmx VIs would control an NI Data Acquisition device like the PCI-6259.
One limitation of running a control system on a desktop PC is the non-deterministic nature of desktop operating
systems. Background processes can interrupt the timing of the algorithm, which can cause inaccurate results.
National Instruments provides Real Time standalone platforms, such as the CompactRIO, that ensure
predictable timing of onboard processes. This provides superior performance with applications that require high
speed and high accuracy control.
The LabVIEW Simulation Module can be used to control real life systems as well as simulated models. To
migrate from simulated control to real life control, the plant model can be replaced with hardware input and
output functions. In this case, we will replace the transfer function representing the motor with DAQmx input
and output VIs that control the actual motor.
Timing is an important consideration when deploying with the Simulation Module. Since the Simulation loop
uses a built in ODE solver with time steps, it is important to set the Simulation Parameters and the Timing
Parameters of the loop to have the same time step. Data acquisition tasks typically use timing parameters, so it
is also important to equate the Simulation loop timing with the data acquisition timing.
1
+_ PID s
Exercise 5:
Note: This exercise requires the NI ELVIS, Quanser QNET DC Motor, and an NI
PCI DAQ device. NI-DAQmx 8.3 or later must also be installed.
1. Open Exercise 4.vi.
2. Save the VI as Exercise 5.vi.
3. Go to the block diagram and select the Transfer Function VI inside the Simulation
loop. Select Edit» Create Simulation Subsystem. This will create a subsystem
that contains the Transfer Function VI, which can be edited in a separate VI.
4. Right-click the new subsystem, and select “Open Subsystem” from the shortcut
menu. This will open the subsystem containing the Transfer Function.
5. Save the new subsystem as Ex 5 Plant.vi. Go to the block diagram.
6. Delete the Transfer Function VI. Remove any broken wires (<CTRL-B>).
7. Place a DAQ Assistant on the block diagram: Measurement I/O » NI-DAQmx »
DAQ Assistant.
End of Exercise 5
3 Degree of
Freedom
Quanser QNET – 010
Helicopter
DC Motor Control Modular
Quanser QNET – 011 Linear Pendulum
Rotary Inverted Pendulum
• LabVIEW Certification
– LabVIEW Fundamentals Exam (free on www.ni.com/academic)
– Certified LabVIEW Associate Developer Exam (industry recognized certification )
http://www.ni.com/academic/controls