Control Application Using Fuzzy Logic: Design of a Fuzzy Temperature Controller

The reason for using fuzzy logic in control applications stems from the idea of modeling uncertainties in the knowledge of a system’s behavior through fuzzy sets and rules that are vaguely or ambiguously specified. By defining a system’s variables as linguistic variables such that the values they can take are also linguistic terms (modeled as fuzzy sets), and by establishing the rules based on said variables, a general method can be devised to control these systems: Fuzzy Control (Babuska, 1998; Chen, 2009). Fuzzy control is a class of control methodology that utilizes fuzzy set theory (Pedrycz, 1993). The advantages of fuzzy control are twofold. First, fuzzy control offers a novel mechanism for implementing control laws that are often based on knowledge or on linguistic descriptions. Second, fuzzy control provides an alternative methodology for facilitating the design of non-linear controllers for plants that rely on generally uncertain control that is very difficult to relate to the conventional theory of non-linear control (Li & Tong, 2003; A. Sala et al., 2005).


Introduction
The reason for using fuzzy logic in control applications stems from the idea of modeling uncertainties in the knowledge of a system's behavior through fuzzy sets and rules that are vaguely or ambiguously specified.By defining a system's variables as linguistic variables such that the values they can take are also linguistic terms (modeled as fuzzy sets), and by establishing the rules based on said variables, a general method can be devised to control these systems: Fuzzy Control (Babuška, 1998;Chen, 2009).Fuzzy control is a class of control methodology that utilizes fuzzy set theory (Pedrycz, 1993).The advantages of fuzzy control are twofold.First, fuzzy control offers a novel mechanism for implementing control laws that are often based on knowledge or on linguistic descriptions.Second, fuzzy control provides an alternative methodology for facilitating the design of non-linear controllers for plants that rely on generally uncertain control that is very difficult to relate to the conventional theory of non-linear control (Li & Tong, 2003;A. Sala et al., 2005).Every day we mindlessly perform complex tasks: parking, driving, recognizing faces, packing the groceries at the supermarket, moving delicate objects, etc.To solve these tasks (overcome an obstacle), we gather all the information necessary for the situation (topology of the terrain, characteristics of the obstacle such as speed, size, …).With this information and by relying on our experience, we can carry out a series of control actions that, thanks to the feedback present between the system under control and our bodies, can achieve the desired goal.
The controller receives the performance indices (reference) and the system output.To replace the human in a control process, a controller must be added.The controller is a mathematical element, and as such all of the tasks that it is able to perform must be perfectly defined.This control link is studied in Control Theory and is based on two principles: 1.The system to be controlled must be known so that its response to a given input can be predicted.This prediction task requires having a complete model of the system.This identification phase is essential to the performance of the control algorithm.2. The objective of the control must be specified in terms of concise mathematical formulas directly related to the system's variables (performance index).
When a system's complexity increases, mathematics cannot be used to define the aforementioned points.The model cannot be defined due to non-linearities, to its nonstationary nature, to the lack of information regarding the model, and so on.
We are, however, living in rapidly evolving times where the main goal is to break the limitations that exist in our use of machines in an effort to increase productivity.The use of and advances in intelligent machines will fundamentally change the way we work and live.
To this end, we are building autonomous control systems that are designed to work properly for long periods of time under given uncertainties in the system and the environment.These systems must be capable of compensating for faults in the system without any outside intervention.Intelligent autonomous control systems use techniques from the field of Artificial Intelligence (AI) to achieve autonomy.These control systems consist of conventional control systems that have been augmented using intelligent components, meaning their development requires interdisciplinary research (Jang et al., 1997).
The emergence and development of Artificial Intelligence is of great importance.AI can be defined as that part of computer science that is charged with the design of intelligent computers, meaning systems that exhibit those characteristics that we associate with intelligent human behavior, such as understanding, learning, reasoning, problem solving, etc. Fuzzy Control is one of the new techniques in Intelligent Control, one that aims to imitate the procedure we humans use when dealing with systems (Cai, 1997).For example, when operating a water tap, if we want to obtain the desired flow rate, we reason using terms such as: "If the flow is low, turn the handle all the way left" "If the flow is high, turn the handle right a little bit", etc.
Precise quantities such as "2 liters/second" of "65 degrees counterclockwise" do not appear in these rules, and yet we manage to achieve the desired flow rate.
We also apply this form of reasoning to more complex situations, from regulating not only the flow rate but the water temperature, and even when driving a car.In none of these cases do we know precise values; rather, vague magnitudes suffice, such as "very hot", "near", "fast", etc.
Another important consideration is that the control can be expressed as a set of rules of the type: "For certain conditions with some variables, do these actions in others".In this structure, the conditions are called antecedents and the actions consequents.
We may conclude that human reasoning in these situations involves applying logic to uncertain magnitudes.If we want to implement this control artificially, the most convenient course of action is to use a tool that models uncertain magnitudes, this being Fuzzy Set Theory, and apply a logic to these magnitudes, this being Fuzzy Logic (Klir & Yuan, 1995).
Both elements belong to a new field in the symbolic branch of Artificial Intelligence that has found in Fuzzy Control one of its main applications, even above other, more formal applications such as expert systems.The fact that it mirrors the process of human reasoning justifies the success of this new method, due to its ease of use and understanding.In a few years AI has blossomed and experienced great commercial success, eclipsing even that of expert systems.
In this chapter we will consider the fuzzy control of a liquid's temperature.This is a very simple academic problem that can be solved using various techniques, such as a classic PI control scheme (Horváth & Rudas, 2004).We will use it in this text, however, to illustrate the design and operation of a fuzzy controller.
An introduction to fuzzy control is presented first, followed by a description of the general outline.In subsequent sections we describe each of the steps in the design of the fuzzy controller: choice of inputs and outputs, rule base, fuzzy quantification, and fuzzification, inference and defuzzification mechanisms.We conclude with a simulation of the proposed temperature controller.

