Stabilization of Inverted Pendulum using Soft Computing

DOI : 10.17577/IJERTV12IS020139

Download Full-Text PDF Cite this Publication

Text Only Version

Stabilization of Inverted Pendulum using Soft Computing

Ahmed Abdalla M. Emam1, Mawada Ezzeldeen Jebril2 , Omer Elfaki Elbashir Elfaki3

1,3 College of Engineering-Karary University- Khartoum- Sudan

College of Graduate Studies & Scientific Research- Karary University-Khartoum-Sudan

Abstract: Inverted pendulum is a highly nonlinear and open loop unstable system. So it is difficult to be modeled and controlled by standard linear techniques. In this paper, various soft computing-based control techniques have been used for balancing inverted pendulum. First, a properly tuned PID controller that is tuned using auto tuning tool in MATLAB was utilized to stabilize the inverted pendulum and to generate training data. Second, a fuzzy controller is designed and simulated. After that a feed-forward neural network that is trained on the basis of the data generated by the PID controller using derivative based algorithms is used. At the last, a genetically optimized neural network was developed. All these techniques are tested and compared. The simulation results proved that genetically tuned neural network has the best performance.

Keywords: Inverted pendulum; PID controller; fuzzy controller; artificial neural network (ANN); genetic algorithm(AG).


    The inverted pendulum is a classical problem in control theory. The inverted pendulum is unstable because it may fall at any time in either direction any direction unless a suitable control force is applied. The control objective of the inverted pendulum is to position the pendulum into the unstable upright state by moving a cart that holds the pendulum. This characteristic of inverted pendulum makes its control a challenging task. Conventional controllers are used to control inverted pendulum after approximating it as a linear system assuming that the perturbation is very small around the vertical state. However, artificially intelligent controllers such as neural and fuzzy controllers may be used for an inverted pendulum without linearization.


Assuming that, the forces applied on the pendulum mass are in the horizontal direction. Using Newton's 2nd law, results in [2]:


Where is the cart mass, is the pendulum mass, is the

horizontal displacement of the pendulum carrying cart, and u is the applied force.

For the point mass.



Where: l is the length of the arm, and is the angle between the arm and the y axis.

Differentiating equations (2and 3) results in:





The cart with an inverted pendulum, shown in figure (1) below, is "bumped" with an impulse force.

Substituting equation (5) in (1) gives:


Figure (1): Inverted pendulum system analysis.

Performing the torque balance in the same manner, gives:




Substitute equations (10) and (11) in (9) gives:

Rearrangement of equation (12) gives:




    Fuzzy Logic Controller is one of the utmost sounding applications of fuzzy set theory. This control technique depends on the human ability to understand the systems behavior and it comprises of a set of qualitative control rules [6]. Fuzzy control is one of the intelligent control techniques that use fuzzy logic to model the control strategies of an

    The pendulum angle dynamics can be obtained by substitute equation (13) in (8) as follows:


    Inverted pendulum can be presented in state space form after linearization as shown in equations (15, 16) below:



    expert operator, which are described in linguistic fuzzy (imprecise) terms.


    Neural networks are mathematical model of the brain. The brain consists of about 1011 processing elements known as neurons that communicate using electrochemical signal through a network of axons and synapses. ANNs, as simplified models of the biological neural system, are massively parallel distributed processing systems made up of highly interconnected computing elements (neurons). NN have the ability to learn and thereby acquire knowledge and make it available for use. Control is one of the many applications of the NNs, where it is trained to minimize the error signal.

    For the simulation purpose the initial condition used is:

    And the specific pendulum parameters used are given in table (1) below:

    Table (1): Pendulum parameters

    Cart mass(kg)


    Pendulum mass(kg)


    Pendulum length(m)


    Center of gravity( )



    A PID controller or Proportional-Integral- Derivative controller is a control loop feedback mechanism, widely used in industrial control systems. A PID control algorithm provides the control signal as a function of the error value. The error signal is defined as the difference between the measured plant, or (process), output variable and desired output. Its output is given by:


    Where is Proportional gain, is Integral gain, is derivative gain, is control signal, and is the error signal.


    Genetic Algorithm (GA) is a search procedure inspired by the laws of natural selection and genetics. It can be viewed as a general-purpose optimization method and have been successfully applied to search, optimization and machine learning tasks. GA has the ability to solve difficult, multi- dimensional problems with little problem-specific information and hence has been chosen as the optimization technique to solve various problems in control systems. It has been shown that compared with other traditional heuristic optimization method, Genetic Algorithm is likely to be more computationally efficient. The controller parameters are usually determined by trial-and-error through simulation. In such case, the paradigm of GA appears to offer an effective way for automatically and efficient searching for a set of control performance [5].

  4. SIMULATION SETUP AND RESULTS MATLAB Simulink provides a graphical environment for simulation and analysis of dynamic systems. It is used in this paper to simulate the inverted pendulum under the control of the proposed controllers.

      1. System Simulation under PID controller

        The simulation diagram of the inverted pendulum under the PID controller is shown in figure (2). The PID block is imported from the Simulink library and tuned by the auto tuning tool provided with the block. The result of this simulation is shown in figure (3).

        Figure (2): PID controller for inverted pendulum.

        Figure (3): System response under PID controller

      2. System Simulation under Fuzzy Controller Figure (4) represents the simulation diagram of the inverted pendulum under the fuzzy logic controller. The controller parameters are tuned by trial and error. The best of the results obtained is shown in Figure (5).

        Figure (4): Simulation diagram of the inverted pendulum with fuzzy controller.

        Figure (5): System response under fuzzy controller.

      3. System simulation under neuro-controller

        The neural network toolbox (NNTool) of MATLAB was used to create a two-layer feed forward network with two neurons in the hidden layer. The created NN was trained with back propagation algorithm. The training data that was generated by the ID controller has been import to the NNTool from the work space. The simulation of the system under the neuro controller was carried out using command and functions rather than Simulink. Response of inverted pendulum controlled by neural network controller shown in Figure (6) below:

        Figure (6): Response of inverted pendulum using neural network.

      4. System Simulation under GA Neuro-Controller

    Back propagation algorithm faces the problem of being trapped in local minima of the error surface. Therefore, the NN trained by this algorithm my not provide the optimum performance. Genetic algorithm is a global search optimization method adopted for the tuning of the neuro controller parameters. The response of inverted pendulum under the control of genetically tuned NN is shown in figure

    (7) below:

    Figure (7): Response of inverted pendulum system controlled by GA-ANN.


