Fuzzy PID Controller Optimization for Robot Dynamics with ...

160
Fuzzy PID Controller Optimization for Robot Dynamics with aid of Differential Evolution A Thesis Submitted to the Faculty of Graduate Studies and Research In Partial Fulfillment of the Requirements For the Degree of Master of Applied Science in Industrial Systems Engineering University of Regina By Mohammad Parhamian Regina, Saskatchewan October 2020 Copyright 2020: M.Parhamian

Transcript of Fuzzy PID Controller Optimization for Robot Dynamics with ...

Page 1: Fuzzy PID Controller Optimization for Robot Dynamics with ...

Fuzzy PID Controller Optimization for Robot Dynamics with

aid of Differential Evolution

A Thesis

Submitted to the Faculty of Graduate Studies and Research

In Partial Fulfillment of the Requirements

For the Degree of

Master of Applied Science

in Industrial Systems Engineering

University of Regina

By

Mohammad Parhamian

Regina, Saskatchewan

October 2020

Copyright 2020: M.Parhamian

Page 2: Fuzzy PID Controller Optimization for Robot Dynamics with ...

UNIVERSITY OF REGINA

FACULTY OF GRADUATE STUDIES AND RESEARCH

SUPERVISORY AND EXAMINING COMMITTEE

Mohammad Parhamian, candidate for the degree of Master of Applied Science in Industrial Systems Engineering, has presented a thesis titled, Fuzzy PID Controller Optimization for Robot Dynamics With Aid of Differential Evolution, in an oral examination held on September 3, 2020. The following committee members have found the thesis acceptable in form and content, and that the candidate demonstrated satisfactory knowledge of the subject material. External Examiner: *Dr. Abdul Bais, Electronic Systems Engineering

Supervisor: *Dr. Rene Mayorga, Industrial Systems Engineering

Committee Member: *Dr. Golam Kabir, Industrial Systems Engineering

Committee Member: *Dr. Wei Peng, General Engineering

Chair of Defense: *Dr. Ronald Camp, Faculty of Business Administration *via ZOOM Conferencing

Page 3: Fuzzy PID Controller Optimization for Robot Dynamics with ...

i

ABSTRACT

In this Thesis, a Fuzzy proportional-integral-derivative (FPID) controller is presented to

control the dynamics of a 3-DOF robot. A Differential Evolution (DE) optimization method

was used to optimize the performance of the FPID controller. The results are compared and

validated with three other optimization methods: Genetic Algorithm (GA), Particle Swarm

Algorithm (PSO), and Imperialistic Competition Algorithm (ICA). In the proposed FPID,

the Membership functions (MFs) for two inputs and one output, fuzzy rules, and scaling

factors have been optimized. The Error is implanted in a cost function and the results have

been compared. The DE method shows the best performance comparing to the other three

methods.

This dissertation proposes an approach to design a fuzzy PID controller to control the plants

with the best performance. With making use of different numerical optimization methods,

the FPID problem changes to a numerical optimization problem. First, a sample FPID

controller is designed, including triangular fuzzy membership functions for input and

output, rules, and scaling factors. Then, the DE method along with three different numerical

optimization methods are used to minimize the cost function by adjusting the MFs points,

rules, and scaling factors. Unlike traditional PIDs, this approach is likely to achieve the

desired control performance. Another unique feature is that the optimized adaptive PID

controller applies to a broad range of time-varying and nonlinear structures.

The purpose of this research is to obtain optimal FPID parameters to control a 3 DOF robot.

The step signals representing desired angles of the robot’s links are imposed on the system

and the behavior of the system is measured by comparing the actual angle in output with

Page 4: Fuzzy PID Controller Optimization for Robot Dynamics with ...

ii

the desired angles in input. Finally, the results for the optimal path using all 4 metaheuristic

methods and FPID are compared. Although this Thesis research investigates the FPID

controller in a 3 DOF robot for performing a specific task, the results can be extendable to

other FPID configurations in the industry.

In this dissertation, we give an introduction and a brief history of the previous works on

PID and Fuzzy PID controllers and optimization methods in Chapters 1 and 2, respectively.

In Chapter 3, the equations related to the dynamics of the robot are obtained. In Chapter 4,

we discuss the FPID and optimization methods, in Chapter 5, first, the architecture of the

proposed control system and optimization is explained, and then, the simulation results are

discussed. The Chapter 6 includes the conclusions and recommendations for future works.

Keywords: Robot Dynamics, Fuzzy PID, Fuzzy PID optimization, Differential Evolution,

Imperial Competitive Algorithm, Genetic Algorithm, Particle Swarm Optimization, Fuzzy

PID tuning

Page 5: Fuzzy PID Controller Optimization for Robot Dynamics with ...

iii

ACKNOWLEDGMENTS

Firsthand and foremost, I would like to express my sincere gratitude to my supervisor Dr.

Rene V. Mayorga for his support and kindness through all these years at the University of

Regina. I also owe an appreciation and sincere thanks to my incredible parents, sisters and

brother for their love and support in every moment of my life.

Page 6: Fuzzy PID Controller Optimization for Robot Dynamics with ...

iv

Contents

1 INTRODUCTION .......................................................................................................1

1.1 Background and Motivation ....................................................................................1

1.2 Research Objectives .................................................................................................4

1.3 Summary ..................................................................................................................6

2 LITERATURE REVIEW ............................................................................................7

2.1 Introduction ..............................................................................................................7

2.2 PID Control for Linear and Non-Linear Systems ....................................................8

2.3 Fuzzy Control...........................................................................................................9

2.3.1 Conventional Fuzzy Control ....................................................................... 10

2.3.2 Fuzzy PID Control ...................................................................................... 11

2.4 Fuzzy Control and Robotics...................................................................................13

2.4.1 Fuzzy PID Control and Robotics ................................................................ 15

2.5 Fuzzy PID Optimization and Metaheuristic Methods ...........................................16

2.6 A Brief Review of Differential Evolution .............................................................17

2.7 Summary ................................................................................................................18

3 DYNAMICS OF A ROBOT ARM............................................................................19

3.1 Introduction ............................................................................................................19

3.2 A Review of Robot Kinematics .............................................................................20

3.3 Kinetics of the Robot Arm .....................................................................................23

Page 7: Fuzzy PID Controller Optimization for Robot Dynamics with ...

v

3.4 Summary ................................................................................................................27

4 FUZZY PID CONTROLLER DESIGN AND OPTIMIZATION .............................28

4.1 Introduction ............................................................................................................28

4.2 Cost Function .........................................................................................................28

4.3 Fundamentals of Fuzzy Inference System .............................................................30

4.3.1 Membership Function ................................................................................. 30

4.3.2 Fuzzification ............................................................................................... 31

4.3.3 Fuzzy Rules and Inference Model .............................................................. 32

4.3.4 Defuzzification ............................................................................................ 35

4.4 PID Controller ........................................................................................................35

4.5 Fuzzy PID Controller .............................................................................................39

4.5.1 Inputs and Outputs of FIS ........................................................................... 41

4.5.2 FIS Rules ..................................................................................................... 43

4.6 Fuzzy PID Optimization ........................................................................................45

4.7 Differential Evolution Optimization ......................................................................49

4.7.1 DE Initialization .......................................................................................... 50

4.7.2 Mutation ...................................................................................................... 51

4.7.3 Crossover .................................................................................................... 52

4.7.4 Selection ...................................................................................................... 53

4.8 Genetic Algorithm Optimization ...........................................................................54

Page 8: Fuzzy PID Controller Optimization for Robot Dynamics with ...

vi

4.8.1 Generating the Initial Population ................................................................ 56

4.8.2 Parent Selection .......................................................................................... 56

4.8.3 Crossover .................................................................................................... 58

4.8.4 Mutation ...................................................................................................... 59

4.8.5 Parameter Selection .................................................................................... 60

4.9 Particle Swarm Optimization .................................................................................61

4.9.1 PSO parameters ........................................................................................... 64

4.10 Imperialist Competitive Algorithm (ICA) .............................................................65

4.10.1 Creation of initial empires .......................................................................... 65

4.10.2 Assimilation ................................................................................................ 67

4.10.3 Revolution ................................................................................................... 68

4.10.4 Position exchange between colonies and imperialist .................................. 68

4.10.5 Empire’s Union ........................................................................................... 68

4.10.6 Imperialistic Competition ........................................................................... 69

4.11 Summary ................................................................................................................71

5 SIMULATION AND DISCUSSION ........................................................................73

5.1 Introduction ............................................................................................................73

5.2 Control System.......................................................................................................73

5.3 Conventional PID Failure ......................................................................................75

5.4 FPID Approach ......................................................................................................76

Page 9: Fuzzy PID Controller Optimization for Robot Dynamics with ...

vii

5.5 Optimized Results ..................................................................................................79

5.5.1 Best Cost ..................................................................................................... 79

5.5.2 System Response ........................................................................................ 80

5.5.3 Optimized Membership Functions .............................................................. 83

5.5.4 Optimized Rules.......................................................................................... 85

5.5.5 PID Gains .................................................................................................... 87

5.6 Summary ................................................................................................................88

6 CONCLUSIONS AND RECOMMENDATIONS ....................................................90

6.1 Calculation Efficiency ...........................................................................................90

6.2 Future Works .........................................................................................................91

7 References ..................................................................................................................93

Appendix A : Codes ......................................................................................................99

A.1 DE Optimization Code ...........................................................................................99

A.2 GA optimization code ..........................................................................................107

A.3 PSO optimization code ........................................................................................118

A.4 ICA optimization code .........................................................................................126

Page 10: Fuzzy PID Controller Optimization for Robot Dynamics with ...

viii

List of Figures

FIGURE 1.1 PID CONTROLLER REPRESENTATION [2] ........................................................................................ 2

FIGURE 1.2 GENERAL SISO CONTROL SYSTEM WITH A STANDARD PID CONTROLLER ..................................... 3

FIGURE 1.3 CONTROL SYSTEM WITH A FUZZY PID PARAMETER TUNER AND A PID CONTROLLER .................... 3

FIGURE 1.4 PROPOSED CONTROL SYSTEM ................................................................................................................. 5

FIGURE 2.1 CLASSIFICATION OF FUZZY CONTROLLERS ................................................................................................ 13

FIGURE 3.1 FRAME P, Q AND R DEMONSTRATION ON A ROBOT LINK [92] ..................................................................... 22

FIGURE 3.2 CONFIGURATION OF THE THREE DOF ROBOT [93] ........................................................................ 24

FIGURE 4.1 MEMBERSHIP FOR FUZZY VARIABLE “ANGULAR VELOCITY” IN RPM [97] ................................... 31

FIGURE 4.2 MEMBERSHIP FUNCTION FOR A)INPUT B)OUTPUT [98] ................................................................. 32

FIGURE 4.3 USING MAMDANI FUZZY INFERENCE MODEL WITH MIN-MAX OPERATORS [98] .......................... 34

FIGURE 4.4 A ROBOT DYNAMIC CONTROL USING FUZZY PID CONTROLLER ................................................... 40

FIGURE 4.5 MEMBERSHIP FUNCTION FOR INPUT 1 .......................................................................................... 42

FIGURE 4.6 MEMBERSHIP FUNCTION FOR INPUT 2 .......................................................................................... 42

FIGURE 4.7 MEMBERSHIP FUNCTIONS FOR OUTPUT 1 OR OUTPUT 2 ................................................................ 43

FIGURE 4.8 MEMBERSHIP FUNCTION FOR OUTPUT 3 ....................................................................................... 43

FIGURE 4.9 DEMONSTRATING THE 7 VARIABLES FOR EACH RULE TABLE ....................................................... 46

FIGURE 4.10 VARIABLES REQUIRED TO BE OPTIMIZED FOR BOTH INPUT ARE DEMONSTRATED WITH RED DOTS

............................................................................................................................................................. 47

FIGURE 4.11 VARIABLES REQUIRED TO BE OPTIMIZED FOR ALPHA ARE DEMONSTRATED WITH RED DOTS ..... 48

FIGURE 4.12 VARIABLE PARAMETERS STRING .......................................................................................................... 48

FIGURE 4.13 CLASSICAL DE FLOWCHART [102] ............................................................................................ 50

FIGURE 4.14 WEIGHTED DIFFERENTIAL MUTATION DEMONSTRATION IN A 2D PARAMETER SPACE [101] ....... 52

FIGURE 4.15 DEMONSTRATION OF POSSIBLE RESULTS OF CROSSOVER IN 2D PARAMETER SPACE [101] ......... 53

FIGURE 4.16 GENETIC ALGORITHM FLOWCHART [67] ................................................................................... 55

FIGURE 4.17 GA RANKING PROCEDURE IN EACH ITERATION [67] .................................................................. 57

Page 11: Fuzzy PID Controller Optimization for Robot Dynamics with ...

ix

FIGURE 4.18 DIFFERENT CROSSOVER METHODS: A) SINGLE-POINT B) DOUBLE-POINT C) UNIFORM [67] ......... 59

FIGURE 4.19 MUTATION OPERATOR [67] ........................................................................................................ 60

FIGURE 4.20 THREE PATH TO OPTIMAL SOLUTION IN PSO ALGORITHM [104] ................................................. 62

FIGURE 4.21 SCHEMATIC OF A PARTICLE MOVEMENT [105] ........................................................................... 63

FIGURE 4.22 INITIAL SITUATION OF EMPIRES IN ICA [109] ............................................................................ 67

FIGURE 4.23 MOVEMENT OF THE COLONY TOWARD THEIR IMPERIALIST IN ASSIMILATION PROCESS ............... 68

FIGURE 4.24 THE IMPERIALISTIC COMPETITION [109] .................................................................................... 70

FIGURE 5.1 SIMULINK LAYOUT FOR A 3DOF ROBOT FPID CONTROL SYSTEM .............................................. 74

FIGURE 5.2 SYSTEM RESPONSE FOR PID CONTROLLERS USING ZIEGLER-NICHOLS METHOD................................................ 75

FIGURE 5.3 SYSTEM RESPONSE FOR PID CONTROLLERS USING THE FINAL FPID CONSTANT GAINS ....................................... 76

FIGURE 5.4 SYSTEM RESPONSE FOR PID CONTROLLERS USING THE AVERAGE FPID CONSTANT GAINS .................................. 76

FIGURE 5.5 DESIRED AND ACTUAL ANGLES ACCORDING TO FPID APPROACH ................................................ 77

FIGURE 5.6 ERROR FOR EACH JOINT ACCORDING TO FPID APPROACH ........................................................... 78

FIGURE 5.7 RULE SURFACE ACCORDING TO FPID APPROACH FOR ERROR AND DERIVATIVE OF ERROR AND A)

𝐾𝐾′𝑝𝑝 B) 𝐾𝐾′𝑑𝑑 C) 𝝰𝝰 .................................................................................................................................... 78

FIGURE 5.8 BEST COST FOR DIFFERENT OPTIMIZATION METHODS IN 100 ITERATIONS ...................................................... 79

FIGURE 5.9 SYSTEM RESPONSE TO STEP INPUT 0.6 (RAD) FOR JOINT 1 .......................................................................... 80

FIGURE 5.10 SYSTEM RESPONSE TO STEP INPUT 0.7 (RAD) FOR JOINT 2 ........................................................................ 80

FIGURE 5.11 SYSTEM RESPONSE TO STEP INPUT 0.8 (RAD) FOR JOINT 3 ........................................................................ 81

FIGURE 5.12 SYSTEM RESPONSE ERROR FOR JOINT 1 ................................................................................................. 82

FIGURE 5.13 SYSTEM RESPONSE ERROR FOR JOINT 2 ................................................................................................. 82

FIGURE 5.14 SYSTEM RESPONSE ERROR FOR JOINT 3 ................................................................................................. 83

FIGURE 5.15 OPTIMIZED MEMBERSHIP FUNCTIONS FOR INPUT 1, USING A)GA B)DE C)PSO D)ICA .............. 84

FIGURE 5.16 OPTIMIZED MEMBERSHIP FUNCTIONS FOR INPUT 2, USING A)GA B)DE C)PSO D)ICA .............. 84

FIGURE 5.17 OPTIMIZED MEMBERSHIP FUNCTIONS FOR OUTPUT 3 (𝝰𝝰), USING A)GA B)DE C)PSO D)ICA..... 85

FIGURE 5.18 OPTIMIZED FUZZY RULE SURFACE FOR 𝐾𝐾′𝑝𝑝, USING A)GA B)DE C)PSO D)ICA ........................ 86

FIGURE 5.19 OPTIMIZED FUZZY RULE SURFACE FOR 𝐾𝐾′𝑑𝑑, , USING A)GA B)DE C)PSO D)ICA ...................... 86

Page 12: Fuzzy PID Controller Optimization for Robot Dynamics with ...

x

FIGURE 5.20 OPTIMIZED FUZZY RULE SURFACE FOR 𝝰𝝰, USING A)GA B)DE C)PSO D)ICA ............................ 87

FIGURE 5.21 PROPORTIONAL, INTEGRAL AND DERIVATIVE GAINS FOR EACH JOINS RESULTED FROM

DIFFERENT APPROACHES ....................................................................................................................... 88

Page 13: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xi

List of Tables

TABLE 3.1 ASSUMPTIONS FOR SIMULATED ROBOT ......................................................................................... 25

TABLE 4.1 THE EFFECT OF EACH TUNING PARAMETER ON THE CONTROLLER [2] ............................................................... 38

TABLE 4.2 FUZZY TUNING RULES FOR NORMALIZED PROPORTIONAL GAIN 𝐾𝐾′𝑝𝑝 .............................................. 44

TABLE 4.3 FUZZY TUNING RULES FOR NORMALIZED DERIVATIVE GAIN 𝐾𝐾′𝑑𝑑 .................................................. 44

TABLE 4.4 FUZZY TUNING RULES FOR 𝝰𝝰 ......................................................................................................... 45

TABLE 4.5 THE SELECTED DE PARAMETERS IN THIS STUDY ........................................................................... 51

TABLE 4.6 DOUBLE-POINTS CROSSOVER GA PARAMETERS ............................................................................ 60

TABLE 4.7 PSO PARAMETERS ........................................................................................................................ 65

TABLE 4.8 ICA SELECTED PARAMETERS ........................................................................................................ 71

TABLE 5.1 SYSTEM RESPONSE PERFORMANCE FOR DIFFERENT APPROACHES .................................................. 81

TABLE 6.1 AVERAGE CALCULATION TIME FOR EACH ITERATION .................................................................... 90

Page 14: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xii

List of Abbreviations

PID Proportional Integral Derivative

DE Differential Evolution

MIMO Multi Input Multi Output

FPID Fuzzy PID

MF Membership Function

GA Genetic Algorithm

FLC Fuzzy Logic Control

PSO Particle Swarm Optimization

ICA Imperial Competitive Algorithm

AVR Automatic Voltage Regulator

DOF Degree of Freedom

FIS Fuzzy inference System

DC Direct Current

COA Centroid of Area

BOA Bisector of Area

MOM Mean of Maximum

AGC Automatic Gain Control

ACO Ant Colony Optimization

BCO Bee Colony Optimization

HBMO Honey Bee Mating Optimization

PEM Proton-Exchange Membrane

DH Denavit-Hartenberg

Page 15: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xiii

NB Negative big

NM Negative medium

NS Negative small

PS Positive small

PM Positive medium

PB Positive big

POP Population of potential solutions

EA Evolutionary Algorithm

2D Two-dimensional

Page 16: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xiv

List of Symbols

Fuzzy and Robotics:

𝑧𝑧 Fuzzy Output

𝜇𝜇𝐴𝐴(𝑧𝑧) Aggregated fuzzy output

𝝰𝝰 𝝰𝝰 constant (ratio of integral and derivative time constant)

𝐾𝐾𝑝𝑝 Proportional gain

𝐾𝐾𝑑𝑑 Derivative gain

𝐾𝐾𝑖𝑖 Integral gain

q Joint angles vector

�̇�𝑞 Joints angular velocity vector

�̈�𝑞 Joints angular acceleration vector

𝜃𝜃 Joint angles

τ Torque

M(q) Matrix of Mass

C�q،q̇� Coriolis and centrifugal matrix

g(q) Gravity matrix

B(q) Coriolis matrix

I Moment of Inertia

Page 17: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xv

m Robot link mass

L Robot link length

r Distance of center of mass from previous joint in a link

Γ (q) Christoffel matrix

𝐽𝐽 Cost function

𝑤𝑤i Weight factor for ith phrase

PO Percentage of overshoot

𝑒𝑒𝑖𝑖 Error in ith step

𝑈𝑈𝑐𝑐(𝑠𝑠) Controller output in Laplace domain

𝐸𝐸(𝑠𝑠) Error input to the controller in Laplace domain

𝑢𝑢𝑐𝑐(𝑡𝑡) Controller output in time domain

𝑒𝑒(𝑡𝑡) Error input to the controller in time domain

𝐾𝐾𝑝𝑝′ Normalized proportional gain

𝐾𝐾𝑖𝑖′ Normalized integral gain

𝐾𝐾𝑑𝑑′ Normalized derivative gain

𝑇𝑇𝑖𝑖 Integral time constants

𝑇𝑇𝑑𝑑 Derivative time constants

𝐾𝐾𝑢𝑢 Ultimate gain

Page 18: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xvi

𝑇𝑇𝑢𝑢 Ultimate oscillation period

�̇�𝑒(t) Derivative of error in time domain

𝛼𝛼𝑛𝑛 Proportional denormalization factor

𝛽𝛽𝑛𝑛 Derivative denormalization factor

GA:

C,C' Crossover points

Np Population size in GA and DE

DE:

𝐱𝐱𝑖𝑖,𝐺𝐺 Characteristics of vector 𝑖𝑖 in generation G

F DE scaling factor

𝐶𝐶𝐶𝐶 Crossover probability

D number of dimension of parameter space

𝐯𝐯𝑖𝑖,𝐺𝐺 Mutant vector of 𝑖𝑖 in generation G

𝐶𝐶0 Base vector index

𝐶𝐶𝑖𝑖 Target vector index

𝐶𝐶1,𝐶𝐶2 Difference vector index

𝐮𝐮𝑖𝑖,𝐺𝐺 Trial vector of 𝑖𝑖 in generation G

PSO:

Page 19: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xvii

𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 𝑗𝑗th component of location vector of the 𝑖𝑖th particle in the 𝑘𝑘th

iteration

𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 𝑗𝑗th component of velocity vector of the 𝑖𝑖th particle in the 𝑘𝑘th

iteration

𝑥𝑥𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡 Best global location

𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖 Best location reached by the 𝑖𝑖th particle

𝑐𝑐1 Cognition parameter

𝑐𝑐2 Social behavior parameter

𝜒𝜒 Constriction factor

𝜑𝜑 Summation of cognition and social behavior parameters

ICA:

𝑋𝑋𝑗𝑗 Country j

𝑁𝑁𝑡𝑡𝑡𝑡𝑡𝑡 Total number of countries

𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝 Number of empires

𝑁𝑁𝑐𝑐𝑡𝑡𝑐𝑐 Number of colonies

𝐶𝐶𝑛𝑛 Imperialist’s 𝑛𝑛th normalized cost

𝑐𝑐𝑛𝑛 Imperialist’s 𝑛𝑛th cost

𝑝𝑝𝑛𝑛 Normalized power

Page 20: Fuzzy PID Controller Optimization for Robot Dynamics with ...

xviii

𝑁𝑁.𝐶𝐶.𝑛𝑛 Number of colonies dedicated to the 𝑛𝑛th imperialist

𝑑𝑑 Distance between the imperialist and the colony

𝛽𝛽 Assimilation factor (random number greater than 1)

𝑅𝑅𝑟𝑟𝑟𝑟𝑟𝑟 revolution rate

𝜉𝜉 Colonies cost factor

𝑇𝑇.𝐶𝐶𝑛𝑛 𝑛𝑛th empire’s overall cost

𝑃𝑃𝑃𝑃 Possession possibility

𝑁𝑁.𝑇𝑇.𝐶𝐶.𝑛𝑛 Total normalized cost of the 𝑛𝑛th empire

𝑃𝑃𝑝𝑝𝑛𝑛 Possession possibility of the 𝑛𝑛th empire

Page 21: Fuzzy PID Controller Optimization for Robot Dynamics with ...

1

1 INTRODUCTION

This dissertation presents a method to optimize a fuzzy PID controller for a 3-DOF robotic

arm based on the Differential Evolutionary algorithm and compares the results with three

more metaheuristic optimization methods. In robotic applications, conventional PID

controllers do not show satisfactory results. In this study, a fuzzy inference system (FIS) is

accountable for determining the appropriate values for PID gains. In order to have a FIS

with a suitable structure and reliable performance, the DE algorithm has been employed to

optimize the FIS structure by modifying the membership functions, rules, and scaling

factors.

1.1 Background and Motivation

PIDs are the most common industrial controller. More than 90 percent of closed-loop

systems in the industry still include a PID controller. [1] The PID controller has a long

history. It has been used successfully since the analog era to the current digital computer

control age. The mathematical evaluation of the performance of PID control is simply

represented by the Laplace transform of an integrator (1/s) and a differentiator (s). The PID

controller is quite versatile. As shown in Figure 1.1, there is a symbolic manifestation

(Figure 1.1(a)), in which different terms can be chosen for different control acts. In

addition, there is a time-dependent form (Figure 1.1(b)), and eventually, there is a Laplace

transform version of the PID (Figure 1.1 (c)). It provides the controller an understanding

of the s-domain operator and allows a connection between the time and the frequency to

reconcile on an efficient output for the PID controller.[2]

Page 22: Fuzzy PID Controller Optimization for Robot Dynamics with ...

2

Figure 1.1 PID controller representation [2]

Although PID controllers are widely used in industry, there are many limitations for

conventional PID controllers in case of time delays, major oscillatory behavior, change in

parameters, nonlinearity, and MIMO systems. [3].

There have been many studies to improve PID tuning in past decades. Efforts have been

made to increase the accuracy of the Ziegler-Nichols method [4, 5], resulting in the so-

called Refined Ziegler-Nichols tuning formula. Such modifications were useful only in

some aspects in a few plants and it worsened the performance of many other systems.

Even though several works have been done in tuning PID controllers, a basic issue still

exists. There are many operating limitations in actual systems, such as highly nonlinear

dynamics with unknown transfer functions that cannot be effectively controlled by

conventional PIDs. [6] Another example is the MIMO systems. Generally, MIMO

systems have more complexity and inconsistencies than SISO systems. It's hard to

implement the SISO tuning methods to MIMO systems PID controllers because of dealing

with long gain matrices. [7].

Page 23: Fuzzy PID Controller Optimization for Robot Dynamics with ...

3

When Fuzzy inference based tuning of PIDs was introduced, it led to more accurate results

[8]. Fuzzy control is an application of Fuzzy logic for complex system control. The fuzzy

logic is a classic logic extension for representation and reasoning regarding approximate

data [9] . The application of the FPID in the industry is presented in [10].

Figure 1.2 General SISO control system with a standard PID controller

Figure 1.2 and Figure 1.3 show two general systems with PID and Fuzzy PID controller,

respectively.

Figure 1.3 Control system with a fuzzy PID parameter tuner and a PID controller

Fuzzy-based PID is often inefficient because the chosen MFs, rules, and parameters for the

FLC are not optimal. Therefore, some studies have been done to guarantee this method's

accuracy. Genetic Algorithm (GA) is one of the most common methods employed to

improve FPIDs. The genetic algorithm is an evolutionary biology-inspired method for

