Real-Time Swing-Up Control of Non-Linear Inverted Pendulum Using Lyapunov Based Optimized Fuzzy Logic Control

This paper investigates the efficacy of an optimized fuzzy logic controller for real-time swing-up control and stabilization to a rigidly coupled twin-arm inverted pendulum system. The proposed fuzzy controller utilizes Lyapunov criteria for controller design to ensure system stability. The membership functions are further optimized based on the entropy function. The controller design is based on the black-box approach, eliminating the need for an accurate mathematical model of the system. The experimental results shows an improvement in the transient and steady-state response of the controlled system as compared to other state-of-the-art controllers. The proposed controller exhibits a small settling time of 4.0 s and reaches the stable swing-up position within 5 oscillations. Various error indices are evaluated that validates an overall improvement in the performance of the system.


I. INTRODUCTION
Inverted pendulum (IP) system has always attracted control system engineers due to its wide range of applications. The inverted pendulum finds direct application in segway and the extended system is also applicable in designing and modeling complex systems like, bipedal walking, robotic manipulator systems, missile control among many others [1], [2]. Being a non-linear underactuated system, the control of inverted pendulum is typically considered as a benchmark to test the efficacy of new control algorithms [3]. Researchers have applied several control strategies for the control and stabilization of the inverted pendulum system. In [4], the authors developed a feedback linearization control to stabilize the inverted pendulum system. The authors added adaptive fuzzy control to ensure asymptotic stability. The control system was applied on a real-time cart-position tracking by keeping The associate editor coordinating the review of this manuscript and approving it for publication was Xiaojie Su. the pendulum angle at its equilibrium position. In [5], the authors proposed a fuzzy logic controller for swing up control of a real-time pendulum. The authors designed a fuzzy separate fuzzy controller for cart position control and the pendulum angle stabilization was achieved in 10 seconds. In [6], the authors proposed an optimized fuzzy controller for an inverted pendulum system based on the minimization of an objective function which is dependent on the mean square error. The Gaussian membership function for the fuzzy controller was optimized using an objective function defined with the help of mean square error. The developed controller is used to track the pendulum angle trajectory. In [7], authors proposed a Takagi-Sugeno based fuzzy logic controller for swing-up control of inverted pendulum. The rule base for the controller is designed using Lyapunov's direct method, which ensures the stability of the system. In [8], the authors proposed an artificial neural network based controller to stabilize an inverted pendulum for a segway. The authors developed the controller of this mobile inverted VOLUME 9, 2021 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ pendulum by using radial basis function to independently determine the gains of the PID controller for both pendulum angle and position control. The real-time implementation of the controller on the mobile inverted pendulum showed the movement of the platform while maintaining the pendulum at an erected position. In [9], the authors used cascaded fuzzy controllers for a flexible joint robot manipulator. The cascade controller employs 3 fuzzy controllers out of which 2 controllers are used to control the motor rotation, and deflection angle. The output of these two fuzzy controllers is then fed to the third controller which produces the final control signal. The cascaded controller approach results in the reduction of link vibrations and achieves faster tracking and reduces the settling time. In [10], authors develoepd a vision based feedback controller for stabilization of inverted pendulum. The authors deployed vision based pendulum angle measurement for feedback in place of encoders which are used in a majority of applications that require angle measurement. The vision based feedback control loop had a maximum time delay of about 35 ms, and a resolution of 0.1 o . The proposed controller demonstrated a satisfactory stabilization and a high disturbance rejection with an accuracy of ±0.2 • . In [11], authors designed a linear quadratic regulator for swing-up stabilization of a real-time inverted pendulum system. The authors used the Lagrangian method for parameter identification and the total energy at the upright position was forced to zero, thereby obtaining the optimal control signal. In [12], authors developed a swing up and stabilization controller for a real-time rotatory inverted pendulum system. The control action is obtained by switching the control objective between two separately designed controllers for swing-up and stabilization action, respectively.. In [13], authors deployed a hybrid self-tuning Fuzzy based adaptive PID controller for swing-up control for a real-time inverted pendulum system. The authors designed two separate adaptive PID controllers to control the cart position and to provide stabilization of the pendulum angle.. In [14], the authors developed a fuzzy based virtual model control (VMC) for stabilization of the pendulum angle under parametric uncertainty. The proposed controller is essentially divided into three steps: (a) imagine and attach virtual components to the system followed by, (b) obtain the virtual forces and torques and finally (c) feeding these values to the real system to realize the virtual forces and torques. The performance of VMC controller was found out to be superior as compared to the linear quadratic regulator.
In [15], the authors developed a fuzzy-based linear quadratic regulator to control a double link rotatory inverted pendulum. The authors employed the Mamdani type fuzzy model to adjust the linear state feedback controller gains. The controller gain matrix was further optimized by adding Kalman filter. In [16], authors developed a fuzzy controller based on a guaranteed cost control objective function for swing up control of the inverted pendulum system. The controller is built around the linearized model of the inverted pendulum system. The stability of the controller is analyzed using the Lyapunov method. The proposed cost controller ensured the stability of the system and aids in disturbance rejection.. In [17], the authors developed a self-tuning linear-quadratic regulator for swing-up control and stabilization of an inverted pendulum system. The authors developed a cognitive model of the inverted pendulum system based on which the actuator dynamics and the controller has been designed.

A. FUZZY LOGIC OPTIMIZATION
The fuzzy logic system is usually used to design controllers for non-linear systems due to its inherent characteristic to handle the system without a need for an accurate mathematical model [18], [19]. Fuzzy logic systems are also advantageous where the control signal is to be generated in presence of vague/noisy measurement data [20]. Fuzzy-logic based systems are beneficial in a wide range of applications which has already been tested and proved by multiple sources [21]- [24]. The selection of the correct membership function has been amongst the most researched area for optimizing the performance of fuzzy controllers. In [25], the authors used s-function for defining membership function (MF) and maximizing fuzzy entropy corresponding to the MF. The performance of the developed method had been evaluated for image processing applications. In [26], the authors proposed the tuning of the gains of a fuzzy type PID controller by applying particle swarm optimization (PSO) technique. The proposed algorithm was implemented to control an industrial DC drive. The simulation and experimental results indicates an improved performance and robustness of the controller. In [27], the authors proposed the optimization of a fuzzy system using cross-mutated operation using PSO. The robust performance of the proposed algorithm is evaluated for: (a) the economic load dispatch system and (b) self-provisioning system used in communication network services. Results indicate an improved system efficiency and better robustness as compared to the hybrid PSO technique. In [28], the authors investigated the application of PD type fuzzy logic controller in trajectory tracking of differential drive mobile bot. The authors used a Takagi-Sugeno based fuzzy controller having 7 sets in each variable. The performance of the controller has been compared with PID and PD controllers. The results indicate a superior performance of PD type fuzzy logic controller as compared to conventional controllers. In [18], the authors investigated a statistical-based optimization approach for finding the optimum support in a fuzzy logic system using fuzzy entropy measures. This paper proposes an algorithm to optimize the membership function for designing a fuzzy logic controller. The proposed algorithm is tested for real-time swing-up control and stabilization of the inverted pendulum system and performance indices for the proposed controller are compared with state-of-the-art controllers. The key novelty features of the proposed work are: 1. Designed an optimal fuzzy controller based on a novel objective function which comprises of fuzzy entropy.
2. Developed a fuzzy controller based on Lyapunov stability criteria to ensure asymptotic stability of the developed controller. 3. The developed controller is deployed for real-time swing up stabilization of a rigidly coupled twin-arm inverted pendulum system. 4. To compare the performance of the proposed controller with other state-f-the-art controllers based on some key parameters to validate the efficacy of the proposed controller. The rest of the paper layout is: Section 2 illustrates the digital pendulum model. Section 3 describes the proposed fuzzy logic controller (FLC) developed for the system. In section 4 the objective function and the optimization technique used to optimise the fuzzy set (FS) is discussed in detail. Section 5 explains the experimental results of a swing-up control for a real-time inverted pendulum system. In section 6, robustness of the proposed algorithm is analyzed. In section 7, the proposed controller is compared with state-of-the-art controllers based on certain key performance parameters.. Finally, Section 7 discusses the salient findings of the study.

