# Fuzzy Logic Control - Why use it? 2016-02-05

Fuzzy logic is an easy to use technique that can replace PID control loops using microcontrollers

1. Proportional-Integral-Differential Control (PID Control or PIDC) dates from the 1890's and was originally developed as the best method for stable feedback control of complex linear dynamic systems, since only analog control methods (originally mechanical/pneumatic and then electronic) were available at that time, and they could readily generate the desired PID function responses. Thus it was (and is) widely used, even though, being a linear control technique, it can have significant limitations in achieving optimum system response in real systems with non-linear or hysteretic characteristics.
Of course those continuous PIDC analog functions are now also emulated in a quantized manner by a digital processor but it still has most of the same limitations that the analog approach has.

Fuzzy logic control is a digital only (and basically non-linear) approach which is readily performed with a microprocessor, but not by analog circuits. In that respect, and because it's generally easier to understand and can give better control of real systems, Fuzzy Logic is a good candidate to consider for any microprocessor feedback-control system.

Since not many people are familiar with Fuzzy Logic I decided to write this short article to cover some basics and indicate why it should be considered in place of PID for feedback control systems.

One reason I like Fuzzy Logic for control is because the main loop is just a simple series of If-Then-Else statements, whose functions are generally easier to understand than that of a PIDC program.
With digitally emulated PIDC, the digital processor code is generating a quantized approximation of the continuous analog proportional, integral, and differential functions of PIDC and it's not always apparent from looking at the code, how that is working, or how the code might need to be changed to improve system response.

A Fuzzy Logic program is written the way a (fast) human operator might tweak knobs or switches to control a system (e.g.
If the temperature is slightly high Then slightly turn down the heater power Else
If the temperature is slightly low Then slightly turn up the heater power Else
If the temperature is correct Then maintain the heater power Else
If the temperature is moderately high Then moderately turn down the heater power Else
.........................
Note that controlling the heater power could be done by changing a low-frequency PWM on/off duty-cycle.)

Fuzzy Logic operation is typically more intuitive than PIDC and it's usually apparent what needs to be tweaked or where more If-Then-Else statements are needed to optimize the system response.
That's not generally true with PIDC, except perhaps if you are reasonably experienced in tuning PIDC systems.

PIDC assumes the system behaves in a linear fashion since it uses linear feedback functions, thus it can be difficult (or impossible) to stabilize a non-linear system with PIDC alone.
Fuzzy Logic doesn't depend upon the system being linear, and thus usually can be designed to more readily handle non-linear responses (e.g. a thermistor temperature sensor) or discontinuities / hysteresis (mechanical backlash) in the system.
In a real world PIDC system you also have to deal with transient saturation issues, such as integrator windup, which a Fuzzy Logic system does not have.

Here are a couple of good links for Fuzzy Logic control to help give you a better feel for it:
Seattle Robotics Fuzzy Logic Tutorial
Building a Fuzzy Logic Controller

Here's a little blurb (post #17) by someone who tried Fuzzy Logic for the first time on a pressure/flow control system (post #12), which I would think is a somewhat non-linear system, and it worked well, better on his first iteration than the PID control loop he had been working with.