global search and optimization. Genetic algorithm optimization for different types of MF

for the same FLC, lead to different results [11]. Different evolutionary optimization

methods have also been applied to optimize FPIDs, among them Particle Swarm

Page 24: Fuzzy PID Controller Optimization for Robot Dynamics with ...

4

Optimization (PSO) [12, 13], Cuckoo algorithm [14], Fruit fly algorithm [15], Ant Colony

[16], Bacterial Foraging [17], Grasshopper Algorithm [18], Imperialist Competitive

Algorithm Optimization [19], etc. These studies use an optimization algorithm to improve

Membership Functions or Gain parameters or rules for FLC. In this research, all mentioned

parameters are optimized using DE algorithm, and in the end, the results are compared with

the results from GA, ICA, and PSO algorithms.

Optimized FPID has been used in many applications, such as mobile robot navigation [9],

nuclear reactors [11], AVR systems [12], Load frequency control in Micro-grids [18].

1.2 Research Objectives

The researchers have proposed different control methods for a variety of different control

systems and targets. In robotic systems, FPID has many applications for building control

systems due to its ability to accuracy and simplicity. In this study, the objective is to use a

DE-optimized FPID controller for the dynamics of a three degree of freedom (3 DOF)

robot. We use the Lagrangian formulation to obtain the dynamic equation of the robotic

system. The desired angles are fed to the system as input and the PID controller provides

the plant with the required torques for each joint. A fuzzy inference system (FIS)

determines the required PID gains for the PID controller. The optimization methods find

the optimal rules, gains, and MFs for the fuzzy control systems. (Figure 1.4)

Page 25: Fuzzy PID Controller Optimization for Robot Dynamics with ...

5

Figure 1.4 Proposed control system

In each iteration, DE algorithm produce the fuzzy rules, MFs and scaling factors and feed

them to the fuzzy inference system. Fuzzy controller generate the PID gains which are fed

to the PID. Then The PID send the torque signals to the robot. The robot output which are

the actual angles along with system reference (desired angles) insert to a cost function

block and the cost for the selected fuzzy parameters are calculated and fed to the DE

algorithm. Now, next iteration starts in order to minimize the cost.

To validate our results, we optimized the same FPID system with three more optimization

methods: GA, PSO, and ICA. In the end, the results from all the four approaches are

compared.

Page 26: Fuzzy PID Controller Optimization for Robot Dynamics with ...

6

1.3 Summary

In the background and motivation section of this chapter, we first gave a brief introduction

about the PID controllers, their popularity, and their limitations. The Fuzzy PID method is

a common way to improve the PID controllers. In this section, few ways for tuning a Fuzzy

PID controller are specified, which among them DE method is applied to optimize the

FPID controller in this dissertation.

In the research objectives section, the key point of this research is briefly described. The

proposed control system demonstrated in the form of a block diagram shows how the DE

algorithm finds the optimal rules, gains, and MFs for the fuzzy controller. In each iteration,

the DE algorithm produces the fuzzy rules, MFs, and scaling factors and feed them to the

fuzzy inference system. The fuzzy system generates the PID gains, which are fed to the

PID. Then the PID sends the torque signals to the robot. The robot output along with system

reference insert to a cost function block and the cost for the selected fuzzy parameters are

calculated and fed to the DE algorithm. Now, the next iteration starts in order to minimize

the cost.

To validate our results, we optimized the same FPID system with three more optimization

methods: GA, PSO, and ICA. In the end, the results from all the four approaches are

compared.

Page 27: Fuzzy PID Controller Optimization for Robot Dynamics with ...

7

2 LITERATURE REVIEW

2.1 Introduction

Industrial robots are substituting humans in manufacturing, in order to increase

the efficiency as well as safety. Industrial robot research and development have drawn the

attention of a broad variety of academics in different countries [20]. PID is a popular

feedback control system commonly used in this industry. It measures the error between

components of the evaluated procedure and target value. The PID requires the calculation

of Proportional integral and derivative gains [21]. The PID controller tuning approaches

can be classified by design and utilization. The following classification can be:

- Analytical methods: determining PID gains are based on the plant model and the

objective.

- Heuristic methods: these methods develop from operational knowledge of manual

tuning i.e. methods based on fuzzy logic.

- Frequency response methods: It was introduced by Astrom in the early 1980s and

was later developed by other scholars. These methods are based on analyzing the frequency

response features of the control system. Transient response methods: these methods are

based on analyzing the effect of a deliberately applied disturbance on the control system.

- Optimization Methods: PID parameters are obtained, using different optimization

methods. This may be viewed as a specific form of optimal control.

- Adaptive tuning methods: These techniques are based on real-time recognition for

automated online tuning, using one or a variety of the previous approaches [22].

Page 28: Fuzzy PID Controller Optimization for Robot Dynamics with ...

8

Among all these methods fuzzy logic based PID controller (FPID) is improved in order to

provide promising results as an experienced human operator tune the gains manually while

the process is running.

In this chapter, we review the historical evolving of the FPID controllers and also the

employed optimization technique that has been used in order to obtain results that are more

accurate.

2.2 PID Control for Linear and Non-Linear Systems

A Proportional-Integral-Derivative (PID) controller is a three-term controller that has a

history as long as a century in the automatic control area. Being simple and user-friendly,

and efficient in a variety of applications, made it the regular controller in industrial

environments, [23].

Nicholas Minorsky offered a straightforward method to use in position control systems in

1922; and proposed a control law that we now call three-term or PID control. His method

was only popular among researchers after Minorsky contributed several papers in late

1930s, [24]. In 1934, Challender established the first controller's parameters tuning law.

His solution involves implementing a proportional-derivative (PD) controller for a system

modeled with an integrator plus delay time, [25]. In 1942 and 1943, J.G. Ziegler and N.B.

published two articles and demonstrated how to pick optimum parameters for PID

controllers based on the plant open-loop and closed-loop tests. Although a number of other

researchers, [26], [27], [28], [29], introduced different tuning methods, Ziegler-Nichols

method continued to be used for decades, [30].

Page 29: Fuzzy PID Controller Optimization for Robot Dynamics with ...

9

Although, PID controllers are a good choice for a simple, linear process with no time-delay,

they fail to deliver accurate results in case of strong non-linearity or when a time-delay

exists. In order to strengthen PIDs to deal with these challenges; several researchers has

proposed modified methods. PID auto-tuning approaches were developed to enhance the

performance of the PID controller and to efficiently tune the PID controllers. For instance,

the original relay feedback identification approach was presented by Astrom and Hagglund

in 1984; since then, several modified relay feedback approaches have been suggested and

even extended to many industrial processes, [31]. Afterwards, Gain Scheduling control was

designed to be applied to nonlinear structures. The idea is to design local controllers to

regulate a global controller. The main aspect is that the parameter-dependent or nonlinear

time-varying process is controlled by using a linear control method, [32].

Other techniques, which have been used for tuning, involve Evolutionary algorithms such

as Ant Colony, Genetic Algorithm, Differential Evolution, etc, Artificial Neural Network,

Fuzzy Logic. The theoretical foundation, in particular for non-linear systems, for PID

control itself is still limited. For example, the optimality of PID control, PID control

performance tuning rules, automated performance tuning procedure, and the PID state

observer have not been precisely studied, [33].

2.3 Fuzzy Control

Fuzzy control is based on fuzzy set theory, which was mathematically first proposed by

Lotfi Zadeh in 1965 [34]. Zadeh introduced fuzzy control theory [35 43] in 1972. It is not

easy to categorize the different type of fuzzy logic control methods since there have been

many approaches that can be unique in the way that they implement different intelligent

Page 30: Fuzzy PID Controller Optimization for Robot Dynamics with ...

10

methods. Nevertheless, some scholars suggested the following categories for Fuzzy Logic

Controls: 1- Traditional Fuzzy Control; 2- Fuzzy PID Control; 3- Neuro-Fuzzy Control; 4-

Fuzzy-Sliding Control Mode; 5- Adaptive Fuzzy Control; and 5- Takagi–Sugeno (T–S)

Model-based Fuzzy control. However, there is a strong possibility of overlapping in this

classification. [36] In this chapter, we mainly review studies about the first and second type

of Fuzzy Logic Control.

2.3.1 Conventional Fuzzy Control

In the 1970s, Mamdani introduced linguistic synthetic in fuzzy control and showed that it

can be far better than expected with an experiment on a laboratory-built steam engine [37]

[38] [39]. In his approach, the fuzzy rules were set to improve according to its previous

behavior. Later in 1981, Holmblad and Ostergaard [40] carried out the first industrial

application of fuzzy controllers. Based on their successful experiment of fuzzy control on

a real cement kiln, they concluded that fuzzy control is a permissible and efficient approach

to control the industrial systems.

Li and Lau [41] investigated the idea of implementing fuzzy algorithms to a servomotor

controller based on microcontrollers, and compared the results with PID control, and model

reference adaptive control in terms of steady-state error, settling time and response time.

To reduce the settling time they presented a coarse-and-fine tuning method for the servo

system. They quantized their two look-up tables to control the plant based on the magnitude

of errors.

Smith and Comer [42] proposed a method to automatically fine-tune the output function

parameters of a fuzzy logic controller based on the idea of cell mapping introduced by Hsu

Page 31: Fuzzy PID Controller Optimization for Robot Dynamics with ...

11

[43]. Modification of the Output function parameter is achieved by applying an algorithm

to evaluate the error gradient. An optimal control table is generated with the optimal

control algorithm. The gradient descent algorithm uses the optimal control table to define

the values of the parameters for the output function.

Flores et al. [44] proposed predictive controller for a solar power plant based on the Fuzzy

optimization framework. Kwok et al. [45] designed a hybrid knowledge-and-model-based

advisory system for intensive care ventilation. It consisted of a high-level Fuzzy rule-based

module to provide qualitative aspect of the output, and a lower-level model-based module

to provide the quantitative aspect of the output. They used real patient data to validate the

module. Abaspour et al. [46] used fuzzy logic in dynamic inversion flight controller. They

obtained optimal value for dynamic inversion gains to improve the performance of the

controller. Aoul et al. [47]proposed a fuzzy control algorithm to improve TCP/IP networks

performance. Conventional Fuzzy Control has a simple structure and easy to design,

therefore, it is by far the most commonly deployed Fuzzy Controller in industry. This

approach has also been widely used in robotics. Some examples in this field are discussed

in section 2.3.

2.3.2 Fuzzy PID Control

Fuzzy PID control has been used with different interpretations. Figure 2.1 shows the

classification of FPID controllers. Generally, if a fuzzy controller is built to trigger control

behavior through PID concepts similar to the traditional PID controller, then it is identified

as the "direct-action" FPID because the inference system directly generates the plant’s

input. The controller developed by Mamdani and Assilian [37], is an FPID of this kind.

Page 32: Fuzzy PID Controller Optimization for Robot Dynamics with ...

12

Traditional controllers are based on open-loop mathematical models in control systems.

The aim of the feedback controller is to minimize the error which is the difference between

output and the setpoint (reference input). In a Fuzzy logic controller (FLC), the dynamic

nature of a fuzzy system is described by a collection of linguistic rules identified by expert

knowledge. These rules are fed to FLC, typically in form of IF-THEN rules referred as

fuzzy conditional statements.

J. Lee proposed two forms of fuzzy logic controllers to improve the weaknesses of the

fuzzy PI controller particularly when applied to high-order systems. The proposed

controller's architecture was inspired by the problems of fuzzy PI controllers that usually

provide eventual overshooting when attempting to minimize response time, particularly

when contemplating a system of order greater than one. The fuzzy controllers they used

removed integrated quantities. One controller calculates the fuzzy resetting rate by

error and error derivative and the other by error and control input. The two systems reduced

rise time and overshoot. They used this method for structures, which are difficult to obtain

satisfactory response by traditional fuzzy PI controllers.

Han-Xiong Li [48] suggested a method for modelling and tuning traditional Fuzzy Logic

Controller (FLC) scaling factors based on their well-tuned PID equivalent. The traditional

FLC is quite similar to its linear PID equivalent. Likewise, the three-term fuzzy controller

has fuzzy proportional, integral and derivative gains. He introduced a new concept of

“fuzzy transfer function” to relate the fuzzy gains with the corresponding scaling factors.

Shi-Zhong He et al. [8] used Ziegler-Nicholas method [4] [5] and suggested a

parametrization of PID gains by a single variable 𝝰𝝰. Zhao et al. [49] used the

parametrization only for integral gain, 𝐾𝐾𝑖𝑖. They proposed an integral gain according to 𝐾𝐾𝑝𝑝,

Page 33: Fuzzy PID Controller Optimization for Robot Dynamics with ...

13

𝐾𝐾𝑑𝑑 and variable 𝝰𝝰. Due to the promising result, in this research, our FPID is based on this

method.

Mann et al. [50] proposed a two-level tuning method; a low level tuning followed by high

level tuning. In the higher level, they performed a nonlinear tuning to evaluate the nonlinear

properties of the fuzzy output. In the lower stage, they applied a linear tuning to assess the

linear characteristics of the fuzzy output to obtain complete fuzzy control performance. So,

they considered various fuzzy structures and simplified them for two-point control. They

built non-linearity tuning diagrams to conduct high-level tuning. They derived the linear

tuning parameters from the traditional PID tuning.

The Fuzzy PID controller used in this dissertation is based on the gain scheduling approach,

while with combination of metaheuristic optimization methods, it also can be considered

as a Hybrid Fuzzy PID controller.

Figure 2.1 Classification of Fuzzy controllers

2.4 Fuzzy Control and Robotics

The idea of using fuzzy logic in robotic systems was proposed in 1973 [51], but the fuzzy

control application in robotics was not truly considered until the 1980s. Mandic et al. [52]

Page 34: Fuzzy PID Controller Optimization for Robot Dynamics with ...

14

practically applied a fuzzy rule-based controller on a robotic arm’s dynamics. They

presented a two-tiered Self-Organizing Controller (SOC). The lower level was a one-stage

fuzzy production rule structure, while the higher level was the automated learning

mechanism that involves both the establishment of rules and the improvement of rules.

Their proposed architecture was a knowledge-based system capable of learning as well as

showing a nonlinear variable input/output relation. Under similar conditions, the self-

organizing controller performed better than a standard PID controller.

Tanscheit and Scharf [53] also used a fuzzy rule-based Self-Organizing Controller for

robotics applications. They investigated the performance of the SOC for both step inputs

and waveform inputs with regarding the effect of process noise. Their results showed that

SOC performs slightly better than PID controller.

Suzuki studied the self-tuning fuzzy control on a mobile robot. Lakov [54] and Murakami

et al. [55] presented a fuzzy-based strategy for controlling arc welding industrial robots.

Takeuchi [56] used fuzzy control for obstacle avoidance in a mobile robot.

Moudgal et al. [57] designed, applied, and examined a fuzzy controller for a two-link

flexible robotic arm and showed that variations in payload may have negative effects on

the output of a well-designed fuzzy control system. They also showed how to create and

incorporate a 'Fuzzy Model Reference Learning Controller' for the flexible robot. Their

automatically created rule-base for a Fuzzy Controller had comparative efficiency to the

case where the controller was manually designed. They also presented a method to modify

the Fuzzy Controller automatically so that it can adjust to payload variations.

Page 35: Fuzzy PID Controller Optimization for Robot Dynamics with ...

15

2.4.1 Fuzzy PID Control and Robotics

The widespread usage of PID control has inspired and supported research to extract the

maximum efficiency from PID controllers. The hunt is on to discover the best PID tuning

technique [58]. Accordingly, to achieve a better performance than a traditional PID

controller, one promising approach is to merge FLC with the standard PID controller.

Fuzzy PID controller design is still a challenging job considering the fact that a vast number

of parameters are engaged in determining the fuzzy rule base and MFs. Lemke et al. [59]

suggested Fuzzy supervisor for conventional PID controllers in 1985. Tzafestas et al.

deployed the classical Ziegler-Nicolas [4, 5] tuning techniques and Macvicar-Whelan [60]

fuzzy matrix and proposed his incremental fuzzy expert PID control. Kwok et al. [61]

suggested combining fuzzy PD and Fuzzy I controllers individually.

Using fuzzy logic, Kumbla and Jamshidi [62] applied a two-level control on a two-link

robotic manipulator. They regarded the kinematic aspect of control as the supervisory mode

on the higher level, and considered the joint control on the lower level. Rules based on

Fuzzy logic specified the inverse kinematic mapping that converts the Cartesian

coordinates to the individual joint angles. They implemented the fuzzy PD controller on a

Rhino robot and compared the output to a standard PD controller. The Fuzzy PD controller

provided improved performance over a standard PD controller.

Malki et al. [63] used FPID control for a flexible-joint robot arm with time-varying load

uncertainties. Carvaja et al. [64] evaluated the performance and analyzed the plant’s

stability for FPID control. Khoury et al. [65] used an FPID controller for a 5 DOF robot.

Page 36: Fuzzy PID Controller Optimization for Robot Dynamics with ...

16

Kumar et al. improved an FPID controller for a redundant robotic manipulator. Fu et al.

[66] studied FPID control for pneumatic driven surgical robots.

2.5 Fuzzy PID Optimization and Metaheuristic Methods

In any field, when the job is to minimize an error, minimize costs, or maximize the benefits,

we face an optimization problem. Although there are many popular optimization problems

with effective proposed solutions, no efficient solution is possible for many other problems

and metaheuristics methods such as GA are the most suitable for them. Metaheuristic and

evolutionary algorithms can be useful in a large variety of situations because these

strategies are not dependent on a specific problem. They have a repetitive algorithm, which

is only terminated when it reaches a result with specific accuracy or due to the number of

iterations. Both algorithms start with the initial population and the goal is to find the most

suitable decision variables where the objective function is optimized [67].

Wang et al. [68] optimized the rule matrix for an FPID controller based on a simple GA

optimization. They applied their simulation to an experimental heating process. Zhou et

al. [69] used simulation annealing optimization method for a fuzzy logic-based PID auto-

tuner. Tang et al. [70] used multi-objective genetic algorithm to optimize a PI+D controller

for a solar plant model. Ghoshal et. al [71] used PSO to optimize FPID gains in multi-area

thermal generating plant. Pradhan et al. [72] optimized a fuzzy PID controller for an AGC

multi-area multi-source power system using firefly algorithm. In recent years some

metaheuristic algorithms such as DE, ICA, Ant colony optimization (ACO), bee colony

optimization (BCO), honey bee mating optimization (HBMO), cuckoo search, bat

Page 37: Fuzzy PID Controller Optimization for Robot Dynamics with ...

17

algorithm, etc. have been used in order to use for optimizing the Fuzzy logic based PID

controllers [14, 16, 73-77].

2.6 A Brief Review of Differential Evolution

Ken Price and Rainer Storn introduced Differential Evolution (DE) in a series of articles

in the 1990s [78-81]. Afterward, it attracted lots of attention among scholars and lots of

research were carried out based on DE. Daniela Zaharie [82] suggested a formula to confine

the minimum value for mutation scale factor. Consequently, several researchers developed

their own modifications of DE. [83-88] Although using these representations showed

promising results in their own studies, they mainly lack generality and are not as useful in

other problems [89].

Using DE for optimizing FPID controllers is only a recent research interest for academics.

Jingcheng et al. [90] used DE-optimized FPID to control the speed of a steam turbine

governing system. Their study indicated that the controller overall performance such as

overshoot, robustness, and response time are far better with using this method compared

with conventional FPID controllers. Sahu et al. [73] applied DE on FPID controller with a

derivative filter to control the load frequency of a deregulated power system. Their results

showed that settling time, peak overshoot, and peak undershoot of the system has been

notably improved with their technique. It also demonstrated that when the loading

condition is under wide variations, the controller keeps its robustness and satisfactory

performance. Beirami et al. [91] optimized a PEM fuel cell air feed system controller by

the use of DE.

Page 38: Fuzzy PID Controller Optimization for Robot Dynamics with ...

18

Although, there has been some research on DE applications, very few of them have been

focused on DE applications in FPID improvement and even in the case of FPID for robotic

arm, there has been no significant study.

2.7 Summary

This chapter presents a brief review on fuzzy control systems applications mainly related

to robotics and metaheuristic optimization particularly the Differential Evolution method.

The particular attention is given to fuzzy PID controllers which are well-known for their

good performance in nonlinear applications. We presented a common classification of

different fuzzy control methods and reviewed the most common types: 1- Conventional

Fuzzy Control 2- Fuzzy PID Control. To show the broad range of applications of fuzzy

control, we used examples in various fields in this review, among them telecommunication,

process, environment, medical, aerospace, mechanical engineering, and robotics.

Later in this chapter, we briefly reviewed some research using different metaheuristic

methods to optimize Fuzzy PID controllers. The presented studies, attempts to improve the

performance of Fuzzy PID controllers by modifying different parts of the fuzzy logic

inference structures, namely Membership functions, rule base or scaling factors. Then, in

the last section, most significant research specifically applying Differential Evolution

algorithm on FPID controllers has been reviewed.

Page 39: Fuzzy PID Controller Optimization for Robot Dynamics with ...

19

3 DYNAMICS OF A ROBOT ARM

3.1 Introduction

In most fields of science, such as engineering, mathematics, physics, chemistry,

agriculture, problems are in the nature of decision-making. In these problems, there is a

continuous or discrete set of solutions. Decision-making intends to choose the best option

according to a set of optimization goals. In order to find the best solution for a decision-

making problem, a set of calculations can be carried out using mathematical equations and

computer algorithms. Due to the overwhelming complexity of most of the real-world

issues, many calculations would be needed to solve the problem.

When the robot manipulator stays in a position, a set of dynamic constraints are created in

the robot. These constraints lead to nonlinear and coupled movements between any two

links. Therefore, in order to design a suitable controller, we first need to analyze the

dynamics of the robot arm.

The direct kinematic is used to obtain the position and the orientation of the end effector,

using the fixed and variable parameters of the robot. In other words, in direct kinematics

features and geometrical variables of robot arm like the dimensions and angles of robot

arm's links are assumed to be known and the objective is to find the final location and

orientation of the end effector with regard to these data.

One of the transformations that define the frame of i based on frame i-1, is a Denavit-

Hartenberg (DH) transformation. By calculating the positions and orientations in one frame

related to their neighboring frame, finally the end effectors position and orientation related

to the origin is calculated.

Page 40: Fuzzy PID Controller Optimization for Robot Dynamics with ...

20

A more important subject in robotics is inverse kinematics. The inverse kinematic helps to

calculate the angles of each joint with knowing the position and orientation of the tool

frame relative to the station frame. To determine the angles of each joint in the robotic arm,

first, the equivalent transform matrix is calculated, and then the inverse kinematic is used

to find appropriate angles.

There have been many studies on the dynamics of mechanisms. Some methods have a

better application in robotics, particularly the methods in which the robot arm is considered

as a chained series. In this chapter, the dynamic equations of robot arms are expressed

using Lagrange approach.

There are two main methods for solving the mechanical arms equations, the closed-form

solution method, and the numerical solution method. In the numerical methods, the

operations are repeated until the error is minimized, but closed-form solution methods are

based on solving a fourth-degree or less polynomial. Therefore, in general, the numerical

methods are slower than the closed-form solution methods. Hence, the closed-form method

is widely used for solving kinematic equations.

3.2 A Review of Robot Kinematics

Although in this study, only the kinetic formulation of the robot is required to design the

controller, having a brief introduction about the kinematics of the robots helps to

understand the idea. The kinematics studies motion regardless of forces. In the robot arms,

kinematic equations are used to express the position and direction of the end-effector as a

function of the displacement of the joints. However, the inverse kinematics is used to

determine the displacements of the joints that lead the end effector to a certain location

Page 41: Fuzzy PID Controller Optimization for Robot Dynamics with ...

21

with a specific orientation. The kinematics of a mechanical arm include all geometrical

characteristics and time-dependent motions. Studying the relation between the motion and

forces and moments that create this motion, is called dynamics.

We want to create a transformation that defines frame i relative to frame i-1. This

transformation would depend on four parameters. These parameters consist of one variable,

with the other three being determined by robot structure. We split the kinematics problem

into 𝑛𝑛 minor sub-problems.

To explain each link's position relative to its neighbors, we define a frame connected to

each link. The frames are called by the number the link they are connected to. therefore,

frame i is connected to link i. The frame attached to the robot base, or link 0 is called frame

0. It is a fixed frame and is regarded as the reference frame for the arm kinematics problem.

Figure 3.1 demonstrates a pair of sample joints with three attached frames P, Q and R. Only

the X and Z axis are shown for simplification. Frame R differs only by a rotation of "𝛼𝛼𝑖𝑖−1"

from frame i-1. Frame Q is generated by adding a translation "𝑎𝑎𝑖𝑖−1" to frame R. Frame P

is created from Frame Q and rotation "𝜃𝜃𝑖𝑖", and Frame i distinguish from Frame P with an

additional translation "𝑑𝑑𝑖𝑖".

Page 42: Fuzzy PID Controller Optimization for Robot Dynamics with ...

22

Figure 3.1 Frame P, Q and R demonstration on a robot link [92]

𝑃𝑃0𝑖𝑖−1 = 𝑇𝑇𝑅𝑅𝑖𝑖−1 𝑇𝑇𝑄𝑄𝑅𝑅 𝑇𝑇𝑃𝑃𝑄𝑄 𝑇𝑇𝑖𝑖𝑃𝑃 𝑇𝑇𝑖𝑖 𝑃𝑃 (3.1)

Or

𝑃𝑃0𝑖𝑖−1 = 𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖 𝑃𝑃 (3.2)

Where

𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖 = 𝑇𝑇𝑅𝑅𝑖𝑖−1 𝑇𝑇𝑄𝑄𝑅𝑅 𝑇𝑇𝑃𝑃𝑄𝑄 𝑇𝑇𝑖𝑖𝑃𝑃

(3.3)

Considering the previously defined parameter alternative denotation of above formula is:

𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖 = 𝑅𝑅𝑋𝑋(𝛼𝛼𝑖𝑖−1) 𝐷𝐷𝑋𝑋(𝑎𝑎𝑖𝑖−1) 𝑅𝑅𝑍𝑍(𝜃𝜃𝑖𝑖) 𝐷𝐷𝑍𝑍(𝑑𝑑𝑖𝑖) (3.4)

Or

𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖 = 𝑆𝑆𝑐𝑐𝐶𝐶𝑒𝑒𝑤𝑤𝑋𝑋(𝑎𝑎𝑖𝑖−1,𝛼𝛼𝑖𝑖−1) 𝑆𝑆𝑐𝑐𝐶𝐶𝑒𝑒𝑤𝑤𝑍𝑍(𝑑𝑑𝑖𝑖,𝜃𝜃𝑖𝑖) (3.5)

Where the term 𝑆𝑆𝑐𝑐𝐶𝐶𝑒𝑒𝑤𝑤𝑄𝑄(𝐶𝐶,𝜑𝜑) describes a combination of a translation along the axis 𝑄𝑄

by the distance 𝐶𝐶, and a rotation along the same axis by an angle 𝜑𝜑, the general structure

of 𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖is as follows:

Page 43: Fuzzy PID Controller Optimization for Robot Dynamics with ...

23

𝑇𝑇𝑖𝑖𝑖𝑖−1 𝑖𝑖 = �

