OPTIMIZATION OF PID PARAMETERS BASED ON PARTICLE SWARM OPTIMIZATION FOR BALL AND BEAM SYSTEM PARAMETERS ON SWARM OPTIMIZATION FOR BALL AND BEAM SYSTEM.”

: This paper introduces the application of an optimization technique, known as Particle Swarm Optimization (PSO) algorithm to the problem of tuning the Proportional-Integral-Derivative (PID) controller for a linearized ball and beam control system. After describing the basic principles of the Particle Swarm Optimization, the proposed method concentrates on finding the optimal solution of PID controller in the cascade control loop of the Ball and Beam Control System. Ball and Beam control system tends to balance a ball on a particular position on the beam as defined by the user. The efficiency of Particle Swarm Optimization algorithm for tuning the controller will be compared with a classical method, Trial and Error method. The comparison is based on the time response performance. The two tuning methods have been developed by simulation study using Matlab\ m-file software. The evaluations show that Evolutionary method Particle Swarm Optimization (PSO) algorithm gives a much better response than trial and error method .


Introduction
The ball and beam system is a simple mechanical system which usually difficult to control [1]. It is one of the most popular and widely used laboratory models for control systems and has always remained one of the favorite introductory control system problems for control engineers [2]. The ball and beam system is connected to real control problem such as horizontally stabilizing an airplane during landing and in turbulent airflow [3]. The ball and beam system is very easy to understand, and many control techniques can be studied on this system to cover many classical control design methods. It consists of rigid beam, which is free to rotate in the vertical plane at the pivot, with a solid ball rolling along the beam [4]. As the name implies, in this system, a ball is placed on a beam and the control system should tend to balance the ball at particular position on the beam as prescribed by the user. The ball and beam system can be categorized into two configurations. The first configuration is shown in figure 1, which illustrates that the beam is supported in the middle, and rotates against its central axis. Most ball and beam systems use this configuration. This type of configuration is normally called as 'Ball and Beam Balancer'. This type has the advantage of easiness of building and the simplicity of the mathematical model. The second configuration is shown in figure 2. In this type, the beam is supported on both ends by two level arms. One of the level arms acts as the pivot, and the other is coupled to motor output gear. The disadvantage is that more consideration of the mechanical parts, which meant adding some difficulties in deriving a mathematical model. This type of configuration is called 'Ball and Beam Module'. The 'Quanser' ball and beam system uses this configuration for its commercial product. The advantage of this system is that relatively small motor can be used due to the existing of gearbox. This type of configuration will be used in this paper. The ball and beam system is an open loop and important to point out that it is unstable and nonlinear since the ball position changes with acceleration without limit for a fixed beam angle [1]. The control problem can be approximated by linearized the model, hence the linear feedback control such as PID control can be applied and the stability analysis can be determined based on linear state-space model or transfer function. In this paper, the PID controller will be used to stabilize a ball and beam system at its equilibrium position. However, tuning a PID controller to acquire the most optimum results is a tricky task and various methods have been proposed to search the parameters of PID controllers in the past to do so. The classical PID tuning methods include: Ziegler Nichol's method [5], ITAE equations method [6], Gain and phase margin tuning method [7], SISO tool and so on [8]. Furthermore, many unconventional techniques have been developed over the past few decades, which have proven to be very fruitful in control systems.
The unconventional techniques have been given much attention by many researchers because of their ability to find global optimal solutions. Evolutionary algorithm and Fuzzy logic [9] are examples of such unconventional methods. Particle Swarm Optimization (PSO) algorithm is one of such evolutionary algorithm. The PSO is recently proposed heuristic search method for optimization of continuous nonlinear functions, which can be used in tuning PID controllers [2], inspired by the swarm methodology. The method was derived through simulation of simplified social models such as bird flocking, fish schooling and swarming theory in particular. Kennedy and Eberhart invented particle swarm optimization in 1990's while trying to simulate the choreographed, graceful motions of swarms of birds. Particle swarm optimization has two roots. One of them is to tie to artificial life. It is also related to evolutionary computation such as genetic algorithms and evolutionary programming. The ability of flocks of birds, schools of fish and herds of animals to adept to their environment, to avoid predators and to fined rich sources of foods by implementing an information sharing approach intrigued the inventors of the methodology [10]. There has been much attention in terms of implementation of PSO in control theory. Particle swarm optimization has successfully been applied to a wide variety of problems such as neural networks [11], structural optimization [12], share topology optimization [13] and fuzzy systems [14].

