# Trajectory Tracking Control of a Manipulator Based on an Adaptive Neuro-Fuzzy Inference System
## 4 Hydraulic Manipulator System Modeling and Controller Design
### Design of ANFIS Self-Tuning PID Controller
#### 4.4.2 Design of ANFIS-PID Controller  
The membership function in FPID control is strongly dependent on expert knowledge and experience; it lacks self-learning and adaptive abilities. Therefore, this paper introduces the learning ability of neural network into the fuzzy inference system, uses ANFIS to adaptively learn, adjusts the membership function and finally adjusts PID parameters to form an ANFIS self-tuning PID controller.  
ANFIS is a fuzzy inference system based on the Takagi-Sugeno model. It implements three basic processes of fuzzy controller: fuzzification, fuzzy inference and defuzzification using a neural network. It adjusts membership functions and generates fuzzy rules automatically by training input and output data [27]. For a Sugeno-type fuzzy inference system with two inputs and one output, if-then rules can be expressed as follows:  
If \(x_{1}\) is \(A_{k}\) and \(x_{2}\) is \(B_{k}\), then \(f_{k}=p_{k}x_{1}+q_{k}x_{2}+r_{k}\).  
Where, \(x_{1}\), \(x_{2}\) are input variables, \(A_{k}\), \(B_{k}\) are the fuzzy linguistic sets corresponding to the inputs for the \(\,k-\,\text{th}\,\text{rule}\) and \(f_{k}\) is the output of the \(\,k-\,\text{th}\,\text{rule}\).  
The ANFIS designed in this paper calculates continuously changing PID parameters according to the error e and error change rate etc. Its network structure consists of five layers, as shown in Figure 8. Each layer is explained below.  
Layer 1: In the first layer, each node \(\,j\) is an adaptive node with a node function:  
\[\left\{\begin{aligned} & O_{j}^{1}=\mu_{A_{j}}(x_{1})\,j=1,2, \cdots 7\\ & O_{j}^{1}=\mu_{B_{j-j}}(x_{2})\,j=8,9,\cdots 14\end{aligned}\right. \tag{18}\]  
where \(x_{1}\), \(x_{2}\) are the inputs to node \(\,j\); \(A_{j}\), \(B_{j}\) are the linguistic labels for inputs, with the number set to 7, respectively, and \(O_{j}^{1}\) is the output of the \(j-\) th node, that is, the  
Figure 8: Structure of ANFIS with two inputs, one output.  
Figure 7: Structure of fuzzy PID controller.  
membership grade of fuzzy set \(A\) (say \(A_{j},B_{j}\)). The membership function selected in this paper is Gaussian function [28]:  
\[\mu_{A_{j}}(x)=\exp\left[-\frac{\left(x-c_{j}\right)^{2}}{\sigma_{j}^{2}}\right] \ j=1,2,\cdots 7 \tag{19}\]  
where, \(\sigma_{j}\) and \(c_{j}\) are referred as premise parameters.  
Layer 2: In the second layer, \(7^{2}=49\) rules are generated, so there are 49 nodes. Each node is a fixed node, and its output represents the firing strength of a rule which is the algebraic product of all inputs:  
\[{O_{k}}^{2}=\omega_{k}=\mu_{A_{j}}(x_{1})\mu_{B_{j}}(x_{2})\ j=1,2,\cdots,7,k=1,2,\cdots,49 \tag{20}\]  
Layer 3: In the third layer, each node is a fixed node and the firing strength of each rule is normalized by calculating the corresponding rule's firing strength to the sum of all rules' firing strengths:  
\[{O_{k}}^{3}=\overline{\omega}_{k}=\frac{\omega_{k}}{\sum_{k=1}^{49}k}\ k=1,2, \cdots,49 \tag{21}\]  
Layer 4: In the fourth layer, each node is an adaptive node, calculating the contribution of the \(k-\)th rule to the overall output:  
\[{O_{k}}^{4}=\overline{\omega}_{k}f_{k}=\overline{\omega}_{k}(p_{k}x_{1}+q_{k }x_{2}+r_{k}) \tag{22}\]  
where \(\omega_{k}\) is the output of layer 3, \(p_{k}\), \(q_{k}\), \(r_{k}\) are referred to as consequent parameters.  
Layer 5: In the fifth layer, the single node is a fixed node that calculates the overall output for all the inputs.  
\[{O_{k}}^{5}=\sum_{k=1}^{49}\overline{\omega}_{k}f_{k}=\frac{\sum_{k=1}^{49} \omega_{k}f_{k}}{\sum_{k=1}^{49}\omega_{k}} \tag{23}\]  
In this paper, a hybrid learning algorithm that combines the least-squares and backpropagation algorithms is utilized. The least-squares method is used to train the consequent parameters, and the error signals of the output layer are iteratively calculated. Then, the premise parameters are updated according to the error backpropagation algorithm, and the modifiable parameters are adjusted so that the system can better simulate the given sample data.