𝑐𝑐𝜃𝜃𝑖𝑖 −𝑠𝑠𝜃𝜃𝑖𝑖 0 𝑎𝑎𝑖𝑖−1𝑠𝑠𝜃𝜃𝑖𝑖𝑐𝑐𝛼𝛼𝑖𝑖−1 𝑐𝑐𝜃𝜃𝑖𝑖𝑐𝑐𝛼𝛼𝑖𝑖−1 −𝑠𝑠𝛼𝛼𝑖𝑖−1 −𝑠𝑠𝛼𝛼𝑖𝑖−1𝑑𝑑𝑖𝑖𝑠𝑠𝜃𝜃𝑖𝑖𝑠𝑠𝛼𝛼𝑖𝑖−1 𝑐𝑐𝜃𝜃𝑖𝑖𝑠𝑠𝛼𝛼𝑖𝑖−1 𝑐𝑐𝛼𝛼𝑖𝑖−1 𝑐𝑐𝛼𝛼𝑖𝑖−1𝑑𝑑𝑖𝑖

0 0 0 1

(3.6)

Where, 𝑐𝑐𝜃𝜃𝑖𝑖 is cos (𝜃𝜃𝑖𝑖) and 𝑠𝑠𝜃𝜃𝑖𝑖 refers to sin (𝜃𝜃𝑖𝑖).

3.3 Kinetics of the Robot Arm

In most cases, the expression of a robot arm’s dynamics is summarized and the details are

omitted. When the Lagrange equation is utilized for a robot arm, the dynamic equation can

be written as:

τ = M(q)q̈ + C�q،q̇�q̇ + g(q) (3.7)

In the above-mentioned equation, τ is the vector of joint torques, M(q) is the n×n mass

matrix for the robot arm, C(q،q̇) is an n×1 vector which consists of the terms related to

Coriolis and centrifugal forces and g (q) is an n×1 vector indicating the gravity forces. It is

a space state equation because C(q،q̇) depends on both position and velocity. Each element

in M(q) and g(q) is a complicated function and dependent on the q which is the joints angles

vector in the robot arm. Each element in C(q،q̇) is a complicated function of q and q̇. We

can separate the various types of expressions generated in the dynamic equations and form

the mass matrix, the centrifugal and Coriolis vector, and the vector of gravity. Therefore,

the new equation can be written as:

τ = M(q)q̈ + B(q)[q̇q̇] + C(q)[q̇2] + g(q) (3.8)

Where B(q) is an n × n(n − 1)/2 Coriolis matrix and [q̇q̇] is an n(n − 1)/2 × 1 vector

resulted from the product of the joint velocities as given in following:

Page 44: Fuzzy PID Controller Optimization for Robot Dynamics with ...

24

[q̇q̇] = [q̇1q̇2q̇2q̇3 … q̇n−1q̇n] (3.9)

Also, C(q) is an n × n matrix of the centrifugal terms and [q̇2] is an n × 1 vector as follows:

[q̇12q̇22 … q̇n2 ]T (3.10)

Equation 3.8 is called the configuration-space equation because its matrices are just

function of the location of the robot joint. In this way of presenting dynamic equations, the

complexity of computation appears in various parameters that are a function of the location

of the robot joints (q). [92]

The robotic arm in this research consists of three series links moving in a zero-gravity two-

dimensional space. It has a fixed base and contains the three joints with one degree of

freedom. All friction force is neglected in this study. The configuration of the robot is

shown in Figure 3.2.

Figure 3.2 configuration of the three DOF robot [93]

In this system, the arms and the body form a closed-chain mechanism. Table 3.1 shows the

assumptions for the robot.

Page 45: Fuzzy PID Controller Optimization for Robot Dynamics with ...

25

Table 3.1 Assumptions for simulated robot

I (kg.m2) m (kg) l (m) r (m) Link 1 0.3 1 0.1 0.02 Link 2 0.3 1 0.1 0.02 Link 3 0.3 1 0.1 0.02

The matrix of Coriolis and centrifugal forces has the following relation:

𝐶𝐶(q, q̇) = Γ (q)q̇ (3.11)

Where, Γ (q) is called Christoffel Matrix, and later, we will see how the elements of this

matrix would be calculated.

Regarding the above-mentioned equations and assumptions, with neglecting the gravity

force, the plant’s dynamic equations can be written as follows:

𝑀𝑀(q)q̈ + q̇𝑇𝑇 Γ (q)q̇ = 𝜏𝜏 (3.12) Where:

𝑀𝑀 = �

𝑀𝑀11 𝑀𝑀12 𝑀𝑀13𝑀𝑀21 𝑀𝑀22 𝑀𝑀23𝑀𝑀31 𝑀𝑀32 𝑀𝑀33

(3.13)

𝑀𝑀11 = 𝐼𝐼1 + 𝐼𝐼2 + 𝐼𝐼3 + 𝑚𝑚1𝐶𝐶12 + 𝑚𝑚2𝑙𝑙12 + 𝑚𝑚2𝐶𝐶22 + 𝑚𝑚3𝑙𝑙1

2 + 𝑚𝑚3𝑙𝑙2

2 + 𝑚𝑚3𝐶𝐶32 + 2𝑚𝑚2𝑙𝑙1𝐶𝐶2 cos 𝜃𝜃2 + 2𝑚𝑚3𝑙𝑙1𝑙𝑙2 cos 𝜃𝜃2 + 2𝑚𝑚3𝐶𝐶3𝑙𝑙2 cos 𝜃𝜃3 + 2𝑚𝑚3𝑙𝑙1𝐶𝐶3 cos(𝜃𝜃2 + 𝜃𝜃3)

(3.14)

𝑀𝑀12 = 𝑀𝑀21 = 𝐼𝐼2 + 𝐼𝐼3 + 𝑚𝑚2𝐶𝐶22 + 𝑚𝑚3𝑙𝑙22 + 𝑚𝑚3𝐶𝐶32

+𝑚𝑚2𝑙𝑙1𝐶𝐶2 cos𝜃𝜃2 + 𝑚𝑚3𝑙𝑙1𝑙𝑙2 cos 𝜃𝜃2 + 2𝑚𝑚3𝐶𝐶3𝑙𝑙2 cos𝜃𝜃3 + 𝑚𝑚3𝑙𝑙1𝐶𝐶3 cos(𝜃𝜃2 + 𝜃𝜃3)

(3.15)

𝑀𝑀13 = 𝑀𝑀31 = 𝐼𝐼3 + 𝑚𝑚3𝐶𝐶32 + 𝑚𝑚2𝑙𝑙1𝐶𝐶2 cos 𝜃𝜃2 + 2𝑚𝑚3𝐶𝐶3𝑙𝑙2 cos 𝜃𝜃3 + 𝑚𝑚3𝑙𝑙1𝐶𝐶3 cos(𝜃𝜃2 + 𝜃𝜃3)

(3.16)

𝑀𝑀22 = 𝐼𝐼2 + 𝐼𝐼3 + 𝑚𝑚2𝐶𝐶22 + 𝑚𝑚3𝑙𝑙22 + 𝑚𝑚3𝐶𝐶32

+ 2𝑚𝑚3𝑙𝑙2𝐶𝐶3 cos(𝜃𝜃3)

(3.17)

𝑀𝑀23 = 𝑀𝑀32 = 𝐼𝐼3 + 𝑚𝑚3𝐶𝐶32 + 𝑚𝑚3𝑙𝑙2𝐶𝐶3 cos(𝜃𝜃3)

(3.18)

𝑀𝑀33 = 𝐼𝐼3 + 𝑚𝑚3𝐶𝐶32

(3.19)

Page 46: Fuzzy PID Controller Optimization for Robot Dynamics with ...

26

Where, 𝑚𝑚𝑖𝑖 is the mass of link 𝑖𝑖, 𝑙𝑙𝑖𝑖 is the length of link 𝑖𝑖, 𝐶𝐶𝑖𝑖 is the distance of joint 𝑖𝑖 to the

center of mass in link 𝑖𝑖 and 𝐼𝐼𝑖𝑖 is the inertia of link 𝑖𝑖 about its center of mass.

Γ is a 3×3×3 matrix of Christoffel symbols, and in this problem the components are as

follows:

Γ111 = Γ212 = Γ221 = Γ222 = Γ313 = Γ331 = Γ323 =Γ332 = Γ333 = 0 (3.20)

Γ112 = Γ121 = Γ122 = −𝑚𝑚2𝑙𝑙1𝐶𝐶2 sin𝜃𝜃2 − 𝑚𝑚3𝑙𝑙1𝑙𝑙2 sin𝜃𝜃2 −𝑚𝑚3𝑙𝑙1𝐶𝐶3 sin(𝜃𝜃2 −𝜃𝜃3) (3.21)

Γ113 = Γ131 = Γ123 = Γ132 = Γ133 = −𝑚𝑚3𝐶𝐶3𝑙𝑙2 sin𝜃𝜃3 −𝑚𝑚3𝑙𝑙1𝐶𝐶3 sin(𝜃𝜃2 −𝜃𝜃3) (3.22)

𝛤𝛤211 = 𝑚𝑚3𝑙𝑙1𝑙𝑙2 𝑠𝑠𝑖𝑖𝑛𝑛 𝜃𝜃2 + 𝑚𝑚2𝑙𝑙1𝐶𝐶2 𝑠𝑠𝑖𝑖𝑛𝑛 𝜃𝜃2 +𝑚𝑚3𝑙𝑙1𝐶𝐶3 𝑠𝑠𝑖𝑖𝑛𝑛(𝜃𝜃2 −𝜃𝜃3) (3.23)

Γ213 = Γ231 = Γ223 = Γ232 = Γ233 = −𝑚𝑚3𝑙𝑙2𝐶𝐶3 sin𝜃𝜃3)

(3.24)

Γ311 = 𝑚𝑚3𝐶𝐶3𝑙𝑙2 sin𝜃𝜃3 + 𝑚𝑚3𝑙𝑙1𝐶𝐶3 sin(𝜃𝜃2 −𝜃𝜃3)

(3.25)

Γ312 = Γ321 = Γ323 = Γ332 = 𝑚𝑚3𝐶𝐶3𝑙𝑙2 sin𝜃𝜃3

(3.26)

By considering the Coriolis matrix as per (3.11) we have:

𝑀𝑀(q)q̈ + 𝐶𝐶(q, q̇) q̇ = 𝜏𝜏 (3.27)

Where the C matrix can be written as: [93]

C= �Γ111�̇�𝜃1+Γ112�̇�𝜃2 + Γ113�̇�𝜃3 Γ121�̇�𝜃1+Γ122�̇�𝜃1 + Γ123�̇�𝜃1 Γ131�̇�𝜃1+Γ132�̇�𝜃1 + Γ133�̇�𝜃1Γ211�̇�𝜃1+Γ212�̇�𝜃2 + Γ213�̇�𝜃3 Γ221�̇�𝜃1+Γ222�̇�𝜃1 + Γ223�̇�𝜃1 Γ231�̇�𝜃1+Γ232�̇�𝜃1 + Γ233�̇�𝜃1Γ311�̇�𝜃1+Γ312�̇�𝜃2 + Γ313�̇�𝜃3 Γ321�̇�𝜃1+Γ322�̇�𝜃1 + Γ323�̇�𝜃1 Γ331�̇�𝜃1+Γ332�̇�𝜃1 + Γ333�̇�𝜃1

� (3.28)

Page 47: Fuzzy PID Controller Optimization for Robot Dynamics with ...

27

3.4 Summary

In this chapter, the dynamic equations of robot arms are expressed using Lagrange

approach. Although in this dissertation, only the kinetic formulation of the robot is

required, a brief introduction of the kinematics of the robots is presented to help

understanding the subject. In Lagrange formulation for robot dynamics vector of joint

torques, depends on mass matrix of the robot arm, gravity forces, and Coriolis and

centrifugal forces. In this formulation, all parameters are a function of the location, velocity

and acceleration of the robot joints (q, q̇, q̈). The robotic arm in this research consists of

three series links moving in a zero-gravity two-dimensional space. It has a fixed base and

contains the three joints with one degree of freedom and the arms and the body form a

closed-chain mechanism. All friction force is neglected in this study. The equation can be

summarized as follow:

𝑀𝑀(q)q̈ + 𝐶𝐶(q, q̇) q̇ = 𝜏𝜏 (3.29)

Where the mass matric (M) is known from robot characteristics and C matrix is calculated

according to equations 3.20 to 3.26 and 3.28. As you can see this is a nonlinear equation.

Page 48: Fuzzy PID Controller Optimization for Robot Dynamics with ...

28

4 FUZZY PID CONTROLLER DESIGN AND OPTIMIZATION

4.1 Introduction

Although there have been many studies about the FPID controllers, it is too soon to say an

optimal fuzzy controller has been introduced. There are several parameters that affect the

performance of the FPID controller and in order to get the optimal result for each system,

all these parameters must be taken into account, but each research investigates the optimal

solution regarding a few of these items.

The approach suggested in this study involves the following steps:

1- Cost Function design

2- Initial Fuzzy PID controller design

3- Design of the fuzzy parameters needed to be adjusted. (Rules, MFs, fuzzy output

scaling factors)

4- Fuzzy PID parameter optimization

5- Results evaluation

4.2 Cost Function

One important category of automatic control theory is optimization. The objective of

optimization in control is to determine an optimal control input u(t) at a given time frame

in order to minimize the cost function [94].

By calculating a cost function, the new optimal Fuzzy PID parameters are acquired. The

cost function determine how high the cost would be when the system runs for a given

period of time t. The cost may be energy, time, or some other target. The cost functions

Page 49: Fuzzy PID Controller Optimization for Robot Dynamics with ...

29

used for regulation of PID are integral of absolute error (IAE). In this study, we used the

discrete form of IAE with 0.01 second intervals.

𝐼𝐼𝐼𝐼𝐸𝐸 = � |𝑒𝑒𝑖𝑖|

𝑡𝑡

0

(4.1)

In this study, the cost function is a weighted summation of errors and overshoots as

described in Equation (4.2) for the first 8 seconds of the simulation.

𝐽𝐽(𝑋𝑋) = 𝑤𝑤1� 𝑖𝑖

𝑗𝑗=1� �𝑒𝑒𝑖𝑖𝑗𝑗� + 𝑤𝑤2�

𝑖𝑖

𝑗𝑗=1𝑃𝑃𝑃𝑃𝑗𝑗

𝑛𝑛

𝑖𝑖=1

(4.2)

𝑋𝑋 = [𝑥𝑥1,𝑥𝑥2, … , 𝑥𝑥31] (4.3)

Where J(X) is the cost function, X is the Fuzzy PID controller parameter vector according

to Equation (4.3 (Also see Figure 4.12), 𝑤𝑤1 and 𝑤𝑤2 are the weight factor for the first and

second phrases, respectively, ∑ |𝑒𝑒𝑖𝑖|𝑛𝑛𝑖𝑖=1 shows the summation of absolute errors and PO is

the percentage of overshoot. The term 𝑚𝑚 indicates the number of robot joints, which is 3

in this case. The term 𝑛𝑛 shows the number of intervals in 8 seconds of simulation. Using

trial and error, it was inferred that in order to have the same significance for both phrases,

the factor of 0.01 and 1 was dedicated to 𝑤𝑤1 and 𝑤𝑤2, respectively.

The parameter vector X is modified in each iteration with DE algorithm, and the simulation

runs according to the new fuzzy controller based on new X. Then, the new cost is calculated

for the new iteration. The DE algorithm acts according to new parameter vector and cost

in new iteration. This procedure goes on until the minimum cost is obtained. In this study,

the optimization loop is terminated after 100 iteration.

Page 50: Fuzzy PID Controller Optimization for Robot Dynamics with ...

30

Other than overshoot, settling time, and rise time can be put into Equation for PID control

applications, however, the concerning issue in the current system is the overshoot. By the

mathematical perspective, optimization is the minimization of the objective function,

which may also have constraints on its variables.

4.3 Fundamentals of Fuzzy Inference System

In classical set theory, an element can either be a member of a set or not, but Zadeh [34]

introduced the Fuzzy set theory in which elements can belong to the set with a certain

degree of membership. This membership degree can range between 0 to 1, however, in a

crisp set, the membership degree can only accept either 0 or 1 values. Fuzzy reasoning is

created to integrate uncertainty into a decision making process. In fact, we use fuzzy so the

logic can be regarded as approximate instead of exact. In reality, fuzzy logic tries to be

similar to human reasoning. Fuzzy logic takes advantage of "linguistic variables" such as

big and small, major and minor, and low, medium, and high with no need for the quantities

to be exactly identified [95].

4.3.1 Membership Function

If U is a universe of discourse set and x is an element of U, then a Fuzzy set A is identified

as:

A = { ( x , 𝜇𝜇𝐴𝐴(x)) | x ∈ 𝑼𝑼 } (4.4)

Where each element x of U is assigned a number 𝜇𝜇𝐴𝐴(x) from [0,1]. 𝜇𝜇𝐴𝐴(x) is the membership

function (MF) for fuzzy set A. The Universe of discourse set some time is called linguistic

variable [96].

Page 51: Fuzzy PID Controller Optimization for Robot Dynamics with ...

31

A sample of MF for variable angular velocity in a DC motor is illustrated in Figure 4.1.

The curves reflect membership function, which relates to different fuzzy variables. In this

example, the linguistic variables are divided into three categories: low, medium, and high.

The number and location and of curves are among the parameters that must be determined

for membership functions. The MFs can have different shapes, triangular,

trapezoidal, Gaussian, etc. [97].

Figure 4.1 Membership for fuzzy variable “angular velocity” in RPM [97]

4.3.2 Fuzzification

Fuzzification is the method of converting a crisp value in universe of discourse to a fuzzy

set. It is the first stage of implementing a fuzzy Inference System. To achieve the desired

output, the crisp variables must be converted to fuzzy variables, and then fuzzy inference

system must be applied to process those data. In general, to perform fuzzification first the

membership functions for input and output variables must be extracted, and then they must

be represented by suitable linguistic variables.

For example, suppose we have an air conditioner heater controller which should be

working when the temperature is low and turned off when the temperature is high. The

temperature range is between 20 and 90 𝐹𝐹 ° :

Page 52: Fuzzy PID Controller Optimization for Robot Dynamics with ...

32

Low temperature: 20 𝐹𝐹 ° to 40 𝐹𝐹 ° , the middle: 30 𝐹𝐹 °

Medium temperature: 30 𝐹𝐹 ° to 80 𝐹𝐹 ° the middle: 55 𝐹𝐹 °

High temperature: 60 𝐹𝐹 ° to 90 𝐹𝐹 ° the middle: 75 𝐹𝐹 °

The MFs of the input in this example is illustrated with trapezoidal curves in Figure 4.2a.

The MFs for output can be determined in a similar way (Figure 4.2b) [98].

Figure 4.2 Membership function for a)input b)output [98]

4.3.3 Fuzzy Rules and Inference Model

Fuzzy inference system (FIS) is built on the Fuzzy conditional statement principle:

IF antecedents THEN consequences

Page 53: Fuzzy PID Controller Optimization for Robot Dynamics with ...

33

The antecedents specify the inputs of the system while the consequences define the outputs

of the fuzzy system. For the indoor heater example in section 4.3.2 we may suggest the

following one-input-one-output rules:

Rule 1: IF Temperature is Low THEN Motor speed is Fast.

Rule 2: IF Temperature is Medium THEN Motor speed is Medium.

Rule 3: IF Temperature is High THEN Motor speed is slow.

In a two-input-one-output system the fuzzy inference system rules can be as:

Rule 1: IF 𝑥𝑥 = 𝐼𝐼1, and 𝑦𝑦 = 𝐵𝐵1 THEN 𝑧𝑧 = 𝐶𝐶1

Rule 2: IF 𝑥𝑥 = 𝐼𝐼2, and 𝑦𝑦 = 𝐵𝐵2 THEN 𝑧𝑧 = 𝐶𝐶2

Rule n: IF 𝑥𝑥 = 𝐼𝐼𝑛𝑛, and 𝑦𝑦 = 𝐵𝐵𝑛𝑛 THEN 𝑧𝑧 = 𝐶𝐶𝑛𝑛

Where x and y are the FIS input, and z is the FIS output. 𝐼𝐼𝑖𝑖 and 𝐵𝐵𝑖𝑖 are the linguistic values

defined on input, and 𝐶𝐶𝑖𝑖 is the linguistic values defined on output. Usually, there is more

than one input in most real systems. In our air conditioner heater, for example, to extract a

precise outcome, the temperature change rate must also be taken into account as the second

input, for instance:

Rule: IF Temperature is Low and the change rate of the temperature is Low

THEN Motor speed is Fast.

The fuzzy control rules should be expanded to allow the consideration of several inputs for

extracting the output.

Page 54: Fuzzy PID Controller Optimization for Robot Dynamics with ...

34

One of the most common methods to apply the fuzzy inference to a multi-input system is

Mamdani inference model. Figure 4.3 illustrates the result of a four-rule Mamdani fuzzy

inference system when the inputs are a four-rule model based on temperature and

temperature change rate.

Figure 4.3 Using Mamdani fuzzy inference model with Min-Max operators [98]

The fuzzy inference requires two phases: determining each rule’s output with the use of

ANDing type aggregation (min, algebraic product, etc.), and then aggregating the actual

rule’s outputs to get the total output of the process with use of ORing type aggregation

(max, algebraic sum, etc.). Generally, the Mamdani model uses either the min-max or the

product-max method. [98]

Page 55: Fuzzy PID Controller Optimization for Robot Dynamics with ...

35

4.3.4 Defuzzification

Defuzzification is the method of converting the result of fuzzy inference system to a crisp

value. There are five common methods of defuzzification. Some of the most important

defuzzification technique are as follows:

- Centroid of Area (COA):

𝐶𝐶𝑃𝑃𝐼𝐼 =

∫ 𝜇𝜇𝐴𝐴(𝑧𝑧)𝑧𝑧𝑑𝑑𝑧𝑧 𝑧𝑧

∫ 𝜇𝜇𝐴𝐴(𝑧𝑧)𝑑𝑑𝑧𝑧 𝑧𝑧

(4.5)

Where, 𝜇𝜇𝐴𝐴(𝑧𝑧) is the aggregated output. COA is the most common defuzzification

technique.

- Bisector of Area (BOA):

� 𝜇𝜇𝐴𝐴(𝑧𝑧)𝑑𝑑𝑧𝑧𝐵𝐵𝐵𝐵𝐴𝐴

𝛼𝛼= � 𝜇𝜇𝐴𝐴(𝑧𝑧)𝑑𝑑𝑧𝑧

𝛽𝛽

𝐵𝐵𝐵𝐵𝐴𝐴

(4.6)

Where, 𝛼𝛼 = min {𝑧𝑧|𝑧𝑧 ∈ 𝑍𝑍} and 𝛽𝛽 = max {𝑧𝑧|𝑧𝑧 ∈ 𝑍𝑍}

- Mean of Maximum (MOM): is the mean of the maximizing z at which the MF

reaches the maximum 𝜇𝜇∗. [99]

4.4 PID Controller

Figure 1.1 shows the representation of a PID controller and demonstrate how it works. PID

control is a name that is widely used for 3-term controls. P indicates the proportional term,

I for the integral term, and D for the controller's derivative term. The development of the

Laplace transform significantly enhanced the application of PID controllers in the

industry.

Page 56: Fuzzy PID Controller Optimization for Robot Dynamics with ...

36

For three reasons PID control is an effective control tool: previous performance record,

wide availability, and ease of use. Thus, it is still the first priority in choosing a controller

in most systems. In some cases, the operation scenario needs a more complicated controller

to control a complex mechanism that the system needs a more advanced controller. Even

in situations where the complexity of the process exists, a combination of PID controller

and other methods such as fuzzy inference system can be used.

The PID controllers are designed to satisfy particular performance expectations using

different combinations of proportional, integral, and derivative terms as required. There

are parallel and series setup of the PID controller to fulfill various requirements for

different applications. In most applications, parallel format is only used, and series format

only applies to some limited applications. For the simple parallel PID controller the

Laplace domain formula is:

𝑈𝑈𝑐𝑐(𝑠𝑠) = �𝐾𝐾𝑃𝑃 + 𝐾𝐾𝐼𝐼 1𝑠𝑠

+ 𝐾𝐾𝐷𝐷𝑠𝑠�𝐸𝐸(𝑠𝑠) (4.7)

Where 𝐾𝐾𝑃𝑃,𝐾𝐾𝐼𝐼 ,𝐾𝐾𝐷𝐷 are proportional, integral and derivative gains in Laplace domain,

respectively. 𝑈𝑈𝑐𝑐(𝑠𝑠) and 𝐸𝐸(𝑠𝑠) are controller output and error input to the controller in

Laplace domain, respectively.

The time domain formula is as follows:

𝑢𝑢𝑐𝑐(𝑡𝑡) = 𝑘𝑘𝑃𝑃𝑒𝑒(𝑡𝑡) + 𝑘𝑘𝐼𝐼 � 𝑒𝑒(𝜏𝜏)

𝑡𝑡

+ 𝑘𝑘𝐷𝐷

𝑑𝑑𝑒𝑒𝑑𝑑𝑡𝑡

(4.8)

Where 𝑘𝑘𝑃𝑃,𝑘𝑘𝐼𝐼 ,𝑘𝑘𝐷𝐷 are proportional, integral and derivative gains in time domain format,

respectively. 𝑢𝑢𝑐𝑐(𝑡𝑡) and 𝑒𝑒(𝑡𝑡) are controller output and error input to the controller in time

domain format, respectively.

Page 57: Fuzzy PID Controller Optimization for Robot Dynamics with ...

37

The early design of industrial PID controllers was analog, and typically such controls had

a very basic interface to manually tune the controller. However, a controller interface

consisting of three basic dials marked P, I, and D was not unfamiliar. Therefore, a manual

operation was sufficient for many of the basic procedures used in the industry. One of the

PID's main strengths is that there are direct correlations between plant responses and tuning

the controller's parameters for simple plants. The tuning method has two parts: one is how

to choose the PID controller configuration and the other is how to select numerical values

for the PID parameters or how to tune the controller.

Table 4.1 shows the effects which tuning parameters have on a PID controller. The P term

minimizes the observed error, regardless to the output and the input phase change; the I

term removes or minimizes the steady-state error; and the D term is often used to minimize

the overshoot. These advantages are generally balanced in a full PID controller to provide

fast rising time and settling time with a minimum fluctuation, overshoot, and steady-state

error.

Page 58: Fuzzy PID Controller Optimization for Robot Dynamics with ...

38

Table 4.1 The effect of each tuning parameter on the controller [2]

Reference tracking tuning

Step reference

Disturbance rejection tuning

Constant load disturbance

Transient Steady state Transient Steady state P Increasing kP, speeds

up the response Increasing kP, reduces but does not eliminate steady state offset

Increasing kP, speeds up the response

Increasing kP, reduces but does not eliminate steady state offset

I Introducing integral action kI, gives a wide range of response types

Introducing integral action kI, eliminates offset in the reference response

Introducing integral action kI, gives a wide range of response types

Introducing integral action kI , eliminates steady state offsets

D Derivative action kD, gives a wide range of responses and can be used to tune response damping

Derivative action has no effect on steady state offset

Derivative action kD, gives a wide range of responses and can be used to tune response damping

Derivative action has no effect on steady state offset

It is possible to include guidelines and experimental formula for the PID controller tuning

for simple systems. Several of these instructions are based on the procedures of the popular

Ziegler – Nichols [4] [5] methods and their several variations of the related principles.

Ziegler – Nichols approaches include an on-line analysis accompanied by some rules to

determine the PID parameters. In the 1980s, as computer processing technology replaced