Mathematical Modeling Materials and Methods
The mathematical description of this system consists of two separated systems, the first one is the DC servomotor, which is an electromechanical system that receives electrical signal from controller and produces an output as a rotational displacement (angle). The second one is the ball and beam model, which is a mechanical system that receives rotational displacement (angle) from the motor and converts it into a linear displacement.

Motor Model
The position of a DC motor is observed to have a transfer function of: Based on the motor parameters in [15], motor model can be written as follow:

Ball and Beam Model
As illustrated in figure 2, a ball is placed on a beam that free to roll along the length of the beam at horizontal plane. A lever arm is attached to the beam at one end and a servo gear at the other. The servo gear turns by an angle ( ), and the lever changes the angle of the beam by ( ). The force that accelerates the ball as it rolls on the beam comes from the component of gravity that acts parallel to the beam. The ball actually accelerates along the beam by rolling, but we can simplify the derivation by assuming that the ball is sliding without friction along the beam. The mathematical modeling of ball and beam system consists of DC servomotor dynamic, alpha theta relation, and ball on the beam dynamic. The dynamic equation of the ball on the beam has been described by [4] using Newton second law as given in equation (3) Where: : Force due to transnational motion : Force due to rotational motion : Mass of ball : Gravitational acceleration : Beam angle coordinate ̈: Acceleration of the ball position The derivation of equation (3) is based on diagram depicted in figure 3. Now, equation (3) can be linearized to obtain a transfer function of the ball and beam system, for small angle, sin( ) = . Therefore, equation (3) becomes: By taking the Laplace transform of equation (4), we find

Particle Swarm Optimization (Pso) Algorithm
Particle Swarm Optimization algorithm, as depicted in the flowchart in figure 4, is one of such evolutionary algorithm, which can be, used in tuning the PID controllers. The algorithm simulates the movement of birds in flocks. The algorithm works on the scenario of birds randomly searching for food. It begins with a swarm of birds/particles being initialized at random positions in the problem space, each particle in the swarm represents a solution to the problem, each of the particles is treated as a point in N-dimensional space which adjusts its flying according to its own flying experience as well as the flying experience of other particles. Each bird keeps track of its coordinates in the problem space. A record is also kept of the least distance (fitness value) from the food achieved by each individual bird so far, called pbest (personal best). The minimum value of pbest in the swarm is called gbest (global best), that is, the minimum distance achieved by any of the birds in the swarm so far [2]. In a physical n-dimensional search space, the velocity and the position of particle (i) are represented as the vectors = ( 1 , … , ) and = ( 1 , … , ) in the PSO algorithm. Therefore, the best position of particles and their neighbours best position are = ( 1 , … , ) and = ( 1 , … , ).
In each iteration, the velocity of each bird is updated and added to the current coordinates of the respective birds.
The velocity is governed by three factors which are inertia ( ), cognitive influence (pbest) and social influence (gbest). The directions of cognitive and social influences depend on the direction vector of the bird's position from pbest and gbest respectively. Both these influences are updated each iteration and added to inertia, to get the new velocity. Furthermore, randomness is maintained in the system by weighing the influences with random numbers between (0) and (1), called weight factors ( 1 2 ) and the inertia with another random number in the same range, called inertia factor (w) [2].
Where; ( ) is the velocity of particle (i) at iteration (k), ( ) is the position of particle (i) at iteration (k), ( ) is the inertia weight, ( 1 , 2 ) is the weight factors, ( 1, 2) denotes random numbers between 0 and 1, ( ) is the best position of particle (i) until iteration (k), and best position of the group until iteration (k) is denoted as ( ). Figure 5 shows the trajectory of the particle in the swarm.

