Tuning PID attitude stabilization of a quadrotor using particle swarm optimization ( experimental )

Proportional, Integral and Derivative (PID) controllers are the most popular type of controller used in industrial applications because of their notable simplicity and effective implementation. However, manual tuning of these controllers is tedious and often leads to poor performance. The conventional Ziegler-Nichols (Z-N) method of PID tuning was done experimentally enables easy identification stable PID parameters in a short time, but is accompanied by overshoot, high steady-state error, and large rise time. Therefore, in this study, the modern heuristics approach of Particle Swarm Optimization (PSO) was employed to enhance the capabilities of the conventional Z-N technique. PSO with the constriction coefficient method experimentally demonstrated the ability to efficiently and effectively identify optimal PID controller parameters for attitude stabilization of a quadrotor.


Introduction
The most popular of Unmanned Arial Vehicles is the quadrotor.Because of its ability to perform agile manoeuvres, take-off and land vertically, and hover, it is an ideal choice for search and surveillance, rescue, monitoring, military, and agriculture applications in both outdoor and indoor environments.
However, it is difficult to model [1,2] complex and suitable quadrotor control systems.Many control methods, such as fractional sliding mode [3], backstepping [4], nonlinear proportional-integral-derivative (PID) [5], sliding model controllers [6], and fuzzy PID [7], have been studied.The simplest control method among these is the PID controller [8] because of its low program complexity, low processing speed, and small program size, occupying little memory.Therefore, the PID can be implemented in a low-cost microcontroller.
In PID control design, the parameters of the controllers are tuned manually or by using the tuning rules found in the linear control-based literature, such as Zieglar-Nichols (Z-N) tuning [9,10].Unfortunately, the manual tuning method has limitations of being time consuming and very tedious.While the conventional Z-N method has been very useful and helpful in our research in terms of practicality, it is criticized by many other researchers.
After developing a quadrotor, we were met with the problem of how to choose PID gains in order for our quadrotor to achieve stability.The fastest method with the least required effort to experimentally select the appropriate PID gains was the Z-N tuning.Within a few minutes of implementation we could obtain the PID gain values required to stabilize the quadrotor.With respect to time and effort, the Z-N method was the most advantageous.However, regarding robustness, overshoot, steady-state error, and rise time, the Z-N method falls short of the necessary standards.To overcome this, we instead employed a modern heuristics approach [11][12][13][14], specifically particle swarm optimization (PSO) with the constriction coefficient method unlike in [15] they use the basic PSO.PSO used to determine the optimal PID gains for attitude stabilization of the quadrotor experimentally counterpart in [15] they applied for position control and is very clear the optimization of the attitude stabilisation has more priority than position control optimization for quadrotor.This stands in contrast with many other research efforts whose results come only from simulations [16][17][18].The second advantage of the Z-N method found in this study is that it produces PID gains that can be put into intervals, such that the PSO search within an interval by determining the sum of the Integral of Square Error (ISE) and the maximum of the overshoot as a multi-objective function [19] or a fitness function.Using this process, we found the optimized PID controller via simulation (offline) and validated the results experimentally.The results demonstrated the effectiveness of PSO applied to PID controllers for attitude stabilization of the quadrotor.
This paper is organized as follows: Section 2 provides a general description and presents a dynamical model of a quadrotor.Section 3 gives an overview of the Z-N method.Section 4 gives an overview of PSO and presents the PID controller design method incorporating PSO using a simulation to achieve stabilization of the quadrotor.Section 5 shows the simulation and experimental results.Section 6 provides the conclusions of the study.

The quadrotor model
A quadrotor has four propellers mounted on the end of two perpendicular arms and is actuated by four brushless DC motors.A basic configuration of a quadrotor [20] is shown in Figure 1.
Each rotor pair of the same arm rotates in the same direction; one pair rotates clockwise, while the other rotates counter clockwise.The quadrotor moves by adjusting the angular velocity of each rotor.We used the simplified attitude dynamical model of a quadrotor same in [1] given by: where f i are the thrust forces generated by four motors, l is the length of the quad-rotor arm, and s h , s u s W are the generated torques of roll and pitch and yaw plans.s m1 , s m2 , s m3 , s m4 are induced moments from there propeller rotation [20], inertial of quadrotor are I x , I y , and I z calculated by SOLIDWORKS, the trust and drag coefficients data I found them in this technical data on this website [23] (see Table 1).
The dynamic thrust of the motor-driven propeller was identified experimentally as described in references [2,21] also the trust coefficient calculated in same experiment is approximate to trust coefficient in [23] (see Table 1).The frequency response of the propeller (GemFan 5030) speed with respect to the duty ratio of the motor speed controller (see Table 2) showed that dynamic thrust and duty ratio could be modelled as a first-order transfer function [21].
Our platform was based on a 250 mm (QAV250) fiberglass frame similar to experiment in this work [24].The onboard autopilot software was developed in home, and the electronic components included an Arduino Due, an IMU, and an electronic speed controller the real photo of quadrotor in Figure 2. The front adds part because Arduino Duo is long and the black thing below it is just polyster to reduce noise affected on Ultrasonic sensor.Since the software was mostly custom-developed, it could easily interface with any additional sensors and modify the control laws of the PID control strategy [17] for attitude stabilization in Figure 3.

