Subscribe Now Subscribe Today
Research Article

PSO-Based Controller Design for Rotary Inverted Pendulum System

Iraj Hassanzadeh and Saleh Mobayen
Facebook Twitter Digg Reddit Linkedin StumbleUpon E-mail

This research presents an optimum approach for designing Rotary Inverted Pendulum (RIP) controller using PSO algorithm. The primary design goal is to balance the pendulum in an inverted position and the control criterion is to minimize the integral absolute error of system angles. Simulation results demonstrate the robustness and effectiveness of proposed controller with regard to parameter variations, various reference trajectory and load disturbances. The proposed method can be considered as a promising way for control of various similar nonlinear systems.

Related Articles in ASCI
Similar Articles in this Journal
Search in Google Scholar
View Citation
Report Citation

  How to cite this article:

Iraj Hassanzadeh and Saleh Mobayen, 2008. PSO-Based Controller Design for Rotary Inverted Pendulum System. Journal of Applied Sciences, 8: 2907-2912.

DOI: 10.3923/jas.2008.2907.2912



During the past decades, many modern control methodologies such as nonlinear control, optimal control, adaptive control and variable structure control have been widely proposed for control approaches (Gaing, 2004). However, these methods are theoretically complex and difficult to implement. PID controller design covering treatment to both transient and steady state responses offers the simplest and most efficient solutions to various control problems (Visioli, 2001). Unfortunately, it has been difficult to tune PID controller gains accurately because many industrial plants are often very complex consisting of issues such as higher order, time delays and nonlinearities (Kwok et al., 1993; Gaing, 2004). The ability of using numerical methods for efficiently and accurately characterizing the quality of a particular design has excited control engineers to apply stochastic global optimizers. Over the past years, several heuristic methods are employed for tuning of controllers. Ziegler and Nichols proposed the first method utilizing the classical tuning rules. Though, it is hard to determine optimal PID controller parameters with Ziegler-Nichols formula in general (Visioli, 2001; Gaing, 2004).

To overcome these difficulties, various methods are employed. Many random search methods, such as Genetic Algorithm (GA), Tabu Search (TS) and Simulated Annealing (SA) have recently received great attention for searching global optimal solution and achieving high efficiency (Zhou and Birdwell, 1994; Haupt and Haupt, 1998). GA method is usually faster than TS and SA methods because of employing parallel search techniques. Though, the GA method has been employed successfully for global optimization, recent research has identified some deficiencies in GA performance. This degradation in efficiency is apparent in applications with highly epistatic objective functions (where the parameters being optimized are highly correlated), the crossover and mutation operations cannot ensure better fitness of offspring because population chromosomes have similar structure and their fitness are high toward the end of the process (Gaing, 2004; Kennedy and Eberhart, 1995). To overcome GA difficulties, a novel method is proposed using PSO approach. PSO is one of the modern heuristic algorithms developed through simulation of a simplified social system. Generally, it is characterized as a simple concept, easy to implement and computationally efficient. Because PSO method is a superior optimization technique than recent heuristic methods, in this study developments of PSO-PID controller to determine optimal PID parameters are considered.


The rotary inverted pendulum system is a well-known test platform for evaluating various control algorithms. It has also some significant real life applications such as pointing control, aerospace vehicles control, robotics, etc (Muskinja and Tovornik, 2006). The system consists of a rotary arm and a pendulum where the rotary arm is actuated by a motor with the objective of balancing the pendulum in an inverted position. A schematic diagram of the RIP system is shown in Fig. 1, where u, lp, mp, α, r, θ and Jb are the motor input, the pendulum length, the pendulum mass, the pendulum angle, the arm length, the arm angle and effective mass moment of inertia, respectively.

Fig. 1: Schematic view of RIP system

Fig. 2: Built in RIP system (Advanced robotics research lab)

The plane of the pendulum is orthogonal to the radial arm. Figure 2 shows the RIP system built in robotics research lab in our department. Also, the block diagram of whole system is shown in Fig. 3.

Here, the dynamic equations of the RIP system considering backlash and friction effects are presented. The RIP dynamics are governed by Yan (2003) and Muskinja and Tovornik (2006):



The above nonlinear model can be found in the following equations:

Fig. 3: Block diagram of whole system

Table 1: Parameters of the RIP system


The parameters of nonlinear model of the system are shown in Table 1.

From Eq. 3, the corresponding nonlinear model is given by:


where, A, B and E matrices are as follows:






From the above Equations, the RIP system is easily simulated using Simulink® and Matlab®. The controller parameters generated by PSO algorithm are employed iteratively in relevant simulation blocks and the cost function is calculated in the manner presented in next section.