PID Controller Design
It was found that the overall open loop transfer function of the system is a fourth order system. However, it is difficult to design a controller to control a third order and higher order system. Therefore, to make the controller design become easier and realizable, the whole system is divided into two feedback loops as shown in figure 6.  The design strategy is to first stabilize the inner loop followed by the outer loop. The purpose of the inner loop is to control the motor angle position. Inner controller should be designed so that the motor angle tracks the reference signal. The outer loop uses the inner feedback loop to control the ball position. Therefore, the inner loop definitely must be designed before the outer loop.

PID Tuning with Particle Swarm Optimization Algorithm
Before implementing the Particle Swarm Optimization technique on a problem, one has to consider first the number of variables to be tuned in order to optimize the solution to the problem. The number of dimensions of the matrices in the algorithm must equal the number of variables in the system. In addition, certain parameters need to be defined. Selection of these parameters decides largely the ability of global minimization. The maximum velocity affects the ability of escaping from local optimization and refining global optimization. The size of swarm balances the requirement of global optimization and computational cost [2]. Initializing the values of the parameters is as per table 1. Table 2 shows the upper and lower limits set for the PID controller gains. The particles are initialized at random positions within these limits and are not allowed to trespass during the algorithm.  Lower bound 0 0 0 Upper bound 10 10 10 The cost function represents the function that measures the performance of the system. In our case, the cost function for the PSO algorithm is defined as a function of closed loop system performance. The following cost function is proposed and applied. Where (Mp) and (ts) are peak-overshoot and settling time respectively. Alternatively, any performance integral can also be used as cost function e.g. IAE (Integral Absolute Error), ISE (Integral Squared Error), MSE (Mean Square Error) ITAE (Integral Time Absolute Error) [2]. Table 3 shows the optimal PID parameters in the inner and the outer loops obtained using PSO algorithm. Figure 7 shows the step response of the system tuned by PSO algorithm.

PID Tuning with Trial and Error Method
Trial and error tuning method is used to determine the parameters of a PID controller by inspection the dynamic behaviour of the controlled process output. It is very important to understand the effects of the tuning parameters on the behaviour of the process output for successful trial and error tuning [16]. By using the effect of increasing the PID parameters on a closed loop system in the table 1, we change the PID parameters until we find the good response.  Table 4 shows some of trials for finding the parameters of the PID controller. Figure 8 shows the step response of the system tuned by trial and error. It is clear that the best PID parameters are obtained by "Trial 5" as shown in figure 8.   Table 5 and figure 9 summarize the performances of the system obtained with PID controller under two different tuning techniques. It can be seen that the PSO-tuned method had better performance for ball and beam system compared to the conventional tuning method, which was trial and error method. It is clear that the PSO method gives promising results better than the Trial and Error method; the PSO gave the settling time of 3.7 seconds and rising time of 0.209 seconds compared to Trial and Error, which gave, 5.88 seconds and 0.235 seconds respectively. The transient response has 3.67 % overshoot for PSO method and 14.6 % overshoot for Trial and Error method. For steady state error (ess) Trial and Error and PSO, methods are zero.

Conclusion
In this paper, the mathematical model for a ball and beam system has been derived successfully. The system consists of three main components which are servomotor model, angle conversion gain, and ball on the beam dynamic equation. Both servomotor and ball beam dynamics have a second order transfer function. It is quite tedious to design the fourth order system, thus for conventional method, two controllers have been implemented to control those second order components. The Particle Swarm Optimization (PSO) algorithm has been implemented successfully as a useful tool for optimizing the parameters of the PID controller. The efficiency of Particle Swarm Optimization algorithm for tuning the parameters of the PID controller has been compared with a classic method, Trial and Error method. From the analysis, PID-tuned by PSO shown a better performance and successfully reduce the values of Ts, Tr, OS and SSE than conventional method. The dynamic performance of the system controlled by Trial and Error method is relatively low and time consuming in comparison to the Particle Swarm Optimization method. The PSO method gives best performance and smooth behavior.