Next Article in Journal
Moving towards the End of Gender Differences in the Habits of Use and Consumption of Mobile Video Games
Previous Article in Journal
The Media in the Construction of Reality in the Context of Colombian Social Nonconformity
Previous Article in Special Issue
A Routing and Task-Allocation Algorithm for Robotic Groups in Warehouse Environments
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Design of a Fuzzy Logic Controller for the Double Pendulum Inverted on a Cart

by
George S. Maraslidis
,
Theodore L. Kottas
,
Markos G. Tsipouras
and
George F. Fragulis
*
Department of Electrical and Computer Engineering, University of Western Macedonia, 50100 Kozani, Greece
*
Author to whom correspondence should be addressed.
Information 2022, 13(8), 379; https://doi.org/10.3390/info13080379
Submission received: 3 July 2022 / Revised: 1 August 2022 / Accepted: 2 August 2022 / Published: 8 August 2022

Abstract

:
The double-inverted pendulum (DIP) constitutes a classical problem in mechanics, whereas the control methods for stabilizing around the equilibrium positions represent the classic standards of control system theory and various control methods in robotics. For instance, it functions as a typical model for the calculation and stability of walking robots. The present study depicts the controlling of a double-inverted pendulum (DIP) on a cart using a fuzzy logic controller (FLC). A linear-quadratic controller (LQR) was used as a benchmark to assess the effectiveness of our method, and the results showed that the proposed FLC can perform significantly better than the LQR under a variety of initial system conditions. This performance is considered very important when the reduction of the peak system output is concerned. The proposed controller equilibration and velocity tracking performance were explored through simulation, and the results obtained point to the validity of the control method.

1. Introduction

Modern control theory flourished during the 1960s, principally due to the development of aerospace dynamics and the emergence of space exploration. Today, automated control systems (ACS) [1] are implemented telecommunications, medicine, economics, power and electrical systems, and biology. Emerging trends of mechatronics, specifically robotics, ref. [2] exploit these mathematical possibilities. Although robotics and informatics have revolutionized commercial enterprises, the need for better and effective control challenged scientists to develop new mathematical models and concepts such as fuzzy logic, machine learning and neural networks to constrain the system closer to human thinking.
Fuzzy logic is a new theory of mathematics, an extension of classical binary logic [3] proposed by the mathematician Lotfi Zadeh in his study of fuzzy sets. Zadeh’s theory was based on a study conducted by Lukasiewicz and Tarski back in the 1920s. The first fuzzy logic controller was developed, manufactured, and integrated into electronic and electrical equipment, such as cameras and washing machines, in Japan in the 1980s [3,4,5,6]. The results were rather encouraging and led to further acceptance of the theory. Intelligent navigation systems can now replace human pilots in helicopters with amazing performance [7,8]. Integrating these controls into difficult and complex systems that previously only humans could operate is very advantageous. Moreover, engineers cooperate with experts to design fuzzy rule-based systems and develop efficient models. In this way, complex processes can be analyzed, and elements closer to human behavior can be found. The descriptor system found in nature is an example of a fuzzy logic controller test case. In this study a double-inverted pendulum on a cart, a classical engineering problem [9,10,11], was used to evaluate a fuzzy logic controller (FLC) compared to a method using a linear-quadratic control (LQR), which will be discussed and analyzed [12,13,14]. The purpose of this paper is to strengthen the arguments in favor of an FLC and to demonstrate its potential and the improvements it can offer to existing control methods for complex physical systems in nature that show chaotic behavior. In that regard, chaotic systems can become more understandable and predictable, while their control can become more efficient with Fuzzy Logic.

2. Double-Inverted Pendulum

2.1. Dip Elements

A DIP is a double pendulum (DP) vertical inversion, a naturally unstable system. It is rather more complicated than a DP, and it is rather difficult to maintain a stable upright position in the event of a disturbance when mounted on an oscillating cart. If the oscillating cart is strictly vertical and of high frequency, the DIP can be stabilized. The system is chaotic because the trajectory of the DIP mass is irregular, and there is no symmetry around the vertical axis y. Figure 1, Figure 2, Figure 3 and Figure 4 illustrate the difference between a single pendulum and a double pendulum.
A DIP is a system with 3 degrees of freedom (DOFs). The first always moves the cart to the right or left along the x axis. The second DOF is the rotational movement of the first link (link 1) connected to the cart via the revolute joint (joint 1). The third DOF is the rotational motion of the second link (link2), which is connected to the first link via a revolute joint (joint2). The DIP system has the following properties: (i) it is non-linear; (ii) it is multivariable; (iii) it changes rapidly; (iv) it is unstable; (v) it is chaotic (tiny changes have a big effect); and it is among the most challenging problems in automatic control theory. A DIP system can be used as a benchmark to assess the performance of various control methods and has been an exciting research topic over the past years. A DIP model consists of three interconnected bodies: the cart, a first pendulum, and a second pendulum. The dynamics of the system are complex, so we used the Lagrange method for reasons of simplicity.

2.2. Double-Inverted Pendulum Dynamics

