Design and Implementation of a Fuzzy Logic Controller for Inverted Pendulum System Based on Evolutionary Optimization Algorithms

The inverted pendulum is a standard classical problem in the branch of control and systems. If a cart is bushed by force then its position and angle of the pendulum will be changed. Several controllers may employed, keeping the pendulum arm upright by controlling at the cart location. In this search paper, the fuzzy-like PID (FPID) controller has been used to control the inverted pendulum, and the parameters of the controller are tuned with several evolutionary optimization algorithms like a genetic algorithm (GA), ant colony optimization (ACO), and social spider optimization (SSO.) The result of tuned FPID with evolutionary optimization is compared with conventional PID, and it shows that FPID with SSO has been given the best result.


Introduction
The inverted pendulum is an excellent system to verify the capability of controllers in the control engineering field, and a perfect test benchmark for various complicated control searching problems. It is a non-linear dynamic system with a single input (force applied to cart) and double output (the cart position and pendulum angle); thus, the inverted pendulum is single-input multi-output (SIMO) system. The inverted pendulum has commonly used, and many application as launching rockets and missiles guidance [1], Commercial application of inverted pendulum model is the two-wheel scooter (Segway) [1], Humanoid robots that walking in an upright way is an application of inverted pendulum model [1]. Some researchers neglect the friction in the mathematical model of the inverted pendulum for linearizing the system [2][3][4]. It is not legal approximation because physically, the cart and the pendulum pole encounter some friction. The researchers of [5,6] provided clear steps in mathematical modeling to the system using Euler-Lagrange's equations to present the equations of motion. There are many different controllers algorithms and design techniques for stabilization of cart position and pendulum angle in inverted pendulum controlling such as Proportional Integral Derivative (PID) controller [10], Fractional Order PID (FOPID) controller [7], Fuzzy logic inference (FLI) controller [2,8,9]. The fuzzy logic inference is widely used to control an inverted pendulum [8,9]. In [11][12][13], fuzzy type one and fuzzy type two controllers combined with PID to product fuzzy like PID controller. The tuning of controller parameters is an essential matter; it can affect system stability as the controller type. Hence, selecting the best parameters is also another target. The first method is the try and error, as in [14]. This way consumes significant effort and time; therefore, many evolutionary optimization algorithms are widely common used as: as Particle Swarm Optimization (PSO), Ant Colony Optimization (ACO), social spider optimization (SSO), Genetic Algorithm (GA), Bees Algorithm. Paper [15] compared both the Genetic Algorithm (GA) and Bees Algorithm in tuning PID parameters. In [16,17] Genetic Algorithm is used to find controller parameters, but searcher of [18] used the Bees Algorithm to get the best selection for parameters. The social spider optimization (SSO) is very rarely used to find the parameters with controllers of Inverted pendulum even with its superiority compared with other artificial intelligent algorithms; as was proven in the results of this paper. This paper implements a fuzzy-PID controller and its parameters tuning by several evolutionary optimization algorithms. This research subject can be extensively modified and applied in several engineering domains. After its introduction, the rest of the paper is organized, as follows; Sections 2 presents the mathematical model of the inverted pendulum system. Section 3 presents a brief explanation of Fuzzy controllers, and Sections 4 presents a type of Optimizations with Evolutionary Algorithms, Section 5 presents the results and discussions. Section 6 presents controller robustness conclusions.

Mathematical Model
The mathematical model of the inverted pendulum system will be derived ( Figure 1). In this paper, according to the Lagrange motion equations of second type [5]. Lagrange equations are the most common way to adopt the mechanical analytical method to deriving the system equation of motion for the complex systems. The system parameters are listed in Table 1.
Totaly Kinetic-energy for system after simplify is Lagrange eq. of velocity of cart (X) and angle of pendulum that describe the system motion of inverted pendulum are ( ̇) (11) ( ̇) (12) The terms of above equations must calculated as follows: And 2 nd equation calculated by same way

Fuzzy Logic Controller
A fuzzy controller is a controlling system that used the fuzzy logic (FLC)ss. Fuzzy logic is a mathematical concept to computing deals with (degrees of truth) instead of (true or false) or Boolean logic (1 and 0) that the computer is dealing with the same logic. In the recent past, a using of fuzzy logic control (FLC) become dominated in control engineering applications, FLC in nowadays used to replace the old control methods as PID to solve complex problem in control processes, it`s contained a good advantages compared to classical controllers, additional to intelligent experience of human worker. The first advantage of the fuzzy logic controller has implemented capability with the nonlinear system when the mathematical model equations are not easily derived. The second advantage of FLC is the ability to use heuristic rules to employ the intelligent experience brain of humans [5]. The first input of FLC is the error, and the second one is the change of error shown in Figure 2. The goal of the fuzzy controller in this paper is to control an inverted pendulum by using a digital pendulum control experiment system 33-936S, as shown in Figure 3. If the pendulum tends one of two sides, the controller will change the location of the cart and select suitable direction and speed. System input is the pendulum angle (theta) and cart position (X), to determine the cart position and fast. The controller is two (multi) input single output (MISO) with Mamdani type of fuzzy system. The two-input is the error of the pendulum angle, and the change in this error ̇, and one output is the DC motor voltage (V) is designed in Figure 4. The membership functions (MF) number of both two inputs and output is the same (7 MF), as shown in Figure 5. The linguistics description of membership functions is abbreviate, as shown in Table 2, for help to keep the linguistic description short but precise. In addition, the fuzzy rule base is shown in Table 3.

Controller design
The controller is designed by Matlab (R2014a) Simulink using a computer with Intel Core i5 @ 253 GHz CPU, 4GB of RAM, and 64-bit Windows 7 Operating system, as shown in Figure 6.

Optimization with Evolutionary Algorithms
The selection of the optimal (best) parameters for the system controller is a challenging task. Sometimes the results may be bad not because the controller is bad design but because of not a good select of the values of the parameters. Evolutionary algorithms researchers look up at several natural creatures. They can note how biological creatures develop and lived in their environment to develop an artificial system acting the same procedure. This branch of science is so-called bionic (biological electronic). E.g., the airplane is an invented idea of how the birds fly, and the radar acts as the bat, submarine comes from fish creating, est. Thus a mechanism of some optimization algorithms based on nature, e.g., Genetic Algorithm (GA), comes from Charles Darwin's theory. This paper presents three types of evolutionary optimization algorithms, first (GA), second (ACO), third (SSO).

I. Genetic algorithm (GA)
The principle lines of the genetic algorithm come from the biological development rules [20]. GA is an efficient evolutionary optimization method with the capability to optimizing complex systems. To carry out a genetic algorithm, the codes of the decision parameters set described primary solution in a binary way (0 and 1) or double string or "chromosome". GA differs from non-evolutionary optimization algorithms [21]. GA is probabilistic and not deterministic, additional to it acts with the coding of the solution set, instead of the solutions themselves. Also, it searches from a pop of solutions, instead of a single solution. Lastly, GA deals with the cost function without derivatives.

GA steps:-
The implementation of GA [20] showed in Figure 7 and as follows: 1. Find the initial pop.

II. Ant Colony Optimization (ACO)
The ant colony optimization (ACO) algorithm inspired by the food searching behavior of ants [22]. The scientists studied the complex behavior of the ant colony and find that these behavior patterns give us a model for solving complex optimization problems. ACO algorithm is an example of designing evolutionary algorithms for optimization problems. ACO study discrete and continuous optimization problems which are suitable to find approximate solutions. The algorithms that come from the food searching behavior of ant colonies have been applied to solve complex optimization problems. Now, ACO is a very powerful and certificated algorithmic.

III. Ant colony procedure
The ants walking between the colony and food source, deposit on the paths a so-called substance pheromone [22]. Ants communicate by depositing pheromones along paths. Other ants can smell this pheromone and it is existing effecting the select of their roads. That meaning, the ants tend to trace high pheromone concentrations. The pheromone laying down on the paths forms a pheromone roads, which, determined a good resources of food that have been previously determined by other ants. The ACO using the adaptively adjusting the pheromone on paths at all points, and as shown in Figure 8 Select of this point is based on a probability way. The ants are guided by a probability to select their best path, known as a tour.

IV. Social Spider Optimization (SSO)
SSO is an evolutionary optimization method, its idea inspired by its cooperative properties in the spider colony society [24]. In the SSO, the space of elements is a group of spiders that behave together simulate to the natural social of a spider colony. In the majority of evolutionary swarm algorithms, each element of colony is formed by similar behavior and characteristics, but SSO uses two distinct elements: female and male. Thus, gender determines the role.Every single element is acting as a distinct operation that simulates its nature in the colony spiders. This element separation improves the significant defects that exist in most evolutionary algorithms. So the SSO has been improved and implemented in several engineering fields. The algorithm assumes that the elements act as common spiders, and all supposed solutions behave a single spider. SSO designed to deals with nonlinear problems with some constraint as shown in the following formula: ( ) Such that: is a non-linear, { | is a minimize productized search space whose limited with a low ( ) and by up ( ) boundaries. SSO algorithm uses a search space from supposed ways to find optimum solutions for the search problem. To simulate a real colony, every solution appear as an element location while the total society appears as the problem to space , the number of female spiders ( ) select by random way between (65-95)% from a total space S, but the remainder (Nm) represents a male spiders Thus, the set represent a female element , thus, the Ms group, represent the male element, , Such that In SSO each element takes weight value ( ) with respect to its fitness function, this weight is calculated by: Such that: ( ):-is a fitness for ( ) element location, { . :-is a best fitness value of entire space.
:-is the worst value of fitness for the entire population. Exchanging information transition is the main technic for the social spider algorithm. This exchange performed by vibrations perform in the spider web, this vibration from spider that a spider perceives it will emulate and models by: Such that: ( ):-is a ( ) spider weight. ( ):-is a distance from the first spider to second spider . Each first element understand (3) ways only for web vibration, ( , , and ) ,such that: :-represent a vibration that performed from most near element by an upper weighting according to ( ). ( :-is performed by the most near female element, it`s applicable if spider represent male element.
:-is performed by a best element in the space (S). With SSO, a population of elements space is started to implement from a first stage (k=0) to a fixed amount of loops (k=i t ). According to the gender, all spiders are managed by a various set of evolutionary processes. With the female element, the new location ( is obtained by updating the current element location ( . The updating operation is controlled randomly by using a probability factor , and the moving is performed with other spiders additional to that, its vibrations send with the search space.
Such that: and are randomly selected values [ ] . is the iteration number. ( and is an individual element symbolize to the nearest element with a weight upper than and they are the best element in the commune social spider respectively. And also, the male element is categorize into two types: [dominant ( ) and non-dominant ( )]. The male element that it`s fitness value is the best with measured to the total male set will integrate with the group. So, the group is constructed by the remnder of the male elements. With SSO optimization the (male) elements are acted with the following optimum model: and :-randomly selected numbers [ ]. :-the nearest female element to the male spider . With the social spider algorithm, the (mating operator) is applied between the dominant male spider and female element in the determined domain to produce a new spider . The weight of every element determines the probability of the influence of every element . The spider with the most prominent weight has more probability of effecting the new spider . When a new element is produced, the rest of the population is compared with it; when the new element is better than the worst element in the population, the worst element is exchanged with . Else it is neglected. Figure 9 shows the complete evolutionary operation by use flow chart way [24].

Results and Discussions
By applying the fuzzy controller on the mathematical model of the inverted pendulum, which is obtained in section 2 by using evolutionary optimization algorithms, then the results changed according to the type of optimization algorithm. The design of the experimental digital pendulum instrument that is used presents two equilibrium points of the pendulum angle; the first one is (θ=0) it means the pendulum is upright (inverted pendulum). The second point is (θ=); it means the pendulum is freely hanging (crane pendulum). In this paper, the pendulum angle always starts from (θ==3.14), which is to say it starts from crane pendulum until it reaches (θ=0) (Inverted pendulum) under the effect of different controllers. The first result was that obtained from applied classical PID controller with the conventional method of parameter tuning, which is (Ziegler-Nichols), the angle of the pendulum in this method has a (16 sec.) of oscillation time until it reaches settling time and high values of overshot and undershot, as shown in Figure 10. The result of using fuzzy PID controller with tuning the parameters by Genetic algorithm (GA) shows in Figure 11, the settling time at (4.6251 seconds), the maximum overshot is (5.2), the time consumption for finding the results is (1827 minutes) that is equal approximately (30.5) hours. Here, the apparent result is that the use of fuzzy PID with GA tuning (evolutionary optimization tuning) on the same plant above causes distinguished influence in system response, there is a significant change in settling time, which leads the oscillation to become less than usuall PID. There is a reduction in the maximum overshot and undershot, but the time delay of parameter finding is considerable. Using an Ant Colony Optimization (ACO) consumes (210.5) minutes, which is equal to approximately (3.5) hours, as shown in Figure 12. The settling time at (1.7271 seconds), the maximum overshot is (3.8693), and the period of oscillation is very short, the time delay of parameters finding for ACO near to (1/10) of GA time delay. Social spider optimization (SSO) consumes (70.287) minutes. It is the lowest time among all three algorithms. The settling time is at (2.3803 sec.). The time of the spiders' algorithm is shorter than the time of the ant algorithm, but the settling time is longer, as shown in Figure 13. The steady-state characteristics comparison for all three controllers with optimization algorithms, including in Table 4. Moreover, the comparison of PID gains parameters and tuning time for all algorithms, including in Table 5. The comparison of the three optimization algorithms (GA, ACO, SSO) controllers results in Figure  14. It is shown clearly that ACO is the best one in peak value, beak time, oversho,t and settling time, but in tuning time, SSO is the first one, as shown in Table 5. The comparison between PID controllers with system factory-tuned parameters and the fuzzy PID (FPID) controller with implementing three optimization algorithms (GA, ACO, SSO) is shown in Figure 15. The least optimization time is (70.287 minutes) in (SSO), and the least inverted pendulum (pendulum angle) settling time is (1.6646 sec.) with (ACO).

Controller Robustness
To check the robustness of the fuzzy PID controller, internal and external disturbances are used , the internal disturbance is applied by changing three of the inverted pendulum system parameters (mass of the pendulum, mass of cart and length of the pendulum) and the external disturbance is applied by applying sudden force at the tip of rod, and Applying the external force at the pendulum rod makes the cart move to the opposite side of the force applied, but with a stable upright pendulum, as shown in Figure 16.
The internal disturbance may be affected at system settling time, but without system breakdown oscillation along the ranges shows in Table 6.

Conclusions
The fuzzy PID (FPID) controller has been used to control the inverted pendulum on a cart by using a digital (pendulum control experiments system 33-936S), and the parameters of the controller (Gains) is tuned with three evolutionary optimizations (GA), (ACO) and (SSO). The result of tuned FPID with evolutionary optimization is compared with conventional PID with inverted pendulum system factory-tuned parameters and shows that FPID with SSO has been given the least optimization time and the least inverted pendulum settling time has been given by (ACO). Therefore, according to the research results, the SSO algorithm is better than the other two methods in optimization algorithm implementation time, an ACO is better in settling time value. The test of robustness shows that the FPID controller prevents the breakdown of the inverted pendulum system when an external force is applied to the pendulum rod. Moreover, it saves the system stability when an internal disturbance occurs by changing the mass of the pendulum, the mass of the cart, and the length of the pendulum along with determined ranges.