You are on page 1of 10

Implementing a PID Control System

Approximate Time
You can complete this exercise in approximately 40 minutes.

Background
LabVIEW programs are called virtual instruments, or VIs, because their appearance and
operation imitate physical instruments, such as oscilloscopes and multimeters. LabVIEW
contains a comprehensive set of tools for acquiring, analyzing, displaying, and storing data, as
well as tools to help you troubleshoot code you write.

In LabVIEW, you build a user interface, or front panel, with controls and indicators. Controls are
knobs, push buttons, dials, and other input mechanisms. Indicators are graphs, LEDs, and other
output displays. After you build the user interface, you add code using VIs and structures to
control the front panel objects. The block diagram contains this code.

Overview
Proportional-Integral-Derivative (PID) control is the most common control algorithm used in
industry and has been universally accepted in industrial control. The popularity of PID
controllers can be attributed partly to their robust performance in a wide range of operating
conditions and partly to their functional simplicity, which allows engineers to operate them in a
simple, straightforward manner.

In this exercise you will learn how to implement a PID control system with LabVIEW. Since you
are not able to interact with hardware in this environment, a physical plant’s response will be
simulated using LabVIEW. However, using the method in this exercise, LabVIEW can be used to
perform PID control on PC-based automation systems, embedded on NI Programmable
Automation Controllers (PACs), or using I/O tags from most PLCs.

1
Completed Exercise

2
Step-by-Step Instructions

1. Explore the Incomplete Application

You will begin with an existing LabVIEW application that contains graphical code to simulate a
physical plant.

a. From the Start menu on the


desktop, open the PID
Control.lvproj
b. This will open the LabVIEW
Project Explorer, which allows
you to organize and manage all
the files associated with your
application. Double-click PID
Control.vi

Press <Ctrl-H> to display the Context Help window. Keep this window open for
helpful information about items under your cursor.

c. Notice that the Run button is broken, indicating that this code is not
currently executable. The user interface, called a front panel, is
completed for you.
d. Select Window » Show Block Diagram. In this exercise you will build the graphical
code of the application.

Use <Ctrl-E> to toggle between the front panel and block diagram.

3
e. The block diagram contains the executable
source code, which determines the
behavior of the application. Each front
panel item is represented by an icon,
known as a terminal, on the block diagram.
f. Double-click on the Setpoint terminal. This
will bring the front panel into focus with
the Setpoint vertical slide selected.
g. Return to the block diagram.
h. Notice the Timed Loop that has already been created on the block diagram. This
structure is used to continually execute the code it contains, at a fixed rate and
priority. This Timed Loop is responsible for simulating the physical plant, which you
will control using PID.

4
2. Build the PID Control System

Now, you will use the existing terminals on the block diagram and the graphical programming
environment to create a PID control system for the simulated physical plant. The basic idea
behind a PID controller is to read a sensor, then compute the desired actuator output by
calculating proportional, integral, and derivative responses and summing those three
components to compute the output. The value of the sensor is known as the process variable.
After performing the PID algorithm on the process variable, the controller output is set to a
desired value.

a. In order to read the process variable in this exercise, a LabVIEW Shared Variable is
used. A Shared Variable is a network published data item, which can be bound to a
variety of I/O, including NI PAC I/O and PLCs via OPC tags (see Connect LabVIEW to
Any PLC exercise). From the Project Explorer, expand PID variables.lvlib and drag-
and-drop the Unfiltered PV Shared Variable to the block diagram.

b. Repeat this for the Controller Output


Shared Variable.
c. Right-click on the Controller Output
Shared Variable on the block diagram
and select Change to Write.

5
d. Arrange the terminals as shown below by clicking and dragging individual terminals,
or selecting multiple items by dragging a box around them.

e. Select View » Functions Palette, or right-click on the block diagram to open the
functions palette. The functions palette contains hundreds of analysis functions,
control functions, and structures to build the graphical code.
f. Navigate to the PID sub-palette by first expanding

the functions palette by click the expand button .


Then navigate to Addons » PID Control » PID and
click the thumbtack to pin down the PID palette.
This palette contains several blocks, known as
Virtual Instruments (VIs) for implementing
advanced PID control.

6
g. Drag the PID VI to the block diagram.
h. Select View » Tools Palette or press <Shift–Right click>, to show
the Tools Palette, which contains various tools for building the
block diagram. By default the Automatic Tool Selection tool is
used, which selects the appropriate tool, based on the location of
the cursor.

i. Using Automatic Tool Selection is recommended,


however, you can also manually select the desired
tool. Select the Connect Wire tool as shown below.
This tool is used to wire terminals together on the
Block Diagram.

j. Data is passed by wires between terminals on


the block diagram. Wire the Unfiltered PV
Shared Variable to the process variable terminal
on the PID VI.

k. Also wire the Setpoint, PID Gains,


and Controller Sampling Time to
the corresponding terminals on the
PID VI, and wire output, from the
PID VI, to the Controller Output
Shared Variable.
l. Wire the Controller Sampling Time

m. Select the Automatic Tool Selection tool from the Tools Palette.

7
n. Placing a While Loop around your code causes
the code to execute repeatedly. Select a While
Loop by navigating the functions palette to
Express » Exec Control » While Loop.

o. Your cursor will indicate that the While Loop is selected .Place your code in the
While Loop by click and dragging a box around your code.

p. Passing a value of TRUE to the conditional terminal stops the While


Loop from executing.
q. Delete the stop button created by the While Loop by selecting it and pressing
Delete. Wire the existing stop button to the conditional terminal. Your block
diagram should appear as shown.

8
r. Notice that the Run button is no longer broken, suggesting that
your code is now executable. View the front panel and click Run.
Click Close when the Shared Variable deployment completes.

s. Experiment with the application by changing the Setpoint to various


values. Notice that the PID algorithm adjusts the controller output to
correct the process variable, bringing it to the desired setpoint.

t. In the Controller Options field, decrease


Controller Sampling Time to 100m. This
simulates the controller sampling the process
variable every 100ms. Notice that the
controller response is much smoother at
higher control rates.
u. Increase Noise Level to 10. Notice that the
controller responds more erratically now, due
to the noise.

9
v. From the Project Explorer, open PID with Filters.vi to view a more advanced,
completed example. This PID control system includes additional functionality to filter
out noise from the process variable, and limit the controller output rate of change.

Congratulations! You have successfully implemented a PID control system with LabVIEW. NI
PACs can run PID control loops at over 25kHz, and using LabVIEW FPGA with CompactRIO,
control loops as high as 150kHz can be achieved (view benchmarks). Increasing control loop
rates can reduce wear on actuators and increase energy efficiency.

For more information on PID control, also see PID Theory Explained and Advanced Features in
PID Tuning.

10

You might also like