The system has three variables: the distance r (or θ 0 ) that the cart travels along the x axis, the angle θ 1 of the first link from the positive y axis, and the angle θ 2 of the second link, again, from the positive y axis. Positive angle values are clockwise and negative angle values are counterclockwise. The horizontal force u on the cart is the sole external force. For the cart, the kinetic energy ( K 1 ), the potential energy ( P 1 ) and the dissipation energy ( D 1 ) will be [18,19,20]:
K 1 = 1 2 m 0 r 2
P 1 = 0
D 1 = 1 2 F r 2 = 1 2 F θ 0 2
where m 0 is the mass of the cart, and F is the coefficient of dynamic friction between the cart and the surface. The kinetic energy ( K 2 ) of the first pendulum, the potential energy ( P 2 ) and the dissipation energy ( D 2 ) will be
K 2 = 1 2 J 1 θ 1 2 + 1 2 m 1 d d t ( l 1 sin θ 1 ) 2 + d d t ( l 1 cos θ 1 ) 2
P 2 = m 1 g l 1 cos θ 1
D 2 = 1 2 c 1 θ 1 2
where m 1 is the mass of the first link; c 1 is the coefficient of dynamic friction at the first joint; J 1 is the moment of inertia of the pendulum; and l 1 is the distance between the center of gravity of the first pendulum and the first joint. For the second pendulum, the kinetic energy ( K 3 ), the potential energy ( P 3 ) and the dissipation energy ( D 3 ) will be
K 3 = 1 2 J 2 θ 2 2 + 1 2 m 2 { d d t ( L sin θ 1 + l 2 sin θ 2 ) 2 + d d t ( L cos θ 1 + l 2 cos θ 2 ) 2 }
P 3 = m 2 g ( L cos θ 1 + l 2 cos θ 2 )
D 3 = 1 2 c 2 ( θ 1 2 + θ 2 2 )
where m 2 is the mass of the second link; c 2 is the dynamic friction coefficient on the second joint; J 2 is the moment of inertia of the second pendulum; and l 2 is the distance between the center of gravity of the second pendulum and the second joint. Both pendulums are considered solid bodies of the same density; therefore, both centers of gravity are at their geometric center. Also, the gravitational acceleration value (g) used in all calculations was 9.81 m/s 2 .

2.3. The Lagrange Method

The Lagrange method [18,21,22] calculates the dynamics of the DIP. Subtracting the potential and dissipative energy from the kinetic energy is equivalent to L.
L K P D
L = 1 2 ( m 0 + m 1 + m 2 ) θ 0 2 + 1 2 ( m 1 l 1 2 + m 2 L 2 + J 1 ) θ 1 2 + 1 2 ( m 2 l 2 2 + J 2 ) θ 2 2 + ( m 1 l 1 + m 2 L ) cos ( θ 1 ) θ 0 θ 1 + m 2 l 2 cos ( θ 2 ) θ 0 θ 2 + m 2 L l 2 cos ( θ 1 θ 2 ) θ 1 θ 2 ( m 1 l 1 + m 2 L ) g cos θ 1 m 2 l 2 g cos θ 2 1 2 F θ 0 2 1 2 c 1 θ 1 2 1 2 c 2 ( θ 1 2 + θ 2 2 )
In this way, L can be applied to Euler–Lagrange (1).
d d t L x = L x
Applying the preceding formula to all three elements of the DIP yields Equations (2) and (3).
d d t K r K r + P r + D r = u
d d t K θ i K θ i + P θ i + D θ i = 0 , i = 0 , 1 , 2
where u is the external force applied to the cart, and r is θ 0 . At this stage, the equations are very complex and software such as MATLAB or Mathematica should be used to solve the symbolic equations, which is why the MATLAB code was built (see [23]).

2.4. Euler–Lagrange Equations

