PID-Fuzzy control design for a nonlinear inverted pendulum

—This study aims to present a PI-Fuzzy and PID-Fuzzy design to control the position while maintaining the balance of an inverted pendulum system. This type of system is well known for its challenge in carrying out the control and its similarities and applications in other systems, such as transport vehicles and robots. Thus, being a famous and important system to be used as a control benchmark. Nonlinear dynamic equations for the inverted pendulum were obtained through the Lagrange formulation. An adaptive PI-Fuzzy and PID-Fuzzy controller was designed and implemented on the nonlinear model. The final results demonstrate a great increase in performance, both on displacement and dynamics balance, when compared to the classic PI and PID controllers, especially when in the presence of parametric changes in the system. Another contribution of this paper is to demonstrate how the proposed fuzzy system can improve the response of a complex system with classical controllers.


I. INTRODUCTION
HE inverted pendulum can be considered a classical problem in the control domain, where the same can be used as a benchmark for the performance of different controllers and designs. This system is also used as the basis for numerous engineering projects, such as vehicles, robots, missile launchers, among several other mechanical and aeronautical devices and systems that need to maintain a certain physical balance [1][2][3].
The system is well known for showing a strong nonlinear behavior and a specific coupling between the linear movement of the cart and the angular displacement of the pendulum. The challenge of the control design is to maintain the system in an unstable equilibrium point i.e., the pendulum pointing upwards, where the angle of the pendulum is indirectly controlled by the displacement of the cart [1], [3][4][5][6].
As it is a classical problem, several studies have proposed controllers for this kind of system, especially optimal state space controllers [7][8]. However, most of these techniques require a great deal of mathematical knowledge, often unavailable in the non-academic industrial environment, as well as a very rigorous analysis of the process plant. Because of these points mentioned, the classic controllers (PI and PID, for the most part), still remains the most practically used and favored controllers [9], when a fast and functional control design is needed. Thus, a way to improve its performance without increasing its complexity is a great challenge of nowadays studies.
The most common design process of a classic controller involves the use of the equations that represents the dynamical system, sometimes called plant. Nevertheless, this model will naturally show some differences when compared to the real system or process. These differences are normal and often result from mathematical considerations such as boundary conditions, physical parameters or simplifications. However, it is clear that the designed control must also satisfy the performance requirements of the real system. This is the fundamental concept when it comes to the robustness of the controller. A good alternative to increase the robustness of the controller are the so-called adaptive systems. In this type of controller, the gains are adjusted in an online manner, according to the system's response and necessities [10]. This kind of control design can be used not only for the parametric uncertainties, but also to adapt an existing controller to work into another similar system, without the need to change or recalculate de control gains.
A way to combine the advantages of a classic controller with characteristics of adaptability is to use the fuzzy logic. In this type of logic, concepts of intuitive linguistic rules are used instead of the common Boolean logic [11][12]. This allows the project of complex system's controllers to be designed in a simplified way, while still maintaining a high-performance level.
One of the objectives of this paper is to show a simple, yet quite powerful, adaptive control design, that combines the ease of the PI an PID design with the robustness of real-time adjusted gains through a fuzzy logic.
Another contribution is to demonstrate how fuzzy inference can help improve the result of a system that has a not so trivial classical controllers design, and how the fuzzy system can contribute to applications where the controllers were initially poorly projected due to some situation like a complex system, high order systems or systems with more than one output and/or input.
This work is organized as follows: Section II presents the process to obtain the non-linear dynamic model of the inverted pendulum; Section III exhibits the PI and PID classical control design used in this system, as well as the linearization and the transfer functions of the plant. Section IV expands the control design, presenting its new structure and the design of the fuzzy logic used; Section V presents and discusses the numerical results for the different tests executed. Finally, Section VI presents the main considerations about the paper. Fig.1 shows the dynamic model with lumped parameters for the inverted pendulum used in this paper. The rigid pendulum's rod was considered to be massless, where all the mass of the pendulum is located in a concentrated point at his tip. This is a common consideration in the literature that aims to simplify the model making the distance to the center of mass of the rod equal to the pendulum length (reducing the elements that acts on the inertia of the rod, generally related to the kinetic energy equation). Several authors make this consideration in a great plethora of different applications (e.g., dynamics analysis, control, education), as can be seen in [12][13][14][15][16][17]. In this paper, we chose to make this consideration in order to facilitate the analysis of the pendulum's rod mass variation and its influence on the control -similar results could be found by varying the center of mass of a pendulum's rod (and thus its mass itself) in a distributed mass case. The objective of the project is to control the position of the cart at the same time that the pendulum is balanced, thus the system will then present two degrees of freedom: the position of the cart and the angle of the pendulum .

II. DYNAMIC MODEL
In this work, Lagrange's Equations were used to obtain the dynamic model of the mechanical system. The system equations can be obtained using (1).
where are the generalized coordinates that define the movement of the system. is called Lagrangean and is given by the difference between the total kinetic energy and the total potential energy .
are the generalized forces. The dissipative frictional forces that exist between the cart and the track, and between the pendulum rod and its fixing point in the cart were defined in this work using the dissipative function of Rayleigh, and both are described by the in the Eq. (1) [18].
The total kinetic energy of the system is given by (2).
where ̇ and ̇ are the velocities in the Cartesian coordinates and of the pendulum point mass. Considering the counterclockwise direction as positive in the angle increment, one will have ̇=̇−̇( ) and ̇= −̇( ). After some substitutions and mathematical treatment, the total kinetic energy of the system has the final form given by (3).
The potential energy comes from the effect of gravity on the pendulum y direction, the same being given by (4).

= cos ( )
where g is the acceleration of gravity.
The two dissipative forces considered in the model are given by (5) and (6).
Considering the two generalized coordinates as and , and replacing (6), (5), (4), (3) and (2) in (1) for both generalized coordinates, it is possible to obtain the system of equations for the dynamic system.
As can be seen, the system consists of two coupled second order nonlinear differential equations. Initially, the system had its equations decoupled. Eq. (9) and (10) presents the system after the calculations. Table 1 shows the initial physical parameters used for the numerical simulations performed in this paper. To test the functioning of the model, Fig. 2 shows the behavior of the system when F = 0 and with the following initial conditions: 0 = 0, ̇0 = 0 0 = 0.1 and ̇0 = 0.  As can be seen, the pendulum starts up with the initial angle value, where it falls over time to rad (180º or pendulum pointed downwards). All the speed values tend to zero, as expected from a system without any kind of force being applied. This simple open-loop simulation was used to demonstrate the functionality of the proposed model.

III. PI AND PID CONTROL
The first step in the design of the controllers for this project is the design of the PI and PID control. The control gains found in this stage of the work will later also be used as part of the PI-Fuzzy and PID-Fuzzy control.

A. Plant Linearization
Before the PI and PID controllers can be designed, the plant needs to be linearized. Assuming that the pendulum will move close to = 0, consequently one will have: ( ) ≈ , ( ) ≈1 and ̇2 = 0. Thus, (7) and (8) will be rewritten in the form presented by (11) and (12).
The next step is to take the Laplace transform of the equations considering initial conditions equal to zero. Since it is desired to control both the position of the cart and the angle of the pendulum, two transfer functions will be necessary. One related to the movement of the cart and another related to the angle of the pendulum. After the Laplace transform, it is enough to isolate each equation with respect to the output variables (X (s) and Θ (s)) through a simple substitution. Eq. (13) and (14) presents the two transfer functions used for the design of the controllers.
where = ( + ) 2 − ( ) 2 . Figure 3 shows the block diagram for the position PI and angle PID control of the inverted pendulum.

B. Controllers project
As can be seen, two controls will be used, a PI for the position and a PID for the pendulum angle. The position error is given by (15).
where is the desired position reference and is the current cart position. The pendulum angle error is defined by (16).
where is the desired angle reference, in this case being zero, and θ is the current angle. The total control signal was considered as the sum of the two control inputs, as stated in (17).
Using Table 1 for the physical parameters and (9), the PI and PID controllers were designed for the system using the Matlab® Sisotool. Manual adjustments were also made through numerical simulations of the controller. Table 2 shows the gains obtained for both the controllers. As can be seen, the design of classic controllers for this system is not so simple due to the two variables to be controlled. To find the gains of the controllers one must analyze the two plants shown by (9) individually, and this makes it difficult to find optimal gains that satisfy the response behavior for both the pendulum and the cart. This is an example of a contribution that comes from the fuzzy system in this more complex plant, where it can help improve the performance of classic controllers that are not so well designed due to some circumstance.  As one can see, first the respective value of error and the rate of change of error enters the fuzzy logic block. After the fuzzification and defuzzification process (that depends on the membership functions and rules) the fuzzy system will have as outputs the Kp, Ki and Kd adjustment gains. This gains will them be added to the previously static PI and PID controller gains.