From the simulation of the four controller presented in the previous section, it is obvious that all of the proposed controller are capable to produce zero steady state error. However, they have different transient behavior. Tables (2) represent a comparing between the values of settling time and undershoot of the four controllers. It was found that settling time and undershoot of PID, and the neuro controllers are better than the fuzzy controller. But the GA-ANN is superior over all the other three controllers.

Table (2): Comparison between four controllers.


Settling Time (sec)

Undershoot (rad)














[1] A journal by Ahmad Nor Kasruddin Bin Nasir, University Technology Malaysia, Modeling and Controller Design for an Inverted pendulum System, 2007.

[2] K. Ogata, Modern Control Engineering, 4th ed, Pearson Education (Singapore) Pvt. Ltd., New Delhi, 2005.

[3] Goldberg, D.E et. Al Genetic Algorithms in Search, Optimization, and Machine Learning. Reading, Mass.: Addison- Wesley, 1989.

[4] Hunt and Sbarbaro, Neural Networks for Control System – A Survey, Automatic, Vol. 28, 1992, pp. 1083-1112.

[5] Elmer P. Dadias, Patrick S. Fererandez, David J,"Genetic Algorithm on Line Controller For The Flexible Inverted Pendulum Problem, Journal Of Advanced Computational Intelligence and Intelligent Informatics.

[6] Aleem Ahmad Khan, and kashan Hussain, Comparative Performance Analysis between Fuzzy Logic Controller (FLC) and PID Controller for an Inverted Pendulum, International Journal of Electrical, Electronics and Computer Systems (IJEECS), Vol 10, October 2012.

Ahmed Abdalla Emam 1, is an Associate Professor in College of Engineering, Karary University. He received the B.Sc. from military technical College (Egypt) in 1989 in communication engineering and M.Sc. degree from Military engineering college (Bagdad) in control and Guidance, and Ph. D. degree from Karary University, Sudan in 2004 in

control and Automation. His research area includes soft computing and control. He published many researches in his field. Now he is teaching digital control and soft computing for graduate students, and classical control, modern control and digital control for junior students at Karary University.

Mawada Ezzeldeen Jebril2, is a teacher assistant in College of Engineering, Gezira College of Technology. She received the B.Sc. from Sudan University of Science and Technology in 2016 in electrical engineering (control). Now she is teaching soft computing and computer application

for graduate students, classical control, modern control and computer application for junior students at Gezira College of Technology.

Omer Elfaki Elbashir Elfaki3, is an Assistant Professor in the College of Engineering, Electrical Engineering department, Karary University. He received the B.Sc. from Sudan university of science and technology (Sudan) in 1999 in Power & Machines and M.Sc. degree from Karary University (Sudan) in 2004 in

Power & Machines, and Ph. D. degree from North China Electric Power University, Beijing, (China) in 2014 in Power

& Machines. His research area includes Power Systems & Electrical Machines. He published many researches in his field. Now he is teaching Power System Distribution and Power System Stability for graduate students, and Electrical Power System 1, 2, and 3, Control and Stability for Power Systems, Electrical Machines 1,2, and 3, DC machines for undergraduate students at Karary University, College of Engineering.