\chapter{FUZZY LOGIC CONTROL}
\section{Controller Structure}
In this chapter we discuss a method of designing fuzzy logic controllers for dynamic systems. The configuration of the closed loop system with a fuzzy logic controller we analyze in this chapter is shown in Figure~\ref{fig:typ_fuz}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip1in\special{bmp:c:/mybook/typ_fuz.bmp x=4.67in y=3.5in}
\caption{A diagram of a common structure of the closed loop system with a fuzzy logic controller.}
\label{fig:typ_fuz}
\end{figure}
A typical fuzzy logic control architecture is depicted in Figure~\ref{fig:typflc1}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip1in\special{bmp:c:/mybook/typflc1.bmp x=4.67in y=3.5in}
\caption{A diagram of a typical fuzzy logic controller.}
\label{fig:typflc1}
\end{figure}
Such a controller is composed of three basic components. They are: a fuzzifier, a decision making logic module also referred to as an inference engine, and a defuzzifier. Crisp inputs are converted into corresponding fuzzy sets by fuzzifier. Then the inference engine processes the fuzzified inputs using the knowledge base. The outputs of the inference engine are fuzzy sets that are converted into crisp values, defuzzified, by a defuzzifier. Designing a fuzzy logic controller can be summarized in the following six-step algorithm:
\begin{enumerate}
\item Identify ranges of the controller inputs;
\item Identify ranges of the controller outputs;
\item Create fuzzy sets for each input and output;
\item Translate the interaction of the inputs and outputs into If-Then rules, and then form the rules matrix;
\item Decide on the fuzzifier, the inference engine, and the defuzzifier, and then apply them to crisp inputs to produce crisp outputs;
\item Implement the controller, test it , and modify it if necessary.
\end{enumerate}
\section{Case Study}
We now apply the above algorithm to the control of a simple, one-link robot manipulator. The motion of the robot arm is controlled by a DC motor via a gear train as in Figure~\ref{fig:onelink}
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip1in\special{bmp:c:/mybook/onelink.bmp x=4.67in y=3.5in}
\caption{A diagram of a simple one-link manipulator controlled by a DC motor via a gear train.}
\label{fig:onelink}
\end{figure}
The DC motor is armature-controlled and it is shown in Figure~\ref{fig:dcmotor}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip1in\special{bmp:c:/mybook/dcmotor.bmp x=4.67in y=3.5in}
\caption{A diagram of an armature-controlled DC motor.}
\label{fig:dcmotor}
\end{figure}
We assume that the motor moment of inertia is negligible compared to the robot arm. We model the arm as a point mass $m$ attached to the end of a massless rod of length $l$. Hence the arm inertia is $J_a=ml^2$. We assume that the gear train has no backlash, and all connecting shafts are rigid.\\
We now construct a state-space model of the one-link robot. For this we choose the following state variables:
\[
x_1=\theta_m, \qquad, x_2=\frac{d\theta_m}{dt}=\omega_m,\qquad, x_3=I_a.
\]
For our plant output we take $y=x_1$. Then the model in state-space format is:
\begin{eqnarray*}
\left[\begin{array}{c}
\dot{x}_1\\
\dot{x}_2\\
\dot{x}_3
\end{array} \right] &=& \left[\begin{array}{c}
x_2\\
\frac{g}{l}\sin x_1+\frac{NK_m}{ml^2}x_3\\
-\frac{K_bN}{L_a}x_2-\frac{R_a}{L_a}x_3
\end{array}\right]+\left[\begin{array}{c}
0\\
0\\
\frac{1}{L_a}
\end{array}\right]u\\
y&=&x_1,
\end{eqnarray*}
where $K_m$ is the motor torque constant, $K_b$ is the back emf constant, $N$ is the gear ratio, and $g=9.8\;m/s^2$ is the gravitational constant. Reasonable parameters for the robot are: $l=1\,m$, $m=1\,kg$, $N=10$, $K_m=0.1\,Nm/A$, $K_b=0.1\,Vs/rad$, $R_a=1\,\Omega$, $L_a=100\,mH$. With the above parameters the robot model takes the form:
\begin{eqnarray*}
\left[\begin{array}{c}
\dot{x}_1\\
\dot{x}_2\\
\dot{x}_3
\end{array} \right] &=& \left[\begin{array}{c}
x_2\\
9.8\,\sin x_1+x_3\\
-10\,x_2-10\,x_3
\end{array}\right]+\left[\begin{array}{c}
0\\
0\\
10
\end{array}\right]u\\
y&=&x_1.
\end{eqnarray*}
As can be seen from Figure~\ref{fig:onelink}, counterclockwise rotation of the arm is defined as positive and clockwise rotation as negative. The response of the robot subject to the initial conditions $x_1=0.01\,rad$, $x_2=0\,rad/s$, $x_3=0\,A$, and $u=0\,V$ is shown in Figure~\ref{fig:ol_resp}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip.7in\special{bmp:c:/mybook/ol_resp.bmp x=4.67in y=3.5in}
\caption{Response of the robot subject to $x_1=0.01\,rad$, $x_2=0\,rad/s$, $x_3=0\,A$, and $u=0\,V$}
\label{fig:ol_resp}
\end{figure}
We can show, using for example the first method of Lyapunov, that the equilibrium point $\mb{\bm$x$} = \mb{\bm$0$}$, $u=0$ is unstable. Our goal is to design a fuzzy logic controller that stabilizes this equilibrium point. We first attempt to design a fuzzy logic controller that can return the robot arm to the equilibrium point when its initial displacement is in the interval $[-0.1\,rad,\;0.1\,rad]$. Following the design algorithm, we first identify the inputs and the output ranges. The error is assumed to be in the interval $[-0.1\,rad,\,0.1\,rad]$, while the change-in-error to be in the interval $[-0.005\,rad,\,0.005\,rad]$. The controller output range, which is the plant input, is assumed to be in the interval $[-1.5\,V,\,1.5\,V]$. We will use the bell-shaped normal membership functions of the form
\[
f(x)=\exp\left(-\left(\frac{x-m}{\sigma}\right)^2\right),
\]
where $m$ and $\sigma$ are adjustable parameters. We decided to use five membership functions for the inputs and the output. The $m$ and $\sigma$-parameters of the membership functions are shown in Table~\ref{tab:small}.
\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|}\hline \hline
\multicolumn{2}{|c|}{\bf error} &
\multicolumn{2}{c|}{\bf change-in-error} &
\multicolumn{2}{c|}{\bf output}\\ \hline \hline
$m$ & $\sigma$ & $m$ & $\sigma$ & $m$ & $\sigma$ \\ \hline \hline
$m_{LN}=-0.1$ & $\sigma _{LN}=0.04$ & $m_{LN}=-0.005$ & $\sigma _{LN}=0.002$ & $m_{LN}=-1.5$ & $\sigma_{LN}=0.6$ \\ \hline 
$m_{N}=-0.04$ & $\sigma _{N}=0.03$ & $m_{N}=-0.002$ & $\sigma _{N}=0.0015$ & $m_{N}=-0.6$ & $\sigma_{N}=0.5$ \\ \hline
$m_{ZE}=0$ & $\sigma _{ZE}=0.02$ & $m_{ZE}=0$ & $\sigma _{ZE}=0.0015$ & $m_{ZE}=0$ & $\sigma_{ZE}=0.3$ \\ \hline
$m_{P}=0.04$ & $\sigma _{P}=0.03$ & $m_{P}=0.002$ & $\sigma _{P}=0.0015$ & $m_{P}=0.6$ & $\sigma_{P}=0.5$ \\ \hline
$m_{LP}=0.1$ & $\sigma _{LP}=0.04$ & $m_{LP}=0.005$ & $\sigma _{LP}=0.002$ & $m_{LP}=1.5$ & $\sigma_{LP}=0.6$ \\ \hline \hline   
\end{tabular}
\end{center}
\caption{The $m$ and $\sigma$-parameters of the membership functions for the inputs and the output}
\label{tab:small}
\end{table}
We then generate the rules. They are shown in Table~\ref{tab:rule_s}.
\begin{table}
\begin{center}
\begin{tabular}{|c||c|c|c|c|c|} \hline \hline
{\bf error} & LN & N & ZE & P & LP \\ \cline{1-1}
{\bf change-in-error}& {}&{}&{}&{}&{}\\ \hline \hline
LN & LN & LN & LN & LN & LN \\ \hline
N & LN & LN & N & N & N \\ \hline
ZE & N & N & ZE & P & P \\ \hline
P & P & P & P & LP & LP \\ \hline
LP & LP & LP & LP & LP & LP \\ \hline \hline
\end{tabular}
\end{center}
\caption{The rules matrix}
\label{tab:rule_s}
\end{table}
The next step involves choosing an inference engine and a defuzzifier. We use the product inference rule and the modified center average defuzzifier. We then create a nonlinear mapping from the input space into the output space and form a table look-up to implement the obtained nonlinear mapping representing our fuzzy logic controller. A diagram of the closed loop system is depicted in Figure~\ref{fig:clcon_s}.
\vspace*{0.05in}
\begin{figure}
\vspace{4.5in}
\hskip.2in\special{bmp:c:/mybook/clcon_s.bmp x=6in y=4.5in}
\caption{A diagram of the closed loop system with fuzzy logic controller implemented as a table look-up.}
\label{fig:clcon_s}
\end{figure}
There are two inputs to the controller. The first input is the change-in-error signal $ec$ and the second is the error signal $e$. The change-in-error is implemented using a delay element. It can be described as
\[
ec(t)=e(t)-e(t-\Delta),
\]
where the delay $\Delta$ used in our implementation is $\Delta=0.01\,sec$. Simulations results for two different initial conditions are shown in Figure~\ref{fig:sim_sc}.
\vspace*{0.05in}
\begin{figure}
\vspace{4in}
\hskip1in\special{bmp:c:/mybook/sim_sc.bmp x=5.32in y=4in}
\caption{Closed loop system response subject to different initial conditions on $x_1$.}
\label{fig:sim_sc}
\end{figure}
As we can see from Figure~\ref{fig:sim_sc}, for small deviations of the arm from the operating point at $x_1=0$, the controller forces it to return back to the vertical position quite fast. However, if the initial displacements are greater than $|0.1\, rad|$, the controller has difficulty to force the arm to return to the vertical position as can be seen in Figure~\ref{fig:sim_sbc}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip.6in\special{bmp:c:/mybook/sim_sbc.bmp x=4.66in y=3.5in}
\caption{The closed loop system response subject to $x_1=0.11\,rad$.}
\label{fig:sim_sbc}
\end{figure} 
For larger deviations from the operating point the actuator needs a larger input signal. We could try to design a fuzzy logic controller for a large range of displacements from the operating point. The closed loop system with such a controller would be able operate over a wider range of initial arm displacements while sacrificing performance in the small displacement region. To alleviate the problem we design a fuzzy logic controller that uses different control strategies in different operating regions. Its implementation is given in Figure~\ref{fig:multirgc}. Based on our knowledge of the plant, we divided the error range into three regions: small, large, and very large. The error $e$ is considered small if $|e|\le\,0.08\,rad$, it is large if $0.08\,rad<|e|\le\,0.8\,rad$, and it is very large if $0.8\,rad<|e|\le\,3.2\,rad$. We then designed fuzzy logic controllers for each of the regions using regional information. The design process of these controllers was similar to the design of the controller for small error, except of course we used different ranges for the error, the change-in-error, and the controller input. We used the rules matrix shown in Table~\ref{tab:rule_s} for each of the controllers. Next, we implemented the controllers using table look-ups. Finally, all the controllers were combined to give a multiregion controller that has a satisfactory performance in all three regions. In combining the individual controllers we used the merge module. This module has three inputs labeled $b$, $t$, and $f$, where $b$ stands for Boolean, $t$ stands for true, and $f$ stands for false. The merge block examines the Boolean signal $b$ to decide about the output signal, call it $y$. The output signal is
\[
y=\left\{\begin{array}{c}
t\qquad \mb{if}\qquad |b|\ge1\\
f\qquad \mb{if}\qquad |b|<1.
\end{array} \right.
\]
The Boolean signals to the merge modules are the outputs of the limiter blocks. The input to the limiter blocks is the error $e$. The action of the limiter can be described by
\[
b=\left\{\begin{array}{ccc}
lb & \mb{if}& e<lb\\
e & \mb{if} & lb\le e \le lb\\
ub & \mb{if} & e>ub.
\end{array} \right.
\]
\vspace*{0.05in}
\begin{figure}
\vspace{4.5in}
\hskip.2in\special{bmp:c:/mybook/multirgc.bmp x=6in y=4.5in}
\caption{A multiregion fuzzy logic controller implementation.}
\label{fig:multirgc}
\end{figure}
We can notice the presence of scaling factors in the diagram. Their presence is the result of tuning of the multiregion controller. The response of closed loop system, driven by the multiregion fuzzy logic controller, subject to two different initial displacements from the operating point is shown in Figure~\ref{fig:clr_mrc}.
\vspace*{0.05in}
\begin{figure}
\vspace{3.5in}
\hskip.6in\special{bmp:c:/mybook/clr_mrc.bmp x=4.66in y=3.5in}
\caption{The closed loop system response, with multiregion fuzzy logic controller, subject to two different initial displacements $x_1=3.0\,rad$ and $x_1=-1.5\,rad$.}
\label{fig:clr_mrc}
\end{figure}  
The idea of using a multiregion fuzzy logic control was already used by Li and Lau in \cite{yfli89}. Li and Lau applied a two-region fuzzy logic controller to control a servomotor. When the magnitude of the control error was large the fuzzy logic coarse controller was in action. For the error magnitude small, the fuzzy logic fine controller was taking over. An alternative approach to designing multiregion fuzzy logic controllers is proposed by Qin and Borders in \cite{sjqin94}. Qin and Borders divide the operating region of the plant gain into fuzzy regions such as low gain, medium gain, and large gain. Then they introduce an auxiliary variable that detects the plant operating region and activates control strategy corresponding to the operating region.
\section{Controller Design Using Numerical Data}
In our fuzzy logic controller design we used either given to us or derived by us If-Then rules describing the process to be controlled. However there are situations when neither experts are available nor because of the complexity of the process to be controlled, a designer can have an access to the rules describing the process. There maybe though input-output numeric data available. We would like to use the available numeric data to generate a set of If-Then rules so that we could use them in the design of a fuzzy logic controller. In what follows we provide a method for generating fuzzy rules from numerical data. This method was proposed by Wang in \cite[pages 65--69]{lxwang94}. 