Fuzzy logic applied to control: Fuzzy control of temperature
The use of the Fuzzy Logic methodology in real systems is immediately applicable to those systems whose behavior is known based on imprecisely defined rules.This imprecision arises from the complexity of the system itself.The way to approach such a problem is to reduce the complexity by increasing the uncertainty of the variables (J.Sala et al., 2000;Yager & Filev, 1994).Thus, in problems that present non-linearities, and to which classical control techniques are hardest to apply, these techniques are very useful and easy to use (Takana & Sugeno, 1992;Tanaka & Wang, 2001;Wang, 1994).
In the vast majority of systems, be they highly complex or not, the systems' behavior can be given by a set of rules that are often imprecise, or that rely on linguistic terms laden with uncertainty.This results in rules of the type "If the volume is large, the pressure is small", which define the behavior of a system.If we focus on the rules that are defined to control the system, we can formulate different rules of the type "If the cost is small and the quality is good, make a large investment".
This last rule type is the most frequently seen in daily life.For example, to regulate water flow from a faucet, we need only apply rules of the type "If the flow is excessive, close the tap a lot", or "If the flow is low, open the tap a little" in order to carry out the desired action.
Using precise magnitudes such as "flow rate of 1.2 gallons/minute" or "turn 45º clockwise" is unnecessary.
Therefore, a general knowledge base for the system is available; that is, a set of rules that aim to model the actions to be carried out on the system so as to achieve the desired action.Said rules are provided by an expert, one whose experience with handling the system provides him with knowledge of how the system behaves.
The Mandani fuzzy inference mechanism is very useful when applying Fuzzy Logic to the control of systems (Passino, 1998).If we consider a classic feedback scheme, the controller has enough information about the system to determine the command that must be applied to said system so as to achieve a desired setpoint.The idea, put forth by Zadeh, for using Fuzzy Control algorithms relies on introducing the knowledge base into the controller such that its output is determined by the control rules proposed by the expert.Said rules contain fuzzy sets (linguistic terms) in the antecedents and in the consequents, and hence they are referred to as a whole as a fuzzy control rule base.
If we wish to apply this control scheme to a real system, the fuzzy controller must be adjusted to existing sensor and actuator technology, which relies on precise magnitudes (Jantzen, 2007).The exact values provided by a sensor must therefore be converted into the fuzzy values that comprise the variables of the antecedent in the rule base.Likewise, the fuzzy values inferred from the rules must be transformed into exact values for use in the actuators.A diagram of this process is shown in Figure 1.