analog control, industrial control companies started to investigate novel PID controllers.

Thus, the Ziegler–Nichols methods have been subsequently the subject of several studies.

Modern variants of the Ziegler – Nichols methods have been presented, namely the Astrom

and Hagglund relay research. This resulted in significant development of the rule-based

PID controller tuning. [2]

Strong nonlinearity in robotic systems makes it impossible to use direct PID controllers in

this field. Therefore, in order to use a PID controller for a robot, intelligent methods such

as fuzzy logic, neural networks, genetic algorithm, etc. must be employed to tune the

system. The ultimate controller is no longer considered as a linear PID controller, but an

intelligent controller, [22].

Page 59: Fuzzy PID Controller Optimization for Robot Dynamics with ...

39

4.5 Fuzzy PID Controller

In a PID controller, it is often challenging to tune the gains notably in the state of the art

of PID controller design. This problem is more significant regarding issues like

specifications, stability, and efficiency. The application of the fuzzy logic in PID

controllers is discussed in this chapter. Fuzzy logic is employed in the PID architecture to

play the role of an experienced operator. In addition to the direct combination of

fuzzy logic and PID controllers, several non-PID controllers were also built using

fuzzy logic.

Fuzzy controllers can have accurate performance based on the human experience. 𝐾𝐾𝑝𝑝, 𝐾𝐾𝑖𝑖,

and 𝐾𝐾𝑑𝑑 values are adjusted by a fuzzy controller in different conditions. In dynamic control

of a robot with an FPID controller, a PID controller regulates the required torque for each

joint. The PID controller’s gains (𝐾𝐾𝑝𝑝, 𝐾𝐾𝑖𝑖, and 𝐾𝐾𝑑𝑑) are tuned by a fuzzy controller depending

on the joint's angular error and its derivatives. This adaptive controller retains the robot’s

links orientations as it exposes to step signals representing the desired angles for each joint.

The architecture of a system with an FPID controller is shown in Figure 4.4. [100]

Page 60: Fuzzy PID Controller Optimization for Robot Dynamics with ...

40

Figure 4.4 A robot dynamic control using Fuzzy PID controller

Zhao et al. [49] studied Fuzzy PID controllers in 1990s. This research was based on the

Ziegler-Nichols method. In the following we will describe his approach on this subject.

𝐾𝐾𝑝𝑝, 𝐾𝐾𝑖𝑖 are in specific ranges, [𝐾𝐾𝑝𝑝𝑖𝑖𝑖𝑖𝑛𝑛, 𝐾𝐾𝑝𝑝𝑖𝑖𝑝𝑝𝑝𝑝] and [𝐾𝐾𝑑𝑑𝑖𝑖𝑖𝑖𝑛𝑛, 𝐾𝐾𝑑𝑑𝑖𝑖𝑝𝑝𝑝𝑝], respectively. Then, the

normalized parameters have been considered in calculation:

𝐾𝐾𝑝𝑝′ = (𝐾𝐾𝑝𝑝 − 𝐾𝐾𝑝𝑝𝑖𝑖𝑖𝑖𝑛𝑛)/(𝐾𝐾𝑝𝑝𝑖𝑖𝑝𝑝𝑝𝑝 − 𝐾𝐾𝑝𝑝𝑖𝑖𝑖𝑖𝑛𝑛) (4.9)

𝐾𝐾𝑑𝑑′ = (𝐾𝐾𝑑𝑑 − 𝐾𝐾𝑑𝑑𝑖𝑖𝑖𝑖𝑛𝑛)/(𝐾𝐾𝑑𝑑𝑖𝑖𝑝𝑝𝑝𝑝 − 𝐾𝐾𝑑𝑑𝑖𝑖𝑖𝑖𝑛𝑛) (4.10)

To calculate the 𝐾𝐾𝑖𝑖 the following formula is used:

𝐾𝐾𝑖𝑖 =

𝐾𝐾𝑝𝑝𝛼𝛼𝑇𝑇𝑑𝑑

=𝐾𝐾𝑝𝑝

2

𝛼𝛼𝐾𝐾𝑑𝑑

(4.11)

Where:

𝑇𝑇𝑑𝑑 =𝐾𝐾𝑑𝑑𝐾𝐾𝑝𝑝

(4.12)

𝑇𝑇𝑖𝑖 =

𝐾𝐾𝑝𝑝𝐾𝐾𝑖𝑖

(4.13)

𝛼𝛼 =

𝑇𝑇𝑖𝑖𝑇𝑇𝑑𝑑

(4.14)

𝑇𝑇𝑖𝑖 and 𝑇𝑇𝑑𝑑 are integral and derivative time constants, respectively.

According to simulation analysis of numerous systems, the rule of thumb for evaluating

the 𝐾𝐾𝑝𝑝 and 𝐾𝐾𝑑𝑑 ranges is specified as:

𝐾𝐾𝑝𝑝𝑖𝑖𝑖𝑖𝑛𝑛 = 0.32 𝐾𝐾𝑢𝑢 (4.15)

𝐾𝐾𝑝𝑝𝑖𝑖𝑝𝑝𝑝𝑝 = 0.6 𝐾𝐾𝑢𝑢 (4.16)

𝐾𝐾𝑑𝑑𝑖𝑖𝑖𝑖𝑛𝑛 = 0.08 𝐾𝐾𝑢𝑢𝑇𝑇𝑢𝑢 (4.17)

Page 61: Fuzzy PID Controller Optimization for Robot Dynamics with ...

41

𝐾𝐾𝑑𝑑𝑖𝑖𝑝𝑝𝑝𝑝 = 0.15 𝐾𝐾𝑢𝑢𝑇𝑇𝑢𝑢 (4.18)

Where 𝐾𝐾𝑢𝑢 and 𝑇𝑇𝑢𝑢 are the gain and the oscillation period at the stability limit under P-

control, respectively.

The output of fuzzy inference system are normalized proportional gain, 𝐾𝐾′𝑝𝑝, normalized

derivative gain, 𝐾𝐾′𝑑𝑑, and 𝝰𝝰 which is a constant used to calculate the integral gain, 𝐾𝐾𝑖𝑖. Then

we use denormalization scale factors, 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 to denormalize 𝐾𝐾′𝑝𝑝 and 𝐾𝐾′𝑑𝑑 and compute

the PID gains 𝐾𝐾𝑝𝑝 and 𝐾𝐾𝑑𝑑. Regarding these two gains and 𝝰𝝰, the integral gain 𝐾𝐾𝑖𝑖 will also

be obtained using equation 4.7. 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 are the scaling factors which are among the

optimization variable parameter string, and update in every iteration.

4.5.1 Inputs and Outputs of FIS

Considering 𝐾𝐾𝑖𝑖 as a function of 𝐾𝐾𝑝𝑝 and 𝐾𝐾𝑑𝑑, the output of the fuzzy inference system will

be 𝐾𝐾′𝑝𝑝 and 𝐾𝐾′𝑑𝑑 and 𝝰𝝰. The input of FIS is still error (e) and derivative of error (�̇�𝑒).

Figure 4.5 and Figure 4.6 show the membership functions for the inputs 𝑒𝑒 and �̇�𝑒. Each input

has 7 membership functions. Nb, nm, ns, z, ps, pm, pb respectively indicating negative big,

negative medium, negative small, zero, positive small, positive medium, positive big. The

range of error is between –𝜋𝜋 to 𝜋𝜋 rad and the range of derivative of error is between -10 to

10 rad/s. Figure 4.7 demonstrates the membership functions for 𝐾𝐾′𝑝𝑝 and 𝐾𝐾′𝑑𝑑. Each function

has two linear membership functions for small and big values of the normalized gains.

Figure 4.8 shows the membership function for 𝝰𝝰. There are 4 membership functions for

this output. s, ms, m and b stand for small, medium-small, medium, and big values with

referencing numbers 2 to 5, respectively. All input and output MFs are triangular.

Page 62: Fuzzy PID Controller Optimization for Robot Dynamics with ...

42

Figure 4.5 Membership Function for input 1

Figure 4.6 Membership Function for input 2

Page 63: Fuzzy PID Controller Optimization for Robot Dynamics with ...

43

Figure 4.7 Membership functions for output 1 or output 2

Figure 4.8 Membership function for output 3

4.5.2 FIS Rules

Table 4.2 shows a set of rules demonstrating the relationship between 𝑒𝑒 and �̇�𝑒 with

proportional gain (𝐾𝐾′𝑝𝑝). Similarly, Table 4.3 indicates tuning rules for 𝑒𝑒 and �̇�𝑒 with

Page 64: Fuzzy PID Controller Optimization for Robot Dynamics with ...

44

derivative gain (𝐾𝐾′𝑑𝑑) and Table 4.4 shows the set of rules showing the relationship between

𝑒𝑒 and �̇�𝑒 with 𝝰𝝰.

Table 4.2 Fuzzy tuning rules for normalized proportional gain 𝐾𝐾′𝑝𝑝

�̇�𝑒 NB NM NS Z PS PM PB

𝑒𝑒

NB B B B B B B B NM S B B B B B S NS S S B B B S S Z S S S B S S S PS S S B B B S S PM S B B B B B S PB B B B B B B B

Table 4.3 Fuzzy tuning rules for normalized derivative gain 𝐾𝐾′𝑑𝑑

�̇�𝑒 NB NM NS Z PS PM PB

𝑒𝑒

NB S S S S S S S NM B B S S S B B NS B B B S B B B Z B B B B B B B PS B B B S B B B PM B B S S S B B PB S S S S S S S

Combining these 3 tables forms the PID rules as follows:

If e(t) is 𝐼𝐼𝑖𝑖 and �̇�𝑒(𝑡𝑡) is 𝐵𝐵𝑖𝑖 then: 𝐾𝐾′𝑝𝑝 is 𝐶𝐶𝑖𝑖, 𝐾𝐾′𝑑𝑑 is 𝐷𝐷𝑖𝑖 and 𝝰𝝰 is α𝑖𝑖.

Where i=1,2, …, m, is the rule number. 𝐼𝐼𝑖𝑖, 𝐵𝐵𝑖𝑖, 𝐶𝐶𝑖𝑖, 𝐷𝐷𝑖𝑖 and are fuzzy set for e(t), �̇�𝑒(𝑡𝑡), 𝐾𝐾′𝑝𝑝,

𝐾𝐾′𝑑𝑑 and 𝝰𝝰. So for this example there is a table with 49 rules, which the first and last rules

would be as follows:

Page 65: Fuzzy PID Controller Optimization for Robot Dynamics with ...

45

1. If e is NB and �̇�𝑒 is NB then: 𝐾𝐾′𝑝𝑝 is big, 𝐾𝐾′𝑑𝑑 is small and 𝝰𝝰 is MF 2 (small).

49. If e is PB and �̇�𝑒 is PB then: 𝐾𝐾′𝑝𝑝 is big, 𝐾𝐾′𝑑𝑑 is small and 𝝰𝝰 is MF 2 (small).

The method used for “and” operator is minimization and the defuzzification method is

centroid.

Table 4.4 Fuzzy tuning rules for 𝝰𝝰

�̇�𝑒 NB NM NS Z PS PM PB

𝑒𝑒

NB 2 2 2 2 2 2 2 NM 3 3 2 2 2 3 3 NS 4 3 3 2 3 3 4 Z 5 4 3 3 3 4 5 PS 4 3 3 2 3 3 4 PM 3 3 2 2 2 3 3 PB 2 2 2 2 2 2 2

The FIS normalized outputs (𝐾𝐾′𝑝𝑝 and 𝐾𝐾′𝑑𝑑) belong to [0 1], so in order to denormalize them

we multiple them to 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 denormalization factors, respectively.

4.6 Fuzzy PID Optimization

Section 4.5 described the parameters for a fuzzy model. Other parameters are the inference

system parameters vary by different systems of logic. There are typically two approaches

in optimal fuzzy controller design: optimization of fuzzy controller structure methods and

optimization of fuzzy controller parameters. The fuzzy controller structure design

approach obtains the optimal control by designing the fuzzy controller structure, such as

the inference method, fuzzification and defuzzification methods, number of inputs and

outputs and the range of them, form and number of MFs for each input and output, and the

rules of a fuzzy controller. However, in the fuzzy Controller Parameter Design approach

Page 66: Fuzzy PID Controller Optimization for Robot Dynamics with ...

46

we attain the optimal solution by optimizing the fuzzy controller parameters with a specific

structure. The parameters may be the form and position of the MFs or the scaling factors

of the input and output of the fuzzy system. In this research, we find the optimal rules

concerning the former approach and MFs position and scaling factors for output regarding

the latter approach based on the Zhao method. In fuzzy modeling, there are two issues with

the parameter identification: first, the significant number of parameters (MFs, Rules,

constants, etc.), second, the parameter identification techniques, e.g. Zhao uses a heuristic

approach to implement his set of rules. Also, MFs for inputs and outputs are not optimal.

In this thesis, the optimization parameters are: rules, MFs and denormalization factors.

There are 7 MFs for each of the two inputs and 2 MFs for first and second output and 4

MFs for the third output. So, as demonstrated in Table 4.2 to Table 4.4 there are 3 tables

of rules with 49 members each. In order to reduce the calculation time, I assumed that in

each table the diagonal MFs are the same (Figure 4.9).

Figure 4.9 Demonstrating the 7 variables for each rule table

Page 67: Fuzzy PID Controller Optimization for Robot Dynamics with ...

47

The assumptions for membership functions are:

1- All MFs are linear.

2- Input MFs are symmetric with respect to the y axes, and the start point of each MF

has the same value as the peak point of the next MF and peak point of each MF has the

same value of its next MF’s end point.

Figure 4.10 Variables required to be optimized for both input are demonstrated with red dots

This method results in 31 variables. 21 variables for the rules (7 variables for each rule

table), 2 variables as demonstrated in Figure 4.10 for each input MFs (4 variables in total),

4 variables for third output MFs points (Figure 4.11), and 2 variables as denormalization

factors 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 .

Building the parameter vector used for the optimization method is an essential step of the

work. The variables of the Fuzzy PID parameters are used as a 1 × 31 matrix. It includes

the rules, the membership functions position, and output scaling factors. It is important to

Page 68: Fuzzy PID Controller Optimization for Robot Dynamics with ...

48

cautiously determine the size of the variable matrix used for the optimization procedure.

It is better to optimize all fuzzy parameters. Though, if the size of the parameter matrix

goes beyond the range which the optimization algorithm can manage, computation cost

may become a critical problem. Figure 4.12 shows the variable parameters string used in

this study.

Figure 4.11 Variables required to be optimized for Alpha are demonstrated with red dots

The notable aspects of the approach described in this study are: first, there is a substantial

reduction in the number of parameters to be tuned; second, different metaheuristic

optimization methods are used instead of the heuristic method.

Figure 4.12 Variable Parameters string

Page 69: Fuzzy PID Controller Optimization for Robot Dynamics with ...

49

4.7 Differential Evolution Optimization

More than twenty years ago, Ken Price and Rainer Storn published Differential Evolution

(DE) in a sequence of papers [78-81, 101]. In the beginning, the capabilities and limitations

of DE were not fully understood. Later on, by modifying the different components of DE,

it was attempted to make it a quick and reliable optimization tool for any type of objective

function. It appeared that several real-world problems are solvable by DE. In addition,

while there can be no single treatment for all optimization problems, DE can be developed

in a general way to have more functionality for different problems. [102]

Like most of the Evolution Algorithms (EAs), DE is a stochastic approach for global

optimization, based on the population that samples the objective function at several

randomly selected initial points to solve the optimization problem. The classical DE

flowchart is demonstrated in Figure 4.13 Predetermined parameters define the range from

which the Np vectors are chosen in the initial population. Every vector is represented by a

number between 0 and Np − 1. DE produces new points with deviations from current

points. DE utilizes the weighted difference of two population vectors picked at random.

DE adds the weighted difference vector to a third randomly chosen population vector to

generate the mutant vector, v0.

The mutant vector competes in the Crossover stage against the initial vectors (also called

target vectors) with the same index. The result is called trial vector. The trial vector takes

part in a competition against the target vector with the same index at the selection stage. In

this competition, the vector with the smaller cost function is labeled as a next generation

participant. The process continues until all populations have been compared to a randomly

Page 70: Fuzzy PID Controller Optimization for Robot Dynamics with ...

50

created trial vector. After the evaluation of the last trial vector in the running iteration, the

winners of the competitions get to be the next generation's parents. The same procedure is

repeated in the next iterations until the termination criteria are satisfied. [101]

Figure 4.13 Classical DE flowchart [102]

4.7.1 DE Initialization

DE is a parallel search strategy that uses Number of 𝑁𝑁𝑃𝑃 vectors to denote each member’s

feature as follows:

Page 71: Fuzzy PID Controller Optimization for Robot Dynamics with ...

51

𝐱𝐱𝑖𝑖,𝐺𝐺 = [𝑥𝑥0,𝐺𝐺 , 𝑥𝑥1,𝐺𝐺 , … , 𝑥𝑥𝑁𝑁𝑝𝑝−1,𝐺𝐺] (4.19)

Where G denotes each generation number, 𝑁𝑁𝑃𝑃 is the Number of population members,

therefore, 𝑥𝑥𝑖𝑖,𝐺𝐺 represent the features of vector 𝑖𝑖 in generation G. During the optimization

cycle, 𝑁𝑁𝑃𝑃 will not change. If nothing is known about the system, the initial population is

picked at random. In general, unless otherwise specified we must presume a uniform

probability distribution for all random decisions [78].

The other DE algorithm parameters are scaling factor (F) and crossover probability (Cr).

Tuning these three parameters and finding the best values for them has been the subject of

many research. For separable functions, small Cr values are suitable, because the search

focuses on the axes of the coordinate system. A rule of thumb given by Storn and Price

for the algorithm parameters are as follows: [102]

𝐹𝐹 ∈ [0.5, 1.0] 𝐶𝐶𝐶𝐶 ∈ [0.8, 1.0] 𝑁𝑁𝑝𝑝 = 10 𝐷𝐷

(4.20)

D represents the number of dimensions of parameter space. Table 4.5 shows the selected

DE parameters in this study.

Table 4.5 The selected DE parameters in this study

Parameter Iterations 𝑁𝑁𝑝𝑝 Cr F Value 100 20 0.2 0.2-0.8

4.7.2 Mutation

After initialization, the DE mutates and merges the population to create Np trial vector set.

In fact, differential mutation applies a weighted difference vector to a third vector, which

is selected randomly. Equation 2.5 illustrates how three separate, randomly selected vectors

are merged to construct a mutant vector, 𝐯𝐯𝑖𝑖,𝐺𝐺:

Page 72: Fuzzy PID Controller Optimization for Robot Dynamics with ...

52

𝐯𝐯𝑖𝑖,𝐺𝐺 = 𝐱𝐱𝑟𝑟0,𝐺𝐺 + 𝐹𝐹(𝐱𝐱𝑟𝑟1,𝐺𝐺 − 𝐱𝐱𝑟𝑟2,𝐺𝐺) (4.21)

The scale factor, F, is a positive real number that regulates the evolution rate. While F has

no upper limit, the effective values are often smaller than 1.

The base vector index, 𝐶𝐶0, may be calculated in a number of forms. In this study, the simple

classic method is used which is a random vector excluding the index of the corresponding

target vector, 𝑖𝑖. The difference vector indices, 𝐶𝐶1 and 𝐶𝐶2, are both randomly chosen in each

mutant, both must be dissimilar to each other and to the base and target vector indices.

Figure 4.14 shows the mutant vector calculation in a two-dimensional parameter space.

Figure 4.14 Weighted differential mutation demonstration in a 2D parameter space [101]

4.7.3 Crossover

DE employs crossover to help the differential mutation search technique. Crossover

creates trial vectors (𝐮𝐮𝑖𝑖,𝐺𝐺) from parameter values borrowed from either the mutant vector

(𝐯𝐯𝑖𝑖,𝐺𝐺) or corresponding target vector (𝐱𝐱𝑖𝑖,𝐺𝐺) according to the following equation:

Page 73: Fuzzy PID Controller Optimization for Robot Dynamics with ...

53

𝐮𝐮𝑖𝑖,𝐺𝐺 = 𝑢𝑢𝑗𝑗,𝑖𝑖,𝐺𝐺 = �

𝑣𝑣𝑗𝑗,𝑖𝑖,𝐺𝐺 𝑖𝑖𝑖𝑖 𝐶𝐶𝑎𝑎𝑛𝑛𝑑𝑑𝑗𝑗(0,1) ≤ 𝐶𝐶𝐶𝐶 𝑃𝑃𝑅𝑅 𝑗𝑗 = 𝑗𝑗𝑟𝑟𝑝𝑝𝑛𝑛𝑑𝑑

𝑥𝑥𝑗𝑗,𝑖𝑖,𝐺𝐺 𝑃𝑃𝑡𝑡ℎ𝑒𝑒𝐶𝐶𝑤𝑤𝑖𝑖𝑠𝑠𝑒𝑒 (4.22)

The probability of crossover, Cr affects the percentage of parameter values borrowed from

the mutant to the trial vector. In crossover Cr is compared with the results of a random

number generator, 𝐶𝐶𝑎𝑎𝑛𝑛𝑑𝑑𝑗𝑗(0,1), to choose the contribution source of a given parameter. If

the random number is smaller than or equal to Cr, the parameter of the trial vector is

borrowed from the mutation vector, 𝐯𝐯𝑖𝑖,𝐺𝐺; otherwise, the parameter is borrowed from the

target vector, 𝐱𝐱𝑖𝑖,𝐺𝐺. Additionally, the trial parameter 𝑗𝑗𝑟𝑟𝑝𝑝𝑛𝑛𝑑𝑑 index parameter, is transferred

from the mutant vector to guarantee that the trial vector is not the same as 𝐱𝐱𝑖𝑖,𝐺𝐺. As depicted

in Figure 4.15 the possible trial vector in a 2D parameter space are 𝐮𝐮𝑖𝑖,𝐺𝐺 ,𝐮𝐮′𝑖𝑖,𝐺𝐺 and 𝐮𝐮′′𝑖𝑖,𝐺𝐺.

Figure 4.15 Demonstration of possible results of crossover in 2D parameter space [101]

4.7.4 Selection

If the trial vector, 𝐮𝐮𝑖𝑖,𝐺𝐺 has a cost function value equal or lower than the cost of its target

vector, 𝐱𝐱𝑖𝑖,𝐺𝐺, it will substitute the target vector in the next generation; else the target will

remain in the population for at least one generation. DE implements recombination and

Page 74: Fuzzy PID Controller Optimization for Robot Dynamics with ...

54

selection more strictly than most EAs By examining all trial vector and their corresponding

target vector:

𝐱𝐱𝑖𝑖,𝐺𝐺+1 = �

𝐮𝐮𝑖𝑖,𝐺𝐺 𝑖𝑖𝑖𝑖 𝑖𝑖�𝐮𝐮𝑖𝑖,𝐺𝐺� ≤ 𝑖𝑖�𝐱𝐱𝑖𝑖,𝐺𝐺�

𝐱𝐱𝑖𝑖,𝐺𝐺 𝑃𝑃𝑡𝑡ℎ𝑒𝑒𝐶𝐶𝑤𝑤𝑖𝑖𝑠𝑠𝑒𝑒 (4.23)

When the new population is built, the mutation, crossover and selection are repeated again

until the optimum is found or a predetermined termination condition is met, e.g. the number

of iteration is achieved. [101]

4.8 Genetic Algorithm Optimization

The introduction of heuristics and meta-heuristics has enhanced the solution to problems

of optimization that previously were challenging or unlikely to solve. Their basic theory is

to model the natural evolutionary concepts with algorithms.

Among them, differential evolution (DE), Genetic algorithm (GA), Particle Swarm

Optimization (PSO), and imperialist competitive algorithm (ICA) methods demonstrated

significant potentials due to their ability to optimize in complex spaces applied to non-

differentiable functions [67].

GA is a method of optimization that evaluates a large search space and ends in more than

one result. The algorithm is based on genetic operators in compliance with organics. The

crossover function tends to improve the results and lead to the best solution, while

mutations search the entire space and resist the early convergence. The effect of

implementing these simple operators contributes to the development of new units with

lower cost function comparing to their parents, and after many operations, the optimum

solution will be achieved [103].

Page 75: Fuzzy PID Controller Optimization for Robot Dynamics with ...

55

Genetic Algorithm (GA) was developed by Holland in 1975 and popularized by Goldberg

in 1989. The fundamental concept motivating the GA is the Darwinian theory of the

survival of species at stake from predators and natural hazards. The fittest participants have

greater success potential than others. It is more probable for the fittest to adjust to changing

environments, and their descendants will inherit their characteristics and develop their

survival abilities, thereby making future generations more immune to the risks. In fact,

genetic mutations happen arbitrary in population members, and many of these mutations

can enhance the likelihood of suitable individuals and their offspring’s long-term survival.

Figure 4.16 shows the GA algorithm flowchart.

Figure 4.16 Genetic Algorithm Flowchart [67]

Page 76: Fuzzy PID Controller Optimization for Robot Dynamics with ...

56

4.8.1 Generating the Initial Population

Any potential solution to the GA-generated optimization problems is called a chromosome.

Hence, in the mathematical model of an optimization problem, each chromosome consists

of a series of genes (decision variables) that provide a possible solution to the problem. As

demonstrated in Figure 4.12, chromosome is a 1 by N matrix in an N-

dimensional problem. Where N is the number of the variables, that in this problem is 31.

The initial population is selected randomly within the range of variables. The population

size is represented by Np. The population of potential solutions (POP) produced is defined

as a chromosome matrix of size Np × 𝑁𝑁:

𝑃𝑃𝑃𝑃𝑃𝑃 = �

𝑃𝑃1,1 ⋯ 𝑃𝑃1,𝑁𝑁⋮ ⋱ ⋮

𝑃𝑃𝑁𝑁𝑝𝑝,1 ⋯ 𝑃𝑃𝑁𝑁𝑝𝑝,𝑁𝑁

� (4.24)

4.8.2 Parent Selection

GA selection is the process by which the best chromosomes are picked from the population

as the next generation parents. There are different ways of choosing parents. Roulette wheel

selection, ranking selection, and tournament selection are the most popular approaches.

In this study, the ranking selection approach is used to select the parents. This method sorts

all the solutions according to the lowest costs. The first rank gets the best solution and the

lowest rank is given the worst. In fact, in this approach, the old generations and copies from

the crossover and mutation are added to a pool and ranked according to their lowest costs.

Then, the top M chromosomes are selected as the next generation population from the pool.

This process goes on to the last iteration. The best solution in the last iteration is the optimal

solution. Figure 4.17 demonstrates the ranking selection method in each iteration.

Page 77: Fuzzy PID Controller Optimization for Robot Dynamics with ...

57

To proceed towards an optimal solution, the GA algorithm requires producing new

solutions. The offspring comprise a part of the next generation. The next generation can be

a combination of parents and offspring. The offspring are generated through crossover or

mutation. The parents' population to offspring's population ratio is defined experimentally.

Different methods were proposed to comprise the next generation, which distinguishes

different GA types. The chosen parents produce new offspring (solutions). Depending on

the crossover ratio, some solutions are randomly selected for crossover. The crossover ratio

is defined by the user. The mutation is the other method to modify some solutions to avoid

early convergence.

Figure 4.17 GA Ranking procedure in each iteration [67]

Page 78: Fuzzy PID Controller Optimization for Robot Dynamics with ...

58

4.8.3 Crossover

Crossover takes place by swapping genes between parents and produces new offspring. In

this process, some decision variables of two solutions are traded. In other terms, a new

solution earns certain variables from one parent, and some from the other parent. The most

common crossover strategies are: single-point crossover, double-point crossover, and

uniform crossover. These three types of crossover are demonstrated in Figure 4.18.

The crossover points (point C or C') are randomly picked. A child is created by getting

some of its genes from one parent's genes located on one side of the point, and the rest of

its variables from the other parent's genes situated on the other side of the point. Every pair

of parents make two offspring. In double-point crossover, the swapping happens two times

each for one point. In an N-dimensional chromosome, the crossover points are a number

between 1 and N-1.

Page 79: Fuzzy PID Controller Optimization for Robot Dynamics with ...

59

Figure 4.18 Different crossover methods: a) single-point b) double-point c) uniform [67]

In the uniform crossover, the children are created when one or more gene from one parent

is randomly picked and exchanged with their corresponding genes on the other parent. Each

parent with swapped genes represents a child, therefore the uniform crossover can create

two offspring from a pair of parents. The number of swapped genes is a user-defined

quantity. In this study, the single-point crossover method is used. In this thesis, the double-

point crossover method is used.

4.8.4 Mutation

The mutation is essential as it extends the search space and creates offspring with different

genetic elements from their parents in a random process. In other terms, one or more

decision variables in a new population are substituted by random values thus the values of

Page 80: Fuzzy PID Controller Optimization for Robot Dynamics with ...

60

the other decision variables remain unchanged. This operation prevents the algorithm to

reach to a premature solution by presenting new options from the workspace. Figure 4.19

shows an example of the mutation operator.

Figure 4.19 Mutation operator [67]

4.8.5 Parameter Selection

A promising parameter selection is not the same for different problems. Mostly the best set

of parameters for one problem may not work for other cases. Moreover, creating a

successful setting of parameters also involves a significant number of time-consuming

tests. A good GA parameter selection depends on practicing with similar optimization

problems. [67] Table 4.6 shows the selected double-points crossover GA parameters in this

study.

Table 4.6 Double-points crossover GA parameters

Parameter Iterations Population Crossover rate

Mutation rate

Mutation samples

Value 100 20 0.7 0.2 4

Page 81: Fuzzy PID Controller Optimization for Robot Dynamics with ...

61

4.9 Particle Swarm Optimization

Kennedy and Eberhart developed the traditional PSO in 1995, being inspired by the social

and computer sciences. The PSO practically is based on the swarm intelligence idea, which

is the characteristic of a system that generates consistent global efficient results through

the cumulative actions of simple agents collaborating locally with their surroundings.

Picture a flock of birds in which each bird screams with a volume relative to the amount of

food they find at their existing spot. Concurrently, each bird can coordinate the nearby

birds and determine which of the nearby birds generates the strongest scream. Typically,

there is a great possibility that the flock would find the global optimal spot with the highest

food accumulation if each bird actually takes a route that combines three directions as

shown in Figure 4.20:

1- The previous route it moved.

2- The best place it had individually found so far.

3- The best place the flock had globally spotted up to this point.

Potential solutions are named particles in the traditional PSO. Such particles move all over

the search space to find the best solution by communicating and exchanging knowledge

with adjacent particles, the best individual and local solution is calculated. Then, the best

global solution obtained in the entire swarm is revised in each iteration according to their

Page 82: Fuzzy PID Controller Optimization for Robot Dynamics with ...

62

cost functions. After enough iterations and with a good selection of algorithm parameters

the particles’ positions will converge to the global optimum. [104]

Figure 4.20 three path to optimal solution in PSO algorithm [104]

Following a number of slight changes and removal of the excessive variables, Kennedy

and Eberhart concluded the formulation for determining a particle's next location as:

𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘+1 = 𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 + 𝑐𝑐1𝐶𝐶1�𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 � + 𝑐𝑐2𝐶𝐶2�𝑥𝑥𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 � (4.25)

𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘+1 = 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 + 𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘+1 (4.26)

Where, 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 and 𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 are the 𝑗𝑗th component of the location and velocity vector of the 𝑖𝑖th

particle in the 𝑘𝑘th iteration respectively. 𝐶𝐶1 and 𝐶𝐶2 are two uniformly distributed random

numbers in the range (1,0). 𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖 and 𝑥𝑥𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡 imply the best location reached by the 𝑖𝑖th

particle and the best global location, respectively. 𝑐𝑐1 and 𝑐𝑐2 are cognition and social

behavior parameters reflecting the confidence of the particle to its own optimal and to the

global optimal. In the original version of the PSO proposed by Kennedy and Eberhart, these

Page 83: Fuzzy PID Controller Optimization for Robot Dynamics with ...

63

two parameters were equivalent to 2 so that the particles would pass over the destination

nearly half the time. These parameters are one of the algorithm's most significant

parameters because they regulate the balance between exploration and exploitation. A

relatively lower c1 value would make the particles travel to their global best positions

whereas lower c2 values would result in a quick convergence to the best local optimum.

Figure 4.21 illustrates a schematic of a particle movement.

Figure 4.21 Schematic of a particle movement [105]

While the equation (4.25) represents the basic definition of PSO that has lasted over time

and shapes the structure of almost all later versions, it was always subject to modification.

To avoid particles from leaving search space, a maximum velocity limit, 𝑉𝑉𝑖𝑖𝑝𝑝𝑝𝑝 is applied

on the absolute value of velocity. It was observed that the first term, 𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 , has a major

influence on global and local search balance. By dropping this term, the particles will not

go beyond their primarily defined search space. This would be similar to a method of local

search. [105] To avoid this, an important modification was required by adding the inertia

factor (w) to substitute 𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 with 𝑤𝑤𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 :

Page 84: Fuzzy PID Controller Optimization for Robot Dynamics with ...

64

𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘+1 = 𝑤𝑤𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 + 𝑐𝑐1𝐶𝐶1�𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 �

+ 𝑐𝑐2𝐶𝐶2�𝑥𝑥𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 �

(4.27)

Adding this weight facilitates the balancing the particle movement. Using this factor impact

the trade-off between the local and global search hence the algorithm can reach the final

best solution faster. Although in theory, 𝑤𝑤 can be a constant in the range (0,1), the inertia

factor usually ranges (0.4,0.9) [106]. Consequently, Clerc [107] introduced a constriction

factor χ to control the magnitude of velocities instead of applying inertia factor only to the

first term. This is essential to ensure the convergence of the particle swarm algorithm and

introduced an alternate velocity vector formulation:

𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘+1 = χ [𝑣𝑣𝑖𝑖,𝑗𝑗𝑘𝑘 + 𝑐𝑐1𝐶𝐶1�𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 � + 𝑐𝑐2𝐶𝐶2�𝑥𝑥𝑥𝑥𝑥𝑥𝑒𝑒𝑠𝑠𝑡𝑡𝑖𝑖,𝑗𝑗𝑘𝑘 − 𝑥𝑥𝑖𝑖,𝑗𝑗𝑘𝑘 �] (4.28)

𝜒𝜒 =

2�2 − 𝜑𝜑 − �𝜑𝜑2 − 4𝜑𝜑�

(4.29)

Where, 𝜑𝜑 = 𝑐𝑐1 + 𝑐𝑐2 > 4. The velocity threshold, 𝑉𝑉𝑖𝑖𝑝𝑝𝑝𝑝 , is no longer needed with this

formulation and the algorithm would guarantee convergence without limiting the velocity.

The recommended amounts for parameters are: 𝜑𝜑 = 4.1 (𝑐𝑐1 = 𝑐𝑐2 = 2.05) and 𝜒𝜒 = 0.729. If

w= 𝜒𝜒 and 𝑐𝑐1 + 𝑐𝑐2 > 4; The constriction and inertia techniques are algebraically similar. In

this research, we use the PSO with a constriction factor. (Equation (4.28))

4.9.1 PSO parameters

PSO success typically depends on the parameter selection as any other metaheuristic

optimization algorithm. The optimal values for the parameters depend mostly on the type

of the problem and the available search for solving the problem. The key problem is to find

a compromise between the algorithm's exploration and exploitation. The parameters

regarded in this PSO method are the number of iterations, number of particles, constriction

Page 85: Fuzzy PID Controller Optimization for Robot Dynamics with ...

65

factor, and coefficients of cognition and social behavior (𝑐𝑐1 and 𝑐𝑐2). A required accuracy

or some other termination condition may substitute the total number of iterations. [105]

Table 4.7 PSO parameters

Parameter Iterations Number of particles 𝑐𝑐1 𝑐𝑐2 𝜒𝜒 Value 100 20 2.05 2.05 0.729

Table 4.7 shows the selected parameters for the PSO algorithm. 𝑐𝑐1, 𝑐𝑐2 and

𝜒𝜒 are determined according to the Clerc’s methods.

4.10 Imperialist Competitive Algorithm (ICA)

The Imperialist Competitive Algorithm (ICA), proposed by Atashpaz-Gargari and Lucas

in 2007, is a recent evolutionary algorithm developed from the human social evolution.

Like other evolutionary algorithms, ICA starts with the initial population but here each

member portrays a country. Some of the strongest (less cost) countries are picked as

imperialists, and remaining countries identified as colonies. Afterward, depending on

imperialist strength the colonies are shared among the imperialists. An imperialist creates

an empire together with its associated colonies. After the establishment of the empires,

imperialist competition among the empires starts. Stronger empires try to occupy the

colonies of the other empires in imperialist competition. This process repeats until all

empires fall and there is only one empire (global empire). The ICA converges at this stage

to the best solution. [108]

4.10.1 Creation of initial empires

The optimization purpose is to locate the optimal solution. For this reason, We construct a

set of values vectors. This vector is called "chromosome" in the GA terminology but in

Page 86: Fuzzy PID Controller Optimization for Robot Dynamics with ...

66

ICA the term "country"(𝑋𝑋𝑗𝑗) is used. A country is a 1 by N vector in an N-dimensional

optimization problem. This vector is shown as:

𝑋𝑋𝑗𝑗 = [𝑥𝑥1, 𝑥𝑥2, … , 𝑥𝑥𝑁𝑁] , 𝑗𝑗=1,2,…, 𝑁𝑁𝑡𝑡𝑡𝑡𝑡𝑡 (4.30)

Where 𝑥𝑥𝑖𝑖 is the optimization variable, And 𝑁𝑁𝑡𝑡𝑡𝑡𝑡𝑡 is the number of countries. In each country,

variables can be interpreted as a socio-political characteristic of the nation. The algorithm

identifies the best solution, which is the country with the best balance of socio-political

characteristics such as economics, culture, military, language, etc. or in optimization form

best fitness function or least cost function. First, Initial countries of size 𝑁𝑁𝑡𝑡𝑡𝑡𝑡𝑡 are generated

and their cost function is calculated. To create the empires, we pick top 𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝 strongest

countries (least costs). The rest of the countries would be 𝑁𝑁𝑐𝑐𝑡𝑡𝑐𝑐 colonies, which belong to

the empires proportional to their strength. So, an empire’s normalized cost is described as

follows:

𝐶𝐶𝑛𝑛 = 𝑐𝑐𝑛𝑛 − 𝑚𝑚𝑎𝑎𝑥𝑥{𝑐𝑐𝑖𝑖} (4.31)

Where 𝑐𝑐𝑛𝑛 is the empire 𝑛𝑛th cost and 𝐶𝐶𝑛𝑛 is its normalized cost. So, each imperialist's

normalized power and the initial number of colonies for nth empire is described by

𝑝𝑝𝑛𝑛 = �

𝐶𝐶𝑛𝑛∑ 𝐶𝐶𝑖𝑖𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝𝑖𝑖=1

� (4.32)

𝑁𝑁.𝐶𝐶.𝑛𝑛 = 𝐶𝐶𝑟𝑟𝑢𝑢𝑛𝑛𝑑𝑑(𝑝𝑝𝑛𝑛.𝑁𝑁𝑐𝑐𝑡𝑡𝑐𝑐) (4.33)

𝑁𝑁.𝐶𝐶.𝑛𝑛 of colonies are randomly dedicated to the 𝑛𝑛th imperialist. So the 𝑛𝑛th empire is

created by this imperialist and all its colonies. Therefore, as it is observable in Figure 4.22

the powerful imperialists have more colonies.

Page 87: Fuzzy PID Controller Optimization for Robot Dynamics with ...

67

Figure 4.22 Initial situation of empires in ICA [109]

4.10.2 Assimilation

In the real world, an imperialist tries to assimilate its colonies in order to guarantee its

future benefits through the colonies. In ICA, assimilation is described as attracting the

colonies toward the imperialist. Figure 4.23 shows how in a 2-dimensional search space

the colonies move toward their imperialists. To find the colony a new position, we select a

random variable with a uniform distribution in the range (0,𝛽𝛽 × 𝑑𝑑), which 𝛽𝛽 > 1, so the

approach can be from both directions. 𝑑𝑑 is the distance between the imperialist and the

colony.

Page 88: Fuzzy PID Controller Optimization for Robot Dynamics with ...

68

Figure 4.23 movement of the colony toward their imperialist in assimilation process

4.10.3 Revolution

In ICA terminology, when a revolution happens in a colony, its characteristics suddenly

change to random values in the search space. The percentage of colonies, which go through

a revolution defined as the revolution rate (𝑅𝑅𝑟𝑟𝑟𝑟𝑟𝑟). Generally, an appropriate revolution rate

avoids premature convergence by having suitable amount explorations, however, a high

revolution rate would avoid convergence in empires. A revolution rate of around 0.3 (30%)

is suitable for most of the applications.

4.10.4 Position exchange between colonies and imperialist

While heading towards the imperialist, a colony can attain a lower-cost location than the

imperialist. In this situation, the colony’s role shift with the imperialist. Therefore, the

empire will continue the algorithm with a new imperialist.

4.10.5 Empire’s Union

In the competition of colonies and imperialists toward the best solution, two imperialists

may move to a similar position. If the difference between the two imperialists were smaller

than the threshold distance (𝑑𝑑𝑡𝑡ℎ𝑟𝑟), then, they will build a new empire with all the colonies

of two empires, and the new imperialist will be one of the two in position.

Page 89: Fuzzy PID Controller Optimization for Robot Dynamics with ...

69

4.10.6 Imperialistic Competition

The power of the imperialist country largely influences the overall strength of an empire.

However, the influence of an empire's colonies has a smaller impact on the empire's overall

strength. This assumption is described by defining an empire's overall cost as:

𝑇𝑇.𝐶𝐶𝑛𝑛 = 𝑐𝑐𝑟𝑟𝑠𝑠𝑡𝑡(𝑖𝑖𝑚𝑚𝑝𝑝𝑒𝑒𝐶𝐶𝑖𝑖𝑎𝑎𝑙𝑙𝑖𝑖𝑠𝑠𝑡𝑡𝑛𝑛) + 𝜉𝜉 𝑚𝑚𝑒𝑒𝑎𝑎𝑛𝑛(𝑐𝑐𝑟𝑟𝑠𝑠𝑡𝑡(𝑐𝑐𝑟𝑟𝑙𝑙𝑟𝑟𝑛𝑛𝑖𝑖𝑒𝑒𝑠𝑠 𝑟𝑟𝑖𝑖 𝑒𝑒𝑚𝑚𝑝𝑝𝑖𝑖𝐶𝐶𝑒𝑒𝑛𝑛)) (4.34)

Where 𝑇𝑇.𝐶𝐶𝑛𝑛 is the overall 𝑛𝑛th empire cost, and 𝜉𝜉 is a small positive number. A small value

for 𝜉𝜉 allows the empire's total power to be calculated by only the imperialist, and it would

give the colonies more weight in the empire's total power. In most applications, the value

of 0.1 for 𝜉𝜉 indicated good results.

The empires attempt to capture each other’s colonies. Imperialist competition gradually

declines the strength of weaker states and increase the power of stronger ones. The

competition model is based on selecting several (usually one) of the weakest colonies in

the weakest empire and making a competition among all other empires for owning them.

The chance of taking the separated colony for each empire depends on their total power.

Figure 4.24 illustrates how the competition takes place in ICA.

Page 90: Fuzzy PID Controller Optimization for Robot Dynamics with ...

70

Figure 4.24 The imperialistic competition [109]

The weakest empire is selected to separate a colony from. Then the possession

possibility, 𝑃𝑃𝑃𝑃, for each empire is determined. 𝑃𝑃𝑃𝑃 depends on the empire's overall strength.

The overall normalized cost of an empire and 𝑃𝑃𝑃𝑃 calculated as follows:

𝑁𝑁.𝑇𝑇.𝐶𝐶.𝑛𝑛 = 𝑇𝑇.𝐶𝐶.𝑛𝑛− 𝑚𝑚𝑎𝑎𝑥𝑥{𝑇𝑇.𝐶𝐶.𝑖𝑖 } (4.35)

𝑃𝑃𝑝𝑝𝑛𝑛 = �

𝑁𝑁.𝑇𝑇.𝐶𝐶.𝑛𝑛∑ 𝑁𝑁.𝑇𝑇.𝐶𝐶.𝑖𝑖𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝𝑖𝑖=1

� (4.36)

Where, 𝑃𝑃𝑃𝑃𝑛𝑛, 𝑇𝑇.𝐶𝐶.𝑛𝑛, and 𝑁𝑁.𝑇𝑇.𝐶𝐶.𝑛𝑛 are possession possibility, Total cost, and total

normalized cost of the 𝑛𝑛th empire, respectively. In order to transfer the separated colony

to an empire in which has the highest chance, three vector P and R and D are created as

follows:

𝑷𝑷 = [𝑃𝑃𝑝𝑝1,𝑃𝑃𝑝𝑝2, … ,𝑃𝑃𝑝𝑝𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝] (4.37)

Page 91: Fuzzy PID Controller Optimization for Robot Dynamics with ...

71

𝑹𝑹 = [𝑅𝑅1,𝑅𝑅2 … ,𝑅𝑅𝑝𝑝𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝] (4.38)

𝑫𝑫 = 𝑷𝑷 − 𝑹𝑹 (4.39)

The empire with the greatest value in vector D wins the competition. [109]

The ICA parameters selected for this study are shown in Table 4.8.

Table 4.8 ICA selected parameters

Parameter Iterations 𝑁𝑁𝐶𝐶 𝑁𝑁𝑖𝑖𝑖𝑖𝑝𝑝 𝛽𝛽 𝑅𝑅𝑟𝑟𝑟𝑟𝑟𝑟 𝜉𝜉

Value 100 20 7 2 0.3 0.02

4.11 Summary

In this chapter, first, the cost function was defined. Using single objective cost function

with only considering error can lead to a response graph with a small settling time but a

considerable overshoot. For this reason, the cost function used in this problem consists of

two terms. The first term is related to absolute error and the second term is related to

overshoot. Regarding both this two factors allows us to have a better performance.

Later in this chapter, we quickly reviewed the fuzzy inference system and PID controller.

In section 4.5, we discussed the fuzzy PID control and presented our fuzzy model. In this

model the input of FIS is error (e) and derivative of error (�̇�𝑒), and the output is normalized

proportional gain, 𝐾𝐾′𝑝𝑝, normalized derivative gain, 𝐾𝐾′𝑑𝑑, and 𝝰𝝰 which is a constant used to

calculate the integral gain, 𝐾𝐾𝑖𝑖. Then, 𝐾𝐾𝑝𝑝 and 𝐾𝐾𝑑𝑑 are calculated using 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 factors.

Afterwards, the integral gain 𝐾𝐾𝑖𝑖 will be obtained. Each input has 7 membership functions,

among them 3 have fixed peak points, and two have dependent peak points so only two

points would be considered as variables, which results in total 4 variables for both input

MFs. For the output, only 𝝰𝝰 MF with variables with total 4 variable peak points. Each rule

Page 92: Fuzzy PID Controller Optimization for Robot Dynamics with ...

72

table consists of 49 rules, but using the diagonal method, we reduced it to 7 variables for

each table resulting to 21 total variables for all three table rules. Adding the 2 scaling

factors will result in total 31 variable parameters in the optimization string.

Later in this chapter, the optimization of above mentioned parameters of FIS using DE

method is explained in section 4.7. in order to compare and validate the results, 3 other

metaheuristic optimization methods (GA, PSO, and ICA) are used. These optimization

methods are explained in section 4.8 to 4.10. In all approaches, the number of iterations

and number of population are equal to 100 and 20, respectively.

Page 93: Fuzzy PID Controller Optimization for Robot Dynamics with ...

73

5 SIMULATION AND DISCUSSION

5.1 Introduction

The mathematical model of the robot arm is presented in chapter 3. This presentation is

modeled using MATLAB 2017a and Simulink. In chapter 4, different optimization

methods used in this research are explained and the selected parameter factors for the

optimization are proposed in Table 4.6 to Table 4.8. In this chapter the Simulink diagram

is described and later the simulation results for initial FPID approach and optimized FPID

are demonstrated. Then, the result of ICA optimized FPID is compared to the one from

initial FPID and also other optimization methods.

5.2 Control System

Figure 5.1 demonstrate the Simulink layout of the FPID control system. Three step signals

are the system input and represent the desired angles for each robot link. The error signal

is generated when the feedback is subtracted from the input, and ends to FPID controllers.

The expanded FPID controllers are shown at the top of the figure. The error and derivative

of error feed the Fuzzy Logic Controller (FLC) and its output is normalized gain (K’),

which is a 1 × 3 matrix with elements between (0,1) representing 𝐾𝐾′𝑝𝑝,𝐾𝐾′𝑑𝑑 and 𝝰𝝰. The

denormalization function uses below equations in order to calculate actual gains.

𝐾𝐾𝑝𝑝 = 𝛼𝛼𝑛𝑛 × 𝐾𝐾′𝑝𝑝 (5.1)

𝐾𝐾𝑑𝑑 = 𝛽𝛽𝑛𝑛 × 𝐾𝐾′𝑑𝑑 (5.2)

𝐾𝐾𝑖𝑖 =

𝐾𝐾𝑝𝑝2

𝐾𝐾𝑑𝑑 × 𝛂𝛂

(5.3)

Page 94: Fuzzy PID Controller Optimization for Robot Dynamics with ...

74

Where, 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 are denormalization factors which are calculated in optimization

process. In fact 𝛼𝛼𝑛𝑛 and 𝛽𝛽𝑛𝑛 are the 30th and 31st factors in variable string. Using 𝐾𝐾𝑝𝑝, 𝐾𝐾𝑑𝑑

along with 𝛂𝛂 to calculate the 𝐾𝐾𝑖𝑖 is represented by Zhen et al. [49]

Figure 5.1 Simulink layout for a 3DOF Robot FPID Control System

Then the torque for each link obtains through the equation (4.7) and feed to the robot

manipulator formulation, so the actual angles of the robot can be calculated. The robot

manipulator equations are presented in section 3.3. The physical properties of the robot are

demonstrated in Table 3.1.

Page 95: Fuzzy PID Controller Optimization for Robot Dynamics with ...

75

5.3 Conventional PID Failure

The implementation of a tuning process for PID control of nonlinear systems like robots is

challenging. In robots, one joint's torque influences the other joints. In addition, there are

several gains to be tuned simultaneously. For example in this research for the 3DOF robot,

there are 9 gains which need to be tuned. Tuning the next joints gains would affect the

performance of the joints which has been previously tuned.

In order to have an assessment about the conventional PID performance for the 3 DOF

robotic arm, a simulation has been applied on the system and the results are shown in the

following. In Figure 5.2 the gains used in the simulation are calculated by Ziegler-Nichols

method.

Figure 5.2 System response for PID controllers using Ziegler-Nichols method

In Figure 5.3 and Figure 5.4 constant gains from FPID simulation has been used for the

conventional PID system. The gains used in Figure 5.3 are the FPID final gains and gains

used in Figure 5.4 are the FPID average gains.

Page 96: Fuzzy PID Controller Optimization for Robot Dynamics with ...

76

Figure 5.3 System response for PID controllers using the final FPID constant gains

Figure 5.4 System response for PID controllers using the average FPID constant gains

None of the three approaches with conventional PID control can produce a stable response.

All methods lead to instability of the system in 3.4, 2.9, and 9.9 Seconds for final FPID

gains, average FPID gains and Ziegler-Nichols gains, respectively.

5.4 FPID Approach

Before running the optimization, the control system was tested according to FPID approach

introduced in section 4.5 in order to be used for research validation purpose. As shown in

Page 97: Fuzzy PID Controller Optimization for Robot Dynamics with ...

77

Figure 5.5 the results shows a significant overshoot in all three links. The average

overshoot in this case is 48.82%. The average settling time is 1.16s.

Figure 5.5 Desired and actual angles according to FPID approach

Figure 5.6 shows the error in time span of 8 seconds for FPID approach. Summation of

absolute error 56.34 rad in this period. As it can be observed, the overshoot and undershoot

have the major effect on the error. In fact, the steady state error is negligible in this case. It

indicates the importance of adding a term to the cost function so we can minimize the

overshoot value other than just minimizing the summation of absolute error.

The MFs and rules for this approach are shown in section 4.5 The Rule surface is a three

dimensional plot which demonstrate the value for a 𝐾𝐾′𝑝𝑝, 𝐾𝐾′𝑑𝑑 and 𝝰𝝰 according to the error

and derivative of error. The rule surfaces for FPID approach are presented in Figure 5.7.

Page 98: Fuzzy PID Controller Optimization for Robot Dynamics with ...

78

Figure 5.6 Error for each joint according to FPID approach

Figure 5.7 Rule surface according to FPID approach for error and derivative of error and a) 𝐾𝐾′𝑝𝑝 b) 𝐾𝐾′𝑑𝑑 c) 𝝰𝝰

Page 99: Fuzzy PID Controller Optimization for Robot Dynamics with ...

79

5.5 Optimized Results

5.5.1 Best Cost

The DE optimization method along with GA, ICA and PSO has been applied to the control

system in order to find the solution with minimum cost. Figure 5.8 shows the best costs for

different methods. After 100 iterations, DE method showed the results with least cost in

comparison with other optimization methods and no optimization approach. The Fuzzy

PID with no optimization has an almost twice cost. ICA and PSO show a fast convergence

while the conventional GA has the slowest convergence rate and also ends up with the

highest cost among the optimization methods.

Figure 5.8 Best Cost for different optimization methods in 100 iterations

Excluding conventional GA, all other optimization methods reach to an acceptable

convergence in around 30 iterations.

Page 100: Fuzzy PID Controller Optimization for Robot Dynamics with ...

80

5.5.2 System Response

Figure 5.9 to Figure 5.11 show the system response to the step input for each joints. The

overall values for system response performance are demonstrated in Table 5.1.

Figure 5.9 system response to step input 0.6 (rad) for joint 1

Figure 5.10 system response to step input 0.7 (rad) for joint 2

Page 101: Fuzzy PID Controller Optimization for Robot Dynamics with ...

81

Figure 5.11 system response to step input 0.8 (rad) for joint 3

Table 5.1 system response performance for different approaches

Overshoot (%) Settling time (s) Rise Time (s) Sum Absolute Error

ICA 11.9310 2.3192 0.1725 53.6493 GA 13.8176 2.0480 0.1795 56.7301 DE 14.1194 1.6752 0.1510 48.6246 PSO 12.7715 2.0470 0.1702 53.4048 FPID 48.8257 1.1638 0.1182 56.3448

As shown in Table 5.1 DE display the best sum absolute error and settling and rise time.

While ICA demonstrate the least overshoot. The performance parameters are calculated by

using the average values of all three joints for each approach.

To have a better sensation of the system error for each approach, the system response errors

for joint 1 to 3 are illustrated in Figure 5.12 to Figure 5.14, respectively.

Page 102: Fuzzy PID Controller Optimization for Robot Dynamics with ...

82

Figure 5.12 System response error for joint 1

Figure 5.13 System response error for joint 2

Page 103: Fuzzy PID Controller Optimization for Robot Dynamics with ...

83

Figure 5.14 System response error for joint 3

5.5.3 Optimized Membership Functions

The optimized MFs are shown in Figure 5.15 to Figure 5.17 for the first input (Error),

second input (derivative of error) and third output (𝝰𝝰), respectively. The original FPID

consist of 7 MFs for inputs and 4 MFs for 𝝰𝝰. The Figure 5.15 shows that MFs are almost

unchanged in conventional GA optimization, comparing to FPID’s, with a slight deviation

in small and medium MFs. DE optimization MF plot shows that the optimization tends to

change the MFs in to a case with 5 MFs by positioning the small and medium MFs’ peak

on a same spot. The result for PSO and ICA are similar in some way.

The Figure 5.16 shows that MFs are slightly changed in conventional GA optimization,

comparing to FPID’s, with a deviation in small and medium MFs. DE, PSO and ICA

optimization MF plot shows that the optimization tends to change the MFs in to a case with

3 MFs. The result for ICA is still developing to this aim.

Page 104: Fuzzy PID Controller Optimization for Robot Dynamics with ...

84

Figure 5.15 Optimized Membership Functions for input 1, using a)GA b)DE c)PSO d)ICA

Figure 5.16 Optimized Membership Functions for input 2, using a)GA b)DE c)PSO d)ICA

Page 105: Fuzzy PID Controller Optimization for Robot Dynamics with ...

85

Figure 5.17 Optimized Membership Functions for output 3 (𝝰𝝰), using a)GA b)DE c)PSO d)ICA

Figure 5.17 demonstrates the optimized MFs for output 𝝰𝝰. GA is developing linear left and

right arm MFs and two symmetric triangular in between. The DE is developing left arm

Mf and one triangular in the middle. ICA is developing three triangular and finally PSO

kept the original MFs with some slight deviations. In this plot, the results are dissimilar in

each approach. This can lead to this conclusion that the shape of MFs for 𝝰𝝰 are not

significantly influencing FPID controller performance in this study.

5.5.4 Optimized Rules

Figure 5.18 to Figure 5.20 show the Rule surface for the first (𝐾𝐾′𝑝𝑝), second (𝐾𝐾′𝑑𝑑) and third

output (𝝰𝝰), respectively. As it can be observed, the Rule surfaces are different for each

optimization approach. This is due to the nature of our problem that variables are dependent

to each other. The rules are based on the membership functions. When the membership

functions change in optimization process, the rules need re-adjustment accordingly.

Furthermore, in multi-objective optimization, which is the nature of our work, there is a set

of solutions rather than a single solution.

Page 106: Fuzzy PID Controller Optimization for Robot Dynamics with ...

86

Figure 5.18 Optimized Fuzzy Rule Surface for 𝐾𝐾′𝑝𝑝, using a)GA b)DE c)PSO d)ICA

Figure 5.19 Optimized Fuzzy Rule Surface for 𝐾𝐾′𝑑𝑑, , using a)GA b)DE c)PSO d)ICA

Page 107: Fuzzy PID Controller Optimization for Robot Dynamics with ...

87

Figure 5.20 Optimized Fuzzy Rule Surface for 𝝰𝝰, using a)GA b)DE c)PSO d)ICA

5.5.5 PID Gains

Figure 5.21 shows the final proportional, integral and derivative gains for controller from

different approaches. Now again because of dealing with a multi-objective, the PID gains

are not necessarily equal. The biggest difference between the FPID and optimized FPID is

that there is a significant oscillation in FPID results, while optimized results have more

monotonic behavior. An interesting point is that the optimized PID gains in almost all

methods converge very fast. In fact, while the gains resulted from normal FPID keep

oscillating even after the settling time, the gains resulted from optimized FPID converge

to the final value quiet before the rise time.

In a PID controller, gains are constant in the whole process. This makes PID controllers

not suitable for nonlinear applications like robotic system. However, in proposed method,

as shown in Figure 5.21, the gains are time variant. This makes the controller sophisticated

enough to perform the task.

Page 108: Fuzzy PID Controller Optimization for Robot Dynamics with ...

88

Figure 5.21 Proportional, Integral and Derivative gains for each joins resulted from different approaches

5.6 Summary

This chapter presents the simulation results of the model using MATLAB 2017a and

Simulink. First, in section 5.2 the Simulink diagram of the model is illustrated and

explained. The input of the system consists of three step signal with amplitude of 0.6 rad,

0.7 rad, and 0.8 rad as desired joint angles. Then the error signal resulted from a negative

feedback from the real joint angles insert to the FPID controllers. The input of robot

manipulator is the controller’s output in form of torque. The output of robot manipulator is

actual joint angles. The diagram of one of the FPID controllers is shown separately at the

top of the figure.

Page 109: Fuzzy PID Controller Optimization for Robot Dynamics with ...

89

The Fuzzy PID system with no optimization shows a significant average overshoot of 48%.

After DE-optimization the overshoot reduces to only 14%. In addition, the error decreases

in optimized approach. Eventually, this drop in overshoot and error, results in a 50%

reduction in cost function. While all the optimization methods shows a significant drop in

cost, after 100 iteration the DE method have the lowest cost.

Later in this chapter, the graphs for optimized membership functions and rules are shown.

The PID gains, rule surfaces and membership functions are different for each optimization

approach. This is due to the nature of our problem that variables are dependent to each

other. In addition, in multi-objective optimization, there is a set of solutions rather than a

single solution.

Page 110: Fuzzy PID Controller Optimization for Robot Dynamics with ...

90

6 CONCLUSIONS AND RECOMMENDATIONS

In this study, a Fuzzy proportional-integral-derivative (FPID) controller is presented to

control the dynamics of a 3-DOF robot. Differential Evolution methods have been used to

optimize the performance of the FPID controller. Then, the results have been compared

with the ones from Genetic Algorithm (GA), Particle Swarm Algorithm (PSO) and

Imperialistic Competition Algorithm (ICA). In the proposed FPID, Membership functions

(MFs) for inputs and outputs, fuzzy rules and gains has been optimized. The objective

function was based on weighted summation of the response absolute sum error and

overshoot.

6.1 Calculation Efficiency

In this research, the DE approach achieved a better control performance in case of settling

time, rise time and sum absolute error, while the ICA showed a better performance in case

of overshoot. The average calculation time for each iteration is shown in Table 6.1.

Table 6.1 Average calculation time for each iteration

Methods ICA PSO GA DE

Average Calculation time

for each iteration (sec) 156.94 197.93 178.84 196.61

The ICA optimization, also have the least computation time. This can be due to the nature

of ICA method. In ICA method in each iteration, the solution with highest cost is added to

the solution group with a lesser cost. This means more local search (exploitation) and less

global search (exploration). Therefore, when all the solutions come under the flag of only

one empire the exploration almost stop and the rest of the iterations keep on with only

exploitation, and because of less exploration, the calculation time decreases gradually. Due

Page 111: Fuzzy PID Controller Optimization for Robot Dynamics with ...

91

to this characteristic, the ICA can result in an immature convergence, which has a sharp

convergence rate in the beginning but later, traps in a suboptimal solution.

When the FPID is optimized, it will be used as an online controller. The average calculation

times for the online controllers, are not very different in various approaches in this study.

This is because the optimization variables are only effecting the quality of FPID not

quantity. For example, the number of MFs are fixed but the position of each membership

function is the subject of optimization.

6.2 Future Works

As described in this dissertation, the classical PID controller is usually not appropriate for

systems with high order dynamics, time-varying systems, and nonlinear systems; while the

DE-optimized FPID approach can lead to results that are more promising. The simulation

results in this thesis have shown the efficacy and feasibility of this approach. In the future,

the proposed optimized FPID implementation requires an experiment with a real-world

control problem to test the controller’s robustness under various situations such as noise

and minor plant changes. The kinetics of a 3 DOF robot was studied in this dissertation. In

order to simulate a real-world problem the robot’s kinematics can also be added to the

control system.

This work can be improved in the future in several areas. Other metaheuristic optimization

methods such as cuckoo algorithm, fruit fly algorithm, ant colony, simulated annealing

algorithm, Grasshopper Algorithm, bee algorithm, etc. can be applied to the system to

evaluate their effectiveness on FPID robotic controllers.

Page 112: Fuzzy PID Controller Optimization for Robot Dynamics with ...

92

In this dissertation, in order to reduce the calculation expense, the variable string consisted

of 31 individuals. We used a diagonal approach to confine the rule table variables from 49

to 7, for each rule table, or in total from 147 to 21. In addition, the variables for MFs was

simplified from 21 to 2, for each input MF, and from 12 to 4 for the third output MF.

Therefore, in the general case there were 193 variables, which simplified to 31 variables.

Other methods could be used to reduce the variables and the results could be compared to

the ones in this thesis.

For ICA optimization, the problem of reduction in exploration capacity when the

population number is less than the iteration number, can also be a subject of improvement.

Page 113: Fuzzy PID Controller Optimization for Robot Dynamics with ...

93

7 References

[1] F. Hoffmann, Soft computing : methodologies and applications, 1st ed. Berlin ; New York: Springer, 2005.

[2] M. A. Johnson, M. H. Moradi, and J. Crowe, PID control : new identification and design methods. New York: Springer, 2005.

[3] D. Driankov, Hellendoorn, H. and Palm, R., "Some research directions in fuzzy control," in Aspects of Fuzzy Control, M. S. H.T. Nguyen, R. Tong and R.R. Yager, Ed., ed Chichester: John Wiley, 1995.

[4] J. G. Ziegler and N. B. Nichols, "Optimum settings for automatic controllers," trans. ASME, vol. 64, 1942.

[5] J. Ziegler and N. Nichols, "Process lags in automatic control circuits," Trans. ASME, vol. 65, pp. 433-443, 1943.

[6] J.-H. Urrea-Quintero, J.-A. Hernández-Riveros, and N. Muñoz-Galeano, "Optimum PI/PID Controllers Tuning via an Evolutionary Algorithm," PID Control for Industrial Processes, p. 43, 2018.

[7] K. Tamura and H. Ohmori, "Adaptive PID control for asymptotic tracking problem of MIMO systems," chapter of the book PID control, implementation and tuning, edited by T. Mansour, publisher: InTech Education and Publishing, pp. 187-200, 2011.

[8] S.-Z. He, S. Tan, F.-L. Xu, and P.-Z. Wang, "Fuzzy self-tuning of PID controllers," Fuzzy sets and systems, vol. 56, pp. 37-46, 1993.

[9] O. Aycard, F. Charpillet, and J.-P. Haton, "A new approach to design fuzzy controllers for mobile robots navigation," in Proceedings 1997 IEEE International Symposium on Computational Intelligence in Robotics and Automation CIRA'97.'Towards New Computational Principles for Robotics and Automation', 1997, pp. 68-73.

[10] J. M. Mendel, Introduction to type-2 fuzzy logic control : theory and applications: Hoboken, New Jersey : IEEE : Wiley, 2014.

[11] C. Liu, J.-F. Peng, F.-Y. Zhao, and C. Li, "Design and optimization of fuzzy-PID controller for the nuclear reactor power control," Nuclear Engineering and Design, vol. 239, pp. 2311-2316, 2009.

[12] K. Yavarian, A. Mohammadian, and F. Hashemi, "Adaptive Neuro Fuzzy Inference System PID Controller for AVR System Using SNR-PSO Optimization," International Journal on Electrical Engineering and Informatics, vol. 7, p. 394, 2015.

[13] A. J. Al Gizi, "A particle swarm optimization, fuzzy PID controller with generator automatic voltage regulator," Soft Computing, vol. 23, pp. 8839-8853, 2019.

[14] M. Gheisarnejad, "An effective hybrid harmony search and cuckoo optimization algorithm based fuzzy PID controller for load frequency control," Applied Soft Computing, vol. 65, pp. 121-138, 2018.

[15] W. Sheng and Y. Bao, "Fruit fly optimization algorithm based fractional order fuzzy-PID controller for electronic throttle," Nonlinear Dynamics, vol. 73, pp. 611-619, 2013.

[16] H. Boubertakh, M. Tadjine, P.-Y. Glorennec, and S. Labiod, "Tuning fuzzy PID controllers using ant colony optimization," in 2009 17th Mediterranean Conference on Control and Automation, 2009, pp. 13-18.

[17] T.-J. Su, G.-Y. Chen, J.-C. Cheng, and C.-J. Yu, "Fuzzy PID controller design using synchronous bacterial foraging optimization," in The 3rd International Conference on Information Sciences and Interaction Sciences, 2010, pp. 639-642.

[18] D. K. Lal, A. K. Barisal, and M. Tripathy, "Load frequency control of multi area interconnected microgrid power system using grasshopper optimization algorithm optimized fuzzy PID controller," in 2018 Recent Advances on Engineering, Technology and Computational Sciences (RAETCS), 2018, pp. 1-6.

Page 114: Fuzzy PID Controller Optimization for Robot Dynamics with ...

94

[19] A. Ahmadi, H. Abdul Rahim, and R. Abdul Rahim, "Optimization of a self-tuning PID type fuzzy controller and a PID controller for an inverted pendulum," Journal of Intelligent & Fuzzy Systems, vol. 26, pp. 1987-1999, 2014.

[20] J. Ju, Y. Zhao, C. Zhang, and Y. Liu, "Vibration suppression of a flexible-joint robot based on parameter identification and fuzzy PID control," Algorithms, vol. 11, p. 189, 2018.

[21] B. Nagaraj and N. Murugananth, "A comparative study of PID controller tuning using GA, EP, PSO and ACO," in 2010 International Conference On Communication Control And Computing Technologies, 2010, pp. 305-313.

[22] X. Li and W. Yu, "A systematic tunning method of PID controller for robot manipulators," in 2011 9th IEEE International Conference on Control and Automation (ICCA), 2011, pp. 274-279.

[23] A. Visioli, Practical PID control: Springer Science & Business Media, 2006. [24] S. Bennett, "A brief history of automatic control," IEEE Control Systems Magazine, vol.

16, pp. 17-25, 1996. [25] H. B. Patel and S. N. Chaphekar, "Developments in PID controllers: literature survey," Int.

J. Eng. Innov. Res, vol. 1, pp. 425-430, 2012. [26] G. Cohen, "Theoretical consideration of retarded control," Trans. Asme, vol. 75, pp. 827-

834, 1953. [27] K. J. Åström and T. Hägglund, "Automatic tuning of simple regulators with specifications

on phase and amplitude margins," Automatica, vol. 20, pp. 645-651, 1984. [28] B. D. Tyreus and W. L. Luyben, "Tuning PI controllers for integrator/dead time processes,"

Industrial & Engineering Chemistry Research, vol. 31, pp. 2625-2628, 1992. [29] C. E. Garcia and M. Morari, "Internal model control. A unifying review and some new

results," Industrial & Engineering Chemistry Process Design and Development, vol. 21, pp. 308-323, 1982.

[30] S. Bennett, "Development of the PID controller," IEEE Control Systems Magazine, vol. 13, pp. 58-62, 1993.

[31] S. W. Sung and I.-B. Lee, "Limitations and countermeasures of PID controllers," Industrial & engineering chemistry research, vol. 35, pp. 2596-2610, 1996.

[32] X.-J. Yao, J. Zhou, Y. Deng, C.-B. Yi, and Q.-D. Guo, "LPV H-infinity controller design for wind power generator," Journal of Shenyang University of Technology, vol. 30, pp. 514-519, 2008.

[33] Y. Choi and W. K. Chung, PID trajectory tracking control for mechanical systems vol. 298: Springer Science & Business Media, 2004.

[34] L. A. Zadeh, "Fuzzy sets," Information and control, vol. 8, pp. 338-353, 1965. [35] L. A. Zadeh, "A rationale for fuzzy control," 1972. [36] G. Feng, "A survey on analysis and design of model-based fuzzy control systems," IEEE

Transactions on Fuzzy systems, vol. 14, pp. 676-697, 2006. [37] E. H. Mamdani and S. Assilian, "An experiment in linguistic synthesis with a fuzzy logic

controller," in Readings in Fuzzy Sets for Intelligent Systems, ed: Elsevier, 1993, pp. 283-289.

[38] E. H. Mamdani, "Advances in the linguistic synthesis of fuzzy controllers," International Journal of Man-Machine Studies, vol. 8, pp. 669-678, 1976.

[39] E. H. Mamdani, "Application of fuzzy algorithms for control of simple dynamic plant," in Proceedings of the institution of electrical engineers, 1974, pp. 1585-1588.

[40] L. Holmblad and J.-J. Ostergaard, "Control of a cement kiln by fuzzy logic techniques," IFAC Proceedings Volumes, vol. 14, pp. 809-814, 1981.

[41] Y. Li and C. Lau, "Development of fuzzy algorithms for servo systems," IEEE Control Systems Magazine, vol. 9, pp. 65-72, 1989.

[42] S. M. Smith and D. J. Comer, "Automated calibration of a fuzzy logic controller using a cell state space algorithm," IEEE Control Systems Magazine, vol. 11, pp. 18-28, 1991.

Page 115: Fuzzy PID Controller Optimization for Robot Dynamics with ...

95

[43] C. Hsu and R. Guttalu, "An unravelling algorithm for global analysis of dynamical systems: An application of cell-to-cell mappings," 1980.

[44] A. Flores, D. Sáez, J. Araya, M. Berenguel, and A. Cipriano, "Fuzzy predictive control of a solar power plant," IEEE Transactions on Fuzzy Systems, vol. 13, pp. 58-68, 2005.

[45] H.-F. Kwok, D. A. Linkens, M. Mahfouf, and G. H. Mills, "SIVA: A hybrid knowledge-and-model-based advisory system for intensive care ventilators," IEEE Transactions on information technology in biomedicine, vol. 8, pp. 161-172, 2004.

[46] A. Abaspour, M. Sadeghi, and S. H. Sadati, "Using fuzzy logic in dynamic inversion flight controller with considering uncertainties," in 2013 13th Iranian Conference on Fuzzy Systems (IFSC), 2013, pp. 1-6.

[47] Y. H. Aoul, A. Nafaa, D. Négru, and A. Mehaoua, "FAFC: fast adaptive fuzzy AQM controller for TCP/IP networks," in IEEE Global Telecommunications Conference, 2004. GLOBECOM'04., 2004, pp. 1319-1323.

[48] H.-X. Li, "A comparative design and tuning for conventional fuzzy control," IEEE Transactions on Systems, Man, and Cybernetics, Part B (Cybernetics), vol. 27, pp. 884-889, 1997.

[49] Z.-Y. Zhao, M. Tomizuka, and S. Isaka, "Fuzzy gain scheduling of PID controllers," IEEE transactions on systems, man, and cybernetics, vol. 23, pp. 1392-1398, 1993.

[50] G. K. Mann, B.-G. Hu, and R. G. Gosine, "Two-level tuning of fuzzy PID controllers," IEEE Transactions on Systems, Man, and Cybernetics, Part B (Cybernetics), vol. 31, pp. 263-269, 2001.

[51] R. Kling, "Fuzzy planner," in Technical Report 168, ed: Computer Science Dept., University of Wisconsin, 1973.

[52] N. Mandič, E. Scharf, and E. Mamdani, "Practical application of a heuristic fuzzy rule-based controller to the dynamic control of a robot arm," in IEE Proceedings D (Control Theory and Applications), 1985, pp. 190-203.

[53] R. Tanscheit and E. Scharf, "Experiments with the use of a rule-based self-organising controller for robotics applications," Fuzzy sets and systems, vol. 26, pp. 195-214, 1988.

[54] D. Lakov, "Adaptive robot under fuzzy control," Fuzzy sets and systems, vol. 17, pp. 1-8, 1985.

[55] S. Murakami, F. Takemoto, H. Fujimura, and E. Ide, "Weld-line tracking control of arc welding robot using fuzzy logic controller," Fuzzy Sets and Systems, vol. 32, pp. 221-237, 1989.

[56] T. Takeuchi, Y. Nagai, and N. Enomoto, "Fuzzy control of a mobile robot for obstacle avoidance," Information sciences, vol. 45, pp. 231-248, 1988.

[57] V. G. Moudgal, W. A. Kwong, K. M. Passino, and S. Yurkovich, "Fuzzy learning control for a flexible-link robot," IEEE Transactions on Fuzzy Systems, vol. 3, pp. 199-210, 1995.

[58] Y. Li, K. H. Ang, and G. C. Chong, "PID control system analysis and design," IEEE Control Systems Magazine, vol. 26, pp. 32-41, 2006.

[59] H. V. N. Lemke and W. De-Zhao, "Fuzzy PID supervisor," in 1985 24th IEEE Conference on Decision and Control, 1985, pp. 602-608.

[60] P. MacVicar-Whelan, "Fuzzy sets for man-machine interaction," International Journal of Man-Machine Studies, vol. 8, pp. 687-697, 1976.

[61] D. Kwok, P. Tam, C. Li, and P. Wang, "Analysis and design of fuzzy PID control systems," in International Conference on Control 1991. Control'91, 1991, pp. 955-960.

[62] K. K. Kumbla and M. Jamshidi, "Control of robotic manipulator using fuzzy logic," in Proceedings of 1994 IEEE 3rd International Fuzzy Systems Conference, 1994, pp. 518-523.

[63] H. A. Malki, D. Misir, D. Feigenspan, and G. Chen, "Fuzzy PID control of a flexible-joint robot arm with uncertainties from time-varying loads," IEEE Transactions on Control Systems Technology, vol. 5, pp. 371-378, 1997.

Page 116: Fuzzy PID Controller Optimization for Robot Dynamics with ...

96

[64] J. Carvajal, G. Chen, and H. Ogmen, "Fuzzy PID controller: Design, performance evaluation, and stability analysis," Information sciences, vol. 123, pp. 249-270, 2000.

[65] G. Khoury, M. Saad, H. Y. Kanaan, and C. Asmar, "Fuzzy PID control of a five DOF robot arm," Journal of Intelligent and Robotic systems, vol. 40, pp. 299-320, 2004.

[66] Y. Fu, B. Zhao, Y. Hu, S. Liu, Y. Qian, and Y. Wan, "Fuzzy-PID Hybrid Control Strategy for Pneumatic Driven Surgical Robot," in 2018 IEEE 8th Annual International Conference on CYBER Technology in Automation, Control, and Intelligent Systems (CYBER), 2018, pp. 261-266.

[67] O. Bozorg-Haddad, M. Solgi, and H. A. Loáiciga, Meta-heuristic and evolutionary algorithms for engineering optimization: John Wiley & Sons, 2017.

[68] P. Wang and D. Kwok, "Optimal fuzzy PID control based on genetic algorithm," in Proceedings of the 1992 International Conference on Industrial Electronics, Control, Instrumentation, and Automation, 1992, pp. 977-981.

[69] G. Zhou and J. Birdwell, "Fuzzy logic-based PID autotuner design using simulated annealing," in Proceedings of IEEE Symposium on Computer-Aided Control Systems Design (CACSD), 1994, pp. 67-72.

[70] K.-S. Tang, K. F. Man, G. Chen, and S. Kwong, "An optimal fuzzy PID controller," IEEE transactions on industrial electronics, vol. 48, pp. 757-765, 2001.

[71] S. P. Ghoshal, "Optimizations of PID gains by particle swarm optimizations in fuzzy based automatic generation control," Electric Power Systems Research, vol. 72, pp. 203-212, 2004.

[72] P. C. Pradhan, R. K. Sahu, and S. Panda, "Firefly algorithm optimized fuzzy PID controller for AGC of multi-area multi-source power systems with UPFC and SMES," Engineering Science and Technology, an International Journal, vol. 19, pp. 338-354, 2016.

[73] R. K. Sahu, G. C. Sekhar, and S. Panda, "DE optimized fuzzy PID controller with derivative filter for LFC of multi source power system in deregulated environment," Ain Shams Engineering Journal, vol. 6, pp. 511-530, 2015.

[74] A. M. Yazdani, A. Ahmadi, S. Buyamin, M. F. a. Rahmat, F. Davoudifar, and H. A. Rahim, "IMPERIALIST COMPETITIVE ALGORITHM-BASED FUZZY PID CONTROL METHODOLOGY FOR SPEED TRACKING ENHANCEMENT OF STEPPER MOTOR," International Journal on Smart Sensing & Intelligent Systems, vol. 5, 2012.

[75] T. Chaiyatham, I. Ngamroo, S. Pothiya, and S. Vachirasricirikul, "Design of optimal fuzzy logic-PID controller using bee colony optimization for frequency control in an isolated wind-diesel system," in 2009 Transmission & Distribution Conference & Exposition: Asia and Pacific, 2009, pp. 1-4.

[76] O. Abedinia, M. S. Naderi, and A. Ghasemi, "Robust LFC in deregulated environment: Fuzzy PID using HBMO," in 2011 10th International Conference on Environment and Electrical Engineering, 2011, pp. 1-4.

[77] K. Premkumar and B. Manikandan, "Bat algorithm optimized fuzzy PD based speed controller for brushless direct current motor," Engineering Science and Technology, an International Journal, vol. 19, pp. 818-840, 2016.

[78] R. Storn and K. Price, "Differential evolution–a simple and efficient adaptive scheme for global optimization over continuous spaces: technical report TR-95-012," International Computer Science, Berkeley, California, 1995.

[79] R. Storn and K. Price, "Minimizing the real functions of the ICEC'96 contest by differential evolution," in Proceedings of IEEE International Conference on Evolutionary Computation, 1996, pp. 842-844.

[80] R. Storn and K. Price, "Differential evolution a simple evolution strategy for fast optimization," Dr. Dobb's Journal, vol. 22, pp. 18-24, 1997.

Page 117: Fuzzy PID Controller Optimization for Robot Dynamics with ...

97

[81] R. Storn and K. Price, "Differential evolution–a simple and efficient heuristic for global optimization over continuous spaces," Journal of global optimization, vol. 11, pp. 341-359, 1997.

[82] D. Zaharie, "Critical values for the control parameters of differential evolution algorithms," in Proc. of MENDEL 2002, 8th Int. Conf. on Soft Computing, 2002, pp. 62-67.

[83] J. Liu, J. Lampinen, R. Matousek, and P. Osmera, "Adaptive parameter control of differential evolution," in Proc. of MENDEL, 2002, pp. 19-26.

[84] J. Rönkkönen and J. Lampinen, "On using normally distributed mutation step length for the differential evolution algorithm," in Mendel, 2003, pp. 11-18.

[85] A. K. Qin and P. N. Suganthan, "Self-adaptive differential evolution algorithm for numerical optimization," in 2005 IEEE congress on evolutionary computation, 2005, pp. 1785-1791.

[86] S. Das, A. Konar, and U. K. Chakraborty, "Two improved differential evolution schemes for faster global search," in Proceedings of the 7th annual conference on Genetic and evolutionary computation, 2005, pp. 991-998.

[87] J. Brest, S. Greiner, B. Boskovic, M. Mernik, and V. Zumer, "Self-adapting control parameters in differential evolution: A comparative study on numerical benchmark problems," IEEE transactions on evolutionary computation, vol. 10, pp. 646-657, 2006.

[88] S. Rahnamayan, H. R. Tizhoosh, and M. M. Salama, "Opposition-based differential evolution," IEEE Transactions on Evolutionary computation, vol. 12, pp. 64-79, 2008.

[89] R. Storn, "Differential evolution research–trends and open questions," in Advances in differential evolution, ed: Springer, 2008, pp. 1-31.

[90] W. Y. W. Jingcheng, "Fuzzy-PID control using a differential evolution for steam turbine speed governing system," Journal of Southeast University (Natural Science Edition), p. S1, 2011.

[91] H. Beirami, A. Z. Shabestari, and M. M. Zerafat, "Optimal PID plus fuzzy controller design for a PEM fuel cell air feed system using the self-adaptive differential evolution algorithm," International journal of hydrogen energy, vol. 40, pp. 9422-9434, 2015.

[92] J. J. Craig, Introduction to robotics: mechanics and control, 3/E: Pearson Education India, 2009.

[93] K. M. Lynch, N. Shiroma, H. Arai, and K. Tanie, "Collision-free trajectory planning for a 3-DOF robot with a passive joint," The International Journal of Robotics Research, vol. 19, pp. 1171-1184, 2000.

[94] F. L. Lewis, D. Vrabie, and V. L. Syrmos, Optimal control: John Wiley & Sons, 2012. [95] I. Türkşen and M. F. Zarandi, "Production planning and scheduling: Fuzzy and crisp

approaches," in Practical applications of fuzzy technologies, ed: Springer, 1999, pp. 479-529.

[96] R. Belohlavek, G. J. Klir, E. Machery, E. Rosch, J. Verkuilen, J. Hampton, et al., Concepts and Fuzzy Logic. Cambridge, UNITED STATES: MIT Press, 2011.

[97] S. Sivanandam, S. Sumathi, and S. Deepa, Introduction to fuzzy logic using MATLAB vol. 1: Springer, 2007.

[98] Y. Bai, H. Zhuang, and D. Wang, Advanced fuzzy logic technologies in industrial applications: Springer Science & Business Media, 2007.

[99] J.-S. R. Jang, C.-T. Sun, and E. Mizutani, "Neuro-fuzzy and soft computing-a computational approach to learning and machine intelligence [Book Review]," IEEE Transactions on automatic control, vol. 42, pp. 1482-1484, 1997.

[100] S. Krishna and S. Vasu, "Fuzzy PID based adaptive control on industrial robot," J. Mater. Today, vol. 5, pp. 13055-13060, 2018.

[101] K. Price, R. M. Storn, and J. A. Lampinen, Differential evolution: a practical approach to global optimization: Springer Science & Business Media, 2006.

[102] U. K. Chakraborty, Advances in differential evolution vol. 143: Springer, 2008.

Page 118: Fuzzy PID Controller Optimization for Robot Dynamics with ...

98

[103] G. Boukhalfa, S. Belkacem, A. Chikhi, and S. Benaggoune, "Genetic algorithm and particle swarm optimization tuned fuzzy PID controller on direct torque control of dual star induction motor," Journal of Central South University, vol. 26, pp. 1886-1896, 2019.

[104] M. Couceiro and P. Ghamisi, "Particle swarm optimization," in Fractional Order Darwinian Particle Swarm Optimization, ed: Springer, 2016, pp. 1-10.

[105] A. Kaveh, Advances in metaheuristic algorithms for optimal design of structures: Springer, 2014.

[106] R. C. Eberhart, Y. Shi, and J. Kennedy, Swarm intelligence: Elsevier, 2001. [107] M. Clerc and J. Kennedy, "The particle swarm-explosion, stability, and convergence in a

multidimensional complex space," IEEE transactions on Evolutionary Computation, vol. 6, pp. 58-73, 2002.

[108] S. Hosseini, A. Al Khaled, and S. Vadlamani, "Hybrid imperialist competitive algorithm, variable neighborhood search, and simulated annealing for dynamic facility layout problem," Neural Computing and Applications, vol. 25, pp. 1871-1885, 2014.

[109] S. Nazari-Shirkouhi, H. Eivazy, R. Ghodsi, K. Rezaie, and E. Atashpaz-Gargari, "Solving the integrated product mix-outsourcing problem using the imperialist competitive algorithm," Expert Systems with Applications, vol. 37, pp. 7615-7626, 2010.

Page 119: Fuzzy PID Controller Optimization for Robot Dynamics with ...

99

Appendix A: Codes

A.1 DE Optimization Code

clc; clear; close all; warning OFF %% Problem Definition global flc1 flc Alpha Beta flc1 = readfis('flc.fis'); %Original fis CostFunction=@(x) flc_cost_function_sim(x); % Cost Function nX=31; %Number of variable XSize=[1 nX]; % Size of Variables Matrix XMin=[ ones(1,14) ones(1,7) 0.01 0.01 0.01 0.01 1 1 1 1 250 25]; % Lower Bound of Variables XMax=[2.99*ones(1,14) 4.99*ones(1,7) pi pi 10 10 6 6 6 6 400 38]; % Upper Bound of Variables %% DE Parameters Iterations=100; % Maximum Number of Iterations n_Pop=20; % Population Size b_min=0.2; % Lower Bound of Scaling Factor b_max=0.8; % Upper Bound of Scaling Factor P_Cr=0.2; % Probability of Crossover %% Initialization disp(['Initialization']); Best_Sol.Cost=inf; empty.Cost=[]; empty.Position=[]; pop=repmat(empty,n_Pop,1); for i=1:n_Pop disp(['Positioning number: ' num2str(i)]); pop(i).Position=unifrnd(XMin,XMax,XSize);

Page 120: Fuzzy PID Controller Optimization for Robot Dynamics with ...

100

[pop(i).Cost]=CostFunction(pop(i).Position); if pop(i).Cost < Best_Sol.Cost Best_Sol=pop(i); end end Best_Cost=zeros(Iterations,1); %% DE Main Loop for it=1:Iterations for i=1:n_Pop x=pop(i).Position; M=randperm(n_Pop); M(M==i)=[]; a1=M(1); a2=M(2); a3=M(3); % Mutation beta=unifrnd(b_min,b_max,XSize); y=pop(a1).Position+beta.*(pop(a2).Position-pop(a3).Position); % Crossover z=zeros(size(x)); b0=randi([1 numel(x)]); for j=1:numel(x) if j==b0 || rand<=P_Cr z(j)=y(j); else z(j)=x(j); end end for ii=1:nX if z(ii) < XMin(ii) z(ii)=XMin(ii); else if z(ii) > XMax(ii) z(ii) = XMax(ii);

Page 121: Fuzzy PID Controller Optimization for Robot Dynamics with ...

101

end end end Next_Sol.Position=z; [Next_Sol.Cost]=CostFunction(Next_Sol.Position); if Next_Sol.Cost<pop(i).Cost pop(i)=Next_Sol; if pop(i).Cost<Best_Sol.Cost Best_Sol=pop(i); end end end % Update Best Cost Best_Cost(it)=Best_Sol.Cost; % Show Iteration Information disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(Best_Cost(it))]); disp(['Best Solution: ' num2str(Best_Sol.Position)]); end set(0,'defaulttextfontsize',14); set(0,'defaultaxesfontsize',14); x=Best_Sol.Position; [cost, out] = flc_cost_function_sim(x); save('DE_result20') %% Plots FigH = figure('Position', get(0, 'Screensize')); plot(Best_Cost); xlabel('Iteration') ylabel('Best Cost(Absolute summatoin of Error)') hold on plot(Best_Cost, 'x') title('Best Cost Result for DE method npop=20') F = getframe(FigH); imwrite(F.cdata, 'Bestcost.jpg', 'jpg')

Page 122: Fuzzy PID Controller Optimization for Robot Dynamics with ...

102