The Euler–Lagrange equations in matrix form are given in the following: the vector x ¯ = [ θ 0 , θ 1 , θ 2 ] is defined and the vector
x = x ¯ , x ¯ T
consists of three system variables: cart position, first pendulum angle and second pendulum angle as well as their derivatives: cart speed, first pendulum angular velocity, and second pendulum angular velocity as shown in (4).
x = θ 0 , θ 1 , θ 2 , θ 0 , θ 1 , θ 2 T
Therefore, the form of the DIP system is (see [18]):
D ( θ ) θ = C ( θ , θ ) θ + G ( θ ) + H u
where
D ( θ ) = d 1 d 2 cos θ 1 d 3 cos θ 2 d 2 cos θ 1 d 4 d 5 cos ( θ 1 θ 2 ) d 3 cos θ 2 d 5 cos ( θ 1 θ 2 ) d 6
C ( θ , θ ) = F d 2 sin ( θ 1 ) θ 1 d 3 sin ( θ 2 ) θ 2 0 c 1 c 2 d 5 sin ( θ 1 θ 2 ) θ 2 + c 2 0 d 5 sin ( θ 1 θ 2 ) θ 1 + c 2 c 2
G ( θ ) = 0 f 1 sin θ 1 f 2 sin θ 2
H = 1 , 0 , 0 T
where:
d 1 = m 0 + m 1 + m 2
d 2 = m 1 l 1 + m 2 L 1 = ( 1 2 m 1 + m 2 ) L 1
d 3 = m 2 l 2 = 1 2 m 2 L 2
d 4 = m 1 l 1 2 + m 2 L 1 2 + J 1 = ( 1 3 m 1 + m 2 ) L 1 2
d 5 = m 2 L 1 l 2 = 1 2 m 2 L 1 L 2
d 6 = m 2 l 2 2 + J 2 = 1 3 m 2 L 2 2
f 1 = ( m 1 l 1 + m 2 L 1 ) g = ( 1 2 m 1 + m 2 ) L 1 g
f 2 = m 2 l 2 g = 1 2 m 2 L 2 g
Since the center of gravity of each pendulum is in its geometrical center, l i = L i 2 are the lengths of the two links respectively, and the moment of inertia can be calculated as J i = m i L i 12 for each pendulum. After some computation, it looks like this:
D ( θ ) = m 0 + m 1 + m 2 ( 1 2 m 1 + m 2 ) L 1 cos θ 1 1 2 m 2 L 2 cos θ 2 ( 1 2 m 1 + m 2 ) L 1 cos θ 1 ( 1 3 m 1 + m 2 ) L 1 2 1 2 m 2 L 1 L 2 cos ( θ 1 θ 2 ) 1 2 m 2 L 2 cos θ 2 1 2 m 2 L 1 L 2 cos ( θ 1 θ 2 ) 1 3 m 2 L 2 2
C ( θ , θ ) = F ( 1 2 m 1 + m 2 ) L 1 sin ( θ 1 ) θ 1 1 2 m 2 L 2 sin ( θ 2 ) θ 2 0 c 1 c 2 1 2 m 2 L 1 L 2 sin ( θ 1 θ 2 ) θ 2 + c 2 0 1 2 m 2 L 1 L 2 sin ( θ 1 θ 2 ) θ 1 + c 2 c 2
G ( θ ) = 0 ( 1 2 m 1 + m 2 ) L 1 g sin θ 1 1 2 m 2 L 2 g sin θ 2
Therefore, the  D ( θ ) matrix is symmetrical and non-singular. From (5) we have:
x = 0 I 0 D 1 C x + 0 D 1 G + 0 D 1 H u
Since the system is non-linear, linearization around the equilibrium point—where the values of the variables are θ 1 = 0 , θ 2 = 0 , θ 1 = 0 and θ 2 = 0 —should be performed to put the model of the system into its the normal format (14),
x = Ax + B u
to obtain an approximation of the linear solution to the problem of optimal control. The matrices A and B are:
A = 0 3 × 3 I 3 × 3 D ( 0 ) 1 G ( 0 ) θ D ( 0 ) 1 C ( 0 , 0 )
B = 0 3 × 1 D ( 0 ) 1 H
where
D ( 0 ) = m 0 + m 1 + m 2 ( 1 2 m 1 + m 2 ) L 1 1 2 m 2 L 2 ( 1 2 m 1 + m 2 ) L 1 ( 1 3 m 1 + m 2 ) L 1 2 1 2 m 2 L 1 L 2 1 2 m 2 L 2 1 2 m 2 L 1 L 2 1 3 m 2 L 2 2
G ( 0 ) = 0 0 0 0 ( 1 2 m 1 + m 2 ) L 1 g 0 0 0 1 2 m 2 L 2 g
C ( 0 , 0 ) = F 0 0 0 c 1 c 2 c 2 0 c 2 c 2
H = 1 , 0 , 0 T
This system is ideal, and we can assume that there is no cart movement or friction between the two joints. In this case, F = 0 ; c 1 = 0 ; and c 2 = 0 , so C ( 0 , 0 ) = 0 , and the matrix A is simplified to the following format:
A = 0 3 × 3 I 3 × 3 D ( 0 ) 1 G ( 0 ) θ 0 3 × 3

2.5. State Space Equations of the Double-Inverted Pendulum

We compute the four A, B, C, and D matrices of the state-space model using the following values: (see Table 1):
We can derive a state-space model of the DIP system (see [18]):
x = Ax + B u
y = Cx + D
where
A = 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 8.10 0.81 0 0 0 0 195.75 93.15 0 0 0 0 116.43 103.61 0 0 0 , B = 0 0 0 0.91 5.50 0.68
and C = d i a g [ I 6 ] , D = [ 0 ] .

3. Linear Quadratic Regulation Control

The derived model is a Single Input Multiple Output (SIMO) model, and it is unstable. We can study our systems using the controllability and observability matrices, for which MATLAB provides the functions ctrb(sys) and obsv(sys). The controllability matrix is:
C o = B A B A n 1 B
and the observability matrix is:
O b = C , C A , , C A n 1 T
Using MATLAB, the ranks of the Co and Ob matrices can be found, and these are equal to n = 6. Hence, the model is controllable and observable.
The aim of LQR is to compute the appropriate matrix of gains to reach reach the optimal solution for the problem [12]. The gain of F control must minimize the integral
V = 0 ( x Q x + u R u ) x = x
where Q R n × n and R R m × m are positive, constant matrices. For infinite time there is
V = x M x
where M satisfies the algebraic Riccati equation and is the solution of
0 = M A + A M M B R 1 B M + Q
If the system is asymptotically unstable, or if the system defined by A and B is controllable and the system defined by A and E where E E = Q is observable, there is a unique positive solution M which minimizes the V:
u = R 1 B M x
MATLAB uses the LQR command to find a K matrix (gain) for a complete state-feedback of the system. The LQR command has four arguments: the A, B, Q, and R matrices. In the fundamental case, Q and R can be defined as:
Q = C C = 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
R = 1
The results for the gain matrix K are
K = 1.0000 168.8356 180.1829 2.6671 5.7882 17.3722 .
Figure 5, shows the open-loop system (grey area) and the closed-loop feedback with the K matrix. The thick lines represent a bus of six signals for the 6 state variables.
At this point, one input variable (external force on the cart) and six output variables are used to derive a new closed-loop system. The six output variables are (Figure 6):
  • θ 0 —Movement of the cart along the x axis
  • θ 1 —Angle of the first pendulum
  • θ 2 —Angle of the second pendulum
  • θ 0 —Velocity of the cart
  • θ 1 —Angular velocity of the first pendulum
  • θ 2 —Angular velocity of the second pendulum

3.1. LQR Customization