Considering the social behavior of swarm of fish, bees and other animals, the concept of PSO is developed. PSO is a robust stochastic evolutionary computation method based on the movement of swarms looking for the most fertile feeding location (Rahmat-Samii, 2003). In general, PSO implementation is easier than GA. Indeed, PSO only has one operator; velocity calculation, so the computation time is decreased significantly. The reason is PSO does not perform the selection and crossover operations in evolutionary process.

Another difference between GA and PSO is the ability to control convergence. Crossover and mutation rates can affect the convergence of GA, but nothing can compare to the level of control achieved through manipulating of the inertial weight. The more decrease of inertial weight the more increase the swarm`s convergence. This type of control allows determining the rate of convergence and the level of stagnation eventually achieved. Stagnation occurs in GA when all of the individuals have the same genetic code. In that case the gene pool is uniform, crossover has little or no effect on population and each successive generation is essentially same as the first. However, in the PSO, this effect can be controlled or prevented (Kennedy and Eberhart, 1995; Rahmat-Samii, 2003).

All solutions in PSO can be represented as particles in a swarm. Each particle has a position and velocity vector and each position coordinate represents a parameter value. Similar to the most optimization techniques, PSO requires a fitness evaluation function relevant to the particle`s position. XPB and XGB are the personal best (Pbest) position and global best (Gbest) position of the ith particle. Each particle is initialized with a random position and velocity. The velocity of each particle is accelerated toward the global best and its own personal best based on the following equation (Gaing, 2004):


Here, rand() and Rand() are two random numbers in the range [0,1]; c1 and c2 are the acceleration constants and w is the inertia weight factor. The parameter w helps the particles converge to Gbest, rather than oscillating around it. Suitable selection of w provides a balance between global and local explorations. In general, w is set according to the following equation (Rahmat-Samii, 2003):


The positions are updated based on their movement over a discrete time interval (Δt) as follows:


where, Δt usually is set to 1. Then the fitness at each position is reevaluated. If any fitness is greater than Gbest, then the new position becomes Gbest and the particles are accelerated toward the new point. If the particle`s fitness value is greater than Pbest, then Pbest is replaced by the current position. The flowchart of PSO-PID controller design procedure is shown in Fig. 4. PSO algorithm parameters are set based on trial and error as follows:

No. of particles for each controller = 30
Acceleration constants c1 = c2 = 1.5
Maximum generation = 20

Fig. 4: Flowchart of PSO-PID controller design procedure


The controller transfer function, Gc(s), is:


where, Kp, Ki and Kd are the proportional, integral and derivative gains, respectively. The performance index including Integrated Absolute Error (IAE) is employed in this research. The proposed control criterion is as follows:


where, tf = 10 sec subject to control input constraint-1 < u < 1.

PSO algorithm stages for searching proper parameters of PID controller are:

First, specify the lower and upper bounds of controller parameters and initialize the particles of the population randomly. Each particle, i.e., K (controller parameters) is sent to Simulink® model. Then, the value of performance criterion is calculated iteratively in Matlab® environment. After that, cost function is evaluated for each particle according to this performance criterion. If the cost for local best solution is less than cost of the current global best solution, the global solution is replaced with the local solution. According to Eq. 11, the velocity of each particle K is modified. At the end of each iteration, program checks the stop criterion. If the number of iterations reaches the maximum designated by the user, the latest global best solution is recorded and the algorithm brings to an end.

In order to examine the dynamic behaviors and convergence characteristics of the proposed method, two statistical indexes, namely the mean value (μ) and the standard deviation (σ) of cost values of all individuals during the computation processes, are used (Haupt and Haupt, 1998). The mean value displays the accuracy of the algorithm and the standard deviation measures the convergence speed of the algorithm. The formulas for calculating these values are as follows, respectively:



where, IAEPi is the cost value of the individual and n is the population size.


The lower and upper bounds of the three controller parameters are shown in Table 2. The Simulink® block diagram of RIP system with PID controller is shown in Fig. 5. In order to highlight the advantages of the proposed method, it also implemented GA-PID controller. GA parameters according to the trial and error manner are given as follows:

Population size = 30 CCrossover rate = 0.5
Mutation rate = 0.02 CMaximum generation = 20

The best controller parameters obtained by GA and PSO algorithms are as follows:

GA: Arm controller kP = -4.237, ki = -4.642, kd = -5.329
Pendulum controller kP = 2.349, ki = 21.145, kd = 0.509

PSO: Arm controller kP = 1.615, ki = 2.6103, kd = -0.0393
Pendulum controller kP = 2.027, ki = 11.229, kd = 0.0318

Figure 6 and 7 shows the arm and pendulum angles using PSO and GA methods. Also, Fig. 8 and 9 shows the system velocities.

Table 2: Range of three controller parameters

Fig. 5: Block diagram of RIP system with PID controller

Fig. 6: The arm angle using GA and PSO based PID control

Fig. 7: The pendulum angle with GA and PSO based PID control

Fig. 8: The arm velocity via GA and PSO based PID control

The integral absolute error of system angles are shown in Table 3. As it can be seen, PSO-based controller makes fine responses, indicating the superiority over GA-PID controller.

Furthermore, under the same conditions, we performed several simulations to compare the controllers` convergence characteristics. After each generation, the mean value (μ) and the standard deviation (σ) of the cost values of all individuals are recorded for observing the dynamic convergence behavior of the individuals in population. As seen in simulations in Fig. 10 and 11, though both controllers can obtain stable mean cost value under the same cost function and simulation conditions, the GA-PID controller brings premature convergence such that the cost value and mean value are bigger. Conversely, the PSO-PID controller has better cost value and mean value, showing that it can achieve better accuracy.