x=Best_Sol.Position; Alpha=x(30);Beta=x(31); t=sim('simul4DOF3'); Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; FigH = figure('Position', get(0, 'Screensize')); plot(t,Theta) xlabel('t(seconds)') ylabel('\theta(rad)') legend('Desired \theta1','Desired \theta2','Desired \theta3','Actual \theta1','Actual \theta2','Actual \theta3') title('Comparison between desired and actual \theta for DE method npop=20') F = getframe(FigH); imwrite(F.cdata, 'theta.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plot(t,error) xlabel('t(seconds)') ylabel('error(rad)') legend('\theta1 Error','\theta2 Error','\theta3 Error') title('Error for DE method, npop=20') F = getframe(FigH); imwrite(F.cdata, 'error.jpg', 'jpg') % plot Fuzzy Parameters FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',1) title('Optimized input 1 MFs by DE method, npop=30,it=20') F = getframe(FigH); imwrite(F.cdata, 'MF1.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',2) title('Optimized input 2 MFs by DE method, npop=30,it=20') F = getframe(FigH); imwrite(F.cdata, 'MF2.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'output',3) title('Optimized output 3 MFs by DE method, npop=30,it=20') F = getframe(FigH); imwrite(F.cdata, 'MF3.jpg', 'jpg')

Page 123: Fuzzy PID Controller Optimization for Robot Dynamics with ...

103

opt1 = gensurfOptions('OutputIndex',1); opt2 = gensurfOptions('OutputIndex',2); opt3 = gensurfOptions('OutputIndex',3); FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt1) title("Optimized rules surface for K'p by DE method, npop=30,it=20") F = getframe(FigH); imwrite(F.cdata, 'Kpp.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt2) title("Optimized rules surface for K'd by DE method, npop=30,it=20") F = getframe(FigH); imwrite(F.cdata, 'Kdd.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt3) title("Optimized rules surface for Alpha by DE method, npop=30,it=20") F = getframe(FigH); imwrite(F.cdata, 'alpha.jpg', 'jpg') %% Gathering information y1_DE=Theta(:,4); y1final=mean(Theta(:,1)); S1_DE= stepinfo(y1_DE,t,y1final); y2_DE=Theta(:,5); y2final=mean(Theta(:,2)); S2_DE= stepinfo(y2_DE,t,y2final); y3_DE=Theta(:,6); y3final=mean(Theta(:,3)); S3_DE= stepinfo(y3_DE,t,y3final); S_DE.Overshoot=(S1_DE.Overshoot+S2_DE.Overshoot+S3_DE.Overshoot)/3; S_DE.MAE=sumabs(error); S_DE.Theta=Theta; S_DE.cost=cost; S_DE.s1=S1_DE; S_DE.s2=S2_DE;

Page 124: Fuzzy PID Controller Optimization for Robot Dynamics with ...

104

S_DE.s3=S3_DE; S_DE.BestSol=Best_Sol; S_DE.BestCost=Best_Cost; S_DE.K1=K1.signals.values; S_DE.K2=K2.signals.values; S_DE.K3=K3.signals.values; S_DE.Torque=Torque.signals.values; save('S_DE','S_DE'); %% Function function [cost, out] = flc_cost_function_sim(p) global flc1 flc Alpha Beta flc = flc1; a = floor(p(1:7)); b = floor(p(8:14)); c = floor(p(15:21)); ix1 = {1; [2 8]; [3 9 15]; [4:6:22]; [5:6:29]; [6:6:36]; [7:6:43]}; ix2 = {[14:6:44]; [21:6:45]; [28:6:46 ]; [35:6:47]; [42 48]; 49}; % update rules for i = 1:7 for j = 1:numel(ix1{i}) flc.rule(ix1{i}(j)).consequent(1) = a(i); flc.rule(ix1{i}(j)).consequent(2) = b(i); flc.rule(ix1{i}(j)).consequent(3) = c(i); end end for i = 1:6

Page 125: Fuzzy PID Controller Optimization for Robot Dynamics with ...

105

for j = 1:numel(ix2{i}) flc.rule(ix2{i}(j)).consequent(1) = 3-a(7-i); flc.rule(ix2{i}(j)).consequent(2) = 3-b(7-i); flc.rule(ix2{i}(j)).consequent(3) = 5-c(7-i); end end for ii=1:7 for jj=1:7 T_Kp(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(1); end end for ii=1:7 for jj=1:7 T_Kd(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(2); end end for ii=1:7 for jj=1:7 T_Alpha(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(3); end end % update input MFs if p(23)<p(22) %swap z = p(22); p(22) = p(23); p(23) = z; end flc.input(1).mf(5).params(2) = p(22); flc.input(1).mf(4).params(3) = p(22); flc.input(1).mf(6).params(1) = p(22); flc.input(1).mf(3).params(2) = -p(22); flc.input(1).mf(2).params(3) = -p(22); flc.input(1).mf(4).params(1) = -p(22); flc.input(1).mf(6).params(2) = p(23); flc.input(1).mf(5).params(3) = p(23); flc.input(1).mf(7).params(1) = p(23);

Page 126: Fuzzy PID Controller Optimization for Robot Dynamics with ...

106

flc.input(1).mf(2).params(2) = -p(23); flc.input(1).mf(1).params(3) = -p(23); flc.input(1).mf(3).params(1) = -p(23); if p(25)<p(24) %swap z = p(24); p(24) = p(25); p(25) = z; end flc.input(2).mf(5).params(2) = p(24); flc.input(2).mf(4).params(3) = p(24); flc.input(2).mf(6).params(1) = p(24); flc.input(2).mf(3).params(2) = -p(24); flc.input(2).mf(2).params(3) = -p(24); flc.input(2).mf(4).params(1) = -p(24); flc.input(2).mf(6).params(2) = p(25); flc.input(2).mf(5).params(3) = p(25); flc.input(2).mf(7).params(1) = p(25); flc.input(2).mf(2).params(2) = -p(25); flc.input(2).mf(1).params(3) = -p(25); flc.input(2).mf(3).params(1) = -p(25); % update output MFs z=[p(26:29)]; [s ind]=sort(z); p(26:29)=z(ind); flc.output(3).mf(1).params(1) = 1; flc.output(3).mf(1).params(2) = p(26); flc.output(3).mf(2).params(1) = p(26); flc.output(3).mf(2).params(2) = p(27); flc.output(3).mf(3).params(1) = p(27); flc.output(3).mf(1).params(3) = p(27); flc.output(3).mf(3).params(2) = p(28); flc.output(3).mf(4).params(1) = p(28); flc.output(3).mf(2).params(3) = p(28); flc.output(3).mf(4).params(2) = p(29); flc.output(3).mf(3).params(3) = p(29); flc.output(3).mf(4).params(3) = 6; % update gains Alpha = p(30); Beta = p(31);

Page 127: Fuzzy PID Controller Optimization for Robot Dynamics with ...

107

dt = 0.01; Tf = 8; sim('simul4DOF3') Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ;Theta(:,2)-Theta(:,5) ; Theta(:,3)-Theta(:,6) ]; [Thmax1 ind1]= max(Theta(:,4)); Os1=Theta(ind1,4)-mean(Theta(:,1)); [Thmax2 ind2]= max(Theta(:,5)); Os2=Theta(ind2,5)-mean(Theta(:,2)); [Thmax3 ind3]= max(Theta(:,6)); Os3=Theta(ind3,6)-mean(Theta(:,3)); cost = 0.01*sumabs(error)+(Os1+Os2+Os3); out.Y = Theta; out.Os = [Os1, Os2, Os3]; out.flc = flc; out.T_Kp = T_Kp; out.T_Kd = T_Kd; out.T_Alpha = T_Alpha; out.t = 0:dt:Tf; A.2 GA optimization code

clc; clear; close all; warning('off') %% Problem Definition global flc1 flc Alpha Beta flc1 = readfis('flc.fis'); %Original fis CostFunction=@(x) flc_cost_function_sim(x); % Cost Function nX=31; % Number of Variables XSize=[1 nX]; % Size of Variables Matrix

Page 128: Fuzzy PID Controller Optimization for Robot Dynamics with ...

108

XMin=[ ones(1,14) ones(1,7) 0.01 0.01 0.01 0.01 1 1 1 1 260 27]; % Lower Bound of Variables XMax=[2.99*ones(1,14) 4.99*ones(1,7) pi pi 10 10 6 6 6 6 380 35]; % Upper Bound of Variables XRange= [XMin;XMax]; % Variation Range of Variables %% GA Parameters Iterations=100; % Maximum Number of Iterations n_Pop=20; % Population Size P_Cross=0.7; % Crossover Percentage n_Cross=round(P_Cross*n_Pop/2)*2; % Number of Parents (Offsprings) P_Mutat=0.2; % Mutation Percentage n_Mutat=round(P_Mutat*n_Pop); % Number of Mutants rat_Mutat=0.2; % Mutation rate in one Mutant %% Initialization disp(['Initialization']); % Empty Structure to keep member's Data empty.Position=[]; empty.Cost=[]; % Create Population Matrix pop=repmat(empty,n_Pop,1); % Initialize Positions for i=1:n_Pop disp(['Positioning number: ' num2str(i)]); pop(i).Position=unifrnd(XMin,XMax,XSize); [pop(i).Cost]=CostFunction(pop(i).Position); end % Sort Population pop=SortPopulation(pop);

Page 129: Fuzzy PID Controller Optimization for Robot Dynamics with ...

109

% Store Best Solution Best_Sol=pop(1); % Vector to Hold Best Cost Values Best_Cost=zeros(Iterations,1); %% GA Main Loop for it=1:2 tic % Crossover disp(['Crossover']); pop_c=repmat(empty,n_Cross/2,2); for k=1:n_Cross/2 i1=randi([1 n_Pop]); i2=randi([1 n_Pop]); p1=pop(i1); p2=pop(i2); [pop_c(k,1).Position pop_c(k,2).Position]=Crossover(p1.Position,p2.Position,XRange); [pop_c(k,1).Cost]=CostFunction(pop_c(k,1).Position); [pop_c(k,2).Cost]=CostFunction(pop_c(k,2).Position); end pop_c=pop_c(:); % Mutation disp(['Mutation ']); popm=repmat(empty,n_Mutat,1); for k=1:n_Mutat i=randi([1 n_Pop]); p=pop(i);

Page 130: Fuzzy PID Controller Optimization for Robot Dynamics with ...

110

popm(k).Position=Mutate(p.Position,XRange,rat_Mutat); [popm(k).Cost ]=CostFunction(popm(k).Position); end % Merge Population pop=[pop pop_c popm]; % Sort Population pop=SortPopulation(pop); % Delete Extra Individuals pop=pop(1:n_Pop); % Update Best Solution Best_Sol=pop(1); % Store Best Cost Best_Cost(it)=Best_Sol.Cost; BestParams.it=Best_Sol.Position; % Show Iteration Information disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(Best_Cost(it))]); disp(['Best Sol ' num2str(Best_Sol.Position)]); end x=Best_Sol.Position; [cost, out] = flc_cost_function_sim(x); save('GA_result20') FigH = figure('Position', get(0, 'Screensize')); plot(Best_Cost); xlabel('MaxIt(iteration)') ylabel('Best Cost(Absolute summatoin of Error)') hold on plot(Best_Cost, 'x') title(['Best Cost Result for GA method npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'BestCost.jpg', 'jpg') x=Best_Sol.Position; Alpha=x(30);Beta=x(31); t=sim('simul4DOF3');

Page 131: Fuzzy PID Controller Optimization for Robot Dynamics with ...

111

Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; FigH = figure('Position', get(0, 'Screensize')); plot(t,Theta) xlabel('t(seconds)') ylabel('\theta(rad)') legend('Desired \theta1','Desired \theta2','Desired \theta3','Actual \theta1','Actual \theta2','Actual \theta3') title(['Comparison between desired and actual \theta for GA method npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Desiredtheta.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plot(t,error) xlabel('t(seconds)') ylabel('error(rad)') legend('\theta1 Error','\theta2 Error','\theta3 Error') title(['Error for GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'errors.jpg', 'jpg') % plot Fuzzy Parameters FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',1) title(['Optimized input 1 MFs by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'MF1.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',2) title(['Optimized input 2 MFs by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'MF2.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'output',3) title(['Optimized output 3 MFs by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)])

Page 132: Fuzzy PID Controller Optimization for Robot Dynamics with ...

112

F = getframe(FigH); imwrite(F.cdata, 'MF3.jpg', 'jpg') opt1 = gensurfOptions('OutputIndex',1); opt2 = gensurfOptions('OutputIndex',2); opt3 = gensurfOptions('OutputIndex',3); FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt1) title(['Optimized rules surface for K''p by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Kpp.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt2) title(['Optimized rules surface for K''d by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Kdd.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt3) title(['Optimized rules surface for Alpha by GA method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'alpha.jpg', 'jpg') %% Gathering information y1_GA=Theta(:,4); y1final=mean(Theta(:,1)); S1_GA= stepinfo(y1_GA,t,y1final); y2_GA=Theta(:,5); y2final=mean(Theta(:,2)); S2_GA= stepinfo(y2_GA,t,y2final); y3_GA=Theta(:,6); y3final=mean(Theta(:,3)); S3_GA= stepinfo(y3_GA,t,y3final);

Page 133: Fuzzy PID Controller Optimization for Robot Dynamics with ...

113

S_GA.Overshoot=(S1_GA.Overshoot+S2_GA.Overshoot+S3_GA.Overshoot)/3; S_GA.MAE=sumabs(error); S_GA.Theta=Theta; S_GA.cost=cost; S_GA.s1=S1_GA; S_GA.s2=S2_GA; S_GA.s3=S3_GA; S_GA.BestCost=Best_Cost; S_GA.BestSol=Best_Sol; S_GA.K1=K1.signals.values; S_GA.K2=K2.signals.values; S_GA.K3=K3.signals.values; S_GA.Torque=Torque.signals.values; save('S_GA','S_GA'); %% Function function [cost, out] = flc_cost_function_sim(p) global flc1 flc Alpha Beta flc = flc1; a = floor(p(1:7)); b = floor(p(8:14)); c = floor(p(15:21)); ix1 = {1; [2 8]; [3 9 15]; [4:6:22]; [5:6:29]; [6:6:36]; [7:6:43]}; ix2 = {[14:6:44]; [21:6:45]; [28:6:46 ]; [35:6:47]; [42 48]; 49};

Page 134: Fuzzy PID Controller Optimization for Robot Dynamics with ...

114

% update rules for i = 1:7 for j = 1:numel(ix1{i}) flc.rule(ix1{i}(j)).consequent(1) = a(i); flc.rule(ix1{i}(j)).consequent(2) = b(i); flc.rule(ix1{i}(j)).consequent(3) = c(i); end end for i = 1:6 for j = 1:numel(ix2{i}) flc.rule(ix2{i}(j)).consequent(1) = 3-a(7-i); flc.rule(ix2{i}(j)).consequent(2) = 3-b(7-i); flc.rule(ix2{i}(j)).consequent(3) = 5-c(7-i); end end for ii=1:7 for jj=1:7 T_Kp(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(1); end end for ii=1:7 for jj=1:7 T_Kd(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(2); end end for ii=1:7 for jj=1:7 T_Alpha(ii,jj)=flc.rule(7*(jj-1)+ii).consequent(3); end end % update input MFs if p(23)<p(22) %swap z = p(22); p(22) = p(23); p(23) = z; end

Page 135: Fuzzy PID Controller Optimization for Robot Dynamics with ...

115

flc.input(1).mf(5).params(2) = p(22); flc.input(1).mf(4).params(3) = p(22); flc.input(1).mf(6).params(1) = p(22); flc.input(1).mf(3).params(2) = -p(22); flc.input(1).mf(2).params(3) = -p(22); flc.input(1).mf(4).params(1) = -p(22); flc.input(1).mf(6).params(2) = p(23); flc.input(1).mf(5).params(3) = p(23); flc.input(1).mf(7).params(1) = p(23); flc.input(1).mf(2).params(2) = -p(23); flc.input(1).mf(1).params(3) = -p(23); flc.input(1).mf(3).params(1) = -p(23); if p(25)<p(24) %swap z = p(24); p(24) = p(25); p(25) = z; end flc.input(2).mf(5).params(2) = p(24); flc.input(2).mf(4).params(3) = p(24); flc.input(2).mf(6).params(1) = p(24); flc.input(2).mf(3).params(2) = -p(24); flc.input(2).mf(2).params(3) = -p(24); flc.input(2).mf(4).params(1) = -p(24); flc.input(2).mf(6).params(2) = p(25); flc.input(2).mf(5).params(3) = p(25); flc.input(2).mf(7).params(1) = p(25); flc.input(2).mf(2).params(2) = -p(25); flc.input(2).mf(1).params(3) = -p(25); flc.input(2).mf(3).params(1) = -p(25); % update output MFs z=[p(26:29)]; [s ind]=sort(z); p(26:29)=z(ind); flc.output(3).mf(1).params(1) = 1; flc.output(3).mf(1).params(2) = p(26); flc.output(3).mf(2).params(1) = p(26); flc.output(3).mf(2).params(2) = p(27); flc.output(3).mf(3).params(1) = p(27);

Page 136: Fuzzy PID Controller Optimization for Robot Dynamics with ...

116

flc.output(3).mf(1).params(3) = p(27); flc.output(3).mf(3).params(2) = p(28); flc.output(3).mf(4).params(1) = p(28); flc.output(3).mf(2).params(3) = p(28); flc.output(3).mf(4).params(2) = p(29); flc.output(3).mf(3).params(3) = p(29); flc.output(3).mf(4).params(3) = 6; % update gains Alpha = p(30); Beta = p(31); dt = 0.01; Tf = 8; sim('simul4DOF3') Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ;Theta(:,2)-Theta(:,5) ; Theta(:,3)-Theta(:,6) ]; [Thmax1 ind1]= max(Theta(:,4)); Os1=Theta(ind1,4)-mean(Theta(:,1)); [Thmax2 ind2]= max(Theta(:,5)); Os2=Theta(ind2,5)-mean(Theta(:,2)); [Thmax3 ind3]= max(Theta(:,6)); Os3=Theta(ind3,6)-mean(Theta(:,3)); cost = 0.01*sumabs(error)+(Os1+Os2+Os3); out.Y = Theta; out.Os = [Os1, Os2, Os3]; out.flc = flc; out.T_Kp = T_Kp; out.T_Kd = T_Kd; out.T_Alpha = T_Alpha; out.t = 0:dt:Tf; %% Mutation Function function y=Mutate(x,XRange,rat_Mutat) XMin=(XRange(1,:)); XMax=(XRange(2,:)); nX=numel(XMin); nm=floor(rat_Mutat*nX);

Page 137: Fuzzy PID Controller Optimization for Robot Dynamics with ...

117

y=x; for i=1:nm j=randi([1 nX]); y(j)=x(j)+0.1*(XMax(j)-XMin(j))*randn; end y=min(max(y,XMin),XMax); end %% Crossover Function function [y1 y2]=Crossover(x1,x2,XRange) nX=numel(x1); for i=1:2 c(i)=randi([1 nX-1]); end c=sort(c); y1=[x1(1:c(1)) ,x2(c(1)+1:c(2)),x1(c(2)+1:end)]; y2=[x2(1:c(1)) ,x1(c(1)+1:c(2)),x2(c(2)+1:end)]; XMin=(XRange(1,:)); XMax=(XRange(2,:)); y1=min(max(y1,XMin),XMax); y2=min(max(y2,XMin),XMax); %% Sort Function function [pop Costs]=SortPopulation(pop) Costs=[pop.Cost]; [Costs SortOrder]=sort(Costs); pop=pop(SortOrder); end

Page 138: Fuzzy PID Controller Optimization for Robot Dynamics with ...

118

A.3 PSO optimization code

clc; clear; close all; warning('off') %% Problem Definition global flc1 flc Alpha Beta flc1 = readfis('flc.fis'); %Original fis CostFunction=@(x) flc_cost_function_sim(x); % Cost Function nX=31; % Number of Variables XSize=[1 nX]; % Size of Variables Matrix XMin=[ ones(1,14) ones(1,7) 0.01 0.01 0.01 0.01 1 1 1 1 250 25]; % Lower Bound of Variables XMax=[2.99*ones(1,14) 4.99*ones(1,7) pi pi 10 10 6 6 6 6 400 38]; % Upper Bound of Variables XRange= XMax-XMin; % Variation Range of Variables VelMax=(XMax-XMin)/10; % Maximum Velocity VelMin=-VelMax; % Minimum Velocity %% PSO Parameters Iterations=100; % Maximum Number of Iterations n_Pop=20; % Swarm (Population) Size % Definition of Constriction Coefficients phi1=2.05; phi2=2.05; phi=phi1+phi2; chi=2/(phi-2+sqrt(phi^2-4*phi)); c1=phi1*chi; c2=phi2*chi; %% Initialization disp(['Initialization ']); % Empty Structure to Hold Individuals Data

Page 139: Fuzzy PID Controller Optimization for Robot Dynamics with ...

119

empty.Position=[]; empty.Velocity=[]; empty.Cost=[]; empty.Best.Position=[]; empty.Best.Cost=[]; % Create Population Matrix pop=repmat(empty,n_Pop,1); % Global Best Best_Sol.Cost=inf; % Initialize Positions for i=1:n_Pop disp(['Positioning Number ' num2str(i)]); pop(i).Position=unifrnd(XMin,XMax,XSize); pop(i).Velocity=zeros(XSize); [pop(i).Cost]=CostFunction(pop(i).Position); pop(i).Best.Position=pop(i).Position; pop(i).Best.Cost=pop(i).Cost; if pop(i).Best.Cost < Best_Sol.Cost Best_Sol=pop(i).Best; end end % Vector to Hold Best Cost Values Best_Cost=zeros(Iterations,1); %% PSO Main Loop for it=1:Iterations for i=1:n_Pop % Update Velocity pop(i).Velocity=chi*pop(i).Velocity ... + c1*rand(XSize).*(pop(i).Best.Position-pop(i).Position) ... + c2*rand(XSize).*(Best_Sol.Position-pop(i).Position);

Page 140: Fuzzy PID Controller Optimization for Robot Dynamics with ...

120

% Apply Velocity Bounds pop(i).Velocity=min(max(pop(i).Velocity,VelMin),VelMax); % Update Position pop(i).Position=pop(i).Position+pop(i).Velocity; % Velocity Reflection flag=(pop(i).Position<XMin | pop(i).Position>XMax); pop(i).Velocity(flag)=-pop(i).Velocity(flag); % Apply Position Bounds pop(i).Position=min(max(pop(i).Position,XMin),XMax); % Evaluation [pop(i).Cost]=CostFunction(pop(i).Position); % Update Personal Best if pop(i).Cost<pop(i).Best.Cost pop(i).Best.Position=pop(i).Position; pop(i).Best.Cost=pop(i).Cost; % pop(i).Best.Out=pop(i).Out; % Update Global Best if pop(i).Best.Cost<Best_Sol.Cost Best_Sol=pop(i).Best; end end end % Store Best Cost Best_Cost(it)=Best_Sol.Cost; % Show Iteration Information disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(Best_Cost(it))]); disp(['Best Sol ' num2str(Best_Sol.Position)]); end %% Plots1 x=Best_Sol.Position;

Page 141: Fuzzy PID Controller Optimization for Robot Dynamics with ...

121

[cost, out] = flc_cost_function_sim(x); save('PSO_result20') FigH = figure('Position', get(0, 'Screensize')); plot(Best_Cost); xlabel('MaxIt(iteration)') ylabel('Best Cost') hold on plot(Best_Cost, 'x') title(['Best Cost Result for PSO method npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'BestCost.jpg', 'jpg') x=Best_Sol.Position; Alpha=x(30);Beta=x(31); t=sim('simul4DOF3'); Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; FigH = figure('Position', get(0, 'Screensize')); plot(t,Theta) xlabel('t(seconds)') ylabel('\theta(rad)') legend('Desired \theta1','Desired \theta2','Desired \theta3','Actual \theta1','Actual \theta2','Actual \theta3') title(['Comparison between desired and actual \theta for PSO method npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Desiredtheta.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plot(t,error) xlabel('t(seconds)') ylabel('error(rad)') legend('\theta1 Error','\theta2 Error','\theta3 Error') title(['Error for PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'errors.jpg', 'jpg')

Page 142: Fuzzy PID Controller Optimization for Robot Dynamics with ...

122

% plot Fuzzy Parameters FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',1) title(['Optimized input 1 MFs by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'MF1.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',2) title(['Optimized input 2 MFs by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'MF2.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'output',3) title(['Optimized output 3 MFs by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'MF3.jpg', 'jpg') opt1 = gensurfOptions('OutputIndex',1); opt2 = gensurfOptions('OutputIndex',2); opt3 = gensurfOptions('OutputIndex',3); FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt1) title(['Optimized rules surface for K''p by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Kpp.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt2) title(['Optimized rules surface for K''d by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'Kdd.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt3)

Page 143: Fuzzy PID Controller Optimization for Robot Dynamics with ...

123

title(['Optimized rules surface for Alpha by PSO method, npop=' , num2str(n_Pop) , ', iterations=', num2str(Iterations)]) F = getframe(FigH); imwrite(F.cdata, 'alpha.jpg', 'jpg') %% Gathering information y1_PSO=Theta(:,4); y1final=mean(Theta(:,1)); S1_PSO= stepinfo(y1_PSO,t,y1final); y2_PSO=Theta(:,5); y2final=mean(Theta(:,2)); S2_PSO= stepinfo(y2_PSO,t,y2final); y3_PSO=Theta(:,6); y3final=mean(Theta(:,3)); S3_PSO= stepinfo(y3_PSO,t,y3final); S_PSO.Overshoot=(S1_PSO.Overshoot+S2_PSO.Overshoot+S3_PSO.Overshoot)/3; S_PSO.MAE=sumabs(error); S_PSO.Theta=Theta; S_PSO.cost=cost; S_PSO.s1=S1_PSO; S_PSO.s2=S2_PSO; S_PSO.s3=S3_PSO; S_PSO.BestCost=Best_Cost; S_PSO.BestSol=Best_Sol; S_PSO.K1=K1.signals.values; S_PSO.K2=K2.signals.values; S_PSO.K3=K3.signals.values; S_PSO.Torque=Torque.signals.values; save('S_PSO','S_PSO'); %% function function [cost, out] = flc_cost_function_sim(p) global flc1 flc Alpha Beta flc = flc1; a = floor(p(1:7));

Page 144: Fuzzy PID Controller Optimization for Robot Dynamics with ...

124

b = floor(p(8:14)); c = floor(p(15:21)); ix1 = {1; [2 8]; [3 9 15]; [4:6:22]; [5:6:29]; [6:6:36] [7:6:43]}; ix2 = {[14:6:44]; [21:6:45]; [28:6:46 ]; [35:6:47]; [42 48]; 49}; % update rules for i = 1:7 for j = 1:numel(ix1{i}) flc.rule(ix1{i}(j)).consequent(1) = a(i); flc.rule(ix1{i}(j)).consequent(2) = b(i); flc.rule(ix1{i}(j)).consequent(3) = c(i); end end for i = 1:6 for j = 1:numel(ix2{i}) flc.rule(ix2{i}(j)).consequent(1) = 3-a(7-i); flc.rule(ix2{i}(j)).consequent(2) = 3-b(7-i); flc.rule(ix2{i}(j)).consequent(3) = 5-c(7-i); end end % update input mfs if p(23)<p(22) %swap z = p(22); p(22) = p(23); p(23) = z; end flc.input(1).mf(5).params(2) = p(22); flc.input(1).mf(4).params(3) = p(22);

Page 145: Fuzzy PID Controller Optimization for Robot Dynamics with ...

125

flc.input(1).mf(6).params(1) = p(22); flc.input(1).mf(3).params(2) = -p(22); flc.input(1).mf(2).params(3) = -p(22); flc.input(1).mf(4).params(1) = -p(22); flc.input(1).mf(6).params(2) = p(23); flc.input(1).mf(5).params(3) = p(23); flc.input(1).mf(7).params(1) = p(23); flc.input(1).mf(2).params(2) = -p(23); flc.input(1).mf(1).params(3) = -p(23); flc.input(1).mf(3).params(1) = -p(23); if p(25)<p(24) %swap z = p(24); p(24) = p(25); p(25) = z; end flc.input(2).mf(5).params(2) = p(24); flc.input(2).mf(4).params(3) = p(24); flc.input(2).mf(6).params(1) = p(24); flc.input(2).mf(3).params(2) = -p(24); flc.input(2).mf(2).params(3) = -p(24); flc.input(2).mf(4).params(1) = -p(24); flc.input(2).mf(6).params(2) = p(25); flc.input(2).mf(5).params(3) = p(25); flc.input(2).mf(7).params(1) = p(25); flc.input(2).mf(2).params(2) = -p(25); flc.input(2).mf(1).params(3) = -p(25); flc.input(2).mf(3).params(1) = -p(25); % update output mfs z=[p(26:29)]; [s ind]=sort(z); p(26:29)=z(ind); flc.output(3).mf(1).params(1) = 1; flc.output(3).mf(1).params(2) = p(26); flc.output(3).mf(2).params(1) = p(26); flc.output(3).mf(2).params(2) = p(27); flc.output(3).mf(3).params(1) = p(27); flc.output(3).mf(1).params(3) = p(27); flc.output(3).mf(3).params(2) = p(28); flc.output(3).mf(4).params(1) = p(28); flc.output(3).mf(2).params(3) = p(28);

Page 146: Fuzzy PID Controller Optimization for Robot Dynamics with ...

126

flc.output(3).mf(4).params(2) = p(29); flc.output(3).mf(3).params(3) = p(29); flc.output(3).mf(4).params(3) = 6; % update gains Alpha = p(30); Beta = p(31); dt = 0.01; Tf = 8; sim('simul4DOF3') Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; [Thmax1 ind1]= max(Theta(:,4)); Os1=Theta(ind1,4)-mean(Theta(:,1)); [Thmax2 ind2]= max(Theta(:,5)); Os2=Theta(ind2,5)-mean(Theta(:,2)); [Thmax3 ind3]= max(Theta(:,6)); Os3=Theta(ind3,6)-mean(Theta(:,3)); cost = 0.01*sumabs(error)+1*(Os1+Os2+Os3); out.Y = Theta; out.Os = [Os1, Os2, Os3]; out.flc = flc; out.t = 0:dt:Tf; A.4 ICA optimization code

clc; clear; close all; warning OFF %% Problem Definition global flc1 flc Alpha Beta flc1 = readfis('flc.fis'); %Original fis CostFunction=@(x) flc_cost_function_sim(x); % Cost Function nX=31; % Number of Variables

Page 147: Fuzzy PID Controller Optimization for Robot Dynamics with ...

127

XSize=[1 nX]; % Size of Variables Matrix XMin=[ ones(1,14) ones(1,7) 0.01 0.01 0.01 0.01 1 1 1 1 250 25]; % Lower Bound of Variables XMax=[2.99*ones(1,14) 4.99*ones(1,7) pi pi 10 10 6 6 6 6 400 38]; % Upper Bound of Variables %% ICA Settings n_Pop=20; % Number of Countries n_Imp=7; % Number of Imperials n_Col=n_Pop-n_Imp; Decades=100; beta=2; P_Revol=0.3; %Probability of Revolution zeta=0.02; %% Initialization %% Problem Definition global ProblemSettings; ProblemSettings.CostFunction=CostFunction; ProblemSettings.nX=nX; ProblemSettings.XMin=XMin; ProblemSettings.XMax=XMax; ProblemSettings.XSize=XSize; %% ICA Settings global ICASettings; ICASettings.n_Pop=n_Pop; ICASettings.n_Imp=n_Imp; ICASettings.n_Col=n_Pop-n_Imp; ICASettings.Decades=Decades; ICASettings.beta=beta; ICASettings.P_Revol=P_Revol; ICASettings.zeta=zeta; imp=InitializeImperials(); Best_Sol.Position=[];

Page 148: Fuzzy PID Controller Optimization for Robot Dynamics with ...

128

Best_Sol.Cost=[]; Best_Sol.Out=[]; Best_Cost=NaN(ICASettings.Decades,1); Mean_Cost=NaN(ICASettings.Decades,1); disp(["Initalized"]); %% ICA for i=1:Decades disp(["Decade:", num2str(i)]); disp(["Assimilate"]); imp=AssimilateColonies(imp); disp(["Revolve Colonies"]); imp=RevolveColonies(imp); disp(["Exchange With Best Colony"]); imp=ExchangeWithBestColony(imp); disp(["Calculate Total Costs"]); imp=CalculateTotalCosts(imp); disp(["Imperialistic Competition"]); imp=ImperialisticCompetition(imp); Imp_Cost=[imp.Cost]; [BestImpCost BestImpIndex]=min(Imp_Cost); Best_Imp=imp(BestImpIndex); Best_Sol.Position=Best_Imp.Position; Best_Sol.Cost=Best_Imp.Cost; Best_Cost(i)=BestImpCost; Mean_Cost(i)=mean(Imp_Cost); disp(['Decade ' num2str(i) ... ': Best Cost = ' num2str(Best_Cost(i)) ... ', Mean Cost = ' num2str(Mean_Cost(i)) ... ', nImp = ' num2str(numel(imp))]); disp(['Best Solution: ' num2str(Best_Sol.Position)]); end set(0,'defaulttextfontsize',14); set(0,'defaultaxesfontsize',14);

Page 149: Fuzzy PID Controller Optimization for Robot Dynamics with ...

129

x=Best_Sol.Position; [cost, out] = flc_cost_function_sim(x); %% Plots FigH = figure('Position', get(0, 'Screensize')); plot(Best_Cost,'bo-','LineWidth',2); hold on; plot(Mean_Cost,'rx:','LineWidth',2); legend('Best Cost','Mean Cost'); xlabel('Decade(iteration)'); title(['Best and mean Cost Result for ICA method nPop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'BestMean.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plot(Best_Cost); xlabel('Decade(iteration)') ylabel('Best Cost') hold on plot(Best_Cost, 'x') title(['Best Cost Result for ICA method npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'BestCost.jpg', 'jpg') x=Best_Sol.Position; Alpha=x(30);Beta=x(31); t=sim('simul4DOF3'); Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; FigH = figure('Position', get(0, 'Screensize')); plot(t,Theta) xlabel('t(seconds)') ylabel('\theta(rad)') legend('Desired \theta1','Desired \theta2','Desired \theta3','Actual \theta1','Actual \theta2','Actual \theta3')

Page 150: Fuzzy PID Controller Optimization for Robot Dynamics with ...

130

title(['Comparison between desired and actual \theta for ICA method npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'Desiredtheta.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plot(t,error) xlabel('t(seconds)') ylabel('error(rad)') legend('\theta1 Error','\theta2 Error','\theta3 Error') title(['Error for ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'errors.jpg', 'jpg') % plot Fuzzy Parameters FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',1) title(['Optimized input 1 MFs by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'MF1.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'input',2) title(['Optimized input 2 MFs by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'MF2.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); plotmf(flc,'output',3) title(['Optimized output 3 MFs by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'MF3.jpg', 'jpg') opt1 = gensurfOptions('OutputIndex',1); opt2 = gensurfOptions('OutputIndex',2); opt3 = gensurfOptions('OutputIndex',3); FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt1)

Page 151: Fuzzy PID Controller Optimization for Robot Dynamics with ...

131

title(['Optimized rules surface for K''p by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'Kpp.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt2) title(['Optimized rules surface for K''d by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'Kdd.jpg', 'jpg') FigH = figure('Position', get(0, 'Screensize')); gensurf(flc,opt3) title(['Optimized rules surface for Alpha by ICA method, npop=' , num2str(n_Pop) , ', nImp=' ,num2str(n_Imp), ', iterations=', num2str(i)]) F = getframe(FigH); imwrite(F.cdata, 'alpha.jpg', 'jpg') %% Gathering information y1_ICA=Theta(:,4); y1final=mean(Theta(:,1)); S1_ICA= stepinfo(y1_ICA,t,y1final); y2_ICA=Theta(:,5); y2final=mean(Theta(:,2)); S2_ICA= stepinfo(y2_ICA,t,y2final); y3_ICA=Theta(:,6); y3final=mean(Theta(:,3)); S3_ICA= stepinfo(y3_ICA,t,y3final); S_ICA.Overshoot=(S1_ICA.Overshoot+S2_ICA.Overshoot+S3_ICA.Overshoot)/3; S_ICA.MAE=sumabs(error); S_ICA.Theta=Theta; S_ICA.cost=cost; S_ICA.s1=S1_ICA; S_ICA.s2=S2_ICA; S_ICA.s3=S3_ICA; S_ICA.BestCost=Best_Cost;

Page 152: Fuzzy PID Controller Optimization for Robot Dynamics with ...

132

S_ICA.BestSol=Best_Sol; S_ICA.K1=K1.signals.values; S_ICA.K2=K2.signals.values; S_ICA.K3=K3.signals.values; S_ICA.Torque=Torque.signals.values; save('S_ICA','S_ICA'); save('ICA_result20'); function i=RouletteWheelSelection(p) c=cumsum(p); r=rand(); i=find(r<=c,1,'first'); end function imp=RevolveColonies(imp) global ProblemSettings; global ICASettings; CostFunction=ProblemSettings.CostFunction; nX=ProblemSettings.nX; XMin=ProblemSettings.XMin; XMax=ProblemSettings.XMax; P_Revol=ICASettings.P_Revol; for i=1:numel(imp) if rand<P_Revol k=randi([1 imp(i).n_Col]); imp(i).Colonies(k).Position=unifrnd(XMin,XMax);

Page 153: Fuzzy PID Controller Optimization for Robot Dynamics with ...

133

[imp(i).Colonies(k).Cost]=CostFunction(imp(i).Colonies(k).Position); end end end function imp=InitializeImperials() global ProblemSettings; global ICASettings; CostFunction=ProblemSettings.CostFunction; nX=ProblemSettings.nX; XMin=ProblemSettings.XMin; XMax=ProblemSettings.XMax; n_Pop=ICASettings.n_Pop; n_Imp=ICASettings.n_Imp; n_Col=ICASettings.n_Col; EmptyCol.Position=[]; EmptyCol.Cost=[]; Colonies=repmat(EmptyCol,n_Pop,1); for k=1:n_Pop Colonies(k).Position=unifrnd(XMin,XMax,[1 nX]); [Colonies(k).Cost]=CostFunction(Colonies(k).Position); end [SortedCosts CostsSortOrder]=sort([Colonies.Cost]); Colonies=Colonies(CostsSortOrder); EmptyImp.Position=[]; EmptyImp.Cost=[]; EmptyImp.TotalCost=[]; EmptyImp.n_Col=[]; EmptyImp.Colonies=[]; imp=repmat(EmptyImp,n_Imp,1); for i=1:n_Imp

Page 154: Fuzzy PID Controller Optimization for Robot Dynamics with ...

134

imp(i).Position=Colonies(i).Position; imp(i).Cost=Colonies(i).Cost; end Colonies=Colonies(n_Imp+1:end); if isempty(Colonies) return; end ImpCosts=[imp.Cost]; MaxImpCost=max(ImpCosts); ImpFitness=1.2*MaxImpCost-ImpCosts; p=ImpFitness/sum(ImpFitness); nc=round(p*n_Col); snc=sum(nc); if snc>n_Col i=1; while snc>n_Col nc(i)=max(nc(i)-1,0); i=i+1; if i>n_Imp i=1; end snc=sum(nc); end elseif snc<n_Col i=n_Imp; while snc<n_Col nc(i)=nc(i)+1; i=i-1; if i<1 i=n_Imp; end snc=sum(nc); end end Colonies=Colonies(randperm(n_Col)); for i=1:n_Imp imp(i).n_Col=nc(i); imp(i).Colonies=Colonies(1:nc(i)); Colonies=Colonies(nc(i)+1:end); end

Page 155: Fuzzy PID Controller Optimization for Robot Dynamics with ...

135

end function imp=ImperialisticCompetition(imp) if numel(imp)<2 return; end ImpTotalCost=[imp.TotalCost]; [MaxImpTotalCost WeakestImpIndex]=max(ImpTotalCost); WeakestImp=imp(WeakestImpIndex); ColCost=[WeakestImp.Colonies.Cost]; [MaxColCost WeakestColIndex]=max(ColCost); WeakestCol=WeakestImp.Colonies(WeakestColIndex); ImpFitness=MaxImpTotalCost-ImpTotalCost; p=ImpFitness/sum(ImpFitness); i=RouletteWheelSelection(p); imp(i).n_Col=imp(i).n_Col+1; imp(i).Colonies(imp(i).n_Col)=WeakestCol; imp(WeakestImpIndex).n_Col=imp(WeakestImpIndex).n_Col-1; imp(WeakestImpIndex).Colonies=imp(WeakestImpIndex).Colonies([1:WeakestColIndex-1 WeakestColIndex+1:end]); if imp(WeakestImpIndex).n_Col==0 j=RouletteWheelSelection(p); imp(j).n_Col=imp(j).n_Col+1; imp(j).Colonies(imp(j).n_Col).Position=WeakestImp.Position; imp(j).Colonies(imp(j).n_Col).Cost=WeakestImp.Cost; imp=imp([1:WeakestImpIndex-1 WeakestImpIndex+1:end]); end end

Page 156: Fuzzy PID Controller Optimization for Robot Dynamics with ...

136

function [cost, out] = flc_cost_function_sim(p) global flc1 flc Alpha Beta flc = flc1; a = floor(p(1:7)); b = floor(p(8:14)); c = floor(p(15:21)); ix1 = {1; [2 8]; [3 9 15]; [4:6:22]; [5:6:29]; [6:6:36] [7:6:43]}; ix2 = {[14:6:44]; [21:6:45]; [28:6:46 ]; [35:6:47]; [42 48]; 49}; % update rules for i = 1:7 for j = 1:numel(ix1{i}) flc.rule(ix1{i}(j)).consequent(1) = a(i); flc.rule(ix1{i}(j)).consequent(2) = b(i); flc.rule(ix1{i}(j)).consequent(3) = c(i); end end for i = 1:6 for j = 1:numel(ix2{i}) flc.rule(ix2{i}(j)).consequent(1) = 3-a(7-i); flc.rule(ix2{i}(j)).consequent(2) = 3-b(7-i); flc.rule(ix2{i}(j)).consequent(3) = 5-c(7-i); end end

Page 157: Fuzzy PID Controller Optimization for Robot Dynamics with ...

137

% update input mfs if p(23)<p(22) %swap z = p(22); p(22) = p(23); p(23) = z; end flc.input(1).mf(5).params(2) = p(22); flc.input(1).mf(4).params(3) = p(22); flc.input(1).mf(6).params(1) = p(22); flc.input(1).mf(3).params(2) = -p(22); flc.input(1).mf(2).params(3) = -p(22); flc.input(1).mf(4).params(1) = -p(22); flc.input(1).mf(6).params(2) = p(23); flc.input(1).mf(5).params(3) = p(23); flc.input(1).mf(7).params(1) = p(23); flc.input(1).mf(2).params(2) = -p(23); flc.input(1).mf(1).params(3) = -p(23); flc.input(1).mf(3).params(1) = -p(23); if p(25)<p(24) %swap z = p(24); p(24) = p(25); p(25) = z; end flc.input(2).mf(5).params(2) = p(24); flc.input(2).mf(4).params(3) = p(24); flc.input(2).mf(6).params(1) = p(24); flc.input(2).mf(3).params(2) = -p(24); flc.input(2).mf(2).params(3) = -p(24); flc.input(2).mf(4).params(1) = -p(24); flc.input(2).mf(6).params(2) = p(25); flc.input(2).mf(5).params(3) = p(25); flc.input(2).mf(7).params(1) = p(25); flc.input(2).mf(2).params(2) = -p(25); flc.input(2).mf(1).params(3) = -p(25); flc.input(2).mf(3).params(1) = -p(25); % update output mfs

Page 158: Fuzzy PID Controller Optimization for Robot Dynamics with ...

138

z=[p(26:29)]; [s ind]=sort(z); p(26:29)=z(ind); flc.output(3).mf(1).params(1) = 1; flc.output(3).mf(1).params(2) = p(26); flc.output(3).mf(2).params(1) = p(26); flc.output(3).mf(2).params(2) = p(27); flc.output(3).mf(3).params(1) = p(27); flc.output(3).mf(1).params(3) = p(27); flc.output(3).mf(3).params(2) = p(28); flc.output(3).mf(4).params(1) = p(28); flc.output(3).mf(2).params(3) = p(28); flc.output(3).mf(4).params(2) = p(29); flc.output(3).mf(3).params(3) = p(29); flc.output(3).mf(4).params(3) = 6; % update gains Alpha = p(30); Beta = p(31); dt = 0.01; Tf = 8; sim('simul4DOF3') Theta=Signals.signals.values; error=[Theta(:,1)-Theta(:,4) ,Theta(:,2)-Theta(:,5) , Theta(:,3)-Theta(:,6) ]; [Thmax1 ind1]= max(Theta(:,4)); Os1=Theta(ind1,4)-mean(Theta(:,1)); [Thmax2 ind2]= max(Theta(:,5)); Os2=Theta(ind2,5)-mean(Theta(:,2)); [Thmax3 ind3]= max(Theta(:,6)); Os3=Theta(ind3,6)-mean(Theta(:,3)); cost = 0.01*sumabs(error)+1*(Os1+Os2+Os3); out.Y = Theta; out.Os = [Os1, Os2, Os3]; out.flc = flc; out.t = 0:dt:Tf; end

Page 159: Fuzzy PID Controller Optimization for Robot Dynamics with ...

139

function imp=AssimilateColonies(imp) global ProblemSettings; global ICASettings; CostFunction=ProblemSettings.CostFunction; XMin=ProblemSettings.XMin; XMax=ProblemSettings.XMax; beta=ICASettings.beta; for i=1:numel(imp) for j=1:imp(i).n_Col d=imp(i).Position-imp(i).Colonies(j).Position; x=beta*rand(size(d)).*d; imp(i).Colonies(j).Position=imp(i).Colonies(j).Position+x; imp(i).Colonies(j).Position=min(max(imp(i).Colonies(j).Position,XMin),XMax); [imp(i).Colonies(j).Cost]=CostFunction(imp(i).Colonies(j).Position); end end end function imp=ExchangeWithBestColony(imp) for i=1:numel(imp) cc=[imp(i).Colonies.Cost]; [min_cc min_cc_index]=min(cc); if min_cc<=imp(i).Cost Best_Colony=imp(i).Colonies(min_cc_index); imp(i).Colonies(min_cc_index).Position=imp(i).Position; imp(i).Colonies(min_cc_index).Cost=imp(i).Cost;

Page 160: Fuzzy PID Controller Optimization for Robot Dynamics with ...

140

imp(i).Position=Best_Colony.Position; imp(i).Cost=Best_Colony.Cost; end end end function imp=CalculateTotalCosts(imp) global ICASettings; zeta=ICASettings.zeta; for i=1:numel(imp) cc=[imp(i).Colonies.Cost]; imp(i).TotalCost=imp(i).Cost+zeta*mean(cc); end end