Fuzzy Application Library/Technical Applications/Practical Design
Practical Fuzzy Logic Design
by Constantin von Altrock (8/96)
Citation Reference: This paper was published at the Embedded Systems Conference in 1996 in Paris. The Fuzzy Logic Application Note series is published by Inform Software Corporation on its Internet server to promote the use of fuzzy logic technologies in applications.
Over the past few years, systems designers have been faced with a rather controversial discussion about a new design technology named "Fuzzy Logic". Some followers of fuzzy logic have pitched it as the "magic bullet" for every type of engineering problem and have made wild and unsupported claims in their publications. This has raised skepticism amongst control engineering specialists and caused some to completely condemn fuzzy logic as a marketing fad of no technical value.
Unlike the U.S., in Asia and Europe the discussion about fuzzy logic has been much less fanatical and was kept closer to the real benefits of the technology. Here, fuzzy logic is considered to be one of the many tools necessary to build systems solutions in a fast, cost-effective, and transparent fashion. Not more, but not less than that. For a detailed study on how fuzzy logic is used in system design in Europe, see .
|Figure 1: When transporting concrete modules for bridges and tunnels by a crane, the sway of the load must be controlled. A Fuzzy Logic Controller can use the experience of a human crane operator and put it directly to work. large|
A lot of recent articles claimed substantial advantages that can be achieved by applying fuzzy logic. However, many articles fell short on describing exactly HOW fuzzy logic does achieve superior performance compared to other engineering design techniques. In this article, I will try very hard exactly to do this.
To illustrate how fuzzy logic solves real-world problems, and to compare it head-to-head with conventional design techniques, the case study of an anti-sway crane controller is used. This real-world application was selected for a number of reasons:
In this article, the assumption is made that you are familiar with the concept of fuzzy logic. If not, refer to the practitioner's introduction in .
Before starting with the case study, let's first clarify some control engineering basics. Closed loop control mostly involves keeping a single figure constant. This could be an electrical current, the mass flow of a liquid, or the temperature of a room. To keep a room temperature constant, a sensor delivers the value of the actual room temperature. The difference between the actual temperature and the desired room temperature is the temperature error. The objective of the controller is to get the temperature error to zero, and to do this, it may turn on or off a heater or an air conditioner. Such controllers are referred to as "on-off" type controllers. If the command variable of the process is continuous, such as with a gradual heat control, a so-called "proportional" type controller is used. This implements a control strategy that computes its output - the command variable of the process - by multiplication of the error with a constant factor.
Many real-world processes involve a time lag. When controlling room temperature and the heater is set to on, it takes a while before the heat reaches the sensor. Because the controller gets the measured room temperature variable with a time delay, it can over-react and apply more heat than what would have actually been required to get the temperature error to zero. This can cause an unwanted oscillation of the room temperature. To compensate for this effect, "proportional-differential" (PD) type controllers are used that add the time derivative of the error multiplied by a constant factor to the error. "Proportional-Integral-Differential" (PID) type controllers also consider the integral of the error and add it to the output signal. This ensures that the error will eventually reach zero, because even a very small offset in the error value will be compensated as its integral eventually raises to a high value over time.
Because on-off, proportional, and PID type controllers only use the error or signals derived from the error as input and the command variable of the process as output, they are called "single-loop" controllers. These controller types are simple to program and easy to tune in most applications. The replacement of such controller types by a fuzzy logic controller only delivers a better performance in cases where the conventional controller does not cope well with the non-linearities of a process under control [1, pp. 82].
A much higher potential for fuzzy logic lies in the fact that it can also facilitate the design of multi-variable control systems. In a multi-variable control loop, the control strategy not only considers one input variable, such as error, but different types of measured variables. In the case of the room thermostat, a multi-variable control strategy could consider both temperature error and room air humidity to set the command variables of heater and air conditioner.
|Figure 2: In many applications, keeping a single figure of the process constant is relatively easy and can be facilitated by conventional PID controllers. However, to optimize the operation point of the process, a supervisory controller modifies the set points of the PID controllers. The conventional control engineering approach would require rigorous mathematical modeling while the Fuzzy Logic approach can shortcut by employing operator experience instead. large|
To deal with multiple input variables, a controller must assume a mathematical model of the process to be controlled. For the multi-variable room thermostat control strategy, such a mathematical model could be the humidity and temperature relation describing comfortable conditions. In most real-world applications, the mathematical relation between the different variables cannot be easily described. Therefore multi-variable control is not commonly used by practitioners.
Other application areas where a multi-variable control strategy is used include continuous process control, as found in food or chemical industry. Keeping single figures of the processes constant is easy in most cases. However, controlling the optimal operation point for the plant does involve multiple variables. Because of the difficulties involved with deriving mathematical models, automated control is rare and human operators often adjust the set points of the individual PID controllers. This type of multi-variable control is also referred to as "supervisory" control because the multi-variable control strategy analyzes and supervises the set points of underlying control loops.
In contrast to conventional design techniques, fuzzy logic enables the design of such multi-variable control strategies directly from human operator experience or experimental results. Using such existing knowledge and circumventing the effort of rigorous mathematical modeling, the fuzzy logic design approach delivers efficient solutions faster. Now the question becomes, how can operator experience be put into a fuzzy logic system? The following case study of an anti-sway controller for a container crane illustrates just this.
Case Study of Container Crane Control
Container cranes are used to load and unload containers on and off ships in most harbors (Figure 3). They pick up single containers with flexible cables that are mounted on the crane head. The crane head moves on a horizontal track. When a container is picked up and the crane head starts to move, the container begins to sway. While sway is no problem during transportation, a swaying container cannot be released.
Two ineffective ways exist to solve this problem. One is to position the crane head exactly over the target position, then wait until the sway dampens to an acceptable level. On a non-windy day, this will eventually happen but it takes by far too much time. A container ship has to be loaded and unloaded in a minimum amount of time for cost reasons. The other option is to pick up the container and just move so slow that no sway ever occurs. This again works on a non-windy day, but however it also takes far too much time. An alternative is to build container cranes where additional cables fix the position of the container during operation. Only very few cranes make use of this due to the much higher cost of the solution.
|Figure 3: The software simulation of a container crane operation visualizes the operation of the Fuzzy Logic anti-sway controller. The Fuzzy Logic control strategy is to first get the container (yellow) off the ship (red) to the target (green car) as quickly as possible. Sway is of no harm until the target is reached. When the target is reached, the sway must be compensated before release of the container. large|
For these reasons, most container cranes still employ human operators to control the speed of the motor. The operator simultaneously compensates the sway and makes sure the target position is quickly reached. This task is not easy, but a skilled operator is capable of achieving good results.
Control Model Alternatives
Many engineers have tried to automate this control task in the years past. They tried:
Conventional PID control was not successful because the control task is inherently non-linear. For example, sway minimization is important only when the container is close to the target. Others have tried to derive a mathematical model of the crane to use this in a model-based controller. They came up with a fifth-degree differential equation that describes the mechanical behavior. Although in theory, controller design based on this model should work, in reality it does not. The reasons for this are:
A Linguistic Control Strategy
On the other hand, a human operator is capable of controlling a crane without differential equations. The operator does not even use a cable length sensor, which a model-based solution would require. Once he has picked up the container, the operator starts the crane with medium motor power to see how the container sways. Depending on the reaction, he adjusts motor power to get the container a little behind the crane head. In this position, maximum speed can be reached with minimum sway. Getting closer to the target position, the operator reduces motor power or even applies negative power to brake. As such, the container gets a little ahead of the crane head until the container almost reaches target position. Then, the motor power is increased so that the crane head is over the target position and sway is zero. No differential equations are required for this, and disturbances and non-linearities are compensated by the operator's observation of the container's position.
The analysis of the operator's actions reveals that the operator uses some "rules of thumb" to describe his control strategy:
Implementing a Linguistic Control Strategy
To automate the control of this crane, sensors for the crane head position ("Distance") and the angle of the container sway ("Angle") are employed. Using these inputs to describe the current condition of the crane, the five rules of thumb can be translated to an "if-then" format:
1. IF Distance = far AND Angle =
zero THEN Power = pos_medium
2a. IF Distance = far AND Angle = neg_small THEN Power = pos_big
2b. IF Distance = far AND Angle = neg_big THEN Power = pos_medium
3. IF Distance = medium AND Angle = neg_small THEN Power = neg_medium
4. IF Distance = close AND Angle = pos_small THEN Power = pos_medium
5. IF Distance = zero AND Angle = zero THEN Power = zero
Note, Rule 2 has been translated into two rules to fit the if-then format.
If-then rules always describe the reaction to a certain situation as:
IF <situation> THEN <action>
In the case of the container crane, each situation is identified by two conditions. The first condition describes the value of Distance, the second the value of Angle. The conditions are combined by AND, representing the fact that both conditions have to be valid for the respective situation.
Once you have set up a set of rules describing the desired behavior of a system, the question becomes: how can you implement these rules? First, consider using a programming language to code the "if-then" rules. The problem is that you have to define the words that the conditions of the rules use. However, exact definitions for these words do not exist. Fuzzy Logic does provide non-exact definitions for the words used in the rules, such as "far" or "medium" and thus lets you directly use linguistic rules for control systems design.
|Figure 4: One way to edit Fuzzy Rules in fuzzyTECH is the Spreadsheet Rule Editor. Each row corresponds to a Fuzzy Rule. The two columns "Angle" and "Distance" underneath the "IF" button form the conditions of the rules. Underneath the "THEN" button, the column "Power" forms the conclusion of the rules. The "DoS" column can contain an individual weight for each rule. large|
Structure of a Fuzzy Logic Crane Controller
Figure 5 shows the complete structure of a fuzzy logic controller. First, all sensor signals have to be translated into linguistic variables. That is, a measured distance of 12 yards has to be translated to the linguistic value "still medium, just slightly far". This step is called "fuzzification" as it uses fuzzy sets for translating real variables into linguistic variables.
|Figure 5: The complete control loop of the Fuzzy Logic Crane Controller involves three steps. The variables "Distance" and "Angle" measured at the crane are translated into linguistic variables (Fuzzification) that are used to evaluate the condition of the Fuzzy Rules (Fuzzy Inference). The conclusion of the Fuzzy Rules is a linguistic value for the variable "Power" that is then translated back into a numerical value (Defuzzification). (large)|
Once all input variable values are translated into respective linguistic variable values, the so-called "fuzzy inference" step evaluates the set of if-then rules that defined system behavior. The result of this is again a linguistic value for the linguistic variable. For example, the linguistic result for Power could be "a little less than medium". The so-called "defuzzification" step translates this linguistic result into a real value that represents the power setting of the motor in kilowatts.
Would you like to try this yourself? Here's how: You can download the complete animated software simulation of the container crane for MS-Windows from the Download Free Demo page together with a simulation-only version of the professional fuzzy logic development software fuzzyTECH and the FTL source code of the crane controller. This lets you develop and test your own fuzzy logic crane controller in minutes.
Design and Implementation
The development of a fuzzy logic system involves a number of design steps:
|Figure 6: Design of the Fuzzy Logic Anti-Sway Controller in the fuzzyTECH development software. The upper left window shows the structure of the system with two inputs, one output, and one rule block. The upper right window visualizes the defuzzification of the output variable "Power", and the lower windows show the fuzzification of the input variables "Angle" and "Distance". (large)|
Most systems today are developed using software tools such as those shown for the crane controller in Figure 6. Such development tools not only support all listed design steps but can generate the entire system for different hardware platforms. For microcontrollers (MCU), the tools generate assembly code, for programmable logic controllers (PLC) they generate function blocks, and for PC/workstation applications they generate C code.
Many years ago, the computation of the fuzzy logic algorithm was so inefficient on a standard MCU that dedicated fuzzy logic processors were developed. Today, the level of code efficiency has improved dramatically. Figure 7 shows different MCUs, a digital signal processor (DSP), and today's fastest dedicated fuzzy logic processor computational performance for four (4) different benchmark systems. The time shown on the vertical logarithmic scale is the total time required to compute the complete fuzzy logic system. You can download the source code of the benchmark suite from .
|Figure 7: Using a set of standardized benchmarks, the performance of different hardware platforms can be compared. On a 8051 MCU, a small fuzzy logic system can be computed in about a Millisecond. Faster MCUs and DSPs can compute even very large fuzzy logic systems in fractions of a millisecond. (large)|
On a standard 12MHz 8051 MCU, small fuzzy logic systems compute in just one millisecond, and 16-bit MCUs can even compute large fuzzy logic systems in the same amount of time. This enables the integration of a fuzzy logic system with most embedded system designs. However, some embedded system applications do require even faster computation, such as ABS systems in cars, ignition control, or hard drive positioning. To expedite the fuzzy logic algorithm, some semiconductor manufacturers include specific fuzzy logic instructions with their new generation MCUs. One example is Motorola's new HC12 MCU, which features a complete fuzzy logic function set in assembly language.
Fuzzy logic enables the use of experience and experimental results to deliver more efficient solutions. It does not replace or compete with conventional control techniques. Fuzzy logic rather extends the way automated control techniques are used in practical applications by adding supervisory control capabilities. The simple case study of a container crane demonstrates that fuzzy logic can deliver a transparent and simple solution for a problem that is much harder to solve using conventional engineering techniques.
The fuzzy logic anti-sway crane controller discussed in this paper can be viewed on the Crane Video.