Tuning the PID controller using the Ziegler-Nichols method
The Ziegler and Nichols proposed rules [9,10] for determining the values of proportional gain K p , integral time K i , and derivative time K d .The determination of such parameters of PID controllers or tuning of PID controllers can be achieved on-site using experiments involving the quadrotor.There are two methods within the Z-N tuning approach.The first method of Z-N tuning is based on the open-loop step response of the system.
The second method of Z-N tuning, used in this paper, is a closed-loop tuning method that requires finding the ultimate gain and period.This can be achieved by adjusting the controller gain (K c ) until the system undergoes sustained oscillations (at the ultimate gain or critical gain), while maintaining the integral time constant (T i ) at infinity and the derivative time constant (T d ) at zero.This paper used the second method as shown in Table 3 [9,10].
After completing development of the quadrotor, we had to determine the PID parameters efficiently, and with little theoretical basis since initially, the quadrotor dynamics were not precisely determined.Therefore, the Z-N method was applied as the first step towards stabilizing the quadrotor because it enabled experiments to be used for real-time acquisition of responses that could be plotted to determine PID parameters.Our quadrotor was symmetric, so therefore we only applied this method to the pitch component of the PID controller.
To verify the performance we used the integral of square error (ISE) as comparison criteria, defined as follows: Therefore, for PSO-PID tuning, this criteria (2) was used as the objective function to seek a set of PID gains such that the control system met the minimum performance criteria.There are a lot of heuristic optimization methods, and one of the most technical of these is PSO, first created by Kennedy and Eberhart in 1995 [13].It is based on Swarm Intelligence methods, and aims to identify the optimal solution by imitating the movement of particles in a swarm similar to fish schooling or birds flocking.
There are several algorithms used for PSO [11][12][13].In this work, the integral of square error (ISE) and maximum overshoot of error were fitness functions (multi-objective functions), and the constriction coefficient [13,22] method was selected because method was selected because never used before with our case.The swarm is guaranteed to converge [13] and with simplest control of the convergence speed, whereby the speed in (3) and position in (4) of each particle changed according the following: where: PSO was used to tune PID gains (K p , K i , and K d ) offline using the model given in equation (1).PSO first produced an initial swarm of particles in the search space.Each particle    represented a solution for PID gains, where their values were set within the range of the produced Z-N gains.Fifteen and 20 were chosen as the number of particles within the swarm and iterations within the search, respectively.A good set of PID controller gains yielded a good system response, and resulted in minimization of the performance criteria in listed in equation (2).The general strategy of the optimization problems is represented in Figure 4.

Results and discussion
In this section we describe the simulation and experimental results for three sets of PID gains.The first PID gains were obtained using the Z-N method.The second PID gains were obtained using PSO, for which the objective function was equal to sum of the integral square of error and maximum of overshoot.The third PID gains were also obtained using the PSO method, but the objective function was replaced with the Integral Square of Error function.

Z-N PID tuning
This First, we employed Z-N tuning experimentally to determine PID controller gains.Then, we varied the Z-N gain (K c ) until an oscillation appeared in our experiment as shown in Figure 5.
Figure 6 shows the pitch angle error when the Z-N gain was varied.Here, a decrease in error could be observed as K c increased, until oscillation occurred.Based on the Z-N method, the critical gain is depicted in the black rectangular region in Figure 6 and its corresponding value is shown in Figure 5 (K c = 40).A magnified rendition of the black rectangle shown in Figure 6 was used to calculate the critical period (P c = 0.2 s), as shown in Figure 7.   Using the second Z-N method in Table 1, we found that:

PSO -PID gains optimization
We established intervals for the resulting PID gains achieved using the Z-N method, as shown in Table 4.The PSO method then searched for the optimal PID gains depending on the objective function.The search for the optimal PID was conducted offline, meaning that all calculations were performed via simulation, for which the determined gains were verified both using the simulation and experimentally.We used two different objective functions: the first was the sum of the maximum of the overshoot and the Integral Square of Error (ISE), and the second was just the Integral Square of Error.The PSO needed to determine number of particles and iterative number in order to calculate the PID gains.In our case the number, of particles was set to 15 and the iterative number was set to 20. Figure 8 shows changes in the particles' positions during the search for optimized PID gains according to the first objective function.The blue points represent the swarms, the black points represent the local best particles, and the red points represent the global best particles.
The calculated PID gains obtained using two objective functions and the Z-N method, are summarized in Table 5.
The PID gains shown in Table 5, were tested in our simulation model, and the step responses for the pitch angles are shown in Figure 9.The comparative simulation results are given in Table 6, based on ISE, overshoot, and rise time.
The objective function of PSO2 was only the Integral Square of Error.From Table 6, it can be seen that the rise time was the same for PID Z-N and PSO2, given the existing overshoot, but with lower ISE in the latter.It is very clear that the rise time and overshoot in the PID Z-N case was ameliorated by the PSO2.However, when we added the maximum of the overshoot as a second criterion to the objective function, it resulted in a lower overshoot, but with a smaller rise in ISE.
The PID controllers in Table 5, were tested experimentally, and the plots of the pitch error angle in steady-state for PID Z-N, PID PSO1, and PID PSO2 are shown in Figures 10, 12, and 14, respectively.The pulse responses are shown in Figures 11,13,and 15, respectively and the comparative results are listed in Table 7, based on ISE for steady-state and pulse response conditions.
The simulation results of the Z-N tuned PID show that the pitch angle error response produced high ISE, high overshoot, and low rise time, but a better PID performance was obtained

Conclusion
This research paper presents an optimized PID controller for attitude stabilization of a quadrotor using PSO the constriction coefficient method was never used before for attitude control of a quadrotor.The main advantage of optimization process that find the optimal solution with scientific method not as manual finding depending on the luck, and let the user of it more confidence with their results.The proposed method was tested both using a MATLAB simulation and experimentally.The simulation and experimental results were also compared with a conventional Z-N tuning PID controller and with two different objective functions that the PSO depends on to search the optimal PID controller.The efficiency of PSO was verified through experimental results.

Figure 1 .
Figure 1.A basic configuration of a quadrotor.

c 1
and c 2 are the acceleration coefficients, and r 1 and r 2 are random values in [0, 1].

Figure 5 .
Figure 5. Critical gain (K c ) variation in real time.

Table 4 .
Limited PSO search interval based on Z-N derived gains.

Figure 6 .
Figure 6.Pitch error angle when K c was varied in real time.

Figure 7 .
Figure 7. Magnified black rectangle to calculate critical period P c in real time.

Figure 8 .
Figure 8. Change in particles' position during the search for the optimal PID controller gains.

Figure 9 .
Figure 9. Pitch angles step responses for the three PID gains in simulation.

Figure 14 .
Figure 14.Pitch error angle in steady-state for PSO2.

Figure 12 .
Figure 12.Pitch error angle in steady-state for PID PSO1.

Figure 10 .
Figure 10.Pitch error angle in steady-state for Z-N PID.

Figure 11 .
Figure 11.Pitch error angle for Z-N PID.

Figure 16 .
Figure 16.Error angle of the roll, pitch and yaw implemented together in experiment.

Table 2 .
Some experiment results for trust calculation.

Table 3 .
Ziegler-Nichols tuning rule based on critical gain K c and critical period P c .

Table 5 .
Summary of PID gains obtained by Z-N tuning and PSO.

Table 6 .
Comparison of the Z-N and PSO gains for pitch angle stabilization.
6 M.A. Khodja et al.: Int.J. Simul.Multisci.Des.Optim.2017,8,A8 by applying PSO.Different objective functions provided different PID controller gains.In case when the overshoot was taken into consideration by the objective function, the pitch error response produced the lowest overshoot with a low ISE, but the highest rise time.In the case when the overshoot was not taken into consideration by the objective function, the response produced the lowest ISE with an existing overshoot.The experimental results in Table7and Figures 10-14 depict the corresponding simulation analyses.However, the Integral Square of Error of PSO1 was lower than PSO2 because the response of the latter had greater overshoot than PSO1.In actual tests, the quadrotor is a noisy system and we cannot eliminate the gyroscopic torque and Coriolis-centripetal force that were neglected in the simulation results.For roll and the yaw