In the previous section, LQR was described using the simplest form of the Q and R matrices, yet there are different approaches to choosing those values. References include methods such as Bryson’s Law and many optimization algorithms for Q and R values. The choice to determine the value is up to the engineer and depends on the needs of the problem. For the Q matrix these values are the weights for every state variable, and bigger numbers move the poles of the closed-loop system more to the left in the complex plane. As a result, the system decays to zero more quickly. On the other hand, high R values affect the control effort and slow down the poles. We chose to plot 5 different cases to compare the Q and R values:
  • Q = 100 0 0 0 0 0 0 100 0 0 0 0 0 0 200 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
    R = 1
    K = 10 184.97 231.56 11.57 3.98 23.97
  • Q = 100 0 0 0 0 0 0 100 0 0 0 0 0 0 200 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
    R = 100
    K = 1 165.74 175.78 2.42 5.75 16.84
  • Q = 100 0 0 0 0 0 0 600 0 0 0 0 0 0 800 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
    R = 1
    K = 10 197.57 259.65 12.86 3.71 26.98
  • Q = 100 0 0 0 0 0 0 600 0 0 0 0 0 0 800 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
    R = 100
    K = 1 166.02 176.34 2.43 5.75 16.89
  • Q = 10 0 0 0 0 0 0 100 0 0 0 0 0 0 200 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
    R = 10
    K = 3.16 171.17 191.40 5.01 5.24 18.85
Figure 7 Results of the step response of the first three variables in all cases.
The results yielded were similar for the first (yellow), the second (orange) and fourth (purple) cases, whereas the first (blue) and the third (green) cases also had similar results. The fifth case (light blue) results were somewhere in the middle.

3.2. Simulink Model for LQR

We modeled the DIP in a block diagram using the Simulink tools provided by MATLAB. For the LQR method, the Simulink model is in Figure 8.
The gain value for each state was calculated from the simplest form:
Q = C C = 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1
and
R = 1
as a result
K = 1 168.83 180.18 2.66 5.78 17.37
For a step response with amplitude value of 1 and an initial value of 0 degrees for the two pendulums, the cart moves from 0 to 1, whereas the two pendulums after an oscillation stabilize at 0 degrees. After the linearization of the system, the LQR method led to a near-optimal solution to the problem, but left enough space for experimentation on the control of the DIP system.
Given a step response with an amplitude value of 1 and an initial value of 0 degrees for the two pendulums, the cart moves from 0 to 1 and the two pendulums stabilize at 0 degrees after the oscillation. After linearizing the system, the LQR method led to a near-optimal solution, but there was plenty of room for experimentation to control the DIP system.

4. Fuzzy Control

4.1. Fuzzy Logic Controllers

A major advantage of Fuzzy Logic Controllers (FLCs) is that they are quite simple. They consist of three stages: input, process, and output layers [8]. The sensor signal is tuned at the input layer and is matched to the membership function to provide fuzzy input. At the processing layer, there is a base rule that is triggered in response to an input signal and the result is sent to the output. The output layer is where the fuzzy output is “defuzzified” to a crisp output. Membership functions come in many forms, but the most common are triangular, but they can also be trapezoidal, sigmoidal or Gaussian.
The value of the membership function can be any value in the closed interval [0 1]. The processing layer consists of a rule base and an inference engine. Rules usually take the form
  • IF input is A THEN output is B
  • IF input1 is A AND input2 is B THEN output is C
The logical operators that could be used are AND, OR, and NOT. The number of basic rules depends on the number of inputs and the number of membership functions for each input. The relationship r u l e s = m n holds, where m is the number of membership functions and n is the number of inputs. When designing an FLC, sometimes there is a problem called the “explosive growth of rules”. This problem exponentially increases the number of rules in the base, making it very difficult to design an FLC. The inference engine takes the input and produces a fuzzy output according to the rules. There are various FLCs, such as the Mamdani and the Takagi-Sugeno type, that were used in this study depending on the inference engine. The final layer is defuzzification, which produces crisp values as the output of control commands [25].

4.2. Fuzzy Logic Controller for the DIP

The FLC Design was created in MATLAB’s Fuzzy Logic Toolbox. The fuzzy system is of the Mamdani type and is based on the results of the LQR method. The shape of the FLC is shown in Figure 9.
Using all six state variables in the DIP as inputs with three membership functions per variable would require 3 6 = 729 rules, which would cause an explosive problem as stated before. Instead, we used the fusion functions [26,27] to create two inputs:
  • the error e
  • the derivative of the error ec
Thus, using the 7 membership functions for each input requires 7 2 = 49 rules. Centroid defuzzification was used because it was the most prevalent and physically appealing of all the defuzzification methods and usually gives superior results [28,29,30,31]. The format of the input and output membership functions is shown below in Figure 10.
For the rules base, 7 categorical variables were used so that the system behaviour wold be human-like: (i) NB—Negative Big, (ii) NM—Negative Medium, (iii) NS—Negative Small, (iv) ZE—Zero, (v) PS—Positive Small, (vi) PM—Positive Medium, (vii) PB—Positive Big.
These categorical variables match the seven fuzzy sets of the two inputs and outputs. The set of rules is shown in Figure 11.
An example of a rule is:
  • IF   E   is   NB  AND  EC   is   NB  THEN  U   is   NB
MATLAB’s Fuzzy Logic Toolbox provides RuleViewer, a useful tool that shows which rules are fired for different values. For example, if E = 0.3 and E C = 0.2 then U = 0.0934 , see Figure 12. Furthermore, in Figure 13, we have the surface plot of the fuzzy system.

4.3. Creating the Fusion Function