Fig. 9: The pendulum velocity via GA and PSO based PID control

Fig. 10: Convergence tendency of mean values of pendulum angles using both methods

Fig. 11: Convergence tendency of standard deviation values of pendulum angles using both methods

Table 3: Integral Absolute Error (IAE) of system angles

Simultaneously, we can also find that the convergence tendency of the standard deviation of cost values in the PSO-PID controller is much faster than the GA-PID controller. This can prove that the PSO method has better convergence efficiency.


In this study, a PSO-based controller for nonlinear model of the rotary inverted pendulum system is presented. Through the simulation results, the proposed controller performs an efficient search for proper PID parameters. This study demonstrates that PSO method can solve searching and tuning the controller parameters more efficiently than GA. The proposed method could be considered as a promising way for nonlinear control systems in general. The topic of our future researches is to utilize other cognitive methods in order to achieve better results for designing controller and improving the performance in real time. Also, implementation of heuristic algorithms for designing adaptive controllers will be our future challenging task. Furthermore, tele-operation control of RIP system using haptic device would be another challenge.


The authors would like to appreciate Mr. Abbas Harifi for his assistance in conducting this research.

1:  Gaing, Z.L., 2004. A particle swarm optimization approach for optimum design of PID controller in AVR system. IEEE Trans. Energy Conver., 19: 384-391.
CrossRef  |  PubMed  |  Direct Link  |  

2:  Haupt, R.L. and S.E. Haupt, 1998. Practical Genetic Algorithms. 2nd Edn. John Wiley and Sons Inc., New York, ISBN: 0-471-18873-5, pp: 123-190.

3:  Kennedy, J. and R. Eberhart, 1995. Particle swarm optimization. Proceedings of the International Conference on Neural Networks, Volume 4, November 27-December 1, 1995, Perth, WA., USA., pp: 1942-1948.

4:  Kwok, D.P., T.P. Leung and F. Sheng, 1993. Genetic algorithms for optimal dynamic control of robot arms. Proceedings of the International Conference on Industrial Electronics, Control and Instrumentation, November 15-19, 1993, San Francisco, CA., pp: 380-385.

5:  Muskinja, N. and B. Tovornik, 2006. Swinging up and stabilization of a real inverted pendulum. IEEE Trans. Ind. Elect., 53: 631-639.
CrossRef  |  

6:  Rahmat-Samii, Y., 2003. Genetic algorithm and particle swarm optimization in engineering electromagnetics. Proceedings of the 17th International Conference on Applied Electromagnetic and Communications, October 1-3, 2003, Dubrovnik, Croatia, pp: 1-5.

7:  Visioli, A., 2001. Tuning of PID controllers with fuzzy logic. IEE Proc. Control Theor. Appl., 148: 1-8.
CrossRef  |  

8:  Yan, Q., 2003. Output tracking of undergraduated rotary inverted pendulum by nonlinear controller. Proceedings of the 42nd IEEE Conference on Decision and Control. December 9-12, 2003, Maui, Hawaii USA., pp: 2395-2400.

9:  Zhou, G. and J. Birdwell, 1994. Fuzzy logic-based PID auto-tuner design using simulated annealing. Proceeding of the IEEE/IFAC Joint Symposium, Computer Aided Control System Design. March 7-9, 1994, Tucson, AZ., USA., pp: 67-72.

©  2021 Science Alert. All Rights Reserved