0% found this document useful (0 votes)
58 views114 pages

Labview Pid and Fuzzy Logic Toolkit Api Reference 2024-10-31-21-26-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views114 pages

Labview Pid and Fuzzy Logic Toolkit Api Reference 2024-10-31-21-26-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 114

LabVIEW PID

and Fuzzy Logic


Toolkit API
Reference

2024-10-31
LabVIEW PID and Fuzzy Logic Toolkit API Reference

Contents
PID and Fuzzy Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
PID and Fuzzy Logic Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Related Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
PID Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
PID Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
PID Topologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Implementing the PID Algorithm with the PID VIs . . . . . . . . . . . . . . . . . . . . . . 18
Advanced PID Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Designing a Control Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Implementing PID Controllers with the PID VIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Fault Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Multi-Loop Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Setpoint Profile Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Gain Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Control Output Rate Limiting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Lead/Lag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Converting Between Percentage of Full Scale and Engineering Units . . . . . 34
Filtering Control Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Autotuning PID Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Implementing Autotuning with the Autotuning Wizard. . . . . . . . . . . . . . . . . . 37
Programmatically Implementing and Autotuning a PID Controller . . . . . . . 38
Programmatically Autotuning a Previously Implemented PID Controller. . 39
Updating PID Parameters After Autotuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Logging Parameter Values After Autotuning. . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Online Autotuning Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Step Open Loop Autotuning Technique . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Step Closed Loop Autotuning Technique . . . . . . . . . . . . . . . . . . . . . . . . . 44
PID Relay Autotuning Technique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Relay Feedback Autotuning Technique . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Autotuning Methods for Testing PID Parameters . . . . . . . . . . . . . . . . . . . . . . . 45
Ziegler-Nichols Autotuning Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Internal Model Control Autotuning Method . . . . . . . . . . . . . . . . . . . . . . . 48

2 ni.com
LabVIEW PID and Fuzzy Logic Toolkit API Reference

Cohen-Coon Autotuning Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49