We used fusion functions to implement the FLC models in Simulink. This function had 6 inputs, 6 DIP status variables, and 2 outputs, an error and its derivative. Figure 14 shows the closed-loop system.
The output of the DIP is sent to the fusion function, which creates two variables as inputs to the FLC. The three blocks K E , K E C , and K U represent the gain of an FLC and were calculated using trial and error to maximize the efficiency of the controller. There are many ways to implement the fusion function, but in this study we chose the upper pendulum angle t h e t a 2 and its angular velocity t h e t a 2 ` as the main variables. We used the following value of K:
K = 1 168.83 180.18 2.66 5.78 17.37
The fusion function block diagram in Simulink is shown in Figure 15:
The method of calculating the six gains is based on the engineer’s choice according to the parameters in question. The fusion function can be interpreted as weighted sums and the normalization of the input signals. In this study, the focus was the steadiness of the upper pendulum and that led to the division of the first three gains by the second pendulum’s position gain (K3), and the last three with the second pendulum’s angular velocity gain (K6). In that way, the most important elements of the DIP, in our test case, were weighted more as the final input to the FLC inference engine. Hence, the fusion function is
F f u s ( x ) = K θ 0 K θ 2 K θ 1 K θ 2 K θ 2 K θ 2 0 0 0 0 0 0 K θ 0 K θ 2 K θ 1 K θ 2 K θ 2 K θ 2 θ 0 θ 1 θ 2 θ 0 θ 1 θ 2
If (29) is applied to (30), we have
F f u s = 0.0058 0.9395 1 0 0 0 0 0 0 0.1697 0.3327 1
Therefore, 6 state variables can be merged into 2 groups to generate 2 output variables. There are alternative ways to develop the fusion function [32]. Engineers may set the position and speed of the first pendulum or the position and speed of the cart as the important elements of the problem. It depends on the restrictions of the problem, and further research in this field is mandatory. Another way to create the fusion function is to divide the 6 gains of (29) by the norm of K.
K = K θ 0 2 + K θ 1 2 + K θ 2 2 + K θ 0 2 + K θ 1 2 + K θ 2 2
The result is the following fusion function:
F f u s 2 ( x ) = K θ 0 K K θ 1 K K θ 2 K 0 0 0 0 0 0 K θ 0 K K θ 1 K K θ 2 K θ 0 θ 1 θ 2 θ 0 θ 1 θ 2

4.4. Design of the FLC in Simulink

Next, we designed the FLC’s Simulink model (see Figure 16 or the equivalent model in Figure 17).
As a reference signal we used the step function, but the FLC gain value was calculated using trial and error and looked like this:
K E = 3 , K E C = 0.3 , K U = 45 .
Figure 18 shows the results of the first three state variables with a step input and an initial value of zero. The results of the LQR method are also shown here for comparison.
As the oscilloscope diagram shows, the FLC controllers had less overshoot and faster settling times than the LQR ones.

4.5. Adjusting the FLC

This section defines another modified FLC that took advantage of different sets of membership functions. After several experiments, we found that the design and intervals of the fuzzy sets had a great influence on the result and the response of the model.
The fix increased the spacing of the membership functions PS, PM, NS, and NM; reduced the ZE interval; and converted the PB and NB triangular functions to Gaussian functions. The new form is shown in Figure 19. The Gaussian membership functions were reported to have shown a smoother response. Input and output ranges were unchanged and in the interval [−1 1]. Moreover, the gain of the new FLC was the same when comparing the result to the first FLC.
This new FLC was designed in Simulink, and the experimental results showed that it provided tighter control over the DIP system. Compared to the first FLC, the overshoot ratio was much lower, but the settling time was longer (Figure 20).

4.6. Test Results for Various Initial Values of the DIP

So far, we have used an initial value of zero for all calculations, that is, the starting position of the angle for t h e t a 1 and t h e t a 2 was at zero degrees (0 ). What follows is the analysis of the four main cases of initial system values and the measured outputs of all controllers (LQR and two FLCs).
The four typical cases are:
  • Both pendulums start at a negative angle, Figure 21 ( α )
  • Both pendulums start at a positive angle, Figure 21 ( β )
  • The first pendulum starts at a negative angle and the second pendulum starts at a positive angle, Figure 21 ( γ )
  • The first pendulum starts at a positive angle and the second pendulum starts at a negative angle, Figure 21 ( δ )
Negative angles go counterclockwise and positive angles go clockwise. The results of the four cases are shown below in Figure 21.

4.6.1. Case 1

For θ 1 ( 0 ) = 10 , θ 2 ( 0 ) = 10 , the output of the models is in Figure 22.

4.6.2. Case 2

For θ 1 ( 0 ) = 10 , θ 2 ( 0 ) = 10 , the output of the models is in Figure 23. Cases 3 and 4 are the most difficult to control, but the two FLCs showed considerable efficiency. The modified FLC had a higher overshoot rate than the first FLC.

4.6.3. Case 3

For θ 1 ( 0 ) = 10 , θ 2 ( 0 ) = 10 , the output of the models is in Figure 24.

4.6.4. Case 4

For θ 1 ( 0 ) = 10 , θ 2 ( 0 ) = 10 , the output of the models is in Figure 25.
Finally in Figure 26, the overall representation of all six state variables including the three derivatives t h e t a 0 ` (cart speed) t h e t a 1 (angular velocity of the first pendulum) and t h e t a 2 (angular velocity of the second pendulum). All three controllers (FLC, LQR, modified FLC) were presented. In these calculations, the reference signal or disturbance from the step source was zero, while the initial values were θ 1 ( 0 ) = 10 , θ 2 ( 0 ) = 10 . The results show that the two FLCs could stabilize the double-inverted pendulum system. In some cases, better results will be obtained and the LQR method will be improved. The rate of overshoot is small, and the settling time for the DIP to reach a steady state is quite short.

4.7. Disturbance

