Labview Pid and Fuzzy Logic Toolkit Api Reference 2024-10-31-21-26-24
Labview Pid and Fuzzy Logic Toolkit Api Reference 2024-10-31-21-26-24
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
© National Instruments 3
LabVIEW PID and Fuzzy Logic Toolkit API Reference
4 ni.com
PID and Fuzzy Logic
PID Control
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.
© National Instruments 5
PID and Fuzzy Logic
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
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.
© National Instruments 7
PID and Fuzzy Logic
downstream
In a cascade, the controller whose setpoint is provided by another controller.
loop
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.
8 ni.com
PID and Fuzzy Logic
magnitude
See gain.
ratio
© National Instruments 9
PID and Fuzzy Logic
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:
© 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:
Related Information
PID Algorithms
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.
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.
A PID controller compares the setpoint (SP) to the process variable (PV) to obtain the
error (e), as follows:
SP is the setpoint
© National Instruments 15
PID and Fuzzy Logic
This equation involves three actions that simultaneously apply to the output of the
controller:
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) 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) 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
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
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:
SP is the setpoint
Proportional Action
Proportional action is the controller gain times the error, as shown in the following
formula:
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.
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:
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:
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.
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
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 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:
SP is the setpoint
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:
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
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:
ß 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.
24 ni.com
PID and Fuzzy Logic
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.
© National Instruments 27
PID and Fuzzy Logic
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
Gain Scheduling
Lead/Lag
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.
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.
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.
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
A ramp and hold setpoint profile also can have two successive array values with the
same setpoint value, as shown in the following image.
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
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.
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
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.
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.
© 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.
• 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
• 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
Related Information
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:
© 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
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
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.
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.
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.
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
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.
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.
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 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.
Related Information
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.
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.
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.
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.
• 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 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.
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 —
Normal Performance
Controller Kc Ti Td
P 0.2Ku — —
PI 0.18Ku 0.8Tu —
46 ni.com
PID and Fuzzy Logic
Slow Performance
Controller Kc Ti Td
P 0.13Ku — —
PI 0.13Ku 0.8Tu —
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 —
Normal Performance
Controller Kc Ti Td
P 0.44TP/ — —
PI 0.4TP/ 5.33 —
Slow Performance
Controller Kc Ti Td
P 0.26TP/ — —
PI 0.24TP/ 5.33 —
© National Instruments 47
PID and Fuzzy Logic
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 (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) —
PID
48 ni.com
PID and Fuzzy Logic
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
Td is the deadtime
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.
Regulator – 0% overshoot
Controller Kc Ti Td
P 0.3TP/ — —
PI 0.6TP/ 4 —
P 0.7TP/ — —
PI 0.7TP/ 2.3 —
Servo – 0% overshoot
Controller Kc Ti Td
P 0.3TP/ — —
PI 0.35TP/ 1.2 —
50 ni.com
PID and Fuzzy Logic
P 0.7TP/ — —
PI 0.6TP/ —
Note The PID (FPGA) Express VI is available only if you install the LabVIEW FPGA Module.
(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
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.
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
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
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 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.
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:
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
Defuzzification Methods
© National Instruments 55
PID and Fuzzy Logic
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.
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.
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
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.
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
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
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
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.
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.
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.
The following topics contain additional important information about creating rule
bases:
62 ni.com
PID and Fuzzy Logic
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.
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.
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)
AND (Product)
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.
Assume the following rules are invoked for the input values of a vehicle maneuvering
fuzzy system.
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.
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.
66 ni.com
PID and Fuzzy Logic
With PID and Fuzzy Logic VIs, you can use either the Minimum or Product 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.
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
These two rules specify two non-zero values for the Steering Angle φ output
linguistic variable:
Note Fuzzy controllers use an implication method to scale the membership functions of
68 ni.com
PID and Fuzzy Logic
Related Information
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
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
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.
The following image illustrates the difference between the Center of Area and modified
Center of Area defuzzification methods.
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
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.
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.
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.
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
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.
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.
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
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
Related Information
78 ni.com
PID and Fuzzy Logic
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.
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.
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
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
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.
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.
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.
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
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
© 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.
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
The previous image shows entirely overlapping membership functions for input and
output terms.
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:
© National Instruments 87
PID and Fuzzy Logic
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
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
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
Fuzzy-PI Controllers
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.
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.
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.
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.
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.
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
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.
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
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.
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
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.
100 ni.com
PID and Fuzzy Logic
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:
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.
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.
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.
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.
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.
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
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
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
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
Before modifying the greenhouse fuzzy system, you must load the .fs file. Complete
the following steps to load the greenhouse.fs file.
Note You also can use the File I/O VIs and functions to create a relative path to wire to the
file path input.
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:
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.
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.
108 ni.com
PID and Fuzzy Logic
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:
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.
6. Creating Antecedents
The first step in creating a rule is to create the antecedents of the rule. Complete the
110 ni.com
PID and Fuzzy Logic
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.
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.
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:
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
system to a .fs file. Complete the following steps to save the modified fuzzy system to
a .fs file.
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.
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