# Design and Evaluation of a New Fuzzy Control Algorithm Applied to a Manipulator Robot
## 5 Fuzzy Logic Controller Design  
The block diagram shown in Figure 4 represents the general structure of a fuzzy logic controller. This controller has three main components: 1. Fuzzification block, in charge of the transformation of each input element into membership degrees for the linguistic terms of the fuzzy sets, each of which has a membership function associated with its elements, indicating to what extent the element is part of the set; 2. Inference engine, which along with the knowledge base makes decisions -based on the membership degree of the input data from the fuzzy sets- and delivers output fuzzy sets that  
Figure 3: Robot complete structure (including actuators). Figure 2: 2-DoF manipulator robot simulation in MatLab/Simulink. are calculated using the rules of the controller; 3. Defuzzification block that transforms fuzzy values \(-\)obtained from the inference\(-\) into values that are useful for the process to be controlled. The output for each fuzzy controller is governed by the defuzzification process and its rule base. The defuzzification process transforms the fuzzy sets into exact values that feed the plant and depend on two Fuzzy Inference Systems (FIS). These systems are applied to achieve appropriate control actions based on assigning two rules: Mamdani and Takagi-Sugeno (TS) [18]. The main difference between the two methods lies in the consequence of fuzzy rules. Mamdani inference systems use fuzzy sets, while TS systems employ linear functions of input variables as a consequence of the rule [40; 41]. The rule structure of the Mamdani-type FIS is expressed as follows: IF x\({}_{1}\) is A\({}_{1}\) and x\({}_{2}\) is A\({}_{2}\) and... and x\({}_{n}\) is A\({}_{n}\) THEN y is B, where x\({}_{i}\) (i = 1, 2... n) are input variables and y is the output variable; A\({}_{1}\)... A\({}_{n}\) and B (linguistic terms) are used to define the distribution of the membership function of fuzzy subsets corresponding to the input and output variables [41]. The crisp output of a Mamdani FIS is obtained when applying one of the following defuzzification methods [40; 42]. Mass center, area or centroid: This technique takes the output distribution and finds its mass center to obtain a crisp number through the following equation:  
\[z=\frac{\sum_{j=1}^{q}Z_{j}\mu_{c}(Z_{j})}{\sum_{j=1}^{q}\mu_{c}(Z_{j})} \tag{19}\]  
where \(z\) is the center of mass and \(\mu_{c}\) is the membership in class \(c\) at value \(z_{j}\).. Maximum value mean: This technique takes the output distribution and finds the mean of its maximum values to obtain a crisp number through the following equation:  
\[z=\sum_{j=1}^{l}\frac{z_{j}}{l} \tag{20}\]  
where \(z\) is the mean of maximum values, \(z_{j}\) is the point at which the membership function reaches its maximum, and \(l\) is the number of times the output distribution reaches the maximum level. This work uses a Mamdani FIS with the max-min composition rule and the centroid method. The control scheme designed for this scenario and simulated in Simulink(r) is shown in Figure 5. It includes two fuzzy logic controllers, one for each joint of the manipulator robot. In addition, each fuzzy block receives three fuzzy inputs. The first input corresponds to position and represents the difference between the desired position qd and the real position q. The following input corresponds to speed q\({}^{\prime}\) (first derivative of position with respect to time) and the last one represents q\({}^{\prime\prime}\) acceleration (second derivative of position with respect to time). Additionally, each block has only one fuzzy output that represents the voltage received by the actuator. The magnitude of this voltage generates the torque force necessary for moving the respective joint. Figure 4: Structure of a fuzzy logic controller. The universes of each fuzzy variable are determined through the analysis of the simulations conducted with a test trajectory.