II. REAL-TIME DIGITAL CONTROL OF TWIN-ARM INVERTED PENDULUM MODEL
The figure of the rigidly coupled twin-arm digital pendulum with the cart system is illustrated in Figure 1. Mathematically the forces acting on the system can be summarized as: where, a = 1 Assuming the state variables: Then: To design a PID controller a linearized model is obtained. The equations are linearized around the inverted position, i.e. θ = 0 (operating point). Table 1 shows the parameters for the real-time model used in the experiment setup, manufactured by ''Feedback instruments the digital pendulum system: 33-936S'' [29].
By substituting the value from Table 1 in (8), the following eigenvalues are obtained: As evident from the eigen values, we can conclude that the system is unstable. The criteria for controller design is to make the eigenvalues negative and in turn, stabilize the system. Figure 2 illustrates the control block diagram for the same. The computer is connected to a data acquisition (DAQ) card which is an interface between the analog pendulum system and the digital computer. The control signal is generated by MATLAB -Simulink and is a digital signal, which is then converted to an analog signal of ±5 volts by the DAQ interface, which is converted to ±24 volts for motor operation by DC motor interface. The position of the cart and the angle of the pendulum are measured using encoders. The first is attached to the DC motor and the latter to the cart-pendulum for respective angular measurements. These encoders give analog signals for real-time measurement which are again converted to digital values via DAQ card.

III. FUZZY LOGIC CONTROLLER
For designing an FLC precise mathematical model of the system is not mandatory, however expert knowledge of the system under study is required, as FLCs are primarily inspired by the decision-making process of human beings. These can infer linear or nonlinear complex relationships between the input and output variable(s) [30]. The controller architecture designed for IP consists of a PD (proportional-derivative) type FLC designed to control the cart for driving the pendulum to an inverted position. The architecture of the PD type fuzzy logic controller used is depicted in Figure 3.

A. PREDEFINED MEMBERSHIP FUNCTIONS
For control applications, FS are commonly named concerning their relevant position with reference to error. As for any control system, the desired error is always 'zero', hence FS associated around 'zero error' is named as 'zero'. Moving on to the positive x-axis the FS which are associated with the positive error is named 'positive' and for the negative x-axis the FS which is associated with the negative error is named 'negative', respectively [31]. Initially, the MFs are distributed uniformly around the universe of discourse and Gaussian fuzzy MFs are chosen. The proposed controller is a two-input one output system; having (i) error in angle ( θ), and (ii) rate of change for error in angle (d( θ ) dt) as input variables and (iii) control signal (u) for DC motor, acting as an output variable. Fuzzy sets for error in pendulum angle are given in Figure 4. Here three overlapping normal (i.e. µ max = 1) Gaussian FS are defined which are distributed uniformly across the universe of discourse. For example, the equation for set zero ''ZE'' can be written as:

B. STABILITY ANALYSIS USING LYAPUNOV TECHNIQUE
The system dynamics can be represented as: The linguistic control rules will be formed without knowing the terms f (x) , g (x) , d(x) and w(disturbance) considering the pendulum as a black box system. The linguistic control rules are: • R1: State variables of the system: :ẋ 2 is proportional to the control input u • R3:ẋ 4 is proportional to −x 3 The statements R1, R2 and R3 ensure the stability of the system. The controller design objective is to find a u (control force) at which the system is stable, considering the operating point as [ 2 4 ] be the Lyapunov function, hence as per the state variables defined for the system we can write:V Using the control rules R2 and R3 As per classical Lyapunov synthesis, the control input u that ensuresV < 0, can be formed using the following rule base: • If x 1 is negative AND x 2 is negative, THEN u is positive • If x 1 is negative AND x 2 is positive, THEN u is zero • If x 1 is positive AND x 2 is positive, THEN u is negative • If x 1 is positive AND x 2 is negative, THEN u is zero Using the product operator for inference and centre of gravity as the defuzzification process, the control signal can be depicted as (13), as shown at the bottom of the next page.
To analyse control law and we assume µ p (x) = e −(x−a x ) 2 , µ n (x) = e −(x+a x ) 2 , µ z (x) = e −x 2 , (14), as shown at the bottom of the next page. Simplifying equation (14) we have, u, as shown at the bottom of the next page.
The fuzzy set design parameters a x 1 , a x 2 and a u are computed using the maximum entropy principle for the fuzzy system. The following section discusses the optimization principle used.