Fig. 1. Fuzzy controller
A block diagram for a fuzzy control system is given in Figure 1.The fuzzy controller consists of the following four components: 1. Rule base: set of fuzzy rules of the type "if-then" which use fuzzy logic to quantify the expert's linguistic descriptions regarding how to control the plant.2. Inference mechanism: emulates the expert's decision-making process by interpreting and applying existing knowledge to determine the best control to apply in a given situation.3. Fuzzification interface: converts the controller inputs into fuzzy information that the inference process can easily use to activate and trigger the corresponding rules.4. Defuzzification interface: converts the inference mechanism's conclusions into exact inputs for the system to be controlled.
We shall now present a simple temperature control example, shown in Figure 2, to introduce each of the fuzzy controller components.Consider the system shown in Figure 2, where T o is the temperature of the liquid that we wish to control and T a is the ambient temperature.The input produced by the heating element is denoted with the letter q, and the desired temperature is T d .The model for the system, keeping in mind that there are two energy sources (one generated by the heating element and one from the environment), is given by the transfer matrix that results when each of the inputs is considered separately.The expression shown in Equation 1 yields G 1 (s) and G 2 (s), given in Equations 2 and 3, respectively. where: 1. M: Mass of liquid 2. C e : Specific heat 3. : heat transfer coefficient between the tank and the environment 4. A: heat transfer area 5. T o : temperature of liquid 6.T a : ambient temperature 7. Q: heat input This is a simple academic problem and many techniques are available for solving it, such as a classic PI controller.We will use it in this text, however, to illustrate the design and operation of a fuzzy controller.

General outline of the fuzzy controller
We may conclude then that the procedure for implementing these fuzzy techniques to control systems consists of two very different stages: These precise values will be the controller's outputs (commands) and be applied to the system to be controlled.

Fuzzy controller inputs and outputs
If we assume the presence of an expert in the feedback loop that controls the temperature system, as shown in Figure 4, then a fuzzy controller must be designed that automates the way in which the human expert carries out this control task.To do this, the expert must indicate (to the designer of the fuzzy controller) what information he receives as the input to his decision-making process.Assume that in the temperature control process, the expert observes the error and the variation in this error to carry out his control function; that is, he makes his decision based on the result obtained from Equation 4: Though there are many other variables that can be used as the input (e.g., the integral of the error), we will adopt this one since it is the one used by the expert.
We must next identify the variables to be controlled.For the temperature control case proposed, we can only control the amount of energy (q) supplied by the heating element.Once the fuzzy controller's inputs and outputs are selected, the next step is to determine the reference input desired, which in our case will be r=60 (step input of sixty).
The fuzzy control system, then, with its inputs and outputs, would be as shown in Figure 5.

Inclusion of control knowledge in the rule base
Assume that the human expert provides a description in his own words of the best way to control the plant.We will have to use this linguistic description to design the fuzzy controller.

Linguistic description
An expert uses linguistic variables to describe the time-varying inputs and outputs of the fuzzy controller.Thus, for our temperature system, we might have: 1. "error" to describe e(t) 2. "error variation" to describe de(t)/dt 3. "increase-energy-supplied" to describe u(t) We used the quotes to emphasize how certain words or phrases.Though there are many possible ways to describe the variables linguistically, choosing one or another has no effect on how the fuzzy controller works, it only simplifies the task of constructing the controller using fuzzy logic.
Just as e(t) takes on a value, for example, 0.1 at t=2 (e(2)=0.1),so do linguistic variables take on "linguistic values", that is, the values of the linguistic variables change over time.For example, to control the temperature, we can have the "error", "error-variation" and "increase-energy-supplied" take on the following values: Let us now consider how we can describe the system's dynamics based on the linguistic variables and the values they assume.In the case of the temperature controller, each of the following phrases represents different system states: 1.The error is Large Negative, indicating that the temperature of the liquid is much higher than desired, Figure 6.a. 2. The error is Small Negative and the error-variation is Small Positive, indicating that the temperature of the liquid is somewhat higher than the setpoint and dropping to the desired value, Figure 6.b. 3. The error is Zero and the error-variation is Small Negative, indicating that the temperature of the liquid is more or less at the setpoint but rising, Figure 6.c. 4. The error is Zero and the error-variation is Small Positive, indicating that the temperature of the liquid is more or less at the setpoint but falling, Figure 6.d. 5.The error is Small Positive and the error-variation is Small Positive, indicating that the temperature of the liquid is below the setpoint and dropping further, Figure 6.e. 6.The error is Large Positive and the error-variation is Large Negative, indicating that the temperature of the liquid is well below the setpoint but increasing, Figure 6.f.