Regarding the stability of an experimental realistic manufactured DIP system, various repetitive disturbances could be generated due the wind, friction or other external forces in the physical environment.
There were three selected placements for Simulink disturbances: the control signal of the fuzzy controller output; one in each output signal from the plant, and one in the upper pendulum signal (Figure 27). It is obvious that these forces can also be applied to specific components of the DIP system, such as the upper or lower pendulum or even on the cart. The disturbance was implemented with a pulse generator block that created a small amplitude pulse ranging from 0.1 to 1, over a period of 5 s with a 10% pulse width.
The results of the system’s response with the LQR, FLC and modified FLC controllers for the cart and lower and upper pendulum positions are depicted in Figure 28, Figure 29 and Figure 30 where it is shown that both FLCs had better control over the disturbance and improved overall stabilization of the system with smaller oscillations during the external pulse.
The system can become more robust with the fuzzy control and solve real-life problems where there are incalculable external factors and energy losses, such as friction, which can result in chaotic behavior. During the disturbance (second placement), the results proved that there was improvement in the overall behavior of the system as depicted in Table 2. The three elemts of both FLCs reached zero faster than the LQR controller did at time 0.1 s before next disturbance occurrence (period of 5 s).
Fuzzy logic can improve and advance existing control theories and methods due to its proximity to the human approach to problem solving. With the capabilities of neural networks, neuro-fuzzy controllers can learn from their operational environment to enhance the potential of control over highly unstable systems.

5. Conclusions