IV. OBJECTIVE FUNCTION AND OPTIMIZATION TECHNIQUE
The proposed optimization principle is based on the maximization of entropy of MF displaced by standard deviation data obtained from the system [32]. The mathematical expression for probability measures of FS according to which fuzzy entropy can be written as [29]: For example, fuzzy entropy for positive MF can be calculated as: As previously discussed in section III. The standard Gaussian fuzzy sets is used for representing the fuzzy variables, namely: error, change in error, and control output. The control signal expressed in equation (15) depends on the membership function parameters which are optimized using the maximum entropy principle with stopping criteria of a minimum optimal control cost function which is defined as: Hence, for obtaining the optimized membership function the optimization problem is defined as: The optimization process is carried out on the membership function by displacing the standard Gaussian membership function using standard deviation for individual fuzzy sets which are to be optimized. For instance, considering the input variable error in pendulum angle 3 membership functions are defined: zero, positive and negative. The membership function zero can be defined as: By displacing the set one can obtain the new fuzzy set µ * z which can be written as: where, σ e is the standard deviation obtained for the error in pendulum angle. The graphical depiction of a displaced membership function is represented in Figure 5. The figure depicts a few intermediate sets for the fuzzy set ''zero' when it is displaced. During the optimization process, the algorithm is supplied with the value of the standard deviation for each of the fuzzy variables which is then optimized using (15), (18) and (19). The standard deviation is obtained through stabilization of the IP system using PID controller: Using the displaced fuzzy sets, the optimization problem can now be defined as: Here µ * i depicts the corresponding displaced fuzzy sets. The objective function is optimized using genetic algorithm.  The parameters used for genetic algorithm (GA) is given in Table 2.. Using the GA based optimization of the objective function, the resultant optimized FS is used to replace predefined MFs and is thus used for designing optimized FLC. The same method is utilized to obtain optimized MFs for the rate of change of error in angle, and the control signal of the DC motor. In swing up stabilization, the pendulum system is at an initial angle of θ = 180 o (the natural equilibrium of a simple pendulum). The control philosophy for the inverted pendulum is fairly simple: here the controller's target is to swing upright and maintain the position of the pendulum to an inverted position by counteracting the earth's gravitational force. To generate this counteractive force, the cart is moved back and forth, due to which the pendulum gains inertia leading to an oscillatory motion. Once the pendulum reaches the desired inverted position the cart tries to maintain the inverted position [33].

A. PID CONTROLLER
The PID control algorithm consists of two controllers with only one being active at a time. One is designed for swinging up the pendulum pole and the other for stabilization of pendulum as it reaches the inverted position. The control algorithm for pendulum swing up is designed to regulate the force applied to the cart in such a way that the pendulum starts to oscillate with a successive increase in the oscillation magnitude. When the pendulum reaches the inverted position the stabilization algorithm then tries to maintain the inverted position with minimal control effort applied to the cart.Here, the PID settings have been optimized for minimum ISE (Integral square error)once the values are obtained using the Ziegler-Nichols method [29]. Pendulum angle stabilization using a PID controller is shown in Figure 7. The controller performance parameters are observed as: (a) Settling time -t s = 18 seconds (b) Peak value -M p = 6.01 radians.