Rules
Next we will use the linguistic quantifiers defined earlier to craft a rule set that captures the expert's knowledge regarding how to control the system.Specifically, we have the following rules to control the temperature: 1.If the error is LN, MN or SN, then increase-energy-supplied is LN.
This rule quantifies the situation in which the liquid's temperature is above that desired, meaning heat must not be supplied.
2. If the error is LP and the error-variation is SP, then increase-energy-supplied is LP.
This rule quantifies the situation in which the liquid's temperature is far below the setpoint (undesired situation) and decreasing, requiring a substantial heat input.
3. If the error is ZE and the error-variation is SP, then increase-energy-supplied is SP.
This rule quantifies the situation in which the liquid's temperature is close to the desired temperature but decreasing slightly, meaning that heat must be supplied to correct the error.
Each of the three rules above is a "linguistic rule", since it uses linguistic variables and values.Since these linguistic values are not precise representations of the magnitudes they describe, then neither are the linguistic rules.They are merely abstract ideas on how to achieve proper control, and may represent different things to different people.And yet, experts very often use linguistic rules to control systems.

Rule base
Using rules of the type described above, we can define every possible temperature control situation.Since we used a finite number of linguistic variables and values, there is a finite number of possible rules.For the temperature control problem, given two inputs and seven linguistic variables, there are 72=49 possible rules (every possible combination of the values of the linguistic variables).
A convenient way of representing the set of rules when the number of inputs to the fuzzy controller is low (three or fewer) is by using a table.Each square represents the linguistic value of the consequent of a rule, with the left column and the top row containing the linguistic values of the antecedent's variables.A temperature control example is shown in Table 1.Note the symmetry exhibited by the table.This is not coincidental, and corresponds to the symmetrical behavior of the system to be controlled.

Fuzzy quantification of knowledge
Until now we have only quantified the expert's knowledge of how to control a system in an abstract manner.Next, we shall see how, using fuzzy logic, we can quantify the meaning of the linguistic descriptions so as to automate the control rules specified by the expert in a fuzzy controller.

Membership functions
Let us now quantify the meaning of the linguistic variables using the membership functions.Depending on the specific application and the designer (expert), we may select from various membership functions.
The fuzzy partitions for both the input variables (error and error-variation) and for the output variable (increase-energy-supplied) will consist of seven diffuse groups uniformly distributed in a normalized universe of discourse with range [-1,1].Figure 7 shows the partition for the input variables, and Figure 8 that corresponding to the output variable.
The membership functions for the controller's input variables, at the edge of the universe of discourse, are saturated.This means that at a given point, the expert regards all values above a given value as capable of being grouped under the same linguistic description of "large-positive" or "large-negative".The membership function of the controller's output variable, however, cannot be saturated at the edge if the controller is to function properly.The basic reason is that the controller cannot tell the actuator that any value above a given value is valid; instead, a specific value must always be specified.Moreover, from a practical standpoint, we could not carry out a defuzzification process that considers the area of conclusion of the rule if, as an output, we have membership functions with an infinite area.

Fuzzification, inference and defuzzification
In order to complete the design of the controller, we need to define the fuzzification, inference and defuzzification procedures.
In most practical applications of fuzzy control, the fuzzification process used is the "singleton", where the membership function is characterized by having degree 1 for a single value of its universe (input value) and 0 for the rest.In other words, the impulse function could be used to represent a membership function of this type, Figure 9.It is especially used in implementations because in the absence of noise, the input variables are guaranteed to equal their measured value.We also avoid the calculations that would be required if another membership function were used, such as Gaussian fuzzification, which requires constructing a Gaussian-shaped membership function to represent the exact value being provided by the sensor.
Fig. 9. Fuzzification process for the controller's input variable.
In order to define the inference mechanism, we have to determine how to carry out the basic operations.Since we are using Mandani's model, we have decided to implement the T-norm as the minimum and the S-norm as the maximum.
The last step is to define the defuzzification process.For this temperature control case, we will use the center of gravity.