A. Fuzzy set
The first step in the design of the fuzzy inference is the definition of the fuzzy set and the construction of the membership functions [12]. In this project, as reported in Fig.  4, the inputs will be the error and the rate of change of error. All the membership functions used are presented, as well as their respective universe of discourse. The fuzzy set was defined as: NB, NM, NS, Z, PS, PM and PB that represent Negative Big, Negative Medium, Negative Small, Zero, Positive Small, Positive Medium and Positive Big, respectively. Through tests, Gaussian functions performed better than other forms in the outputs, and thus this type of curve was used on all the outputs. For the inputs, simple triangular and trapezoidal functions where used. For the second input, named rate of change of error, five triangular functions and two trapezoids were also used, and again, one can have negative and positive values in an equal manner. Fig. 7 shows the mentioned fuzzy input set.   Fig. 8 shows the membership functions for the Kp gain of the position controller. Seven Gaussian membership functions were used. These functions are known for achieving a certain degree of smoothness in the transition of the results. In this part, it was necessary to do empirical tests to decide what would be the best form of the functions that would be used, and they were selected due to a better performance when considering parametric changes in the system.

2) PID-Fuzzy angle controller
For this controller, again were used as inputs the variable error and the rate of change of error of the angular position. The fuzzy sets and membership functions used were the same as those used for the position control. Fig. 10 presents the relationship between the inputs and outputs for the pendulum balance controller. e (7) ep (7) Kp (7) Ki (7) Kd (7) Pendulum_Angle (mamdani) 49 rules    As shown in fig. 4, a PID controller was required to control the angular position and balance of the pendulum, and therefore there is a differential gain Kd. Fig. 13 shows the membership functions for the Kd gain of the pendulum angle control loop.

B. Fuzzy rules
The fuzzy rules for the controllers were estimated based on the following premises: when there is a big error, the Kp gain must also be big, Ki and Kd will be small. When the error and the rate of change of error have an intermediate value, there is an intermediate Kp value as well as an intermediate Ki value. When the error is small, Kp and Ki will be proportionally small. Kd will depend of the error and the rate of change of error: Kd is small if the rate of change of error is small (to minimize derivative gain problems), conversely, if the rate of change of error is big, Kd will receive bigger values. Similar ideas can be found in the works of [19] and [20].
For all the rules here presented, an "AND" connective and the centroid defuzzification method were used. Table 2 presents the rules used for the Kp gains, showing every possible combination between the error and the rate of change of this error (its derivative in time).

V. NUMERICAL RESULTS
For the tests, it was considered a path that the inverted pendulum cart must follow while balancing the pendulum. This route consists of traveling 0.2 meters in a positive direction. In 5 seconds of elapsed time, the system should then return 0.2 meters. The pendulum starts at an angle equal to zero (perfectly balanced). Table 1 Initially, the system was tested with the parameters shown in Table 1. Fig.14 presents a comparison between the PID control and the PID-Fuzzy control for the displacement of the cart. The grey dotted line is the reference signal that the system needs to follow. ' DOI:

A. Numerical results for the parameters of
ISSN: 2318-4531  Table 1. Fig. 15 shows the same controllers' comparison, now for the angular displacement of the pendulum rod.  Table 1.
As can be seen, the PID-fuzzy control showed a performance advantage when compared to the pure PID control. This was mostly due to the gains projected for the PID control not being optimal because of the natural difficulty present in the classical controller design for complex systems, where the fuzzy logic helped the control system to achieve a better result.

B. Increase in the length of the pendulum rod (l=0.8m)
To show a better influence of the fuzzy logic in the designed controller, tests were performed by changing the physical parameter of the pendulum length. All other parameters were maintained, as well as the gains from the PI and PID control. Fig.16 presents a comparison between the PID control and the PID-Fuzzy control for the displacement of the cart now considering a pendulum length of l = 0.8 meters -double of the value presented in Table 1 and used in the other simulations.   C. Increase in the length of the pendulum rod (l=1.2m) For the last test, the pendulum length has been tripled from its original value. This extreme change was used to demonstrate the adaptability of the fuzzy control designed, where without changing any parameters of the PI or PID control the performance remained acceptable and far superior to the pure PI and PID controls.  As mentioned, even with an extreme three-fold change in pendulum's length, the PI-Fuzzy and PID-Fuzzy control was able to maintain the performance of the required task without any changes or readjustments being necessary. Thus, this type of controller, which combines the ease of the PID design with the fuzzy adaptability, can be used for physically indeterminate systems, or for systems that require some kind of constant physical changes, such as weight loading systems, vehicle transports, among others.

VI. CONCLUSION
This paper presented the design of a PI-Fuzzy and PID-fuzzy controller to control the position and balance of an inverted pendulum. The controller designed was compared to a classical PID controller, showing to be much superior in performance, especially considering parametric variations. Another aspect that can be observed is that the pure classical controllers proved to be challenges in terms of finding their optimal or even functional gains, either due to the complexity of the system or due to the use of multiple controllers that must work together. Thus, the fuzzy logic showed thought the obtained results his ability to improve the performance of the PI and PID controllers without the necessity to redesign the gains for each situation. ' DOI: ISSN: 2318-4531