Chien-Hrones-Reswick Autotuning Method . . . . . . . . . . . . . . . . . . . . . . . 49
Using PID on FPGA Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Fuzzy Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Fuzzy Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Fuzzy System Design Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Creating Linguistic Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Creating Membership Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Creating a Rule Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Complete Rule Bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Specifying an Antecedent Connective . . . . . . . . . . . . . . . . . . . . . . . 64
Specifying a Degree of Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Specifying a Consequent Implication Method . . . . . . . . . . . . . . . . 66
Defuzzification Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Center of Area (CoA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Modified Center of Area (mCoA) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Center of Maximum (CoM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Mean of Maximum (MoM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Center of Sums (CoS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Selecting a Defuzzification Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Fuzzy Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
I/O Characteristics of Fuzzy Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Partially Overlapping Input Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Fully Overlapping Input Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Non-Overlapping Input Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Undefined Input Term Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Different Overlapping Degrees of Membership Functions for Output
Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Wide and Small Membership Functions for Output Terms . . . . . . . . . . 84
Singletons as Output Terms with Fully Overlapping Input Terms . . . . 85
Using the Mean of Maximum (MoM) Defuzzification Method . . . . . . . . 86
Reproducing a Given I/O Characteristic . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Dual-Input Fuzzy Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Fuzzy Controllers in Closed-Loop Control Structures . . . . . . . . . . . . . . . . . . . 91
Fuzzy-PI Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Using Fuzzy Controllers with PID Controllers . . . . . . . . . . . . . . . . . . . . . 93

© National Instruments 3
LabVIEW PID and Fuzzy Logic Toolkit API Reference

Tutorial: Using the Fuzzy System Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95


1. Creating Input Linguistic Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2. Creating Output Linguistic Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3. Creating a Rule Base with Pre-Generated Rules . . . . . . . . . . . . . . . . . . . . . . 99
4. Modifying Pre-Generated Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
5. Specifying a Defuzzification Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
6. Testing the Fuzzy System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7. Controlling the Fuzzy System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Tutorial: Modifying a Fuzzy System with the Fuzzy Logic VIs . . . . . . . . . . . . . . . . . 104
1. Observing the Fuzzy System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
2. Loading the Fuzzy System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3. Modifying a Linguistic Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4. Modifying Membership Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
5. Modifying a Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
6. Creating Antecedents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
7. Creating Consequents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
8. Combining the Antecedents and Consequents for a Rule . . . . . . . . . . . . 112
9. Saving the Fuzzy System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

4 ni.com
PID and Fuzzy Logic

PID and Fuzzy Logic


Use PID and Fuzzy Logic VIs for Proportional-Integral-Derivative (PID) and fuzzy logic
control. These VIs appear under the Control & Simulation palette. You can use the PID
VIs with input/output (I/O) functions such as data acquisition (DAQ) to implement
control of physical processes.

PID Control

The Proportional-Integral-Derivative (PID) algorithm is the most common control


algorithm used in industry. A PID controller is a feedback controller you can use to
control processes such as heating and cooling systems, fluid level monitoring, flow
control, pressure control, and so on. You can use the PID VIs with National Instruments
hardware such as a DAQ device, FieldPoint I/O module, or GPIB board, to connect your
PC to a system and develop LabVIEW control applications. You also can use the PID VIs
with LabVIEW math and logic functions to create block diagrams for real control
strategies.

Fuzzy Logic

Fuzzy logic is a method of rule-based decision making for expert systems and process
control. Fuzzy logic differs from traditional Boolean logic in that fuzzy logic allows for
partial membership in a set. You can use fuzzy logic to control processes represented
by subjective, linguistic descriptions. You can wire acquired data to a fuzzy controller
to implement real-time decision making or control of a physical system. You also can
use outputs of the fuzzy controller with DAQ analog output hardware to implement
real-time process control.

Use the Fuzzy System Designer to design a fuzzy system interactively. Use the Fuzzy
Logic VIs to design and control fuzzy systems programmatically.

© 2011–2014 National Instruments. All rights reserved.

© National Instruments 5
PID and Fuzzy Logic

PID and Fuzzy Logic Glossary


A B C D E F G I K L M N O P Q R S T W

A prescribed set of well-defined rules or processes for the solution of a problem in


algorithm
a finite number of steps.
antecedent The IF portion of a rule in a fuzzy system.
antecedent An operator that specifies how to calculate the truth value of an aggregated rule
connective antecedent.
anti-reset A method that prevents the integral term of the PID algorithm from moving too far
windup beyond saturation when an error persists.
Automatically testing a process under control to determine the controller gains
autotuning
that will provide the best controller performance.
An automated graphical user interface provided in the PID Autotuning VI. The
Autotuning
Autotuning Wizard gathers some information about the desired control from the
Wizard
user and then steps through the PID autotuning process.

bias The offset added to a controller output (manipulate variable).


Boolean set Traditional set theory based on strict membership or non-membership of elements
theory to a set. Examples are TRUE or FALSE, ON or OFF, 1 or 0, and so on.
A process in which the next output always increments from the current output,
bumpless
regardless of the current controller output value; therefore, transfer from
transfer
automatic to manual control is always bumpless.

cascade
Control in which the output of one controller is the setpoint for another controller.
control
Method of defuzzification in which the crisp output is determined by the
Center of Area
geometrical center of area of the composite output membership functions within
(CoA)
the range of the output linguistic variable. Also known as Center of Gravity (CoG).

6 ni.com
PID and Fuzzy Logic

Center of Method of defuzzification in which the crisp output is determined by a weighted


Maximum average of the typical values of each output membership function. This method is
(CoM) equivalent to the Center of Area method using singleton sets.
Center of Method of defuzzification in which the crisp output is determined by a weighted
Sums (CoS) average of the center of area of each output membership function.
A signal path which includes a forward path, a feedback path, and a summing point
closed loop
and which forms a closed circuit. Also called a feedback loop.
consequent The THEN portion of a rule in a fuzzy system.
Hardware and/or software used to maintain parameters of a physical process at
controller
desired values.
controller
See manipulated variable.
output

crisp value A finite single value such as a measured physical quantity, for example, x = 5.3 m.
cycle time The time between samples in a discrete digital control system.

damping The progressive reduction or suppression of oscillation in a device or system.


The interval of time, expressed in minutes, between initiation of an input change or
deadtime (Td)
stimulus and the start of the resulting observable response.
The process of converting the degrees of membership of output linguistic variables
defuzzification
within their linguistic terms into crisp numerical values.
degree of A value that represents the degree of partial membership of a linguistic variable
membership within a linguistic term. This value can range from 0 to 1.
A weighting value, ranging from 0 to 1, that is applied to each rule in the rule base
degree of
of a fuzzy controller. This weighting value represents the relative significance of
support
each rule and allows for fine-tuning of the rule base.
derivative
(control) Control response to the time rate of change of a variable. Also called rate action.
action
A sudden change in PID controller output resulting from derivative action applied
to the error signal after a change in setpoint value. Derivative kick is normally
derivative kick
avoided in PID control by applying derivative action only to the process variable
and not to the error signal.
deviation Any departure from a desired value or expected value or pattern.

© National Instruments 7
PID and Fuzzy Logic

downstream
In a cascade, the controller whose setpoint is provided by another controller.
loop

EGU Engineering units. Also abbreviated EU.


A human operator of a system or process that has acquired knowledge related to
expert
controlling the process through experience.

FC Flow controller.
Control in which a measured variable is compared to its desired value to produce
feedback
an actuating error signal that is acted upon in such a way as to reduce the
control
magnitude of the error.
feedback loop See closed loop.
The process of associating crisp input values with the linguistic terms of
fuzzification
corresponding input linguistic variables..
fuzzy A controller that uses defined rules to control a fuzzy system based on the current
controller values of input linguistic variables.
An extension of traditional Boolean set theory that allows for partial membership
fuzzy logic
in a set.
fuzzy system A system of input and output variables associated using fuzzy logic.

For a linear system or element, the ratio of the magnitude, or amplitude, of a


steady-state sinusoidal output relative to the causal input; the length of a phasor
gain
from the origin to a point of the transfer locus in a complex plane. Also called the
magnitude ratio.
The process of applying different controller gains for different regions of operation
gain
of a controller. Gain scheduling is most often used in controlling nonlinear physical
scheduling
processes.

8 ni.com
PID and Fuzzy Logic

implication A mathematical method for scaling the membership functions of an output


method linguistic variable based on the rule weight before performing defuzzification.
integral
Control action in which the output is proportional to the time integral of the input.
(control)
That is, the rate of change of output is proportional to the input.
action
Instrument Society of America. The organization that sets standards for process
ISA
control instrumentation in the United States.

K Process gain. See also process gain (K).


Kc Controller gain.

lag A lowpass filter or integrating response with respect to time.


A value ranging from 0 to 1, used to specify the linearity of a calculation. A value of
linearity factor 1 indicates a linear operation. A value of 0.1 indicates a squared nonlinear
operation.
A word or set of words that represents categories for the values of a linguistic
linguistic term variable. A linguistic term is defined quantitatively by the corresponding
membership function.
linguistic A word or set of words that represents an input variable or output variable of a
variable fuzzy system.
load The ability of a controller to compensate for changes in physical parameters of a
disturbance controlled process while the setpoint value remains constant.
loop cycle
Time interval between calls to a control algorithm.
time

magnitude
See gain.
ratio

© National Instruments 9
PID and Fuzzy Logic

A quantity or condition that is varied as a function of the actuating error signal so


manipulated
as to change the value of the directly controlled variable. Also called controller
variable
output.
Method of defuzzification in which the crisp output is determined by selecting a
Mean of
value corresponding to the maximum degree of membership of the composite
Maximum
output membership function. If there are multiple maximums, the mean of the
(MoM)
corresponding values is selected.
membership A numerical function that quantitatively defines the degrees of membership of a
function linguistic variable within a linguistic term.
Method of defuzzification in which the crisp output is determined by the
modified
geometrical center of area of the composite output membership functions. Unlike
Center of Area
the Center of Area method, this method allows the crisp output to realize the full
(mCoA)
range of the output variable.

In process instrumentation, an unwanted component of a signal or variable. Noise


noise
may be expressed in units of the output or in percent of output span.

output Preventing a controller output (manipulated variable) from traveling beyond a


limiting desired maximum range.
The maximum excursion beyond the final steady-state value of output as the result
overshoot
of an input change. Also called transient overshoot.

P Proportional.
A controller which produces proportional control action only; that is, a controller
P controller
that has only a simple gain response.
partial In fuzzy logic, a condition in which the value of a member partially fulfills the
membership requirements of the membership function of a set.
PC Pressure controller.
PD Proportional, derivative.
PD controller A controller that produces proportional plus derivative (rate) control action.

10 ni.com
PID and Fuzzy Logic

PI Proportional, integral.
PI controller A controller that produces proportional plus integral (reset) control action.
PID Proportional, integral, derivative.
A common control strategy in which a process variable is measured and compared
to a desired set point to determine an error signal. A proportional gain (P) is
PID control applied to the error signal, an integral gain (I) is applied to the integral of the error
signal, and a derivative gain (D) is applied to the derivative of the error signal. The
controller output is a linear combination of the three resulting values.
A controller that produces proportional plus integral (reset) plus derivative (rate)
PID controller
control action.
process gain For a linear process, the ratio of the magnitudes of the measured process response
(K) to that of the manipulated variable.
process The measured variable (such as pressure or temperature) in a process to be
variable (PV) controlled.
proportional
Control response in which the output is proportional to the input.
action

proportional The change in input required to produce a full range change in output due to
band (PB) proportional control action. PB = 100 /Kc.

quarter-decay A response in which the amplitude of each oscillation is one-quarter that of the
ratio previous oscillation.

The total (transient plus steady-state) time response resulting from a sudden
ramp increase in the rate of change from zero to some finite value of the input stimulus.
Also called ramp response.
Control response to the time rate of change of a variable. Also called derivative
rate action
control action.
Of proportional plus integral or proportional plus integral plus derivative control
action devices: for a step input, the ratio of the initial rate of change of output due
reset rate to integral control action to the change in steady-state output due to proportional
control action.

© National Instruments 11
PID and Fuzzy Logic

Of integral control action devices: for a step input, the ratio of the initial rate of
change of output to the input change. Also called integral action rate.
A linguistic representation of the relationships between input and output linguistic
rule
variables based on their linguistic terms.
rule base The set of rules for a fuzzy system.

selector The use of multiple controllers and/or multiple process variables in which the
control connections may change dynamically depending on process conditions.
setpoint (SP) An input variable which sets the desired value of the controlled process variable.
A normalized membership function with an infinitely small width. A singleton is
singleton
used to model a crisp value with a fuzzy set.
SP See setpoint.
span The algebraic difference between the upper and lower range values.
stochastic The degree of uncertainty of the occurrence of a given future nondeterministic
uncertainty event.

time constant In process instrumentation, the value T (in minutes) in an exponential response
(T) term, A exp (–t/T), or in one of the transform factors, such as 1 + sT.
transient
See overshoot.
overshoot
trapezoidal A numerical of integration in which the current value and the previous value are
integration used to calculate the addition of the current value to the integral value.

The time during which the controller output is saturated at the maximum or
windup area minimum value. The integral action of a simple PID controller continues to
increase (wind up) while the controller is in the windup area.

12 ni.com
PID and Fuzzy Logic

Related Documentation
The following documents contain information that you might find helpful as you use
the LabVIEW PID and Fuzzy Logic VIs:

• LabVIEW PID and Fuzzy Logic Example VIs—Refer to the labview\examples\c


ontrol directory for example VIs that demonstrate common tasks using the PID
and Fuzzy Logic.
• The following resources offer useful background information on the general
concepts discussed in this documentation. These resources are provided for
general informational purposes only and are not affiliated, sponsored, or endorsed
by National Instruments. The content of these resources is not a representation of,
may not correspond to, and does not imply current or future functionality in PID
and Fuzzy Logic VIs or any other National Instruments product:
◦ Aström, K. J. and T. Hagglund. 1984. Automatic tuning of simple regulators. In
Proceedings of IFAC 9th World Congress, Budapest: 1867–72.
◦ Aström, K. J., T. Hagglund, C. C. Hang, and W. K. Ho. 1993. Automatic tuning
and adaptation for PID controllers: a survey. Control Engineering Practice
1, no. 4:699–714.
◦ Corripio, A. B. 2000. Tuning of Industrial Control Systems. 2d ed. Raleigh,
North Carolina: ISA.
◦ Seborg, Dale E., Thomas F. Edgar, and Duncan A. Mellichamp. 2004. Process
Dynamics and Control. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc.
◦ Shinskey, F. G. 1996. Process Control Systems: Application, Design,
and Tuning. 4th ed. Texas: McGraw-Hill Professional.
◦ Yen, J., R. Langari, and L. A. Zadeh, eds. 1995. Industrial Applications of
Fuzzy Logic and Intelligent Systems. Piscataway, NJ: IEEE Press.
◦ Ziegler, J. G., and N. B. Nichols. 1942. Optimum settings for automatic
controllers. Trans. ASME 64:759–68.
◦ Zimmerman, H.-J. 2001. Fuzzy Set Theory – and Its Applications. 4th ed.
Dordrecht, Netherlands: Springer.
◦ Zimmerman, H.-J. 1987. Fuzzy Sets, Decision Making, and Expert
Systems. Dordrecht, Netherlands: Springer.

© National Instruments 13
PID and Fuzzy Logic

PID Control
Proportional-Integral-Derivative (PID) controllers are common feedback controllers. In
PID control, you specify a process variable and a setpoint. The process variable is the
system parameter you want to control, such as temperature, pressure, or flow rate,
and the setpoint is the desired value for that system parameter. A PID controller
determines a controller output value, for example the heater power or valve position,
and applies the controller output value to the system to drive the process variable
toward the setpoint value.

Use the PID VIs to develop the following control applications based on PID controllers:

• Proportional (P); proportional-integral (PI); proportional-derivative (PD); and


proportional-integral-derivative (PID) algorithms
• Gain-scheduled PID
• PID autotuning
• Error-squared PID
• Lead-Lag compensation
• Setpoint profile generation
• Multi-loop cascade control
• Feedforward control

Related Information

PID Algorithms

Designing a Control Strategy

Implementing PID Controllers with the PID VIs

Autotuning PID Controllers

Using PID on FPGA Targets

PID Algorithms
The following equations describe the basic PID algorithm. This section also provides

14 ni.com
PID and Fuzzy Logic

information about how the PID VIs implement this algorithm, as well as the advanced
PID algorithm.

Basic PID Controller

The following simulation diagram represents the basic PID (Proportional-Integral-


Derivative) controller:

Note Constructing a simulation diagram like the one in the previous image requires the
LabVIEW Control Design and Simulation Module. However, the PID VIs implement PID
controllers for you. You do not need the Control Design and Simulation Module to build PID
controllers.

Error Calculation (e)

A PID controller compares the setpoint (SP) to the process variable (PV) to obtain the
error (e), as follows:

where e is the error

SP is the setpoint

PV is the process variable

Controller Action (u(t))

The PID controller calculates the controller action, u(t) as follows:

© National Instruments 15
PID and Fuzzy Logic

where Kc is controller gain

Ti is the integral time in minutes, also called the reset time

Td is the derivative time in minutes, also called the rate time

This equation involves three actions that simultaneously apply to the output of the
controller:

Proportional Action (P)

Proportional action (P) is proportional to the error (e). This term defines how quickly
the controller must respond to changes in the error. The following formula represents
the proportional action:

Integral Action (I)

Integral action (I) is proportional to the integral of the error (e). This term is generally
used to correct steady-state error and to avoid disturbances in the system. The
following formula represents the integral action:

Derivative Action (D)

Derivative action (D) is proportional to the derivative of the error (e). This term works
as a brake to the response, avoiding the system to overshoot. The following formula
represents the derivative action:

16 ni.com
PID and Fuzzy Logic

Related Information

PID Topologies

Implementing the PID Algorithm with the PID VIs

Advanced PID Algorithm

PID Topologies

Standard PID literature provides several ways to define a PID controller. In general, PID
controllers are classified using the following forms.

Academic Form

In the Academic form, the proportional parameter (P) actuates on the integral (I) and
derivative (D) terms, as represented by the following equation:

The algorithms implemented by the PID VIs are based on the Academic form with time
expressed in minutes.

Parallel Form

In the Parallel form, the three parameters P, I, and D are independent of each other
and control each interaction. This form also is referred to as non-interacting PID. The
Parallel form is represented by the following equation:

Series Form

In the Series form, the parameters are coupled and in series with each component, as
represented by the following equation:

© National Instruments 17
PID and Fuzzy Logic

Converting Topologies

You can use the PID Structure Conversion VI to convert a PID controller from one
topology, or form, to another.

Add

Implementing the PID Algorithm with the PID VIs

This following sections describe how the basic PID VIs (not including PID Advanced,
PID Advanced Autotuning, and other VIs with advanced options) implement the PID
algorithm, and the assumptions and transformations necessary to implement the PID
controller. To implement a PID controller, LabVIEW requires the algorithm to sample
the input signals and discretize the integral and derivative action.

Note The following formulas apply to most VIs on the PID palette. The PID Advanced and PID
Advanced Autotuning VIs use extended formulas with more advanced optional features.

The following simulation diagram represents the PID implementation provided by the
basic PID VIs:

18 ni.com
PID and Fuzzy Logic

Note Constructing a simulation diagram like the one in the previous image requires the
LabVIEW Control Design and Simulation Module. However, the PID VIs implement PID
controllers for you. You do not need the Control Design and Simulation Module to build PID
controllers.

Error Calculation

The following formula represents the current error used in calculating proportional,
integral, and derivative action:

where k is the index of the sampled signal at time k*t

e(k) is the current error

SP is the setpoint

PV is the process variable

Proportional Action

Proportional action is the controller gain times the error, as shown in the following
formula:

where Kc is the controller gain

e(k) is the current error

The PID VIs express the proportional component in terms of controller gain. The
relationship between controller gain (Kc) and proportional band (PB) is Kc = 100 / PB.

Integral Action (Trapezoidal Integration)

There are several options for discretizing integral action, such as forward difference,
backward difference, and trapezoidal approximation, which is also known as Tustin or

© National Instruments 19
PID and Fuzzy Logic

Bilinear transformation. The PID VIs use trapezoidal integration to avoid sharp changes
in integral action when there is a sudden change in PV or SP, as represented by the
following formula:

where ΔT is the sampling time of the controller

Derivative Action

Abrupt changes in SP can generate bumps to the output of the controller as a result of
applying derivative action to the error e. These bumps are referred to as derivative
kick. To avoid derivative kick, you can apply derivative action to the PV only, and not
to the error e. The following formula represents the derivative action implemented by
the PID VIs, which avoids derivative kick:

Controller Output

Controller output is the summation of the proportional, integral, and derivative action,
as shown in the following formula:

Output Limiting and the Anti-Windup Algorithm

The actual controller output is limited to the range specified for control output.

If then

and

if then

20 ni.com
PID and Fuzzy Logic

The PID VIs use an integral sum correction algorithm that facilitates anti-windup.
Windup occurs at the upper limit of the controller output. When the error e decreases,
the controller output decreases, moving out of the windup area. The integral sum
correction algorithm prevents abrupt controller output changes when you switch from
manual to automatic mode or change any other parameters. The integral sum
correction works as follows:

If then

The previous statement demonstrates that the integral sum correction does not take
into account the derivative action on value changes.

Default PID Values and Gain Changes

The default ranges for the parameters SP, PV, and output range correspond to
percentage values. However, you can use actual engineering units. Adjust
corresponding ranges accordingly. The parameters Ti and Td are specified in minutes.

You can call the PID VIs from inside a While Loop with a fixed cycle time. All the PID VIs
are reentrant. Multiple calls from high-level VIs use separate and distinct data. Also, the
PID VI has a multi-channel mode where you provide an array that represents an input
for each channel.

PID gains can change at any time. When a change is detected, the PID algorithm tries
to perform a bumpless transition by adjusting the integral action to keep the output
constant with the new parameters. This avoids output changes when you try to modify
the PID parameters, and is useful in gain scheduling.

Gain Scheduling

Gain scheduling refers to a system where you change controller parameters based on
measured operating conditions. For example, the scheduling variable can be the
setpoint, the process variable, a controller output, or an external signal. For historical
reasons, the term gain scheduling is used even if other parameters such as derivative
time or integral time change. Gain scheduling effectively controls a system with
dynamics that change with operating conditions.

© National Instruments 21
PID and Fuzzy Logic

With the PID Gain Schedule VI, you can define unlimited sets of PID parameters for gain
scheduling. For each schedule, you can use autotuning to update the PID parameters.

Add

Advanced PID Algorithm

The PID Advanced VI uses the same algorithm and assumptions as the PID VIs
algorithm, but adds the functionality described in the following sections.

The following simulation diagram represents the PID implementation provided by the
PID Advanced VI:

Note Constructing a simulation diagram like the one in the previous image requires the
LabVIEW Control Design and Simulation Module. However, the PID VIs implement PID
controllers for you. You do not need the Control Design and Simulation Module to build PID
controllers.

Manual/Automatic Operation

In some situations, you might need to switch off the PID controller and operate the
system in open-loop, or manual, mode. The PID Advanced VI uses a method similar to
the anti-windup algorithm to ensure the transition between manual and automatic
modes does not cause any bump to the output of the controller.

22 ni.com
PID and Fuzzy Logic

Setpoint Weighting for Proportional Action and Derivative Action

Setpoint weighting refers to corrections applied to the error value of the controller.
The beta input (Β), which can range between 0 and 1, is applied to the proportional
action as:

where e is the error

SP is the setpoint

PV is the process variable

Kc is controller gain

You can use the beta input to reduce the overshoot of setpoint change and to allow
increasing the gain of the controller to improve the disturbance rejection of the
controller.

The gamma (γ) input, which also can range between 0 and 1, is applied to the error
and to the derivative as:

Filter for Derivative Action ( )

The derivative action implemented by the PID Advanced VI is based on the backward
method for derivative action. However, depending on the values of the derivative
action, proportional gain, and sampling time, the controller could generate responses
with fast oscillation, especially when performing autotuning with PID. To prevent this
issue, this VI provides an alpha ( ) parameter that implements an additional filter for
the derivative action (D). This filter reduces the bandwidth content as defined by:

where Td is the derivative time in minutes, also called the rate time.

© National Instruments 23
PID and Fuzzy Logic

Error-Squared PID Implemented by the Linearity Factor (L)

The linearity input introduces linearity change on the gain, as shown in the following
equations:

The error for calculating proportional action with two degree-of-freedom control is
shown in the following formula:

where SPrange is the range of the setpoint

ß is the setpoint factor for the two degree-of-freedom PID algorithm described by the
proportional action formula

L is the linearity factor that produces a nonlinear gain term in which the controller gain
increases with the magnitude of the error

If L is 1, the controller is linear. A value of 0.1 makes the minimum gain of the controller
10% Kc. Use of a nonlinear gain term is referred to as an error-squared PID algorithm.

Designing a Control Strategy


You can design a control strategy by sketching a flowchart that includes the physical
process and control elements such as valves and measurements. Also include
feedback from the process and any required computations. You then can use the PID
VIs, combined with the math and logic VIs and functions in LabVIEW, to translate the
flowchart into a LabVIEW block diagram.

The following image shows a sample control flowchart:

24 ni.com
PID and Fuzzy Logic

The following image shows the equivalent LabVIEW block diagram:

In the previous images, FT is the flow transmitter, LT is the level transmitter, LC is the
level of control, and SP is the setpoint. The only elements missing from this simplified
VI are the loop-tuning parameters and the automatic-to-manual switching.

You can handle the inputs and outputs through DAQ devices, FieldPoint I/O modules,
GPIB instruments, or serial I/O ports. You can adjust polling rates in real time. Potential
polling rates are limited only by your hardware and by the number and graphical
complexity of your VIs.

© National Instruments 25
PID and Fuzzy Logic

Setting Timing

The PID VI and the PID Lead-Lag VI are time-dependent. A VI can acquire timing
information either from a value you supply to the cycle time control, dt, or from a time
keeper such as those built into the PID VIs. If dt is less than or equal to zero, the VI
calculates new timing information each time LabVIEW calls it. At each call, the VI
measures the time since the last call and uses that difference in its calculations. If you
call a VI from a While Loop that uses one of the LabVIEW Timing VIs and functions, you
can achieve fairly regular timing, and the internal time keeper compensates for
variations. However, the resolution of the Tick Count (ms) function is limited to 1 ms.

If dt is a positive value in seconds, the VI uses that value in the calculations, regardless
of the elapsed time. National Instruments recommends you use this method for fast
loops, such as when you use acquisition hardware to time the controller input or real-
time applications. Refer to the example VIs located in the labview\examples\con
trol\PID directory for examples of using timing with the PID VIs.

Note If you installed NI-DAQmx, you also can view relevant examples in the labview\exam
ples\DAQmx\Control\Control.llb directory.

According to control theory, a control system must sample a physical process at a rate
about 10 times faster than the fastest time constant in the physical process. For
example, a time constant of 60 seconds is typical for a temperature control loop in a
small system. In this case, a cycle time of about 6 seconds is sufficient. Faster cycling
does not improve performance. In fact, running all your control VIs too fast can
degrade the response time of your LabVIEW application.

All VIs within a loop execute once per iteration at the same cycle time. To run several
control VIs at different cycle times and still share data between them, as for example in
a cascade, you must separate the VIs into independently timed While Loops. The
following block diagram shows a cascade with two independently timed While Loops:

26 ni.com
PID and Fuzzy Logic

A global variable passes the output of the PID VI in Loop A to the process variable
input of the PID VI in Loop B. You can place both While Loops on the same block
diagram or in separate VIs. Use additional global or local variables to pass any other
necessary data between the two While Loops.

If the front panel of your VI does not contain graphics that LabVIEW must update
frequently, the PID VIs can execute at kilohertz (kHz) rates. However, actions such as
mouse activity and window scrolling interfere with these rates.

Implementing PID Controllers with the PID VIs


The PID VIs are all variations of the basic PID VI, and each variation provides additional
functionality as described in the following table. You can use these VIs interchangeably
because they use consistent inputs and outputs where possible. Refer to the help topic
for the VI you want to use for specific information about the VI.

Use Case VI Name

© National Instruments 27
PID and Fuzzy Logic

• Simple systems, or when an efficient algorithm is required.


PID VI
• Implements the basic PID algorithm

• Complex systems that require options for manual or automatic operation,


setpoint weighting, filtering of derivative action, and so on.
PID Advanced VI
• Implements the advanced PID algorithm and provides extra input
parameters to expand on the functionality of the PID VI.

Complex systems that require the same advanced options as the PID Advanced PID Advanced
VI and the ability to autotune parameters. Autotuning VI

PID Autotuning
Systems that contain significant dead time.
(Temperature) VI
Systems that require lead/lag function. PID Lead-Lag VI

(Windows) To view related topics, click the Locate button, shown at left, in the toolbar at the
top of this window. The LabVIEW Help highlights this topic in the Contents tab so you can
navigate the related topics.

Related Information

Fault Protection

Multi-Loop Control

Setpoint Profile Generation

Gain Scheduling

Control Output Rate Limiting

Lead/Lag

Converting Between Percentage of Full Scale and Engineering Units

Filtering Control Inputs

28 ni.com
PID and Fuzzy Logic

Fault Protection

If a PID VI receives an invalid input, such as NaN (Not a Number), the VI outputs NaN
until you reinitialize the VI. However, you can use the Not A Number/Path/Refnum?
function to check for invalid inputs and respond in a way that is appropriate to the
application. The following block diagram uses the Not A Number/Path/Refnum?
function with a Select function and a Feedback Node to reuse the last valid input when
the VI receives an invalid input.

Refer to the General PID with Fault Protection VI in the labview\examples\contr


ol\PID directory for an example of a single-channel PID implementation that
includes fault protection.

Multi-Loop Control

Most of the PID VIs are polymorphic VIs for use in multiple control-loop applications.
For example, you can design a multi-loop PID control application using the PID VI and
DAQ functions for input and output. A DAQ analog input function returns an array of
data when you configure it for multiple channels. You can wire this array directly into
the process variable input of the PID VI. The polymorphic type of the PID VI
automatically switches from DBL to DBL Array, which calculates and returns an array of
output values corresponding to the number of values in the process variable array.
You also can switch the type of the polymorphic VI manually by right-clicking the VI
icon and selecting Select Type from the shortcut menu.

When the polymorphic type is DBL Array, other inputs automatically change to array

© National Instruments 29
PID and Fuzzy Logic

inputs as well. For example, the PID VI inputs setpoint, PID gains, and output range all
become array inputs. Each of these inputs can have an array length ranging from 1 to
the array length of the process variable input. If the array length of any of these inputs
is less than the array length of the process variable input, the PID VI reuses the last
value in the array for other calculations. For example, if you specify only one set of PID
gains in the PID gains array, the PID VI uses these gains to calculate each output value
corresponding to each process variable input value. Other polymorphic PID and Fuzzy
Logic VIs operate in the same manner.

Setpoint Profile Generation

You can use the PID Setpoint Profile VI inside a control loop to generate a profile of
setpoint values over time for a ramp and soak type PID application. For example, you
might want to ramp the setpoint temperature of an oven control system over time, and
then hold, or soak, the setpoint at a certain temperature for another period of time.
You can use the PID Setpoint Profile VI to implement any arbitrary combination of
ramp, hold, and step functions.

Specify the setpoint profile as an array of pairs of time and setpoint values with the
time values in ascending order.

Ramp Setpoint Profile

You can specify a ramp setpoint profile with two setpoint profile array values, as
shown in the following image.

30 ni.com
PID and Fuzzy Logic

Ramp and Hold Setpoint Profile

A ramp and hold setpoint profile also can have two successive array values with the
same setpoint value, as shown in the following image.

Step Setpoint Profile

A step setpoint profile can have two successive array values with the same time value
but different setpoint values, as shown in the following image.

The PID Setpoint Profile VI returns a single setpoint value determined from the current
elapsed time. The first call to the VI initializes the current time in the setpoint profile to
0. On subsequent calls, the VI determines the current time from the previous time and
the dt input value. If you reinitialize the current time to 0 by passing a value of TRUE to
the reinitialize? input, you can repeat the specified setpoint profile.

© National Instruments 31
PID and Fuzzy Logic

Gain Scheduling

Gain scheduling refers to a system where you change controller parameters based on
measured operating conditions. For example, the scheduling variable can be the
setpoint, the process variable, a controller output, or an external signal. For historical
reasons, the term gain scheduling is used even if other parameters such as derivative
time, Td, or integral time, Ti change. Gain scheduling effectively controls a system
whose dynamics change with the operating conditions.

You can use the PID Gain Schedule VI, to apply different sets of PID parameters for
different regions of operation of your controller. Because most processes are
nonlinear, PID parameters that produce a desired response at one operating point
might not produce a satisfactory response at another operating point. The PID Gain
Schedule VI selects and outputs one set of PID gains from a gain schedule based on the
current value of its gain scheduling value input. For example, to implement a gain
schedule based on the value of the process variable, wire the process variable value to
the gain scheduling value input and wire the PID gains out output to the PID gains
input of the PID VI.

The PID gain schedule input of the PID Gain Schedule VI is an array of clusters of PID
gains and corresponding maximum values. Each set of PID gains corresponds to the
range of input values from the max value of the previous element of the array to the
max value of the same element of the array. The input range of the PID gains of the
first element of PID gain schedule is all values less than or equal to the corresponding
max value.

The following front panel shows a VI that uses the setpoint value as the gain
scheduling variable with a default range of 0 to 100.

32 ni.com
PID and Fuzzy Logic

The following table summarizes parameter ranges specified in the previous image:

Range Parameters

Kc = 10
0 SP 30 Ti = 0.02
Td = 0.02

Kc = 12
30 SP 70 Ti = 0.02
Td = 0.01

Kc = 15
70 SP 100 Ti = 0.02
Td = 0.005

© National Instruments 33
PID and Fuzzy Logic

Control Output Rate Limiting

Sudden changes in control output are often undesirable or even dangerous for many
control applications. For example, a sudden large change in setpoint can cause a very
large change in controller output. Although in theory this large change in controller
output results in fast response of the system, it also can cause unnecessary wear on
actuators or sudden large power demands. In addition, the PID controller can amplify
noise in the system and result in a constantly changing controller output.

You can use the PID Output Rate Limiter VI to avoid the problem of sudden changes in
controller output. Wire the output value of the PID VI to the input (controller output)
input of the PID Output Rate Limiter VI to limit the slew, or rate of change, of the
output to the value of the output rate (EGU/min).

Assign a value to initial output to specify the output value on the first call to the VI.
Use the dt (s) input to specify the same control-loop cycle time you use for the PID VI.

Lead/Lag

You can use the PID Lead-Lag VI to implement a PID controller with a lead/lag function.
The VI uses a positional algorithm that approximates a true exponential lead/lag.
Feedforward control schemes often use this kind of algorithm as a dynamic
compensator.

The output value on the first call to the VI is the same as the input value.

Converting Between Percentage of Full Scale and Engineering Units

The default setpoint, process variable, and output ranges for the PID VIs correspond to
percentage of full scale. In other words, proportional gain (Kc) relates percentage of
full scale output to percentage of full scale input. This is the default behavior of many
PID controllers used for process control applications. To implement PID in this way,
you must scale all inputs to percentage of full scale and all controller outputs to actual
engineering units, for example, volts for analog output.

You can use the PID EGU to Percentage VI to convert any input from real engineering
units to percentage of full scale, and you can use the PID Percentage to EGU VI to

34 ni.com
PID and Fuzzy Logic

convert the controller output from percentage to real engineering units.

Note The PID VIs do not use the setpoint range and output range information to convert
values to percentages in the PID algorithm. The controller gain relates the output in
engineering units to the input in engineering units. For example, a gain value of 1 produces an
output of 10 for a difference between setpoint and process variable of 10, regardless of the
output range and setpoint range.

Filtering Control Inputs

You can use the PID Control Input Filter VI to filter unwanted, high-frequency noise
from measured values in a control application. For example, if you are measuring
process variable values using a DAQ device, you can use the this VI to filter noise from
input values in the control loop before passing the values to control functions such as
the PID VI.

When filtering noise, set the sampling rate of the control system to at least 10 times the
fastest time constant of the physical system. This ensures that any frequency
components of the measured signal greater than 1/10 of the sampling frequency are a
result of noise in the measured signal. Gains in the PID controller can amplify this
noise and produce unnecessary wear on actuators and other system components.

The PID Control Input Filter VI uses a lowpass fifth-order finite impulse response (FIR)
filter. The cutoff frequency of the lowpass filter is 1/10 of the sampling frequency,
regardless of the actual sampling frequency value.

You can use the Filters PtByPt VIs or the LabVIEW Digital Filter Design Toolkit to
perform additional filtering tasks.

Autotuning PID Controllers (PID and Fuzzy Logic)


Often, many PID controllers are poorly tuned. As a result, some controllers are too
aggressive and some controllers are too sluggish. Tuning a controller involves
adjusting the parameters of the system to get the desired, or optimal, response.
However, manually tuning PID controllers can be difficult when you do not know the
process dynamics or disturbances. In this case, you can use autotuning to
automatically test different parameter values and determine the best response.

© National Instruments 35
PID and Fuzzy Logic

Choose from the following VIs that integrate autotuning based on your specific
application needs and your knowledge of tuning theory.

Use Case VI Name

• Autotuning that runs with minimal user input or knowledge of tuning


PID Advanced
algorithms.
Autotuning VI
• Single VI implements a controller for a system and allows tuning.

• Autotuning that runs with minimal user input or knowledge of tuning


algorithms. PID
• Single VI implements a controller for a system with significant deadtime and Autotuning
allows tuning. (Temperature)
VI
How-To: Programmatically Implementing and Autotuning a PID Controller

• Controlling the autotuning technique used to identify the system. Other PID VIs
automatically determine the technique.
• Tuning system parameters, then passing the output parameters to the PID
PID Online
Advanced VI to implement that controller.
Autotuning VI
How-To: Programmatically Autotuning a Previously Implemented PID
Controller

• Generating PID parameters for a system given an input/output signal. This


technique is useful when you have insufficient information about the system PID
and you want to develop initial parameters based on system response. Autotuning
• Provides access to multiple methods for determining PID parameters. Other Design VI
PID VIs automatically determine the method.

• Performing interactive autotuning in a dialog box that you use to configure the
process.
PID
• Not supported on RT or FPGA hardware targets.
Autotuning VI
How-To: Implementing Autotuning with the Autotuning Wizard

36 ni.com
PID and Fuzzy Logic

• PID applications with high-speed control and/or high channel count on an


FPGA target. PID (FPGA) VI
• Implements a fixed-point PID algorithm.

Related Information

Updating PID Parameters After Autotuning

Logging Parameter Values After Autotuning

Online Autotuning Techniques

Autotuning Methods for Testing PID Parameters

Implementing Autotuning with the Autotuning Wizard

To use the Autotuning Wizard to improve your controller performance, you must first
create your control application and determine PID parameters that produce stable
control of the system. You can develop the control application using either the PID VI,
the PID Gain Schedule VI, or the PID Autotuning VI. Because the PID Autotuning VI has
inputs and outputs consistent with the other PID VIs, you can replace many PID VIs
with it.

Note The PID Autotuning VI cannot directly replace the PID Advanced VI or the more
advanced autotuning VIs, such as PID Advanced Autotuning or PID Online Autotuning. These
VIs provide advanced functionality that the PID Autotuning VI does not support.

Autotuning-Specific Inputs

The PID Autotuning VI has several inputs and outputs specific to the autotuning
procedure, including the following inputs:

• autotuning parameters—A cluster of parameters that the PID Autotuning VI uses


for the autotuning process. The Autotuning Wizard allows you to specify all of
these parameters manually, so wiring this input is optional.
• autotune?—Specifies whether to invoke the Autotuning Wizard and begin

© National Instruments 37
PID and Fuzzy Logic

autotuning. Wire a Boolean control, such as a button, to this input so a user can
press the button to open the Autotuning Wizard. The Autotuning Wizard steps the
user through the autotuning process.

Note Set the Boolean control mechanical action to Latch When Released so the
Autotuning Wizard does not open repeatedly when the user presses the button.

Autotuning-Specific Outputs

The following outputs are specific to the autotuning procedure:

• tuning completed?—Indicates when the autotuning process is complete. You can


use this output to determine when to update the PID gains values.
• PID gains out—Returns the tuned PID gains. Before autotuning completes, PID
gains out returns the same values as the PID gains input. PID gains out updates
only when autotuning completes and tuning completed? returns TRUE.

Programmatically Implementing and Autotuning a PID Controller

You can use the PID Advanced Autotuning VI both to implement and autotune a PID
controller.

Note The PID Advanced Autotuning VI incorporates the functionality of the PID Advanced VI
and the PID Online Autotuning VI. You also can use the PID Online Autotuning VI to
programmatically autotune a previously implemented PID controller.

Complete the following steps to implement a tuned PID controller with the PID
Advanced Autotuning VI.

1. Add the PID Advanced Autotuning VI to the block diagram within a control loop.
2. Wire the inputs you want to use to implement the controller. Minimally, wire the
setpoint, process variable, and PID gains inputs.
3. Create a control for the autotuning parameters input and select the controller
type and control specification you want to use.
4. Set the technique component of the autotuning parameters input to the
autotuning technique you want to use.
5. Create a Boolean control with latched mechanical action and a default value of

38 ni.com
PID and Fuzzy Logic

FALSE for the Autotune? input.


6. Run the VI.
7. Set Autotune? to TRUE to begin autotuning.

Refer to the Autotuning PID Online VI in the labview\examples\control\PID


for an example of implementing autotuning with the PID Advanced Autotuning VI.

Programmatically Autotuning a Previously Implemented PID


Controller

You can use the PID Online Autotuning VI to tune a controller you implement or
previously implemented with the PID Advanced VI.

Note You must use the PID Advanced VI to implement the controller. You can implement PID
controllers with various PID VIs, but PID Advanced is the only VI that supports putting the
controller under manual control, which is necessary for using the PID Online Autotuning VI.

You also can use the PID Advanced Autotuning VI to implement and autotune a PID controller
from a single VI.

Complete the following steps autotune a previously implemented PID controller.

1. If you have not already done so, implement a PID controller using the PID
Advanced VI.
2. Put the controller in manual mode by setting the auto? input of the PID Advanced
VI to FALSE.
3. Add the PID Online Autotuning VI to the block diagram within the control loop but
to the left of the PID Advanced VI.
4. Manually select the polymorphic instance of the PID Online Autotuning VI.
5. Without deleting the controls, constants, or shift registers that contain the values,
delete the wires to the setpoint, process variable, and PID gains inputs of the PID
Advanced VI.
6. Wire the values to the Setpoint in, Process Variable, and PID gains in inputs of the
PID Online Autotuning VI.
7. Create a Boolean control with latched mechanical action and a default value of
FALSE, and wire the control to the Autotune? input of the PID Online Autotuning VI.
8. Wire the setpoint out, Process Variable Out, and PID gains out outputs of the PID

© National Instruments 39
PID and Fuzzy Logic

Online Autotuning VI to the setpoint, process variable, and PID gains inputs of the
PID Advanced VI.
9. (Optional) If you are specifying a value for the dt (s) input, wire the same value to
both VIs.
10. Run the VI.
11. Set Autotune? to TRUE to begin autotuning.

Refer to the Autotuning PID Online and Inline VI in the labview\examples\contr


ol\PID for an example of implementing autotuning with the PID Online Autotuning VI
and the PID Advanced VI.

Updating PID Parameters After Autotuning

The PID autotuning VIs, including PID Autotuning, PID Advanced Autotuning, and PID
Online Autotuning, calculate new parameters for a PID controller that result in the best
response. When autotuning, you must write your code to apply the new PID controller
parameters (the PID gains) when the autotuning is complete.

You can use the following methods to update PID parameters after autotuning.

Note In both of the following methods, you must manually save the PID gains so that you can
use the PID gains out values the next time you run the control application. Ensure that the PID
gains control shows the current updated parameters, select Operate»Make Current Values
Default, and save the VI. If you do not want to manually save the VI after each run, you can use
a datalog file to save PID gains values.

Using Shift Registers to Update PID Parameters

The following block diagram shows a simple implementation of using shift registers to
update PID parameters in the PID Autotuning VI. The shift register on the left stores the
initial value of the PID gains. PID gains out then passes an updated value to the right-
hand shift register terminal when each control loop iteration completes. This method
is simple, but limited in that the user cannot change PID gains manually while the
control loop runs.

40 ni.com
PID and Fuzzy Logic

Using Local Variables to Update PID Parameters

In place of shift registers, you can use a local variable to store updated PID gains
values. In the following block diagram, PID Autotuning VI reads the PID gains control
on each iteration of the While Loop, and a local variable updates the control only when
tuning complete? is TRUE. This method allows for manual control of the PID gains
while the control loop executes.

Logging Parameter Values After Autotuning

The PID autotuning VIs, including PID Autotuning, PID Advanced Autotuning, and PID
Online Autotuning, update the parameters of a PID controller and return updated PID
gains values for the next iteration of the control application. To ensure that the correct
PID gains values are available each time you run your control application, you must
either save the VI you are using to implement the application each time it runs, or use
a datalog file to save the PID gains.

The following block diagram shows a VI that uses the File I/O VIs and functions to
create a datalog file and save the latest value of the PID gains out output of the PID
Autotuning VI to the file.

© National Instruments 41
PID and Fuzzy Logic

Before the control loop begins, the Open/Create/Replace File function opens a datalog
file, and the Read from Binary File function reads the file to obtain the PID gains
parameters. When the autotuning procedure runs, a local variable updates the PID
gains control. After the control loop is complete, the Write to Binary File function
writes the current PID gains cluster to the datalog file and saves the file. This ensures
that each time the control application runs, the PID Autotuning VI uses updated
parameters.

Online Autotuning Techniques

To tune PID parameters of a system, some PID VIs allow you to select the technique to
apply to the system. You can choose from two techniques that implement a step
response-based measurement and two techniques that implement a frequency
response-based measurement.

On the PID Advanced Autotuning VI, the autotuning parameters input allows you to
configure the technique to use. With the PID Online Autotuning polymorphic VI, select
the polymorphic instance that corresponds to a tuning technique you want to use.
Other PID VIs control the tuning technique for you.

Step Response Techniques

The following techniques are based on step response measurement:

• Step Open Loop—Performs an open-loop step test. This technique applies a step to
the input and waits until it reaches steady-state, when the process variable does

42 ni.com
PID and Fuzzy Logic

not change. This technique assumes that you can model any process as a first-
order lag and a pure deadtime system.
• Step Closed Loop—Performs a closed-loop step test similar to the Step Open Loop
technique.

If you do not know the characteristics of the model, such as initial PID gains, you can
first perform Step Open Loop tuning on the model to obtain the parameters. Wait until
the input reaches steady-state. This process is also known as commissioning. Next,
perform Step Closed Loop tuning on the model using the parameters computed by the
Step Open Loop tuning process as initial parameters. Both techniques assume a first-
order model with delay. If your system is not a first-order model, these techniques try
to approximate one during tuning.

Frequency Response Techniques

The following techniques are based on frequency response measurement

• PID Relay—Uses the setpoint relay experiment to determine the information


needed to tune the controller. The Autotuning Wizard uses this technique.
• Relay Feedback—Uses an on-off relay in a feedback loop to determine ultimate
gain and ultimate frequency. This technique is a variation on a closed-loop step
test, but is more efficient for systems with a large time constant. This method also
incorporates hysteresis to avoid noise in the system.

Related Information

Step Open Loop Autotuning Technique

Step Closed Loop Autotuning Technique

PID Relay Autotuning Technique

Relay Feedback Autotuning Technique

Step Open Loop Autotuning Technique

The Step Open Loop autotuning technique, which is used by the Step Open Loop
instance of the PID Online Autotuning VI, performs an open-loop step test. This

© National Instruments 43
PID and Fuzzy Logic

technique assumes that you can model any process as a first-order lag and a pure
deadtime.

The Step Open Loop autotuning technique measures the deadtime (Td), time constant
(T), and process gain (K) values of a controller and multiplies them according to the
formulas for the heuristic method in place. For example, most PID VIs use the Ziegler-
Nichols method.

Step Closed Loop Autotuning Technique

The Step Closed Loop autotuning technique, which is used by the Step Closed Loop
instance of the PID Online Autotuning VI, performs a closed-loop step test. This
technique is very accurate and reaches steady state faster than the Step Open Loop
technique.

In closed-loop tuning, the PID Online Autotuning VI applies the Step Open Loop
response with the controller in a closed loop, and then back-calculates the dynamics
of the system by removing the closed loop gain.

The Step Closed Loop autotuning technique measures the deadtime (Td), time
constant (T), and process gain (K) values of a controller and multiplies them according
to the formulas for the heuristic method in place. For example, most PID VIs use the
Ziegler-Nichols method.

PID Relay Autotuning Technique

The PID Relay autotuning technique, which is used by the Autotuning Wizard and the
PID Relay instance of the PID Online Autotuning VI, uses the setpoint relay experiment
to determining the information needed to tune the controller.

The following image illustrates the autotuning procedure excited by the setpoint relay
experiment, which connects a relay and an extra feedback signal with the setpoint.
The setpoint relay steps the setpoint up or down, exciting the autotuning procedure
and allowing the controller to respond to the change and tune the system for an
acceptable response. The PID Autotuning VI and the PID Relay instance of the PID
Online Autotuning polymorphic VI directly implement this process. The existing
controller remains in the loop.

44 ni.com
PID and Fuzzy Logic

For most systems, the nonlinear relay characteristic generates a limiting cycle, from
which the autotuning algorithm identifies the relevant information needed for PID
tuning. If the existing controller is proportional only, the autotuning algorithm
identifies the ultimate gain Ku and ultimate period Tu. If the existing model is PI or
PID, the autotuning algorithm identifies the dead time and time constant TP, which
are two parameters in the integral-plus-deadtime model.

Relay Feedback Autotuning Technique

The Relay Feedback autotuning technique, which is used by the Relay Feedback
instance of the PID Online Autotuning VI, uses an on-off relay in a feedback loop to
determine ultimate gain and ultimate frequency. This technique is a variation on a
closed-loop (ultimate gain) test, but is more efficient for systems with a large time
constant. This method also incorporates hysteresis to avoid noise in the system.

Autotuning Methods for Testing PID Parameters

Autotuning automatically tests different parameter values for a PID controller to


determine the best response. A variety of methods exist for testing these parameters.
PID and Fuzzy Logic VIs support the following methods for PID autotuning:

• Ziegler-Nichols
• Internal Model Control
• Cohen-Coon
• Chien-Hrones-Reswick

The Autotuning Wizard and most of the autotuning PID VIs use the Ziegler-Nichols
method or, if Ziegler-Nichols is not possible, the Internal Model Control method. Only
the PID Autotuning Design VI can implement the Cohen-Coon and Chien-Hrones-
Reswick tuning methods.

© National Instruments 45
PID and Fuzzy Logic

Ziegler-Nichols Autotuning Method

Ziegler and Nichols developed heuristic methods for determining the parameters of a
PID controller. The Autotuning Wizard and PID VIs that use the PID Relay autotuning
technique use this method.

When using the Ziegler-Nichols autotuning method, select one of the following three
types of desired loop response performance: fast (1/4 damping ratio), normal (some
overshoot), and slow (little overshoot). The following tables show the tuning formulas
for each type of loop performance.

Note During tuning, the process remains under closed-loop PID control. You do not need to
switch off the existing controller and perform the experiment under open-loop conditions. In
the setpoint relay experiment, the setpoint signal mirrors the setpoint for the PID controller.

Ziegler-Nichols Closed Loop/Frequency Response Method

The following tables show the tuning formulas for different types of loop performance
under proportional-only control, where Ku is the controller gain and Tu is the period
of oscillation.

Fast Performance
Controller Kc Ti Td

P 0.5Ku — —

PI 0.4Ku 0.8Tu —

PID 0.6Ku 0.5Tu 0.12Tu

Normal Performance
Controller Kc Ti Td

P 0.2Ku — —

PI 0.18Ku 0.8Tu —

PID 0.25Ku 0.5Tu 0.12Tu

46 ni.com
PID and Fuzzy Logic

Slow Performance
Controller Kc Ti Td

P 0.13Ku — —

PI 0.13Ku 0.8Tu —

PID 0.15Ku 0.5Tu 0.12Tu

Ziegler-Nichols Open Loop/Step Response Method

The following tables shows the tuning formulas for different types of loop
performance under PI or PID control, where TP is the time constant and is the dead
time.

Fast Performance
Controller Kc Ti Td

P TP/ — —

PI 0.9TP/ 3.33 —

PID 1.1TP/ 2.0 0.5

Normal Performance
Controller Kc Ti Td

P 0.44TP/ — —

PI 0.4TP/ 5.33 —

PID 0.53TP/ 4.0 0.8

Slow Performance
Controller Kc Ti Td

P 0.26TP/ — —

PI 0.24TP/ 5.33 —

© National Instruments 47
PID and Fuzzy Logic

PID 0.32TP/ 4.0 0.8

Note The previous tables provides proportional gain (Kc) values. The following equation
describes the relationship between proportional gain and proportional band (PB):

Kc = 100/PB

Internal Model Control Autotuning Method

Internal model control (IMC) is a control technique that uses an internal model to try to
estimate the system response. PID and Fuzzy Logic VIs use IMC when it cannot
successfully implement the Ziegler-Nichols method, such as when a model has no
delay. You also can use the PID Autotuning Design VI to directly implement this
autotuning method.

This method assumes a first-order model with delay. If your system is not a first-order
model, these techniques try to approximate one during tuning.

The following table shows the tuning formula for the internal model control technique,
where K is the model gain, is the plant time constant, c is the desired time constant,
and is the plant delay.

Controller Model Kc Ti Td

PI (delay-free) —

PI + Plant (with delay) —

PID

This method is based on algorithms and techniques described in reference material by


Seborg, Dale E., Thomas F. Edgar, and Duncan A. Mellichamp. For more information
about this method, refer to the reference material by those authors.

48 ni.com
PID and Fuzzy Logic

Cohen-Coon Autotuning Method

The Cohen-Coon autotuning method is an offline method for tuning PID controllers.
This method uses PID parameters obtained from an open-loop transfer function
experiment. This method is similar to the Ziegler-Nichols method, but provides better
results when the controller has a large deadtime (Td) relative to the time constant (T).

Note You must use the PID Autotuning Design VI to implement this autotuning method.

The following table shows the Cohen-Coon recommendations for tuning parameters
under different tuning specifications:

Controller Kc Ti Td

P — —

PI —

PID

Where T is the time constant

Kc is the proportional gain

Td is the deadtime

Chien-Hrones-Reswick Autotuning Method

The Chien-Hrones-Reswick autotuning method focuses on setpoint response and


disturbance response. This method provides formulas for 0% and 20% overshoot.

Note You must use the PID Autotuning Design VI to implement this autotuning method. Select

© National Instruments 49
PID and Fuzzy Logic

the Chien-Hrones-Reswick polymorphic instance and use the Tuning specifications input to
configure which formula you want to use.

The following tables shows the Chien-Hrones-Reswick recommendations for each


tuning formula:

Regulator – 0% overshoot
Controller Kc Ti Td

P 0.3TP/ — —

PI 0.6TP/ 4 —

PID 0.95TP/ 2.4 0.42

where TP is the time constant and is the deadtime.

Regulator – 20% overshoot


Controller Kc Ti Td

P 0.7TP/ — —

PI 0.7TP/ 2.3 —

PID 1.2TP/ 2 0.42

where TP is the time constant and is the deadtime.

Servo – 0% overshoot
Controller Kc Ti Td

P 0.3TP/ — —

PI 0.35TP/ 1.2 —

PID 0.6TP/ 0.5

where TP is the time constant and is the deadtime.

50 ni.com
PID and Fuzzy Logic

Servo – 20% overshoot


Controller Kc Ti Td

P 0.7TP/ — —

PI 0.6TP/ —

PID 0.95TP/ 1.4 0.47

where TP is the time constant and is the deadtime.

Using PID on FPGA Targets


You can use the PID (FPGA) Express VI to implement single-channel or multi-channel
PID on a LabVIEW FPGA target. The PID (FPGA) Express VI implements a fixed-point PID
algorithm. Refer to the VI topic for details about the algorithm the VI uses.

Note The PID (FPGA) Express VI is available only if you install the LabVIEW FPGA Module.

Implementing a Single-Channel PID on FPGA Targets

To configure the PID (FPGA) Express VI for a single-channel implementation, enter 1 in


the Number of channels control on the configuration dialog box. For single-channel
PID implementations, any changes you make to the PID parameters on the host VI take
effect immediately on the FPGA target.

(NI-RIO) If you have the NI-RIO software installed, refer to the Using Discrete PID - cRIO
project in the labview\examples\CompactRIO\FPGA Fundamentals\FPGA
Math and Analysis\PID Toolkit directory for an example of a single-channel
PID implementation on an FPGA target.

(NI-RIO) If you have the NI-RIO software installed, you also can refer to the Using
Discrete PID - R Series project in the labview\examples\R Series\FPGA Fund
amentals\FPGA Math and Analysis\PID Toolkit directory for an
example of a single-channel PID implementation on an FPGA target.

© National Instruments 51
PID and Fuzzy Logic

Implementing a Multi-Channel PID on FPGA Targets

To configure the PID (FPGA) Express VI for a multi-channel implementation, enter a


number greater than 1 in the Number of channels control on the configuration dialog
box. To handle the values for each channel, the host VI can include an initialization
loop and processing loop, which you can use to modify parameters or reset channels.

Initialization Loop on the Host VI

The initial parameter values you enter on the configuration dialog box for the PID
(FPGA) Express VI set the initial values for all channels. To specify unique values for
individual channels, you must create an initialization loop on the host VI.

In the initialization loop, you might update the parameter values of some channels
while other channels retain the initial values you specified in the configuration dialog
box. In the following block diagram, the initialization loop initializes the parameters of
all channels.

Note The following block diagram contains some functions available only if you install FPGA
target driver software or the LabVIEW FPGA Module.

Processing Loop on the Host VI

After initializing the PID parameters and while running the VI on the FPGA target, you
might want to modify parameters or reset channels on a per-channel basis, without
affecting the execution of other channels. Create a processing loop on the host VI to
modify parameters or reset channels asynchronously during execution of the FPGA VI.

Resetting a PID channel resets the internal channel states to 0 and restarts the PID
algorithm while using either the parameter values stored in memory or the parameter
values from the host VI. To modify different parameters, you must specify the channel
index, which tells the PID algorithm the channel number to which to apply the new

52 ni.com
PID and Fuzzy Logic

parameter values. The following block diagram shows an example of a processing


loop.

Note The following block diagram contains some functions available only if you install FPGA
target driver software or the LabVIEW FPGA Module.

Fuzzy Logic
Fuzzy logic is a method of rule-based decision making used for expert systems and
process control. Fuzzy logic differs from traditional Boolean logic in that fuzzy logic
allows for partial membership in a set.

Traditional Boolean logic is two-valued in the sense that a member either belongs to a
set or does not. Values of one and zero represent the membership of a member to the
set with one representing absolute membership and zero representing no
membership. Fuzzy logic allows for partial membership, or a degree of membership,
which might be any value along the continuum of zero to one.

You can think of fuzzy logic in terms of fuzzy systems, which are systems of variables
associated with fuzzy logic, and fuzzy controllers, which use defined rules to control a
fuzzy system based on the current values of input variables. You can use the Fuzzy
Logic VIs to design and control fuzzy systems. You also can use the Fuzzy System
Designer to design fuzzy systems interactively.

© National Instruments 53
PID and Fuzzy Logic

Related Information

Fuzzy Systems

Fuzzy Controllers

Tutorial: Using the Fuzzy System Designer

Tutorial: Modifying a Fuzzy System with the Fuzzy Logic VIs

Fuzzy Systems
A fuzzy system is a system of variables that are associated using fuzzy logic. A fuzzy
controller uses defined rules to control a fuzzy system based on the current values of
input variables. You can use the Fuzzy System Designer and the Fuzzy Logic VIs to
design and control fuzzy systems.

Fuzzy systems consist of three main parts: linguistic variables, membership functions,
and rules.

Linguistic Variables

Linguistic variables represent, in words, the input variables and output variables of the
system you want to control. For a heater, you might have two input linguistic variables,
current temperature and desired temperature, and one output linguistic
variable, heater setting. Each linguistic variable has a range of expected values. For
example, the range of current temperature might be 0 to 100 degrees. The range of
desired temperature might be 50 to 80 degrees.

A fuzzy controller requires at least one input linguistic variable and one output
linguistic variable.

Linguistic Terms and Membership Functions

Linguistic terms represent, in words, categories for the values of a linguistic variable.
The linguistic variables current temperature and desired temperature each
might include the linguistic terms cold, moderate, and hot. The linguistic variable

54 ni.com
PID and Fuzzy Logic

heater setting might include the linguistic terms off, low, and high.

Membership functions are numerical functions corresponding to linguistic terms. A


membership function represents the degree of membership of linguistic variables
within their linguistic terms. The degree of membership is continuous between 0 and
1, where 0 is equal to 0% membership and 1 is equal to 100% membership. For
example, the linguistic variable current temperature might have full membership
(1) within the linguistic term hot at 100 degrees, no membership (0) within that term
at 70 degrees or less, and partial membership at all temperatures between 70 and 100
degrees.

Rules

Rules describe, in words, the relationships between input and output linguistic
variables based on their linguistic terms. For example, you might define the following
rule:

IF current temperature is cold AND desired temperature is moderate, THEN heater


setting is low.

The clauses "current temperature is cold" and "desired temperature is


moderate" are the antecedents of this rule. The AND connective specifies how the
fuzzy logic controller relates the two antecedents to determine the truth value for the
aggregated rule antecedent. The clause "heater setting is low" is the consequent of
this rule.

A rule base is the set of rules for a fuzzy system. The rule base is equivalent to the
control strategy of the controller.

Related Information

Fuzzy System Design Overview

Defuzzification Methods

© National Instruments 55
PID and Fuzzy Logic

Fuzzy System Design Overview

The topics in this section use an example fuzzy system that automates a vehicle to
park itself to illustrate the basics of fuzzy system design.

Note The topics in this section describe the general process of designing a fuzzy system. You
also can refer to the tutorials Using the Fuzzy System Designer and Modifying a Fuzzy System
with the Fuzzy Logic VIs for examples with step-by-step instructions of how to design a fuzzy
system with the PID and Fuzzy Logic VIs.

A fuzzy system consists of three main parts: linguistic variables, membership


functions, and rules. Therefore, fuzzy system design is a three-step process:

1. Creating Linguistic Variables


2. Creating Membership Functions
3. Creating a Rule Base

Creating Linguistic Variables

When you design a fuzzy system, linguistic variables represent, in words, the input
variables and output variables of the system you want to control.

When you create a linguistic variable to represent an input or output variable, decide
how many linguistic terms, or categories of values of the linguistic variable, you want
to create. Linguistic variables usually have an odd number of linguistic terms, with a
middle linguistic term and symmetric linguistic terms at each extreme. In most
applications, three to seven linguistic terms are sufficient for categorizing the values of
a linguistic variable.

Consider an example in which you want to automate a vehicle to park itself from an
arbitrary starting position. A driver can control the vehicle by constantly evaluating the
current status of the vehicle, such as the distance from the target position and the
orientation of the vehicle, to derive the correct steering angle. The following image
illustrates this example.

56 ni.com
PID and Fuzzy Logic

You can define two input linguistic variables for this example. Vehicle Position x
represents the vehicle position in relation to the destination. Vehicle Orientation β
represents the orientation of the vehicle. You also can define an output linguistic
variable, Steering Angle φ, to represent the steering angle of the vehicle that you
want to control.

Defining Linguistic Terms

You can define linguistic terms of Left, Left Center, Center, Right Center, and
Right for the Vehicle Position x input linguistic variable to describe the possible
positions of the vehicle in relation to the destination. You can define linguistic terms of
Left Down, Left, Left Up, Up, Right Up, Right, and Right Down for the Vehicle
Orientation β input linguistic variable to describe the possible orientations of the
vehicle. The linguistic terms of the Steering Angle φ output linguistic variable must
represent both the direction and magnitude that the steering angle changes.
Therefore, you can use the linguistic terms Negative Large, Negative Medium,
Negative Small, Zero, Positive Small, Positive Medium, and Positive Large
for this output linguistic variable.

The next step in designing a fuzzy system is creating membership functions that
correspond to the linguistic terms you define.

© National Instruments 57
PID and Fuzzy Logic

Creating Membership Functions

When you design a fuzzy system, you first create linguistic variables for which you
define linguistic terms. After you define the linguistic terms, you must apply
membership functions to those terms. Membership functions are simply numerical
functions that correspond to linguistic terms. A membership function represents the
degree of membership of linguistic variables within their linguistic terms.

You can apply the normalized standard membership functions shown in the following
image to most technical processes. These standard functions include Λ-type
(triangular shape), Π-type (trapezoidal shape), singleton-type (vertical line shape),
Sigmoid-type (wave shape), and Gaussian-type (bell shape) membership functions.

Example Triangle Membership Function for the Linguistic Term Center

For example, the linguistic variable Vehicle Position x might have full membership
(1) within the linguistic term Center at 5 meters, no membership (0) within that term
at 4 meters or less and 6 meters or greater, and partial membership at all distances
between 4 and 6 meters. If you plot the degree of membership against the value of
Vehicle Position x, you can see that the resulting membership function is a triangle
function.

58 ni.com
PID and Fuzzy Logic

Example Trapezoidal Membership Function for the Linguistic Term


Center

Sometimes a linguistic variable has full membership within a linguistic term at a range
of values rather than at a point value. If, for example, the linguistic variable Vehicle
Position x has full membership within the linguistic term Center at values x = 5 ± 0.25
m, a trapezoidal membership function applies, as shown in the following image.

© National Instruments 59
PID and Fuzzy Logic

Membership Functions for a Vehicle Maneuvering Fuzzy System

The following image shows the membership functions for Vehicle Position x.

The following image shows the membership functions for Vehicle Orientation β.

The following image shows the membership functions for Steering Angle φ.

60 ni.com
PID and Fuzzy Logic

Creating a Rule Base

After create linguistic variables, defining linguistic terms, and creating membership
functions, the last step of fuzzy system design is creating a rule base. Rules describe, in
words, the relationships between input and output linguistic variables based on their
linguistic terms. A rule base is the set of rules for a fuzzy system.

To create a rule, you must specify the antecedents, or IF portions, and consequents, or
THEN portions, of the rule. For example, consider the following rule for a vehicle
maneuvering fuzzy system:

IF Vehicle Position x is Left Center AND Vehicle Orientation β is Left Up, THEN Steering
Angle φ is Positive Small.

The clauses "Vehicle Position x is Left Center" and "Vehicle Orientation β is


Left Up" are the antecedents of this rule. The clause "Steering Angle φ is Positive
Small" is the consequent of this rule.

Associate an input linguistic variable with a corresponding linguistic term to form an


antecedent. Associate an output linguistic variable with a corresponding linguistic
term to form a consequent. The consequent of a rule represents the action you want
the fuzzy controller to take if the linguistic terms of the input linguistic variables in the
rule are met.

When constructing a rule base, avoid contradictory rules, or rules with the same IF

© National Instruments 61
PID and Fuzzy Logic

portion but different THEN portions. A consistent rule base is a rule base that has no
contradictory rules.

Note The rule base itself is the biggest influence on the I/O characteristics of a fuzzy
controller. The rule base determines the principal functionality of the controller. Refer to the
Using the Mean of Maximum (MoM) Defuzzification Method example to see how changing the
rule base can affect the output characteristic of a fuzzy controller.

Total Possible Rules

The total number N of possible rules for a fuzzy system is defined by the following
equation:

N = p1*p2*...*pn

where pn is the number of linguistic terms for the input linguistic variable n.

If each input linguistic variable has the same number of linguistic terms, the total
number N of possible rules is defined by the following equation:

m
N=p

where p is the number of linguistic terms for each input linguistic variable and m is the
number of input linguistic variables. For example, for three input linguistic variables
with five linguistic terms each, the total number of possible rules is N = 53 = 125.

Additional Information About Rule Bases

The following topics contain additional important information about creating rule
bases:

• Complete Rule Bases


• Specifying an Antecedent Connective
• Specifying a Degree of Support
• Specifying a Consequent Implication Method

62 ni.com
PID and Fuzzy Logic

Complete Rule Bases


A rule base with at least one active rule for each possible combination of input
linguistic variables and linguistic terms is a complete rule base. If you define an
incomplete rule base, you must specify a default linguistic term for each output
linguistic variable so the fuzzy controller can handle situations in which no rules are
active.

The Vehicle Position x input linguistic variable has five linguistic terms, and the
Vehicle Orientation β linguistic variable has seven linguistic terms. Therefore, the
rule base of the vehicle maneuvering example consists of N = 5*7 = 35 rules. You can
document the complete rule base in matrix form, as shown in the following image for
the vehicle maneuvering fuzzy system.

In the previous image, each column or row represents an antecedent of a rule. The
term at the intersection of a column and a row is the consequent of the rule
corresponding to the aggregated rule antecedent. For example, the following rule is
highlighted:

© National Instruments 63
PID and Fuzzy Logic

IF Vehicle Position x is Left Center AND Vehicle Orientation β is Left, THEN Steering
Angle φ is Negative Small.

Cascading Fuzzy Systems

Plotting a rule base in matrix form, as in the previous image, is helpful for detecting
inconsistencies, such as contradictory rules. However, plotting a rule base in matrix
form is efficient only for small rule bases. Detecting inconsistencies in large rule bases
is difficult. For fuzzy systems with numerous controller inputs, you can use cascading
fuzzy systems to avoid large rule bases. In cascading fuzzy systems, the outputs of the
first fuzzy system serve as the inputs to the next fuzzy system, and so on.

Specifying an Antecedent Connective


When creating a rule base, if a rule has more than one antecedent, you must specify an
antecedent connective to determine how to calculate the truth value of the aggregated
rule antecedent.

Because linguistic variables can have partial degrees of membership within linguistic
terms, you cannot use Boolean operators from conventional dual logic as antecedent
connectives. PID and Fuzzy Logic VIs use the following antecedent connectives instead.

AND (Minimum)

μA*B = min(μA, μB)

AND (Product)

μA*B = (μA, μB)

OR (Maximum)

μA + B = max(μA, μB)

64 ni.com
PID and Fuzzy Logic

OR (Probabilistic)

A + B = ((A + B) - (AB))

Notice that these definitions agree with the logical operators used in Boolean logic. A
truth table uses conventional operators to yield equivalent results.

The AND (Minimum) antecedent connective specifies to use the smallest degree of
membership of the antecedents as the truth value of the aggregated rule antecedent,
while the AND (Product) specifies to use the product of the degrees of membership of
the antecedents. The OR (Maximum) antecedent connective specifies to use the largest
degree of membership of the antecedents. The OR (Probabilistic) antecedent
connective specifies to use the probabilistic sum of the degrees of membership of the
antecedents.

Antecedent Connectives for a Vehicle Maneuvering Fuzzy System

Assume the following rules are invoked for the input values of a vehicle maneuvering
fuzzy system.

Vehicle Orientation β is Left


IF Vehicle Position x is Center AND
(1)
(Minimum) Up
(degree of membership = 0.8)
(degree of membership = 1.0) = 0.8

THEN Steering Angle φ is Negative Small

IF Vehicle Position x is Right Vehicle Orientation β is Left


AND
(2) Center Up
(Minimum)
(degree of membership = 0.1) (degree of membership = 1.0) = 0.1

THEN Steering Angle φ is Negative Medium

Notice that each rule uses the AND (Minimum) antecedent connective. In Rule 1,
Vehicle Position x has a degree of membership of 0.8 within the linguistic term
Center and Vehicle Orientation β has a degree of membership of 1.0 within the
linguistic term Left Up. Because the antecedent connective is AND (Minimum), the
fuzzy controller for this fuzzy system uses the smallest degree of membership of the
antecedents, or 0.8, as the truth value of the aggregated rule antecedent. Similarly, the

© National Instruments 65
PID and Fuzzy Logic

smallest degree of membership of the antecedents in Rule 2 is 0.1. Therefore, the fuzzy
controller uses 0.1 as the truth value of the aggregated rule antecedent. The truth
value of the aggregated rule antecedent is equivalent to the degree of truth of the rule.

If these two rules are the only rules invoked for a given set of input values, the other
linguistic terms for the Steering Angle φ output linguistic variable have a truth value
of 0. The following list describes the final truth values for each of the linguistic terms.

Negative Large to a degree of 0.0


Negative Medium to a degree of 0.1
Negative Small to a degree of 0.8
Zero to a degree of 0.0
Positive Small to a degree of 0.0
Positive Medium to a degree of 0.0
to a degree of 0.0
Positive Large

If a rule has more than one consequent, the fuzzy logic controller must evaluate the
aggregated rule consequent. When you implement a fuzzy controller with PID and
Fuzzy Logic VIs, the fuzzy controller always considers only the consequent that has the
largest degree of membership.

Specifying a Degree of Support


You can specify a degree of support, between 0 and 1, for each rule of a fuzzy system.
The degree of support represents the relative significance of each rule and allows for
fine-tuning of the rule base. In most cases, the degree of support is 1. The final weight
of a rule is equal to the degree of support multiplied by the truth value of the
aggregated rule antecedent.

Specifying a Consequent Implication Method


A fuzzy controller uses a consequent implication method to scale the membership
functions of each output linguistic variable based on the corresponding rule weight
before performing defuzzification.

66 ni.com
PID and Fuzzy Logic

With PID and Fuzzy Logic VIs, you can use either the Minimum or Product consequent
implication method.

Minimum Consequent Implication Method

In the Minimum implication method, the fuzzy logic controller truncates the output
membership functions at the value of the corresponding rule weights. For example, if
an output linguistic variable has three membership functions with rule weights 0.5,
0.8, and 0.3, respectively, the scaled membership functions might appear similar to the
following image.

Product Consequent Implication Method

In the Product implication method, the fuzzy logic controller scales the output
membership functions at the value of the corresponding rule weights. For example, if
an output linguistic variable has three membership functions with rule weights 0.5,
0.8, and 0.3, respectively, the scaled membership functions might appear similar to the
following image.

© National Instruments 67
PID and Fuzzy Logic

Defuzzification Methods

Defuzzification is the process of converting the degrees of membership of output


linguistic variables within their linguistic terms into crisp numerical values. Consider
the following rules:

Vehicle Orientation β is Left


IF Vehicle Position x is Center AND
(1)
(Minimum) Up
(degree of membership = 0.8)
(degree of membership = 1.0) = 0.8

THEN Steering Angle φ is Negative Small

IF Vehicle Position x is Right Vehicle Orientation β is Left


AND
(2) Center Up
(Minimum)
(degree of membership = 0.1) (degree of membership = 1.0) = 0.1

THEN Steering Angle φ is Negative Medium

These two rules specify two non-zero values for the Steering Angle φ output
linguistic variable:

Negative Medium to a degree of 0.1


Negative Small to a degree of 0.8

Note Fuzzy controllers use an implication method to scale the membership functions of

68 ni.com
PID and Fuzzy Logic

output linguistic variables before performing defuzzification.

A fuzzy controller can use one of several mathematical methods to perform


defuzzification: Center of Area (CoA), modified Center of Area (mCoA), Center of Sums
(CoS), Center of Maximum (CoM), or Mean of Maximum (MoM). Selecting a
defuzzification method depends on the context of the design you want to calculate
with the fuzzy controller.

Related Information

Center of Area (CoA)

Modified Center of Area (mCoA)

Center of Maximum (CoM)

Mean of Maximum (MoM)

Center of Sums (CoS)

Selecting a Defuzzification Method

Center of Area (CoA)

In the Center of Area (CoA) defuzzification method, also called the Center of Gravity
(CoG) method, the fuzzy controller first calculates the area under the scaled
membership functions and within the range of the output variable. The fuzzy logic
controller then uses the following equation to calculate the geometric center of this
area.

where CoA is the center of area, x is the value of the linguistic variable, and xmin and

© National Instruments 69
PID and Fuzzy Logic

xmax represent the range of the linguistic variable. The Center of Area defuzzification
method effectively calculates the best compromise between multiple output linguistic
terms.

The following image shows the Center of Area defuzzification method for the
Steering Angle φ output linguistic variable of a vehicle maneuvering fuzzy system,
assuming the Minimum implication method. The shaded portion of the graph
represents the area under the scaled membership functions.

The following image summarizes the process of a fuzzy controller for the vehicle
maneuvering example using the Center of Area defuzzification method.

70 ni.com
PID and Fuzzy Logic

Modified Center of Area (mCoA)

Because the Center of Area (CoA) defuzzification method evaluates the area under the
scaled membership functions only within the range of the output linguistic variable,
the resulting crisp output values cannot span the full range. To solve this problem, use
the modified Center of Area defuzzification method.

The modified Center of Area defuzzification method is similar to the Center of Area
defuzzification method. However, the fuzzy logic controller considers the full area
under the scaled membership functions, even if this area extends beyond the range of
the output variable. The fuzzy logic controller uses the following equation to calculate
the geometric center of the full area under the scaled membership functions.

© National Instruments 71
PID and Fuzzy Logic

where mCoA is the modified center of area.

The interval of integration is between the minimum membership function value and
the maximum membership function value. Note that this interval might extend
beyond the range of the output variable.

Comparing CoA and Modified CoA Defuzzification Methods

The following image illustrates the difference between the Center of Area and modified
Center of Area defuzzification methods.

Center of Maximum (CoM)

In the Center of Maximum (CoM) defuzzification method, the fuzzy logic controller first
determines the typical numerical value for each scaled membership function. The
typical numerical value is the mean of the numerical values corresponding to the
degree of membership at which the membership function was scaled.

72 ni.com
PID and Fuzzy Logic

where xn is the typical numerical value for the scaled membership function n, and μn
is the degree of membership at which the membership function n was scaled.

The following image illustrates how to use the CoM defuzzification method with the
vehicle maneuvering example.

The values -15° and -5° are the typical values of the linguistic terms Negative
Medium and Negative Small. The degrees of truth for these linguistic terms are 0.1
and 0.8, respectively. Therefore, the defuzzified crisp output value φfinal is calculated
by the following equation:

The CoM defuzzification method is identical to the Center of Area (CoA) method with
singleton membership functions.

The CoM and CoA defuzzification methods usually apply to closed-loop control
applications of fuzzy logic. These methods usually result in continuous output signals
because a small change in input values does not change the best compromise value
for the output.

© National Instruments 73
PID and Fuzzy Logic

Mean of Maximum (MoM)

Use the Mean of Maximum (MoM) defuzzification method for pattern recognition
applications. This defuzzification method calculates the most plausible result. Rather
than averaging the degrees of membership of the output linguistic terms, the MoM
defuzzification method selects the typical value of the most valid output linguistic
term.

The following image illustrates the MoM defuzzification method.

Center of Sums (CoS)

In the Center of Sums (CoS) defuzzification method, the fuzzy logic controller first
calculates the geometric center of area for each membership function, as shown in the
following image.

74 ni.com
PID and Fuzzy Logic

The fuzzy controller then uses the following equation to calculate a weighted average
of the geometric center of area for all membership functions.

where CoAn is the geometric center of area of the scaled membership function n, and
arean is the area of the scaled membership function n.

Selecting a Defuzzification Method

In decision support systems, the choice of the defuzzification method depends on the
context of the decision you want to calculate with the fuzzy controller. For quantitative
decisions like project prioritization, apply the Center of Maximum (CoM) method. For
qualitative decisions, such as an evaluation of credit worthiness, Mean of Maximum
(MoM) is the correct method.

An important aspect of a defuzzification method is the continuity of the output signal.


Consider a fuzzy system with a complete rule base and overlapping membership
functions. A defuzzification method is continuous if an arbitrary small change of an
input value never causes an abrupt change in the output signal.

In this respect, the defuzzification methods CoM and Center of Area (CoA) are
continuous because, assuming overlapping output membership functions, the best
compromise does not jump to a different value with a small change to the inputs. The

© National Instruments 75
PID and Fuzzy Logic

defuzzification method MoM, however, is discontinuous because an arbitrary small


change in the input values of the fuzzy system can cause the output value to switch to
another, more plausible result.

Using CoA or CoM as the defuzzification method results in continuous controller


characteristic functions, especially within those intervals of the input values in which
two or more rules are active simultaneously. This behavior results from the averaging
character of the defuzzification methods.

The following table compares the different defuzzification methods based on various
assessment criteria.

Method
Center of Area
(CoA)
Assessment Center of Mean of
Criteria Center of Sums
and Maximum Maximum
(CoS)
(CoM) (MoM)
Modified Center of Area
(mCoA)
Most
Linguistic Best
Best Compromise Best Compromise Plausible
Characteristic Compromise
Result
Implausible with varying Implausible with varying
membership function membership function
Fit with
shapes and strong shapes and strong Good Good
Intuition
overlapping membership overlapping membership
functions functions
Continuity Yes Yes Yes No
Computational
Very High Medium Low Very Low
Effort
Closed-Loop Pattern
Control, Recognition,
Closed-Loop Control, Closed-Loop Control,
Application Decision Decision
Decision Support, Data Decision Support, Data
Field Support, Support,
Analysis Analysis
Data Data
Analysis Analysis

76 ni.com
PID and Fuzzy Logic

Fuzzy Controllers
You can use fuzzy controllers to control fuzzy systems. Most traditional control
algorithms require a mathematical model of the system you want to control. However,
many physical systems are difficult or impossible to model mathematically. In
addition, many processes are either nonlinear or too complex for you to control with
traditional strategies. However, if you can describe a control strategy qualitatively, you
can use fuzzy logic to create a fuzzy controller that emulates a heuristic rule-of-thumb
strategy.

The following image illustrates the process of a fuzzy controller.

Fuzzification

Fuzzification is the process of associating crisp, or numerical, input values with the
linguistic terms of the corresponding input linguistic variables.

For example, a fuzzy controller might associate the temperature reading from a
thermometer with the linguistic terms cold, moderate, and hot for the current
temperature linguistic variable. Depending on the membership functions for the
linguistic terms, the temperature value might correspond to one or more of the
linguistic terms.

Implementing a Linguistic Control Strategy

After a fuzzy controller fuzzifies the input values of a fuzzy system, the fuzzy controller
uses the corresponding input linguistic terms and the rule base to determine the
resulting linguistic terms of the output linguistic variables.

© National Instruments 77
PID and Fuzzy Logic

For example, suppose the current temperature of a room is 50 degrees, which


corresponds to a linguistic term of cold with a degree of membership of 0.4. Also
suppose the desired temperature is 70, which corresponds to a linguistic term of
moderate with a degree of membership of 0.8. The fuzzy controller invokes the
following rule of the fuzzy system: IF current temperature is cold AND desired
temperature is moderate, THEN heater setting is low.

Notice that this rule consists of two antecedents, "current temperature is cold"
and "desired temperature is moderate". The truth value of each antecedent is
equal to the degree of membership of the linguistic variable within the corresponding
linguistic term. The fuzzy logic controller uses an antecedent connective to determine
how to calculate the truth value of the aggregated rule antecedent. Suppose the
invoked rule in this example uses the AND (Minimum) antecedent connective, which
specifies to use the smallest degree of membership of the antecedents as the truth
value of the aggregated rule antecedent. Therefore, the truth value of the aggregated
rule antecedent is 0.4.

You can specify a degree of support for each rule of a fuzzy system. The weight of a rule
is equal to the degree of support multiplied by the truth value of the aggregated rule
antecedent. The fuzzy controller uses an implication method to scale the membership
functions of an output linguistic variable based on the rule weight before performing
defuzzification.

Defuzzification

Defuzzification is the process of converting the degrees of membership of output


linguistic variables within their linguistic terms into crisp numerical values. A fuzzy
controller can use one of several mathematical methods to perform defuzzification.
The most accurate defuzzification method for a fuzzy controller varies based on the
control application.

Related Information

I/O Characteristics of Fuzzy Controllers

Fuzzy Controllers in Closed-Loop Control Structures

78 ni.com
PID and Fuzzy Logic

I/O Characteristics of Fuzzy Controllers

You can consider a fuzzy controller to be a nonlinear characteristic field controller. The
rule base and membership functions of the fuzzy system determine the behavior of the
controller. Because the controller has no internal dynamic aspects, the I/O
characteristics can describe the transient response of the controller completely.

This section includes examples that show the I/O characteristics of a fuzzy controller
under various of conditions. Select an item from the list for information about I/O
characteristics of a fuzzy controller with the described conditions.

• Partially Overlapping Input Terms


• Fully Overlapping Input Terms
• Non-Overlapping Input Terms
• Undefined Input Term Intervals
• Singletons as Output Terms with Fully Overlapping Input Terms
• Different Overlapping Degrees of Membership Functions for Output Terms
• Wide and Small Membership Functions for the Output Terms
• Using the Mean of Maximum (MoM) Defuzzification Method
• Reproducing a Given I/O Characteristic
• Dual-Input Fuzzy Controllers

These examples show that you can use a fuzzy controller to perform arbitrary I/O
operations. The number of input and output linguistic terms depends on the desired
characteristic type and the precision to which you approximate the given I/O
characteristic.

Partially Overlapping Input Terms

To illustrate how the I/O characteristics of a fuzzy controller depend on design


parameters such as the rule base and membership function specifications of the fuzzy
system, consider a single-input fuzzy controller. Many of the characteristics of a single-
input fuzzy controller apply to fuzzy controllers with two or more inputs.

The following image shows the I/O characteristic of a fuzzy controller for a fuzzy
system that has only three linguistic terms for the input variable x and the output
variable y. The rule base consists of three rules, which indicate that the increasing

© National Instruments 79
PID and Fuzzy Logic

input values cause the output value to increase.

The resulting controller characteristic shows nonlinear behavior. You obtain different
intervals within the controller characteristic because the input linguistic terms
partially overlap. The rule base has only one valid rule outside of the overlapping
regions. The output therefore has a constant value determined by the output linguistic
term of the output linguistic variable, which is independent of the degree of truth for
that rule.

The overlapping sections of the antecedent terms lead to the rising intervals of the
controller characteristic. Within these parts, two rules are simultaneously active. The
different consequent terms, weighted by the degrees of truth of the different active
rules, determine the output value. Notice that the overlapping triangular consequent
terms cause the rising edges of the controller characteristic to be nonlinear.

80 ni.com
PID and Fuzzy Logic

Fully Overlapping Input Terms

The following image shows the resulting controller I/O characteristic for antecedent
terms that overlap entirely. The consequent term distribution and the rule base
remain unchanged for this case.

Non-Overlapping Input Terms

The following image shows the controller I/O characteristic that results when non-
overlapping antecedent terms describe the input variable.

© National Instruments 81
PID and Fuzzy Logic

Only one rule is active for each input situation that leads to the stepped controller
characteristic.

Undefined Input Term Intervals

If the rule base has undefined intervals within input and output linguistic terms, or if
the rule base is incomplete, you must specify the output of the fuzzy controller. If no
rule is available for a certain situation, the output value remains undefined. One way
to avoid this problem is to leave the current output value unchanged until the
controller encounters a situation that is covered by the rules. The following image
shows the resulting effect on the controller characteristic.

82 ni.com
PID and Fuzzy Logic

If you use an old output value as a default value, undefined intervals or incomplete
rule bases can lead to hysteretic effects on the controller characteristic.

You can use non-overlapping, rectangular-shaped consequent terms to obtain an exact


linear controller characteristic for a single-input controller. In this case, both the area
and momentum vary linearly with the degree of truth, and overlapping regions of the
output linguistic terms do not cause any distortion.

Different Overlapping Degrees of Membership Functions for Output Terms

The following image shows that if all the consequent terms are equal in width, the
overlapping degree of the membership functions for the consequent terms has no
significant influence on the controller characteristic.

© National Instruments 83
PID and Fuzzy Logic

Wide and Small Membership Functions for Output Terms

If you want to significantly influence the controller characteristic, use output terms
that membership functions model with equally distributed typical values but different
scopes of influence instead. The different terms have different areas and thus different
weights with respect to the defuzzification process. A wide output term has more
influence on the inference result than a small neighboring output term. The following
image demonstrates this effect.

84 ni.com
PID and Fuzzy Logic

Singletons as Output Terms with Fully Overlapping Input Terms

The simplest way to obtain a linear controller characteristic is to use singletons as


consequent terms with entirely overlapping input terms. Singletons are normalized
rectangular membership functions with an infinitely small width. Using singleton
membership functions for consequent terms makes the Center of Area (CoA)
defuzzification method identical to the Center of Maximum (CoM) method. The
following image shows the controller for the CoA method using singleton membership
functions.

© National Instruments 85
PID and Fuzzy Logic

The controller characteristic remains relatively unchanged when you leave the input
terms entirely overlapped to vary the overlapping degree of the membership functions
for the consequent terms, especially if all the consequent terms are equal in width.
Then only the typical values of the consequent terms are significant.

Therefore, in most closed-loop control applications, you can use singleton


membership functions to model the output terms sufficiently rather than using
triangular or other membership function types.

Using the Mean of Maximum (MoM) Defuzzification Method

When you use the Mean of Maximum (MoM) defuzzification method, you calculate the
most plausible result. In other words, the fuzzy controller uses the typical value of the
consequent term of the most valid rule as the crisp output value. This behavior results

86 ni.com
PID and Fuzzy Logic

in stepped output characteristics, as shown in the following image.

The previous image shows entirely overlapping membership functions for input and
output terms.

Changing the Rule Base

The rule base itself has the biggest influence on the controller characteristic. The rule
base determines the principal functionality of the controller.

The following image illustrates how the controller characteristic changes if you change
the rule base of the previous example to include the following rules:

Rule 1: IF x = negative THEN y = negative

© National Instruments 87
PID and Fuzzy Logic

Rule 2: IF x = zero THEN y = positive

Rule 3: IF x = positive THEN y = negative

Reproducing a Given I/O Characteristic

Consider the stepped linear characteristic curve shown in the following image. You can
describe the four linear sections with the five circled base points (xi, yi).

88 ni.com
PID and Fuzzy Logic

To use a single-input fuzzy controller to reproduce the given characteristic, use five
linguistic terms each for the input and output quantities, naming them x1, x2, ..., x5
and y1, y2, ..., y5, respectively. To obtain the stepped linear sections between the base
points, you always must have exactly two available active rules. To implement this
situation, entirely overlap the triangular membership functions for the input variable,
giving each a typical value that corresponds to a certain base point component, xi.

To obtain characteristic sections that are exactly linear, you must model the output
variable with singleton membership functions, each of which has a typical value that
corresponds to a certain base point component, yi. The rule base is then a linguistic
enumeration of the five base points.

© National Instruments 89
PID and Fuzzy Logic

Dual-Input Fuzzy Controllers

In principle, the conclusions about I/O characteristics for single-input fuzzy controllers
also are valid for controllers with two or more inputs. However, using the AND
(Minimum) antecedent connective to combine the different input conditions raises an
additional nonlinear effect. The fuzzy controller considers the antecedent of the rule
with the lowest degree of truth as shown in the Reproducing a Given I/O Characteristic
example.

The following image shows the I/O characteristic field for a dual-input fuzzy controller.

90 ni.com
PID and Fuzzy Logic

Because the AND (Minimum) antecedent connective is nonlinear, the characteristic


field is not exactly linear despite the membership functions that overlap entirely for
both input variables. Non-overlapping membership functions yield a stepped
characteristic field with constant planes, as shown in the following image.

Fuzzy Controllers in Closed-Loop Control Structures

The most common use case for fuzzy controllers is in closed-loop control structures.
The most basic structure of closed-loop control applications uses sensor signals as
input signals for the system and the outputs as command values to drive the actuators
of the process. The following image shows a simple closed-loop control structure with
a fuzzy controller.

© National Instruments 91
PID and Fuzzy Logic

Pure fuzzy control applications are more the exception than the rule. In most cases the
fuzzy controller outputs serve as reference parameters, such as gains, that you provide
to a conventional controller instead of directly to driving actuators.

Because you can regard a fuzzy controller as a nonlinear characteristic field controller,
it has no internal dynamic aspects. Thus, you must implement any dynamic property
by an appropriate preprocessing of the measured input data.

PID and Fuzzy Logic VIs enable you to integrate fuzzy controllers and PID control. For
example, you can use fuzzy controllers with conventional PID controllers or create
hybrid fuzzy-PI controllers. Use either the Fuzzy System Designer or the Fuzzy Logic VIs
to design a fuzzy system. Then use the FL Fuzzy Controller VI to implement a fuzzy
controller for the fuzzy system. Finally, you can integrate the fuzzy controller into a
control structure you create using the PID VIs.

Related Information

Fuzzy-PI Controllers

Using Fuzzy Controllers with PID Controllers

Fuzzy-PI Controllers

A PI controller is a controller that produces proportional plus integral control action.


The PI controller has only one input and one output. The output value increases when
the input value increases.

A fuzzy-PI controller is a generalization of the conventional PI controller that uses an

92 ni.com
PID and Fuzzy Logic

error signal and its derivative as input signals. Fuzzy-PI controllers have two inputs and
one output. Multiple inputs allow for greater control diversity for a fuzzy-PI controller
over a conventional PI controller.

The fuzzy-PI controller shown in the following image uses the error signal e(t) and its
derivative de(t)/dt from the measured data preprocessing step as inputs. If the output
signal describes the necessary difference toward the current output value, you need a
subsequent integrator device to build up the command variable value.

Advantages of Fuzzy-PI Controllers

The benefit of the fuzzy-PI controller is that it does not have a special operating point.
The rules evaluate the difference between the measured value and the set value,
which is the error signal. The rules also evaluate the tendency of the error signal to
determine whether to increase or decrease the control variable. The absolute value of
the command variable has no influence.

Another advantage of a fuzzy-PI controller over a conventional PI controller is that it


can implement nonlinear control strategies and that it uses linguistic rules. With fuzzy-
PI controllers, you can consider the error tendency by itself when the error becomes
small.

Using Fuzzy Controllers with PID Controllers

The chemical industries and process technologies often use fuzzy controllers with
underlying PID control loops. The fuzzy controllers these industries use are PID fuzzy
controllers that control single-process parameters. Usually, people supervise the
operating point of the entire process.

© National Instruments 93
PID and Fuzzy Logic

The following image shows the controller structure of the fuzzy controller with
underlying PID control loops.

For automatic operation of such multi-variable control problems, you must build a
model-based controller. However, for most applications, either the process is too
complex to model adequately, or the mathematical modeling task requires too much
time.

Using a Fuzzy Controller to Tune PID Controller Parameters

The following image shows how to use a fuzzy controller to tune the parameters of a
conventional PID controller automatically. This fuzzy controller constantly interprets
the process reaction and calculates the optimal P, I, and D gains. You can apply this
control structure to processes that change their characteristics over time.

Using a Fuzzy Controller to Correct PID Controller Output

In the following image, both the fuzzy controller and the PID controller work in

94 ni.com
PID and Fuzzy Logic

parallel. The process adds the output signals from both controllers, but the output
signal from the fuzzy controller is zero under normal operating conditions. The PID
controller output leads the process. The fuzzy controller intervenes only when it
detects abnormal operating conditions, such as strong disturbances.

Tutorial: Using the Fuzzy System Designer


You can use the PID and Fuzzy Logic VIs to design a fuzzy system in one of two ways:
using the Fuzzy System Designer or using the Fuzzy Logic VIs. This tutorial teaches you
to design a fuzzy system interactively using the Fuzzy System Designer.

Tip Refer to the Modifying a Fuzzy System with the Fuzzy Logic VIs tutorial to learn how to
design and modify fuzzy systems using the Fuzzy Logic VIs.

In this tutorial, you use the Fuzzy System Designer to design a fuzzy system similar to
the vehicle maneuvering example described in the topics on fuzzy system design. As a
reference, you can find the complete fuzzy system you design in this tutorial, Truck
- backward.fs, in the labview\examples\control\fuzzy\Car Parkin
g directory.

Next
1. Creating Input Linguistic Variables

1. Creating Input Linguistic Variables

The first step in designing a fuzzy system with the Fuzzy System Designer is to create

© National Instruments 95
PID and Fuzzy Logic

the input and output linguistic variables for the system. In the vehicle maneuvering
example described in the topics on fuzzy system design, the fuzzy system has two
linguistic input variables, Vehicle Position x and Vehicle Orientation β, and one
linguistic output variable, Steering Angle φ.

Tip The graphs in the Creating Membership Functions topic illustrate the range and
membership functions for each of these linguistic variables.

Complete the following steps to create an input linguistic variable that corresponds to
the Vehicle Position x input linguistic variable of the vehicle maneuvering example.

1. Select Tools»Control Design and Simulation»Fuzzy System Designer to launch


the Fuzzy System Designer and display the Variables page.
2. Click the Add Input Variable button to the right of the Input variables list to
display the Edit Variable dialog box.
3. In the Name text box, enter vehicle-position.
4. Specify the Range by entering 0 in the minimum field and 10 in the maximum
field. This specifies that the position of the vehicle relative to the destination
ranges from 0.0 to 10.0 meters.
5. Click the Add Membership Function button under the Membership functions
control to enable the control and create a new membership function for the
vehicle-position linguistic variable.
6. In the Name text box, enter left.
7. Select Trapezoid from the Shape pull-down menu to specify that a trapezoid
function determines the degrees of membership for the linguistic variable.
8. Click the Color field to select the color to use for the membership function in the
Membership functions graph.
9. In the Points array, enter the following numbers, one for each element of the array:
0, 0, 1, 4. These points specify the values of the linguistic variable corresponding
to the base and top points, in order from left to right and base to top, of the
membership function.
10. Repeat steps 5 through 9 for each of the following membership functions for
Vehicle Position x, using the shape and points shown in the following table:

Membership Function Shape Points

96 ni.com
PID and Fuzzy Logic

left-center Triangle 3, 4, 5
center Triangle 4.5, 5, 5.5
right-center Triangle 5, 6, 7
right Trapezoid 6, 9, 10, 10

Note The Points array requires that each point for a given membership function be
greater than or equal to all previous points. If the array automatically changes your
entries to fit this requirement, try entering points from left to right.

You can compare the Membership functions graph to the Vehicle Position graph in
the Creating Membership Functions topic to confirm your entries.
11. Click the OK button to save your changes and return to the Variables page. The
vehicle-position input variable appears in the Input variables list and the
corresponding membership functions appear in the Input variable membership
functions graph.
12. Repeat steps 2 through 11 to create a vehicle-orientation input linguistic
variable that corresponds to the Vehicle Orientation β variable of the vehicle
maneuvering example. The following graph shows the range and membership
functions for the variable.

Note For the purposes of this tutorial, you can use approximate values for the points of
the membership functions.

© National Instruments 97
PID and Fuzzy Logic

Home Next
Tutorial: Using the Fuzzy System Designer 2. Creating Output Linguistic Variables

2. Creating Output Linguistic Variables

You create output linguistic variables similarly to how you create input linguistic
variables in the Fuzzy System Designer. Complete the following steps to create an
output linguistic variable that corresponds to the Steering Angle φ output linguistic
variable of the vehicle maneuvering example.

1. Click the Add Output Variable button to the right of the Output variables list to
display the Edit Variable dialog box.
2. Enter steering-angle in the Name text box.
3. Enter a minimum value of -30 and a maximum value of 30. This range specifies
that the amount that the steering wheel can turn ranges from -30.0 to 30.0
degrees.
4. Click the Add Membership Function button to create a new membership function
for the steering-angle output variable.
5. Enter neg-large in the Name text box.
6. Select Triangle from the Shape pull-down menu to specify that a triangle function
determines the degrees of membership for the linguistic variable.
7. Select the color you want to use for the membership function in the Membership
functions graph from the Color picker.

98 ni.com
PID and Fuzzy Logic

8. Enter -30, -30, and -15 in the fields of the Points array. These points specify the
values of the linguistic variable corresponding to the base and top points, in order
from left to right and base to top, of the membership function.
9. Repeat steps 4 through 8 to create each of the membership functions shown in the
following graph.

10. Click the OK button to save your changes.


11. Select File»Save As to save the fuzzy system as vehicle_maneuvering.fs in
an easily accessible location.

Previous Home Next


1. Creating Input Tutorial: Using the Fuzzy 3. Creating a Rule Base with Pre-
Linguistic Variables System Designer Generated Rules

3. Creating a Rule Base with Pre-Generated Rules

Rules describe, in words, the relationships between input and output linguistic
variables based on their linguistic terms. The rule base of a fuzzy system determines
the output values of the fuzzy system based on the input values.

The vehicle-position input linguistic variable you created in step 1 has five
membership functions, and the vehicle-orientation input linguistic variable has
seven. Therefore, you can construct rules to associate 35 possible combinations of the
linguistic terms of these input linguistic variables with the linguistic terms of the

© National Instruments 99
PID and Fuzzy Logic

steering-angle output linguistic variable you created in step 2.

Note The table in the Complete Rule Bases topic illustrates this rule base.

Complete the following steps to create the complete rule base for the vehicle
maneuvering example. You must have created both input linguistic variables and the
output linguistic variable before creating this rule base.

1. Click the Rules tab of the Fuzzy System Designer to display the Rules page.
2. Select Operate»Pre-Generate Rules to display the Pre-Generate Rules dialog box.
3. Select AND (Minimum) from the Antecedent connective pull-down menu. This
antecedent connective specifies that the smallest degree of membership of the
antecedents determines the truth value of the aggregated rule antecedent for each
rule.
4. Enter a Degree of support of 1 to specify the weight that you want to apply to each
rule. The final rule weight for each rule is equal to the Degree of support
multiplied by the truth value of the aggregated rule antecedent.
5. Select Minimum from the Consequent implication pull-down menu to specify that
the fuzzy logic controller truncates the output membership functions at the value
of the corresponding rule weights before performing defuzzification.
Defuzzification is the process of converting the degrees of membership of output
linguistic variables into numerical values.
6. Click the OK button to return to the Rules page. The Fuzzy System Designer
populates the Rules list with all 35 combinations of linguistic terms of the input
variables. Each rule uses the same antecedent connective, degree of support, and
implication method that you specified in the Pre-Generate Rules dialog box.

Notice that the consequent of each rule in the Rules list is THEN 'steering-angle' IS
'neg-large'. However, the linguistic term of the steering-angle output variable
depends on the combination of linguistic terms of the input variables. Therefore, you
must modify the pre-generated rules to use the correct consequents.

Previous Home Next


2. Creating Output Linguistic Tutorial: Using the Fuzzy System 4. Modifying Pre-
Variables Designer Generated Rules

100 ni.com
PID and Fuzzy Logic

4. Modifying Pre-Generated Rules

Complete the following steps to modify the pre-generated rules to use the correct
consequents.

1. Select the first rule in the Rules list to display an IF THEN diagram that shows the
Antecedents and Consequents of the rule.
2. In the THEN column, select neg-small as the linguistic term for the steering-angle
output linguistic variable. Notice the consequent of the rule in the Rules list
changes to THEN 'steering-angle' IS 'neg-small'.
3. Repeat steps 1 and 2 for each rule using the consequents in the following table:

4. Select File»Save to save the fuzzy system.

The fuzzy system now has a complete linguistic rule base with which to analyze input
data and produce output data. However, the rule base returns the output data as
linguistic terms. The fuzzy controller must defuzzify the output data before the output
can apply to the control structure that the fuzzy system automates. You therefore must
specify a defuzzification method for the fuzzy controller to use.

© National Instruments 101


PID and Fuzzy Logic

Previous Home Next


3. Creating a Rule Base with Pre- Tutorial: Using the Fuzzy 5. Specifying a
Generated Rules System Designer Defuzzification Method

5. Specifying a Defuzzification Method

After you create the rule base for a fuzzy system, you must specify how a fuzzy
controller performs defuzzification for the system.

In the vehicle maneuvering example, you must supply a continuous output signal to
control the steering angle of the vehicle. Therefore, you must use a defuzzification
method that calculates the best compromise between any rules that apply at a given
time. According to the guidelines for selecting a defuzzification method the Center of
Maximum (CoM), Center of Area (CoA), and Center of Sums (CoS) defuzzification
methods all fit this requirement.

Complete the following steps to specify the defuzzification method.

1. On the Rules page of the Fuzzy System Designer, select the method you want to
use from the Defuzzification method pull-down menu.
2. Select File»Save to save the fuzzy system.

The fuzzy system is complete. However, before you integrate the fuzzy system into the
control structure you want to automate, you must test the functionality of the system.

Previous Home Next


4. Modifying Pre-Generated Tutorial: Using the Fuzzy System 6. Testing the Fuzzy
Rules Designer System

6. Testing the Fuzzy System

You can test the relationship between the input and output values of a fuzzy system to
validate the rule base of the fuzzy system.

Complete the following steps to test the vehicle maneuvering fuzzy system you created
in the previous steps.

102 ni.com
PID and Fuzzy Logic

1. Click the Test System tab of the Fuzzy System Designer to display the Test System
page.
2. Enter an Input value of 5 for the vehicle-position input linguistic variable.
Recall from creating the input linguistic variables in step 1 that a value of 5 for
vehicle-position corresponds to the center linguistic term.
3. Enter an Input value of -30 for the vehicle-orientation input linguistic variable,
which corresponds to the left-down linguistic term.
4. In the Invoked Rules table at the bottom of the page, notice that the fuzzy system
invokes rule 15: IF 'vehicle-position' IS 'center' AND 'vehicle-orientation' IS 'left-
down' THEN 'steering-angle' IS 'neg-medium'.

Recall from creating the output linguistic variable in step 2 that the neg-medium
linguistic term for the steering-angle variable corresponds to the range between
-30 and -5. If you configured the fuzzy system correctly, the Output value indicator
for the steering-angle displays a value within that range. The fuzzy controller
calculates the Output value based on the weight of the rule, the consequent
implication method, and the defuzzification method.
5. (Optional) Use the Input variable 1 and Input variable 2 slide controls to sweep a
range of values for the input linguistic variables and observe the corresponding
changes in the Input/Output relationship graph. You can use this graph to verify
that the rule base is reasonable and complete. For example, if the Input/Output
relationship graph displays 0 at some points, the rule base might be incomplete.
6. Fix any errors you find while testing and save the fuzzy system.
7. Click the Close button to exit the Fuzzy System Designer.

Previous Home Next


5. Specifying a Defuzzification Tutorial: Using the Fuzzy System 7. Controlling the Fuzzy
Method Designer System

7. Controlling the Fuzzy System

After you create a fuzzy system in the Fuzzy System Designer, you can use the FL Fuzzy
Controller VI to implement a controller for the fuzzy system. The FuzzyEx Car Backward
Parking VI, located in the labview\examples\control\fuzzy\Car Parking
directory, illustrates how to implement a controller for a fuzzy system.

© National Instruments 103


PID and Fuzzy Logic

This example uses the FL Load Fuzzy System VI to load both the Truck - forwar
d.fs and Truck - backward.fs files. These files represent the fuzzy systems for
moving the vehicle forward and backwards, respectively. Each FL Load Fuzzy System VI
passes a .fs file to a FL Fuzzy Controller VI, which implements a fuzzy controller for
the fuzzy system.

The fuzzy system you created in this tutorial is similar to the Truck - backward.f
s file. You can implement a fuzzy controller for the fuzzy system you created in the
same fashion that the FuzzyEx Car Backward Parking VI implements a controller for the
Truck - backward.fs file.

Previous Home
6. Testing the Fuzzy System Tutorial: Using the Fuzzy System Designer

Tutorial: Modifying a Fuzzy System with the Fuzzy Logic VIs


In the Using the Fuzzy System Designer tutorial, you design a fuzzy system interactively
using the Fuzzy System Designer and then implement a fuzzy controller for that system
using the FL Fuzzy Controller VI. You also can design a fuzzy system programmatically
using the Fuzzy Logic VIs. However, in most cases, it is easier to use the Fuzzy System
Designer to design a fuzzy system first and then use the Fuzzy Logic VIs to make
programmatic modifications to the system. In this tutorial, you modify a fuzzy system
programmatically using the Fuzzy Logic VIs.

This tutorial uses the example of a greenhouse control system to illustrate how to
modify a fuzzy system using the Fuzzy Logic VIs. The greenhouse.fs file, located in
the labview\examples\control\fuzzy\Dynamic greenhouse control
ler directory, represents the fuzzy system that you modify in this chapter.

Next
1. Observing the Fuzzy System

1. Observing the Fuzzy System

Before you modify a fuzzy system, you must familiarize yourself with the design of the
system. Complete the following steps to open and observe the greenhouse fuzzy

104 ni.com
PID and Fuzzy Logic

system in the Fuzzy System Designer.

1. Select Tools»Control Design and Simulation»Fuzzy System Designer to launch


the Fuzzy System Designer.
2. Select File»Open and navigate to greenhouse.fs in the labview\example
s\control\fuzzy\Dynamic greenhouse controller directory.
3. Click the OK button to open the greenhouse fuzzy system in the file dialog box. The
Variables page displays details about the input and output variables of the fuzzy
system.
4. Observe the input and output linguistic variables. The greenhouse fuzzy system
has two input variables, Temperature and Humidity, and two output variables,
Electric Roof and Water Spills.
5. Observe the ranges and membership functions for the linguistic variables. For
example, the Temperature input variable represents the temperature, in degrees
Celsius, inside the greenhouse, with a range of 0 to 50 and three membership
functions: Cold, Normal, and Warm. You can see on the Input variable
membership functions graph that a trapezoid function represents the shape of the
Cold membership function. The left base, left top, right top, and right base points
of this membership function are 0, 0, 13, and 21, respectively.
6. Click the Rules tab to display the Rules page. The Rules list displays nine rules for
the fuzzy system, which correspond to all possible combinations of the
membership functions of the two input linguistic variables. Also notice that the
Defuzzification method for the fuzzy system is Center of Area (CoA).
7. Select the first rule in the Rules list: IF 'Temperature' IS 'Cold' AND 'Humidity' IS
'Dry' THEN 'Electric Roof' IS 'Closed' ALSO 'Water Spills' IS 'Moderate'.

Notice the characteristics of this rule. For example, the Antecedent connective is
AND (Minimum), the Degree of support is 1, and the Consequent implication is
Product.
8. Continue exploring the fuzzy system in the Fuzzy System Designer. When you are
familiar with the system, you can click the Close button to exit the Fuzzy System
Designer.

Home Next
Tutorial: Modifying a Fuzzy System with the Fuzzy Logic VIs 2. Loading the Fuzzy System

© National Instruments 105


PID and Fuzzy Logic

2. Loading the Fuzzy System

Before modifying the greenhouse fuzzy system, you must load the .fs file. Complete
the following steps to load the greenhouse.fs file.

1. Select File»New VI to create a new, blank VI.


2. Press the <Ctrl-E> keys to display the block diagram.
3. Add the FL Load Fuzzy System VI to the block diagram.
4. Right-click the file path input of the FL Load Fuzzy System VI and select
Create»Constant from the shortcut menu.
5. Enter the absolute path to the greenhouse.fs file in the path constant.

Note You also can use the File I/O VIs and functions to create a relative path to wire to the
file path input.

6. Select File»Save and save the VI as Modified Greenhouse Fuzzy Syste


m.vi in an easily accessible location.

Previous Home Next


1. Observing the Tutorial: Modifying a Fuzzy System with 3. Modifying a
Fuzzy System the Fuzzy Logic VIs Linguistic Variable

3. Modifying a Linguistic Variable

You can use the Variables VIs to modify the linguistic variables in a fuzzy system.
Complete the following steps to modify the range of the Temperature input
linguistic variable of the greenhouse fuzzy system to use degrees Fahrenheit instead of
degrees Celsius.

1. Add the FL Set Variable VI to the block diagram. This VI modifies the name, range,
or membership functions of a linguistic variable in a fuzzy system.
2. Wire the fuzzy system out output of the FL Load Fuzzy System VI to the fuzzy
system in input of the FL Set Variable VI.
3. Right-click the input/output input of the FL Set Variable VI and select
Create»Constant from the shortcut menu.
4. Select Input from the input/output constant to specify that you want to modify an
input linguistic variable.

106 ni.com
PID and Fuzzy Logic

5. Right-click the variable index input of the FL Set Variable VI and select
Create»Constant from the shortcut menu.
6. Enter 0 in the variable index constant to specify that you want to modify the first
linguistic variable. The index is zero-based and corresponds to the order in which
the linguistic variable was created. Recall that the Temperature variable is the
first input linguistic variable in the fuzzy system.
7. Create constants for the minimum and maximum inputs of the FL Set Variable VI
and set them to 32 and 122, respectively. This new range represents the possible
temperature, in degrees Fahrenheit, inside the greenhouse. The block diagram
now resembles the following image:

8. Save the VI.

This VI sets the new range of the Temperature variable when it runs. However, you
still must modify the membership functions of the Temperature variable to
complete the Celsius to Fahrenheit conversion.

Previous Home Next


2. Loading the Tutorial: Modifying a Fuzzy System with 4. Modifying Membership
Fuzzy System the Fuzzy Logic VIs Functions

4. Modifying Membership Functions

You can use the Membership VIs to modify the membership functions for linguistic
variables in a fuzzy system. Complete the following steps to modify the membership
functions of the Temperature input linguistic variable to use degrees Fahrenheit
instead of degrees Celsius.

© National Instruments 107


PID and Fuzzy Logic

1. Add the FL Set Membership Function VI to the block diagram.


2. Wire the fuzzy system out output of the FL Set Variable VI to the fuzzy system in
input of the FL Set Membership Function VI.
3. Create constants for the membership function index, variable index, and input/
output inputs of the FL Set Membership Function VI and set them to 0, 0, and
Input, respectively. These inputs specify that you want to modify the first
membership function, Cold, of the Temperature input linguistic variable.
4. Create a constant for the shape input of the FL Set Membership Function VI.
5. Select Trapezoid from the shape constant to specify the shape of the function that
determines the degrees of membership for the linguistic variable.
6. Create a constant for the points input of the FL Set Membership Function VI. This
input specifies the values of the linguistic variable corresponding to the base and
top points, in order from left to right and base to top, of the membership function.
7. In the first four elements of the points array constant, enter the values 32, 32, 55,
and 70, respectively.
8. Repeat steps 1 through 5 for the Normal and Warm membership functions. For
each membership function, add a new FL Set Membership Function VI to the block
diagram and wire the fuzzy system out output of the previous VI to the fuzzy
system in input of the next VI. Use the shapes and points shown in the following
table:

Membership Function Shape Points

Normal Gaussian 59, 68, 77, 86

Warm Trapezoid 75, 90, 122, 122

The block diagram now resembles the following image:

108 ni.com
PID and Fuzzy Logic

9. Save the VI.

Previous Home Next


3. Modifying a Linguistic Tutorial: Modifying a Fuzzy System with the 5. Modifying a
Variable Fuzzy Logic VIs Rule

5. Modifying a Rule

You can use the Rules VIs to modify the rules for a fuzzy system. This section
demonstrates how to recreate the first rule of the greenhouse fuzzy system:

IF 'Temperature' IS 'Cold' AND 'Humidity' IS 'Dry' THEN 'Electric Roof' IS 'Closed'


ALSO 'Water Spills' IS 'Moderate'

and replace the existing first rule of the fuzzy system with the rule you create.

When you use the Rules VIs to create rules, you must create the rules in parts. First, you
create the antecedents. Then, you create the consequents. Finally, you combine the
antecedents and consequents for a specific rule. The next three steps of this tutorial
walk you through each of these actions.

Previous Home Next


4. Modifying Membership Tutorial: Modifying a Fuzzy System with the 6. Creating
Functions Fuzzy Logic VIs Antecedents

6. Creating Antecedents

The first step in creating a rule is to create the antecedents of the rule. Complete the

© National Instruments 109


PID and Fuzzy Logic

following steps to create the 'Temperature' IS 'Cold' and 'Humidity' IS 'Dry'


antecedents.

1. Add the FL Create Antecedent VI to the block diagram. This VI creates an


antecedent, or IF portion, of a rule for a fuzzy system.
2. Create constants for the variable index and membership function index inputs of
the FL Create Antecedent VI and set them both to 0. These inputs specify that you
want to associate the Temperature input linguistic variable with the Cold
membership function.
3. Create a constant for the condition input of the FL Create Antecedent VI.
4. Select = from the condition constant to calculate the degree of membership of the
linguistic variable within the membership function. FL Create Antecedent VI now
creates the 'Temperature' IS 'Cold' antecedent.
5. Repeat steps 1 through 4 to create the 'Humidity' IS 'Dry' antecedent. In the
greenhouse fuzzy system, Dry is the first membership function of the second input
linguistic variable, so use 1 as the variable index and 0 as the membership
function index.
6. Add a Build Array function to the block diagram.
7. Resize the Build Array function to display two input elements.
8. Wire the antecedent output of the first FL Create Antecedent VI to the first element
input of the Build Array function.
9. Wire the antecedent output of the second FL Create Antecedent VI to the second
element input of the Build Array function. The section of block diagram you just
created resembles the following image:

10. Save the VI.

Previous Home Next

110 ni.com
PID and Fuzzy Logic

5. Modifying a Tutorial: Modifying a Fuzzy System with the Fuzzy 7. Creating


Rule Logic VIs Consequents

7. Creating Consequents

You create rule consequents similarly to how you create rule antecedents. Complete
the following steps to create the 'Electric Roof' IS 'Closed' and 'Water Spills' IS
'Moderate' consequents.

1. Add the FL Create Consequent VI to the block diagram. This VI creates a


consequent, or THEN portion, of a rule for a fuzzy system.
2. Create constants for the variable index and membership function index inputs of
the FL Create Consequent VI and set them both to 0. These inputs specify that you
want to associate the Electric Roof output linguistic variable with the Closed
membership function.

Note Unlike the FL Create Antecedent VI, the FL Create Consequent VI does not have a
condition input. The FL Create Consequent VI always returns the consequent
corresponding to the degree of membership of the output variable within the
membership function.

3. Repeat steps 1 and 2 to create the 'Water Spills' IS 'Moderate' consequent. In


the greenhouse fuzzy system, Moderate is the second membership function of
the second output linguistic variable (Water Spills), so set both the variable
index and membership function index to 1.
4. Add a Build Array function to the block diagram.
5. Resize the Build Array function to display two input elements.
6. Wire the consequent output of the first FL Create Consequent VI to the first
element input of the Build Array function.
7. Wire the consequent output of the second FL Create Consequent VI to the second
element input of the Build Array function. The section of block diagram you just
created resembles the following image:

© National Instruments 111


PID and Fuzzy Logic

8. Save the VI.

Previous Home Next


6. Creating Tutorial: Modifying a Fuzzy System 8. Combining the Antecedents and
Antecedents with the Fuzzy Logic VIs Consequents for a Rule

8. Combining the Antecedents and Consequents for a Rule

Complete the following steps to combine the antecedents and consequents you
created in the previous steps to form a specific rule.

1. Add an FL Set Rule VI to the block diagram. This VI modifies the antecedents,
consequents, or relationships of a rule in a fuzzy system.
2. Wire the fuzzy system out output of the last FL Set Membership Function VI to the
fuzzy system in input of the FL Set Rule VI.
3. Create a constant for the rule index input of the FL Set Rule VI and set it to 0 to
specify that you want to modify the first rule in the fuzzy system.
4. Wire the appended array output of the first Build Array function to the
antecedents input of the FL Set Rule VI.
5. Wire the appended array output of the second Build Array function to the
consequents input of the FL Set Rule VI.
6. Create a constant for the antecedent connective input of the FL Set Rule VI to
specify how the VI calculates the truth value of the aggregated rule antecedent.
7. Select AND (Minimum) from the antecedent connective constant. The aggregated
rule antecedent now is IF 'Temperature' IS 'Cold' AND 'Humidity' IS 'Dry',
where this VI uses the smallest degree of membership of the individual
antecedents to calculate the truth value of the aggregated rule antecedent.

Note You cannot specify how this VI calculates the truth value of an aggregated rule
consequent. This VI always uses the greatest degree of membership of the individual
consequents to calculate the truth value of the aggregated rule consequent.

112 ni.com
PID and Fuzzy Logic

8. Create a constant for the consequent implication input of the FL Set Rule VI. This
input specifies the implication method this VI uses to scale the membership
functions of the output linguistic variables based on the rule weight.
9. Select Product from the consequent implication constant to specify that this VI
uses the Product implication method.
10. Create a constant for the degree of support input and set it to 1. This input
specifies the weight that you want to apply to the rule. The final rule weight is
equal to the degree of support multiplied by the truth value of the aggregated rule
antecedent.

The section of block diagram you just created resembles the following image:

11. Save the VI.

Previous Home Next


7. Creating Tutorial: Modifying a Fuzzy System with the 9. Saving the Fuzzy
Consequents Fuzzy Logic VIs System

9. Saving the Fuzzy System

In previous sections of this tutorial, you modified the linguistic variables, membership
functions, and rules of the greenhouse fuzzy system. You now can save the fuzzy

© National Instruments 113


PID and Fuzzy Logic

system to a .fs file. Complete the following steps to save the modified fuzzy system to
a .fs file.

1. Add the FL Save Fuzzy System VI to the block diagram.


2. Wire the fuzzy system out output of the FL Set Rule VI to the fuzzy system in input
of the FL Save Fuzzy System VI.
3. Right-click the file path input of the FL Save Fuzzy System VI and select
Create»Constant from the shortcut menu.
4. Enter the absolute path to a modified greenhouse.fs file in the path
constant. The FL Save Fuzzy System VI creates the .fs file when it runs.

Note You also can use the File I/O VIs and functions to create a relative path to wire to the
file path input of the FL Save Fuzzy System VI.

5. Save the Modified Greenhouse Fuzzy System VI.


6. Run the VI. The VI loads the original greenhouse.fs file, modifies the linguistic
variable and membership functions you specified, creates new antecedents and
consequents for a rule, and saves all the changes to the modified greenhous
e.fs file.

You now can use the Fuzzy System Designer to open the modified greenhouse.f
s file and observe the modifications you made to the greenhouse fuzzy system.

You also can use the FL Fuzzy Controller VI to implement a fuzzy logic controller for the
modified greenhouse fuzzy system. The FuzzyEx Dynamic Fuzzy Controller for a
greenhouse example VI in the labview\examples\control\fuzzy\Dynamic
greenhouse controller directory implements a controller for the greenhouse
fuzzy system. This example VI uses the FL Load Fuzzy System VI to load the greenhou
se.fs file.

You can load the modified greenhouse.fs file instead and then run the example
VI to implement a controller for the modified greenhouse fuzzy system.

Previous Home
8. Combining the Antecedents and Tutorial: Modifying a Fuzzy System with the
Consequents for a Rule Fuzzy Logic VIs

114 ni.com © 2024 National Instruments Corporation.

You might also like