Simulation of fuzzy temperature control
Normally, before proceeding with the implementation of the controller, a simulation is performed to evaluate its performance.The results of the simulation can aid in improving the design of the fuzzy controller and in verifying that it will work correctly when it is implemented.Such a simulation is shown below, implemented using Matlab (Sivanandam et al., 2007), specifically Simulink to simulate the control loop and fuzzy toolbox to implement the fuzzy controller.
The controller designed earlier is defined using the fuzzy toolbox in Matlab, yielding the fuzzy system shown in Figure 10.The fuzzy partition of the inputs and output is shown in Figure 11.As for the output surface, it is shown in Figure 12.
With this tool, we can see how the inference process is carried out, Figure 13.The next step is to carry out a simulation with the temperature system to check the control system's performance.To do this, we will use the simulation tool Simulink, which allows us to implement the control loop in blocks and to use the fuzzy system made with the fuzzy toolbox as the controller.The diagram of the control system, then, is as shown in Figure 14.A prerequisite step to studying the results of the fuzzy controller is to adjust its parameters.
In other words, we used fuzzy partitions that were normalized between -1 and 1, and yet the error, the error variation and the commanded increase have to take on values within a different range.To do this, we use gains that scale these variables within the design range of the fuzzy controller, adjusting these gains to achieve the desired specifications.These gains are called gains of scale (g s ) and their effect is as follows: 1.If g s = 1, there is no effect on the membership functions.
2. If g s > 1, then the membership functions are uniformly contracted by a factor of 1/g s .
3. If g s < 1, then the membership functions are uniformly expanded by a factor of 1/g s .For the temperature controller, we have selected a gain of scale for the controller's error input of K e =0.0238, of K ev =1 for the error variation and of K ci =5000 for the command increase.The values K e and K ev are needed to keep the error and the error variation bounded in the same margins.The K ci value is used to match up the maximum command to the maximum value of resistance (2000 watts).The values used in the gains of scale have been selected through an adaptive method based on the results of successive simulations.
The results yielded by this system are as shown in Figure 15.By applying the maximum command (2000 watts), we can reach the setpoint value in 1000 seconds.The rules that are applied at first (trigger force equal to 0 is shown in black, with the brightness increasing to white as we progress to a trigger force equal to 1) correspond to rules 27-31, which involve LP.Then the 20-22 group takes over, these rules controlling MP errors and small error variations.Next to activate are those rules for dealing with SP errors.Lastly, rule 7, with trigger force 1, is activated for dealing with ZE error and ZE error variation.
If the setpoint is changed at t=2,200 seconds, the result is as shown in Figure 16.When the setpoint is changed, a new command is output since the MP and SP error rules are activated.

Conclusions
Fuzzy logic is based on the method of reasoning that is typically used by experts to handle all kinds of systems, from the simplest to the very complex.This method (control) can be formulated with rules of the type if-then applied to inexact magnitudes such as "many", "fast", "cold", etc. Implementing this method of reasoning requires a representation of these vague magnitudes and an associated logic.These are the Theory of Diffuse Groups and Diffuse Logic, respectively.
In this chapter we have presented the steps required to implement fuzzy controllers.Such controllers, when integrated into systems that handle precise values, require a translation process before and after the reasoning method is applied.Hence the three-step structure of fuzzy controllers: fuzzification, inference and defuzzification.
The different stages were explained using an example involving temperature control.This is a trivial, academic problem that can be solved using many techniques, such as with a classical PI controller; in this chapter, however, we used this example to illustrate the design of a fuzzy controller, as well as its mode of operation.

1.
First stage, to be completed before the control algorithm is executed, and consisting of: a. Establishing the controller's input and output variables (linguistic variables).b.Defining each variable's fuzzy sets.c.Defining the sets' membership functions.d.Establishing the rule base.e. Defining the fuzzification, inference and defuzzification mechanisms.2. Second stage, to be completed with each step of the control algorithm, and consisting of: a. Obtaining the precise input values.b.Fuzzification: Assigning the precise values to the fuzzy input sets and calculating the degree of membership for each of those sets.c.Inference: Applying the rule base and calculating the output fuzzy sets inferred from the input sets.d.Defuzzification: Calculating the precise output values from the inferred fuzzy sets.

Fig. 4 .
Fig. 4. Human control of a temperature system.

Fig. 11 .
Fig. 11.Fuzzy partition of the fuzzy controller inputs (error and error-variation) and output (increase command).

Fig. 16 .
Fig. 16.Output of fuzzy temperature controller with change at t=2200 seconds.

Table 1 .
Rule base for controlling temperature.