B. FUZZY LOGIC CONTROLLER AND NOVEL OPTIMIZED FLC
The PID control is now replaced by the fuzzy logic controller as illustrated in Figure 3. Pendulum angle stabilization control using FLC is given in Figure 8. With this result, the controller performance parameters are observed as (a) Settling time -t s = 8.4 seconds (b) Peak value -M p = 4.9 radians. This indicates an improvement over PID control, with the settling time being reduced by 53.33% and peak value by 18%.  The predefined MFs used in FLC are replaced by optimized MFs obtained from the proposed algorithm and optimized FLC is used to control the digital pendulum. The pendulum angle stabilization using optimized FLC is given in Figure 9.
With this result the controller performance parameters are observed as: (a) Settling time -t s = 4.0 seconds (b) Peak value -M p = 5.52 radians. These values indicate an improvement over PID control, with the settling time being reduced by 77.78% and peak value by 8.2%. However, the comparison of these parameters over FLC indicates a reduction of settling time by 52.38% but an increase in peak value by 12.6%. One of the biggest improvements exhibited by the proposed controller is the reduction in oscillations, as the pendulum angle gets stabilized in 5 oscillations, while it took 26 oscillations for PID and 9 oscillations for FLC to stabilize the pendulum angle.    Figure 11 depicts the control forces (u) generated by the respective controllers. The back and forth cart movements can be associated with crisp control forces generated before the sudden spike in the control force where the spike is generated while the pendulum is being balanced to stabilize it to an VOLUME 9, 2021 inverted position. After which the motor continuously tries to counter the effect of gravity on the pendulum.

C. COMPARATIVE ANALYSIS OF RESULTS OBTAINED FOR PENDULUM STABILIZATION
Comparison of performance (pendulum angle stabilization) in swing up mode for PID control, FLC, and optimized FLC are given in Figure 12. Pendulum angle stabilization comparison indicates that steady-state error for all the controllers is ''0''. It can, however, be concluded that the pendulum angle is stabilized within a shorter duration for optimized FLC as compared to PID control or FLC. Table 3 summarizes ''Settling time (t s )'', ''Peak Value (M p )'' and the oscillations exhibited by the pendulum to be stabilized by the three distinct controllers.  Table 4 summarizes error indices (error in pendulum angle) for PID, FLC, and proposed controller; these indices include: root mean square error (RMSE), integral square error (ISE), integral time multiplied square error (ITSE), integral absolute error (IAE), integral time multiplied square error (ITAE) [34]:  As the steady-state error for the (PID, FLC, and novel FLC) controllers is: ''0'', the comparisons have been carried out for: Settling time, Peak value, and error indices. The proposed 'optimized FLC' exhibits minimum settling time (fast convergence) among the three controllers. The peak value is however only marginally different between the three controllers, which is an unavoidable phenomenon in swing up angle stabilization of an inverted pendulum. Further, the minimum values of the performance indices are demonstrated by optimized FLC. Hence it is innocuous to say that the proposed optimized FLC is an efficient and effective controller, and shows an improvement over benchmark PID control and conventional FLC.

VI. ROBUSTNESS ANALYSIS
In this section, the authors have examined the robustness of the proposed algorithm. The robust analysis is carried out under small disturbances within: (a) the system parameters and (b) the measurement unit by adding external noise. The block diagram illustrating both internal and external disturbances that are added to the system is shown in Figure 13.

A. SYSTEM PARAMETERS VARIATION
For robustness analysis the first step is to vary system parameters to evaluate the robustness of the proposed controller. The parameters chosen for this investigation are: (a) mass of cart, (b) combined mass of pendulum. Both the parameter values are varied with a deviation of 10% and the proposed entropy based fuzzy controller is tested to determine the robustness of the system.
In the first case, the controller response is tested under cart mass variation of 10% as compared to the default parameters value. The result validates the robustness of the proposed controller as the controller successfully stabilizes the system with a slight increase in the settling time as shown in Figure 14. In the second case, the controller response is observed under a 10% variation in pendulum mass when compared with the default system parameters. The result obtain indicates the robustness of the proposed controller as the controller aids in stabilizing the system. The controller response shows that the pendulum stabilizes at 360 • (equivalent to inverted position) with a minor effect in the settling time as depicted in Figure 15.
In the last case, the response of the controller is observed when there is 10% variation in both pendulum and cart mass. The response under twin parameter variation validates the robustness of the proposed controller as the overall system remain stable with a marginal increase in settling time as shown in Figure 16.

B. EXTERNAL DISTURBANCE
To check the robustness under external disturbance, the authors included a random noise generator which is added to the measurement unit as shown in Figure 13. The peakto-peak amplitude of the external noise is kept at 10% of  the controller signal, which is 0.5 V. Figure 17 shows the comparison of controller response to the system subjected to the external noise condition. The results obtain indicate the robustness of the proposed controller as it helps in stabilizing the system and the performance indices observed remains fairly unchanged with a small increase in the system overshoot. It is important to point out that the noise signal frequency is kept same as the transients observed by the controller.

VII. COMPARISON OF PROPOSED CONTROLLER WITH STATE-OF-THE-ART REFERENCE CONTROLLERS
The performance parameters for the proposed novel controller algorithm are compared with state-of-the-art controllers. It is well-known that the steady-state error for efficient controllers is 0. Hence, the comparison between the controllers is based on transient performance parameters. For performance evaluation the state-of-the-art work has been selected based on the similarity of either or all of the following parameters: (a), controller algorithm used, (b) simulation and (c) real-time experimental deployment. For steady-state performance evaluation, the settling times are compared and to determine the transient performance, the number of oscillations exhibited by the system to reach steady-state are observed.
In [13], the authors developed Fuzzy logic based adaptive PID controller for swing-up stabilization of pendulum angle. The hardware platform used for validating the experiment results by authors is the same as used to validate this research work. The authors used the fuzzy logic system to optimize the gains of the PID controller and hence it utilizes the principle of adaptive PID controller. The authors reported a settling time of 5 seconds. In [16], the authors utilized a hybrid controller approach using fuzzy logic control for swing up controller, switching to state feedback control for stabilization, and using LQR (guaranteed cost control) for uncertainty handling. The authors reported a settling time of 7.7 seconds. In [17], the authors developed a self-tuning regulator based on a precise actuator model. The controller achieved a settling time of 8 seconds. In [7], the authors developed a FLC based on Lyapunov's direct method to achieve swing-up stabilization of an inverted pendulum system. The authors didn't compute the optimized fuzzy logic system and the controller is designed using Lyapunov stability criteria. In contrast, the algorithm proposed in this paper utilizes the Lyapunov method and the fuzzy sets are further optimized to compute the optimum controller. The authors reported a settling time of 8.7 seconds. In [35], the authors deployed a Takagi-Sugeno based fuzzy controller, state feedback controller, and sliding mode controller strategies for swing-up stabilization of an inverted pendulum system. The controller had four input variables. The authors deployed Takagi-Sugeno based controller and didn't compute the optimum membership functions, although the authors compared the performance of three different controllers. The proposed controller in this paper is based on the Mamdani method and hence optimization of fuzzy sets becomes an integral part of controller implementation. The author reported a settling time of 12.8 seconds. Table 5 summarizes the comparison of the proposed controller with other benchmark control algorithms.   It is observed that the proposed controller exhibits the fastest settling time along with minimum oscillations when compared with benchmarked controllers. This proves the efficacy of the proposed optimization algorithm in finding the optimal membership function for a fuzzy logic controller design problem.

VIII. CONCLUSION
In this work, a novel optimization method has been proposed to find the membership function for fuzzy controller based on the ''Fuzzy Entropy'' function. The proposed method uses predefined fuzzy sets and optimizes the support of the set by evaluating the objective function. The fuzzy sets are optimized using genetic algorithms with stopping criteria as minimizing the optimal control cost function.
The proposed algorithm is applied for the swing-up stabilization for a real-time inverted pendulum system. A PD type fuzzy logic controller is designed based on the Lyapunov method which ensures asymptotic stability. Furthermore, the membership functions of the FLC are optimized based on the data obtained from the real-time PID swing-up control of the pendulum. The control objective of the experiment is to achieve swing-up stabilization in an inverted pendulum system. The results depict an improvement in system performance parameters (like t s , M p, etc.) for optimized-FLC as compared to FLC or PID. The performance of the proposed controller is also compared with other state-of-theart controllers present in the literature that adopted similar hardware/controller principle. The experimental results indicate an improvement in the performance parameters of the proposed controller.
In the current research work, the proposed methodology is used to optimize FS having Gaussian MF. In the future the authors intend to develop the same optimization technique for fuzzy-logic based systems having different membership functions like triangular, trapezoidal, s-function, etc. The applicability of this technique is limited to systems having the availability of reference data as a constrained requirement. For the majority of practical systems data is available as a reference set or can be determined with the help of simulation/experimental analysis, therefore availability of data will not be a major constraint for applicability of the proposed technique.