In the present study, the control of a double-inverted pendulum (DIP) on a cart using a fuzzy logic controller (FLC)-based detailed model was proposed in a MATLAB/Simulink environment to test its behavior and achieve good system stability. The simulation results pointed to the efficacy of the FLC in comparison to other widely accepted methods, such as LQR. Although both fuzzy logic and the LQR controller stabilized the system normally, the FLC substantially reduced peak levels as well. An expansion of this controller could be also applied to a triple-inverted pendulum and there are notable efforts in the global bibliography regarding that problem [33]. All documentation (MATLAB code/Simulink model used was retrieved from [23]. Suggestions for future research could include expansion of our method using a type 2 fuzzy membership function as well as the Tagaki-Sugeno FLC rather than the Mandani one [34,35,36].

Author Contributions

Conceptualization, G.S.M. and G.F.F.; methodology, G.S.M.; software, G.S.M.; validation, T.L.K. and M.G.T.; writing—original draft preparation, G.S.M.; writing—review and editing, T.L.K., M.G.T. and G.F.F.; supervision, M.G.T. and G.F.F.; funding acquisition, M.G.T. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Acknowledgments

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Dorf, R.C.; Bishop, R.H. Modern Control Systems; Pearson: London, UK, 2011. [Google Scholar]
  2. Craig, J. Introduction to Robotics: Mechanics and Control; Pearson: London, UK, 2018. [Google Scholar]
  3. Zadeh, L.A. Fuzzy sets. Inf. Control 1965, 8, 338–353. [Google Scholar] [CrossRef]
  4. Zadeh, L.A. Outline of a new approach to the analysis of complex systems and decision processes. IEEE Trans. Syst. Man Cybern. 1973, SMC-3, 28–44. [Google Scholar] [CrossRef]
  5. Zadeh, L.A. Fuzzy algorithms. Inf. Control 1968, 12, 94–102. [Google Scholar] [CrossRef]
  6. King, R.E. Computational Intelligence in Control Engineering; CRC Press: Boca Raton, FL, USA, 1999. [Google Scholar]
  7. Kosko, B.; Toms, M. Fuzzy Thinking: The New Science of Fuzzy Logic; Hyperion: New York, NY, USA, 1993. [Google Scholar]
  8. Theodorou, Y. Introduction to Fuzzy Logic (Book in Greek), 1st ed.; Editions TZIOLA: Thessaloniki, Greece, 2010. [Google Scholar]
  9. Hazem, Z.B.; Fotuhi, M.J.; Bingül, Z. Development of a Fuzzy-LQR and Fuzzy-LQG stability control for a double link rotary inverted pendulum. J. Frankl. Inst. 2020, 357, 10529–10556. [Google Scholar] [CrossRef]
  10. Hazem, Z.B.; Fotuhi, M.J.; Bingül, Z. A study of anti-swing fuzzy LQR control of a double serial link rotary pendulum. IETE J. Res. 2021, 1–12. [Google Scholar] [CrossRef]
  11. Fotuhi, M.J.; Hazem, Z.B.; Bingül, Z. Modelling and torque control of an non-linear friction inverted pendulum driven with a rotary series elastic actuator. In Proceedings of the 2019 3rd International Symposium on Multidisciplinary Studies and Innovative Technologies (ISMSIT), Ankara, Turkey, 11–13 October 2019; pp. 1–6. [Google Scholar]
  12. Luhao, W.; Zhanshi, S. LQR-Fuzzy control for double-inverted pendulum. In Proceedings of the 2010 International Conference on Digital Manufacturing & Automation, Changcha, China, 18–20 December 2010; Volume 1, pp. 900–903. [Google Scholar]
  13. Kudinov, Y.; Pashchenko, F.; Kelina, A.; Vasutin, D.; Duvanov, E.; Pashchenko, A. Analysis of Control System Models with Conventional LQR and Fuzzy LQR Controller. Procedia Comput. Sci. 2019, 150, 737–742. [Google Scholar] [CrossRef]
  14. Hazem, Z.B.; Fotuhi, M.J.; Bingül, Z. Anti-swing radial basis neuro-fuzzy linear quadratic regulator control of double link rotary pendulum. Proc. Inst. Mech. Eng. Part I J. Syst. Control Eng. 2022, 236, 531–545. [Google Scholar] [CrossRef]
  15. The Pendulum. My Attempt at Building a Diverse Company from the Start. Available online: https://medium.com/assist/the-pendulum-my-attempt-at-building-a-diverse-company-from-the-start-bd9e50523a3d (accessed on 1 May 2022).
  16. Izadgoshasb, I.; Lim, Y.Y.; Tang, L.; Padilla, R.V.; Tang, Z.S.; Sedighi, M. Improving efficiency of piezoelectric based energy harvesting from human motions using double pendulum system. Energy Convers. Manag. 2019, 184, 559–570. [Google Scholar] [CrossRef]
  17. Bhounsule, P. A Controller Design Framework for Bipedal Robots: Trajectory Optimization and Event-Based Stabilization. Ph.D. Thesis, Cornell University, Ithaca, NY, USA, 2012. [Google Scholar]
  18. Bogdanov, A. Optimal Control of a Double-Inverted Pendulum on a Cart; Tech. Rep. CSE-04-006; Oregon Health and Science University, OGI School of Science and Engineering: Beaverton, OR, USA, 2004. [Google Scholar]
  19. Brull, T. Course: Systems and Control Theory; Lecture Notes: Equations of Motion for an Inverted Double Pendulum on a Cart (in Generalized Coordinates); Institute of Mathematics: Berlin, Germany; Available online: https://www3.math.tu-berlin.de/Vorlesungen/SoSe12/Kontrolltheorie/matlab/inverted_pendulum.pdf (accessed on 2 July 2022).
  20. Jaiwat, P.; Ohtsuka, T. Real-time swing-up of double-inverted pendulum by nonlinear model predictive control. In Proceedings of the 5th International Symposium on Advanced Control of Industrial Processes, Hiroshima, Japan, 28–30 May 2014; pp. 290–295. [Google Scholar]
  21. Demirci, M. Design of feedback controllers for linear system with applications to control of a double-inverted pendulum. Int. J. Comput. Cogn. 2004, 2, 65–84. [Google Scholar]
  22. Morin, D. Introduction to Classical Mechanics: With Problems and Solutions; Cambridge University Press: Cambridge, UK, 2008. [Google Scholar]
  23. Available online: https://gitfront.io/r/marasgeon/d401cb516187aa5b83beaeab04b15d3885621b56/MATLAB-code/tree/SEEDA/ (accessed on 2 July 2022).
  24. Inverted Pendulum: System Modeling. Available online: https://ctms.engin.umich.edu/CTMS/index.php?example=InvertedPendulum&section=ControlStateSpace (accessed on 1 May 2022).
  25. Van Leekwijck, W.; Kerre, E.E. Defuzzification: Criteria and classification. Fuzzy Sets Syst. 1999, 108, 159–178. [Google Scholar] [CrossRef]
  26. Han, Y.; Liu, Y. Reduced-dimensional fuzzy controller design based on fusion function and application in double-inverted pendulum. In Proceedings of the 2010 The 2nd International Conference on Industrial Mechatronics and Automation, Wuhan, China, 30–31 May 2010; Volume 2, pp. 337–340. [Google Scholar]
  27. Wang, L.; Zheng, S.; Wang, X.; Fan, L. Fuzzy control of a double-inverted pendulum based on information fusion. In Proceedings of the 2010 International Conference on Intelligent Control and Information Processing, Dalian, China, 13–15 August 2010; pp. 327–331. [Google Scholar]
  28. Lee, C.C. Fuzzy logic in control systems: Fuzzy logic controller. I. IEEE Trans. Syst. Man Cybern. 1990, 20, 404–418. [Google Scholar] [CrossRef]
  29. Sugeno, M. An introductory survey of fuzzy control. Inf. Sci. 1985, 36, 59–83. [Google Scholar] [CrossRef]
  30. Braae, M.; Rutherford, D. Fuzzy relations in a control setting. Kybernetes 1978, 7, 185–188. [Google Scholar] [CrossRef]
  31. Larkin, L.I. A fuzzy logic controller for aircraft flight control. In Proceedings of the 23rd IEEE Conference on Decision and Control, Las Vegas, NV, USA, 12–14 December 1984; pp. 894–897. [Google Scholar]
  32. Li, Q.R.; Tao, W.H.; Sun, N.; Zhang, C.Y.; Yao, L.H. Stabilization control of double-inverted pendulum system. In Proceedings of the 2008 3rd International Conference on Innovative Computing Information and Control, Dalian, China, 18–20 June 2008; p. 417. [Google Scholar]
  33. Hazem, Z.B.; Fotuhi, M.J.; Bingül, Z. A comparative study of the friction models with adaptive coefficients for a rotary triple inverted pendulum. In Proceedings of the 2018 6th International Conference on Control Engineering & Information Technology (CEIT), Istanbul, Turkey, 25–27 October 2018; pp. 1–6. [Google Scholar]
  34. Elkinany, B.; Alfidi, M.; Chaibi, R.; Chalh, Z. TS fuzzy system controller for stabilizing the double-inverted pendulum. Adv. Fuzzy Syst. 2020, 2020, 8835511. [Google Scholar]
  35. Chen, W.; Theodomile, N. Simulation of a triple inverted pendulum based on fuzzy control. World J. Eng. Technol. 2016, 4, 267. [Google Scholar] [CrossRef]
  36. Zhang, C.; Bai, C.; Ding, Y.; Zhang, Q. LQR optimal control of triple inverted pendulum based on fuzzy quotient space theory. In Proceedings of the 2012 IEEE International Conference on Granular Computing, Hangzhou, China, 11–13 August 2012; pp. 633–638. [Google Scholar]
Figure 1. Single Pendulum [15].
Figure 1. Single Pendulum [15].
Information 13 00379 g001
Figure 2. Double Pendulum [16].
Figure 2. Double Pendulum [16].
Information 13 00379 g002
Figure 3. Inverted Pendulum [17].
Figure 3. Inverted Pendulum [17].
Information 13 00379 g003
Figure 4. Double-Inverted Pendulum [18].
Figure 4. Double-Inverted Pendulum [18].
Information 13 00379 g004
Figure 5. Block representation of the system with K feedback [24].
Figure 5. Block representation of the system with K feedback [24].
Information 13 00379 g005
Figure 6. Step response of the system.
Figure 6. Step response of the system.
Information 13 00379 g006
Figure 7. Step response of all 6 cases (including the initial one). Yellow—Initial simplest form, Blue—1st case (very close to green), Orange—2nd case (very close to purple), Green—3rd case, Purple—4th case, Light Blue—5th case.
Figure 7. Step response of all 6 cases (including the initial one). Yellow—Initial simplest form, Blue—1st case (very close to green), Orange—2nd case (very close to purple), Green—3rd case, Purple—4th case, Light Blue—5th case.
Information 13 00379 g007
Figure 8. Simulink model of the LQR control.
Figure 8. Simulink model of the LQR control.
Information 13 00379 g008
Figure 9. Form of FLC.
Figure 9. Form of FLC.
Information 13 00379 g009
Figure 10. Inputs e, ec and Output u.
Figure 10. Inputs e, ec and Output u.
Information 13 00379 g010
Figure 11. Rule Base.
Figure 11. Rule Base.
Information 13 00379 g011
Figure 12. Rule Viewer.
Figure 12. Rule Viewer.
Information 13 00379 g012
Figure 13. Surface Graph.
Figure 13. Surface Graph.
Information 13 00379 g013
Figure 14. Closed-loop system.
Figure 14. Closed-loop system.
Information 13 00379 g014
Figure 15. The fusion function.
Figure 15. The fusion function.
Information 13 00379 g015
Figure 16. Simulink blocks of the DIP with the FLC (a).
Figure 16. Simulink blocks of the DIP with the FLC (a).
Information 13 00379 g016
Figure 17. Simulink blocks of the DIP with the FLC (b).
Figure 17. Simulink blocks of the DIP with the FLC (b).
Information 13 00379 g017
Figure 18. Comparison of the LQR (yellow) and FLC (light blue) for θ 0 , θ 1 and θ 2 .
Figure 18. Comparison of the LQR (yellow) and FLC (light blue) for θ 0 , θ 1 and θ 2 .
Information 13 00379 g018
Figure 19. Inputs/Outputs E, EC and U of the modified FLC.
Figure 19. Inputs/Outputs E, EC and U of the modified FLC.
Information 13 00379 g019
Figure 20. Comparison of FLC (light blue), LQR (yellow), and the modified FLC (orange).
Figure 20. Comparison of FLC (light blue), LQR (yellow), and the modified FLC (orange).
Information 13 00379 g020
Figure 21. Set of Initial values.
Figure 21. Set of Initial values.
Information 13 00379 g021
Figure 22. FLC (light blue), LQR (yellow), and modified FLC (orange).
Figure 22. FLC (light blue), LQR (yellow), and modified FLC (orange).
Information 13 00379 g022
Figure 23. FLC (light blue), LQR (yellow), and modified FLC (orange).
Figure 23. FLC (light blue), LQR (yellow), and modified FLC (orange).
Information 13 00379 g023
Figure 24. FLC (light blue), LQR (yellow), and modified FLC (orange).
Figure 24. FLC (light blue), LQR (yellow), and modified FLC (orange).
Information 13 00379 g024
Figure 25. FLC (light blue), LQR (yellow), and modified FLC (orange).
Figure 25. FLC (light blue), LQR (yellow), and modified FLC (orange).
Information 13 00379 g025
Figure 26. LQR (yellow), FLC (light blue) and new FLC (orange).
Figure 26. LQR (yellow), FLC (light blue) and new FLC (orange).
Information 13 00379 g026
Figure 27. The external repetitive disturbances in Simulink.
Figure 27. The external repetitive disturbances in Simulink.
Information 13 00379 g027
Figure 28. The DIP response under disturbance (first placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Figure 28. The DIP response under disturbance (first placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Information 13 00379 g028
Figure 29. The DIP response under disturbance (second placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Figure 29. The DIP response under disturbance (second placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Information 13 00379 g029
Figure 30. The DIP response under disturbance (third placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Figure 30. The DIP response under disturbance (third placement point) in the control signal with the LQR (yellow), FLC (blue) and modified FLC* (orange) controllers.
Information 13 00379 g030
Table 1. The parameter values used for the model.
Table 1. The parameter values used for the model.
VariableValue
m 0 1 Kg
m 1 0.3 Kg
m 2 0.6 Kg
L 1 0.2 m
L 2 0.4 m
g9.81 m s 2
Table 2. Comparative values under disturbance for all elements at simulation time 4.9 s.
Table 2. Comparative values under disturbance for all elements at simulation time 4.9 s.
Values at time 4.9 s
Cart1st Pendulum2nd Pendulum
LQR−1.048−0.02574−0.02547
FLC−0.620−0.02513−0.02504
FLC modified−0.167−0.01635−0.01716
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Maraslidis, G.S.; Kottas, T.L.; Tsipouras, M.G.; Fragulis, G.F. Design of a Fuzzy Logic Controller for the Double Pendulum Inverted on a Cart. Information 2022, 13, 379. https://doi.org/10.3390/info13080379

AMA Style

Maraslidis GS, Kottas TL, Tsipouras MG, Fragulis GF. Design of a Fuzzy Logic Controller for the Double Pendulum Inverted on a Cart. Information. 2022; 13(8):379. https://doi.org/10.3390/info13080379

Chicago/Turabian Style

Maraslidis, George S., Theodore L. Kottas, Markos G. Tsipouras, and George F. Fragulis. 2022. "Design of a Fuzzy Logic Controller for the Double Pendulum Inverted on a Cart" Information 13, no. 8: 379. https://doi.org/10.3390/info13080379

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop