#### Abstract

The proportional integral derivative (PID) controller has gained wide acceptance and use as the most useful control approach in the industry. However, the PID controller lacks robustness to uncertainties and stability under disturbances. To address this problem, this paper proposes an optimal fuzzy-PID technique for a two-degree-of-freedom cart-pole system. Fuzzy rules can be combined with controllers such as PID to tune their coefficients and allow the controller to deliver substantially improved performance. To achieve this, the fuzzy logic method is applied in conjunction with the PID approach to provide essential control inputs and improve the control algorithm efficiency. The achieved control gains are then optimized via the imperialist competitive algorithm. Consequently, the objective function for the cart-pole system is regarded as the summation of the displacement error of the cart, the angular error of the pole, and the control force. This control concept has been tested via simulation and experimental validations. Obtained results are presented to confirm the accuracy and efficiency of the suggested method.

#### 1. Introduction

##### 1.1. Background and Motivation

The proportional-integral-derivative (PID) control method is one of the most technical approaches in the control field, which has experienced remarkable development with regard to its use in mechanical systems [1–5]. In fact, this control approach is renowned for its simple structure. However, tuning its parameters is a challenge that requires carrying out some strategies such as classical tuning rules, adaptation laws, optimal techniques, and fuzzy systems [6–11]. Through these methods, fuzzy logic, which was initially introduced by Zadeh [12], is a very effective way to adjust and determine the PID control gains [13].

##### 1.2. Literature Review

The improvement of fuzzy-PID methods for diverse mechanical systems has attracted attention in the last couple of years. Wang et al. designed a novel fuzzy-PID on a model of a coke furnace and compared its efficiency with conventional PID control [14]. Lapa and Cpalka proposed a nature-inspired technique to automate the determination of the parameters and structure of a flexible fuzzy-PID technique [15]. Kumar employed a new application of the genetic algorithm to optimize the parameters of type-2 fuzzy-PID controllers used for five-degrees of freedom robot manipulators [16]. Sa-ngiamvibool applied an optimal fuzzy-PID controller for hydrothermal systems [17]. Barik et al. [18] used a fuzzy proportional, derivative integral controller to investigate the frequency fluctuations due to wind and solar-thermal based renewable power [19]. Acharya and Das [20] introduced a fuzzy-PID controller to enhance the pressure tracking profile of pressure-controlled ventilators [16].

In this respect, the heuristic parameters of such controllers should be defined by a proper method. One of the effective methods to determine these parameters is to take advantage of evolutionary algorithms such as ICA [21]. For instance, Ahmadi et al. used a novel scenario using the composition of the ICA and fuzzy-PID to solve the speed matter in an electric motor [22]. Cornejo et al. developed a tuning method for PID schemes based on evolutionary algorithms, particularly the ICA, the genetic algorithm (GA), and the active-set algorithm [23]. Kusama et al. used various artificial intelligence methods such as the ICA and particle swarm optimization to tune the PID controller gains [24]. Eventually, in [25], the ICA was utilized for a fractional-order fuzzy PI method to optimize the control gains.

##### 1.3. Contributions

This paper develops some previous studies [26–30] by proposing a new optimal fuzzy-PID method that is introduced and executed on a given test-bed system. The innovation of this research is the novel control strategy presented, specifically the design of its fuzzy systems. In the proposed strategy, two fuzzy inference engines are applied to enhance the performance of the control approach. Next, the imperialist competitive algorithm is employed to optimize the proposed controller gains. Obtained results confirm the better time response and high stabilization accuracy for the presented approach in comparison to the other methods.

##### 1.4. Organization of Paper

The study is structured and presented in seven sections. Section 2 defines the dynamic model of the 2-DOF cart-pole system. Section 3 explains the fuzzy-PID approach. Section 4 presents the ICA algorithm. Section 5 demonstrates how to apply the proposed optimal fuzzy-PID control to the cart-pole system. Section 6 demonstrates the simulation and experimental outcomes for the cart-pole system. Section 7 presents discussion and conclusions.

#### 2. Cart-Pole System Formulation

The 2-DOF cart-pole system is regarded as a nonlinear under-actuated system. Indeed, it is a reputable test-bed to analyze control strategies [31, 32]. Generally, such systems include practical applications such as hypersonic vehicles, overhead cranes, rockets, and robots [33, 34]. The tracker’s design and control require thorough consideration. Therefore, stabilization of under-actuated systems has recently attracted many researchers’ attention. Accordingly, various control methods such as feedback linearization, sliding mode control, *H*_{∞} control, neural networks, and other robust control have been designed to apply proper controllers for these systems [26–30]. In fact, the under-actuated systems include many benefits, such as decreasing the construction cost, having a minimal number of actuators, and lightening the system.

Consider a fourth-order nonlinear cart-pole system shown as follows [25]:where, is the state vector, and are nonlinear functions displaying system dynamics, and defines the uncertainty. respectively represent the position and the velocity of the cart, the angle and the angular velocity of the pole. In addition, , and respectively show the gravity acceleration, the mass of the pole, the mass of the cart, and the half-length of the pole. The general schematic of the cart-pole system is demonstrated in Figure 1.

In the next sections, we define general concepts of an optimal fuzzy-PID approach and then derive a controller for the 2-DOF cart-pole system based on fuzzy logic and an imperialist competitive algorithm.

#### 3. Fuzzy-PID Controller

PID control is the most prevalent method among all feedback controls because of its simplicity and wide applications. As the method with a simple control structure that is straightforward to adjust, it was utilized by plant operators. The control inputs of the control scheme can be obtained through the following procedure [28]:where, is the control input. Also, , and are nonlinear functions. Consider the state-space formulation of the nonlinear system with the following: in which

Is the state vector while its desired value is as follows:

Accordinglyand

As the control inputs, the common form of the PID controller is written according to the following equations:where, and are the proportional gains, and denote the integral gains, and and represent the derivative gains. The selection and tuning of the gain values are crucial issues in the design of PID controllers. Fuzzy rules have the capability to be combined with controllers such as PID to tune their coefficients and allow the controller to provide more precise answers. Thus, to provide adaptive gains for the PID controller, the fuzzy logic technique as a regulator method is used. The following equation defines fuzzy-PID control:where, *i* = 1, 2, …, 6 represent the fuzzy variables containing inputs , achieved by first fuzzy system (FFS). and are obtained with respect to the following procedure:where, *i* = 1, 2, …, 6 denote input items , achieved by second fuzzy system (SFS). are weight constants that can be acquired by trial and error. Meanwhile, one effective technique to determine such parameters is evolutionary algorithms. Accordingly, in this paper, the imperialist competition algorithm (ICA) is used to determine the parameters of the proposed controller.

#### 4. Imperialist Competition Algorithm

Considering the complicated world where we live, it can be divided into local places controlled by local powers and superpowers, which can have global scale influence. This pattern is more obvious when we look at that part of history when countries were colonized by more powerful imperialists. Generally, the more powerful country, the more colonies it could have. Therefore, there was a strict competition between powerful countries to conquest weaker countries and extended their territory. This model leads to an evolutionary algorithm termed the imperialist competition algorithm (ICA). Although most optimization algorithms are based upon modeling of natural processes, the ICA is inspired by imperialist competition and begins with initial populations, which are called countries. In this regard, several of the best countries would be chosen as the imperialist states, while the rest would be their colonies. If the optimization problem is -dimensional, a country is a array, illustrated by the following equation:where, are variables that are optimized. Since our optimization problem is designing constant parameters of the fuzzy-PID method, the initial countries are those variables such as and

The function of the ICA is defined as looking for a country with the greatest socio-political specifications such as culture, religion, and economic. From an optimization standpoint, it gives rise to acquire an optimal answer of a problem, which has the minimum cost value. In this regard, each country’s cost can be determined as follows:

In this paper, there are 50 countries, which will result in 50 initial cost functions. Moreover, a country which has less cost is regarded as a powerful one; thus, of the strongest countries would be selected from empires while the remains are the colonies of these imperialists. With regard to initial cost functions, is determined as 10 in this paper.

This competition is simulated by selecting some of the feeblest empires to start a rivalry out of all empires to govern the weak colonies. Starting the rivalry, imperialists tend to possess colonies. The most powerful empires are more likely to possess these colonies. This movement is simulated by shifting all colonies to imperialist ones. For random variable , the following relation can be written as:

In which represents the distance of colony and imperialist while denotes a number which is greater than 1. More precisely, leads to keep out colonies from the imperialist state, and an approaching value to one for decreases the seeking capability of the ICA. It is worth noting that is regarded as 2 in this study that results to approach countries toward the global minimum. Meanwhile, approaching the imperialist, a colony may obtain a location with smaller cost in comparison to that. In such a situation, the colony and imperialist alter their locations. Subsequently, the ICA would proceed by the imperialist in the fresh location so that the colonies would be incorporated by the imperialist in the fresh location. This movement is depicted in Figure 2.

Although the overall vigor of an empire is chiefly influenced by the vigor of an imperialist country, the vigor of colonies of a given empire affects the entire vigor of that empire too. The process can be formulated as follows:

In which represents the overall cost of the *n-th* empire, as well as denotes a positive constant less than 1. Through imperialistic competition, gradually the weaker empires’ power is reduced and the power of stronger ones is enhanced. Therefore, weak empires would miss out their colonies so that eventually, the most powerful empire would remain while others would collapse. On the other hand, one idea to end the process can be taken advantage of a number of maximum iterations that is regarded as 200 in this study. The suggested ICA is briefly explained in Figure 3 as a flowchart.

#### 5. Optimal Fuzzy-PID Control on the Cart-Pole System

This section describes the design of an optimal fuzzy-PID method based on two fuzzy inference engines for stabilization of the cart-pole system. The controller includes six inputs so that each of them contains one first fuzzy system (FFS) and second fuzzy system (SFS). These FFSs and SFSs are exclusively designed for the stabilization of the cart position and the pole angular. Regarding Equation (1), as a control input is considered as , and other parameters are regarded as The block diagram relevant to the fuzzy-PID controller is illustrated in Figure 4 indicates that each of the state variables related to the cart-pole system is compared with its desired value. These state variables (, ) are normalized with control correction factors (CCFs) and then are fed into the fuzzy system. The values of correction factors related to , in FFS blocks are shown in Table 1 as they are considered a constant value for SFSs as . Moreover, the absolute value of is selected as the only input variable for all SFS blocks. In more details, in the first step, output values of FFS-*i* and SFS-*i* are multiplied, and then, by addition of all output values, the fuzzy-PID control output would be obtained. Eventually, the CCF block converts the output value of the suggested controller to the cart-pole control force . In what follows, two fuzzy inference engines utilized in this paper is explained.

##### 5.1. First Fuzzy System (FFS)

Generally, every input of the fuzzy system includes one FFS and SFS. To calculate each FFS-*i,* fuzzy rules are regulated according to Table 2. The membership functions of FFS -*i* input including are defined as triangular and trapezoidal, as Figure 5. Further, and shown in Table 2 are fuzzy outputs, which should be optimized. FFS -*i* outputs () for the cart and pole are the same and calculated as follows:

##### 5.2. Second Fuzzy System (SFS)

As mentioned above, FFSs affect directly the output while for the determination of output values , each input section indirectly relates to one SFS. The inference the dynamic variables of SFSs, fuzzy rules are given in Table 3. After normalization, the absolute value of the pole angle would be determined as the single input value (). Figure 6 shows membership functions related to which are defined triangular. Coefficients shown in Tables 3 and 4 are fuzzy system outputs that should be optimized. In addition, SFS-*i* outputs () for the pole and cart are respectively calculated as follows:

Hence, after calculation of it is possible to obtain the SFS variable, and with respect to for the FFS variable, as an output control force would be obtained as follows:

Finally, would perform as a control effort on the cart-pole system after applying the control correction factor on it, as follows:

In the next step, the optimum design variables would be determined by means of the ICA algorithm mentioned in Section 4. For this purpose, objective functions should be determined as the first step by the following equations:where, = denotes the desired setpoints while , and respectively represent the error of the cart and angle position, as well as the system force control. To optimize all three objective functions, the final objective function is expressed as the summation of them as follows:

#### 6. Results and Discussion

In what follows, the system performance is considered in various conditions to challenge the proposed strategy. Hence, the results are obtained for three different initial values. For all cases, the specifications of the cart-pole system and the ICA parameters are written according to Tables 5 and 6.

##### 6.1. Case Study 1

In the first case study, the initial condition is and compared with three existing studies [28–30] including Yi and Yabazaki, 2000; Mahmoodabadi et al. 2016; and Mahmoodabadi and Jahanshahi, 2016. In Figure 7, the settling time of the proposed method for the cart position is shorter than other methods. According to Figure 8, the settling time for the pole angle is also shorter than all three methods while it has a smaller undershoot in comparison with the two other approaches. Figure 9 displays the comparison of the control efforts between the proposed methods and other techniques.

##### 6.2. Case Study 2

In the second case study, the initial condition *i* is compared with Yi and Yabazaki’s approach. According to Figure 10, the settling time of the proposed approach for the cart position is shorter than Yi and Yabazaki’s method. Similarly, Figure 11 indicates that the settling time of the suggested method for the pole angle also has a better value while it has greater overshoot. In addition, the highest absolute value of the control input of the presented method is smaller than Yi and Yabazaki’s scheme, as is seen in Figure 12.

##### 6.3. Case Study 3

In the third case study, the initial condition is and compared with Yi and Yabazaki’s method. According to Figures 13 and 14, the proposed method has a better time response in comparison to those techniques. Figure 15 indicates the comparison of the control inputs between the two methods. Further, the optimum design variables of the proposed control approach for three case studies are given in Table 7.

##### 6.4. Case Study 4

In this section, the authors intend to examine the suggested approach through an experimental setup. The practical tests are executed by using the Simulink® toolboxes and MATLAB® Real-Time®. Figure 16 displays the practical cart-pole system, which is created in University of Zanjan, in the hanging and inverted modes. The angular position of the pendulum and position of the cart are computed via E40S Autonics Company encoders. The PCI-1751 data acquisition card (PCI-1751 DAQ) is used for the collection of input-output data and formation of interrelation amid computer and practical cart-pole system. The PCI-1751 DAQ includes the digital-to-analog and analog-to-digital converters. The cart position and the angular position of the pole controlled by the fuzzy-PID technique are respectively shown in Figures 17 and 18. In more detail, the considered system is in the swing-up mode in the first 4.5 seconds. Then, the control signal switches to the balancing controller. As a result, the pendulum was in the upright situation after 4.5 seconds. As observed in Figure 17, the proposed controller is succeeded in bringing the pole from radian to 0 in about 8 seconds. The pendulum remains almost equal to zero afterward. Moreover, as it can be observed from Figure 18, the cart position changes rapidly in the swing-up period. Moreover, Figure 19 depicts the control effort obtained by the proposed control method during the experimental test. These experimental outcomes are compatible with the simulation ones that approve the efficiency of the offered method.

#### 7. Conclusions

In this research paper, a fuzzy proportional-integral-derivative controller was designed to handle the cart-pole system as a test-bed. More precisely, the objective was to tune and update the proportional-integral-derivative coefficients using fuzzy rules. In addition, the constant parameters of the fuzzy proportional-integral-derivative controller were optimized via the imperialist competitive algorithm. The objective function was regarded as the summation of the angle error of the pole, the error of the cart position, and the system control force. Furthermore, the proposed control approach was further examined by comparison with existing studies with three different initial conditions. The reported results confirmed that the introduced strategy is effectively able to control the given under-actuated system. In case study 1, the proposed method proposed the minimum settling time of the cart position and pole angle compared to References [26, 27]. As shown in case study 2, the suggested control strategy could reduce the settling time of the cart position around 50%. With respect to case study 3, the settling time of the cart position decreased around 43%. The results exhibited the appropriate performance of the proposed controller by showing an optimal smooth control input. Although the presented scheme is appropriate, there are some developments that can be still made. To design the fuzzy system, other membership functions, fuzzifiers, and defuzzifiers such as Gaussian membership function, pseudo-exponential membership function, triangular fuzzifier, Gaussian fuzzifier, and center of gravity defuzzifier can be also used. The suggested strategy can be applied for stabilizing other under-actuated systems such as ball and beam, seesaw, and ball and wheel systems. The introduced scenario can be combined with other linear and nonlinear control strategies to stabilize different higher-order dynamical systems. Other evolutionary algorithms such as bacterial foraging algorithm, whale optimization algorithm, particle swarm optimization, and ant colony among others can be utilized to select the controller parameters.

#### Nomenclature

: | Nonlinear function displaying system dynamics |

: | Nonlinear function displaying system dynamics |

: | The uncertainty |

: | The position of the cart |

: | The velocity of the cart |

: | The angle of the pole |

: | The angular velocity of the pole |

: | The gravity acceleration |

: | The mass of the pole |

: | The mass of the cart |

: | The half-length of the pole |

: | The control input |

: | The state vector |

: | The desired value of the state vector |

: | The error of |

: | The error of |

: | The proportional gain of the PID controller |

: | The integral gain of the PID controller |

: | The derivative gain of the PID controller |

: | Fuzzy variables |

: | Input items of the fuzzy system |

: | Weight constants of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The weight constant of the fuzzy system |

: | The number of imperialists |

: | The distance of colony and imperialist |

: | A coefficient |

: | The overall cost of the n-th empire |

: | A positive constant less than 1 |

: | Fuzzy outputs of the first fuzzy system |

: | Fuzzy outputs of the first fuzzy system |

: | Fuzzy outputs of the second fuzzy system |

: | Fuzzy outputs of the second fuzzy system |

: | Fuzzy outputs of the second fuzzy system |

: | Fuzzy outputs of the second fuzzy system |

: | The control correction factor |

: | The error of the cart position |

: | The error of the angle position |

: | The error of the system force control |

: | The fuzzy-PID control gain |

: | The fuzzy-PID controller gain |

: | The fuzzy-PID controller gain |

: | The fuzzy-PID controller gain |

: | The fuzzy-PID controller gain. |

#### Data Availability

The data that support the findings of this study are available within the article.

#### Conflicts of Interest

The authors declare that they have no conflicts of interest.