J. Eng. Technol. Sci. Vol. No. 5, 2020, 745-764 Real Time Optimal Tuning of Quadcopter Attitude Controller Using Particle Swarm Optimization Musa Abdalla1* & Salam Al-Baradie The University of Jordan. Mechanical Enineering. Department. Amman 11942. Jordan *E-mail: musa_abdalla@mechatronix. Highlights: This work highlights a Quadcopter real-time PID controller tuning. Real-time application of the PSO search technique is presented. Effective blended control of fuzzy logic and conventional PID controllers is used. Experimental verification and validation of the method is presented. Abstract. A real-time novel algorithm for proportional, integral and derivative (PID) controller tuning for quadcopters is introduced. The particle swarm optimization (PSO) method is utilized to search the quadcopter solution space to find the best PID controller parameters. A fuzzy logic (FL) controller is used to provide proper velocity reference signals to serve as tracking set points to be achieved by the PID controller. This nested loop design is proposed for stabilizing the quadcopter, where the fuzzy logic controller (FL) is used in the stable loop . outer loo. to control the desired angle, while the PID controller is used for the rate loop . inner loo. Finally, the optimum generated PID parameters were achieved in real time using the PSO search algorithm. The generated parameters were tested successfully using an experimental quadcopter setup at the University of Jordan. Keywords: fuzzy control. PID control. PSO tuning. PID tuning. Introduction The popular unmanned aerial vehicles (UAV), self-propelled aerial vehicles that operate without the presence of a human pilot, are increasingly catching the attention of researchers and engineers. These vehicles are found in many important applications, including for military and surveillance purposes of great importance . The control of the UAVAos attitude, altitude and position poses many difficulties and challenges and it has been the subject of numerous studies . ,5-. Researchers and engineers are overwhelmed by the number of advanced algorithms that have been proposed to address the quadcopter control problem in The nonlinearity of the quadrotor behavior poses major obstacles in synthesizing effective controllers and control algorithms. Proportional, integral and derivative (PID) controllers are among the popular controllers that have been studied due to Received December 20th, 2019. Revised April 23rd, 2020. Accepted for publication September 24th, 2020. Copyright A2020 Published by ITB Institute for Research and Community Services. ISSN: 2337-5779. DOI: 10. 5614/j. Musa Abdalla & Salam Baradie their simple structure, good performance, reliability and effectiveness when tuned properly . A wide range of control systems have been introduced with a classic PID The ubiquitous PID controller was successfully used for achieving attitude stabilization and horizontal position control in several studies . ,19-. Recent studies have revealed the proposal of a multi-loop . inner-loop and outer-loo. control architecture to control quadcopters for specific applications. The outer-loop controllers were designed based on a diversity of controllers while the inner-loop controllers were all implemented using a conventional PID control strategy . This work proposes an optimal tuning method for the ubiquitous PID controller focusing on attitude stabilization using particle swarm optimization (PSO). PSO was used previously in the literature for controller tuning . , where several authors proposed to perform tuning using simulation of a dynamical model and then implemented the results to a physical model of a quadcopter. However, the unmodeled quadcopter dynamics and the diversity of uncertainties in dimensions and physical parameters all combined prevented finding well-tuned parameters. In this work, to overcome these problems the tuning of the PID controller is performed online in a real-time environment using the particle swarm optimization (PSO) search algorithm. This paper follows the following flow of material. Section 2 gives an overview of fuzzy PID controllers, while section 3 introduces the quadcopter controller design and section 4 discusses the theory of the fuzzy logic controllers (FL). Section 5 introduces the particle swarm optimization (PSO) and proposes its use for online FL-PID controller parameter tuning as a research methodology. Section 6 presents the experimental results and their discussion, which is used to verify and validate the online controllerAos tuning technique as applied to a quadcopter to demonstrate its effectiveness. Finally, section 7 highlights the main conclusions of this work. Fuzzy PID Controller Overview PID controllers have been used successfully in the industry for a long time owing to their simple structure and robust performance in a wide range of operating However, lately more demands on performance are placed on these Unfortunately, the PID controllers are linear in nature and they are ill suited for strongly nonlinear systems. This has motivated many researchers to complement the PID controller with FL based controller because FL is typically parameterized using rules and membership functions, which makes it easy to add nonlinearities, logic, and additional input signals to the controllerAos control law. On-Line Optimal Tuning of Quadcopter Attitude Controller 747 The PID controller currently takes many forms: direct action (DA), gain scheduling (GS) and hybrid types of FL-PID controllers. For DA control, the FL controller replaces the PD controller part in the conventional PID structure, while the I-control action stays the same. However, this modification in the PID structure requires providing two measured inputs for the FL controller, as depicted in Figure 1. Several researchers have proven that the two PD systems are equivalent with the addition of providing more intelligence due to FLAos heuristic nature and ability to handle both linear and nonlinear systems . Figure 1 Direct action FL-PID controller implementation. In GS controllers the FL part provides a dynamical mean to adjust the conventional PID controllerAos parameters in relation to the current dynamical system behavior. This adaptation turns out to be very useful in handling nonlinear systems with varying properties, characteristics, uncertainties, etc. Figure 2 illustrates the GS fuzzy based PID controller implementation scheme. In hybrid FL-PID controller designs, the PID controllerAos effective working space is extended by using an FL based controller. However, both controllers utilize the error signal as input. Figure 3 illustrates the implementation of a hybrid FL-PID An intelligent switching scheme that makes a decision on the priority of the controllersAo contributions may be utilized for further enhancement. Musa Abdalla & Salam Baradie Figure 2 Gain scheduling FL-PID controller implementation. Figure 3 Hybrid FL-PID controller implementation. Quadcopter Controller Design Typically, the attitude controller of a quadcopter requires the controlling of angular velocities and the corresponding Euler angles . yaw, roll and pitc. The velocities and angles are measured using an accurate inertial measurement unit (IMU). An FL controller will be used to provide proper velocity reference signals to serve as tracking set points to be achieved by the PID controller. This nested loop design was used in this study for stabilizing the quadcopter, where an FL controller was used for the stable loop . outer loo. to control the desired angle and the PID controller was used for the rate loop . inner loo. Figure 4 depicts the nested control loops that are proposed to stabilize the altitude. The top of the diagram shows a box designating the PSO algorithm that is used online to dynamically adjust the PID parameters searching for optimal parameters. On-Line Optimal Tuning of Quadcopter Attitude Controller 749 Figure 4 Controller strategy for attitude stabilization. Fuzzy Logic Controller (FLC) Since Zadeh first introduced fuzzy set theory and Mamdani applied it to replace operators in control many newly developed FL applications have emerged. All these applications may be categorized into two distinct fields: control and expert Both fields apply inference and approximate reasoning using rule bases with the aid of membership functions over fuzzy logic sets . , . in contrast to classical logic sets . , . In control applications, the two most widely accepted fuzzy linguistic inference tools are the Mamdani and the Takagi-Sugeno methods. This work considered a Mamdani-based FL controller design methodology. The FL controller provides its crisp output . based on crisp input . uzzified internall. by utilizing the inference process via a rule base. Hence, the FL controller design involves designing three stages: fuzzification, rule-base, and Normally the FL controller design is sequential in the fuzzification stage. the membership functions are first selected and partitioned and then the rule base is constructed. finally, the defuzzification stage is Figure 5 summarizes the conventional top/bottom design approach and the main components of the FL controller. The difficulty in designing a FL controller comes from having to capture and cover all the aspects of the systemAos dynamics, which is heavily dependent on the rule base and the selection of the membership functions (MF). The rule base should be constructed in such a way that the rule set spans the solution space. Musa Abdalla & Salam Baradie On the other hand, the designer must choose the type of fuzzification . ingleton or non-singleto. , the number of membership functions, the functional forms of the membership functions . iecewise linear. Gaussian, sigmoida. , the parameters of the membership functions . ixed or tuned during a training procedur. , the conjunction operator . -norm, t-conor. , the implication or inference operator . , the aggregation operator . -norm, t-conor. and the type of defuzzification . entroid, maxima, heigh. This demonstrates the richness and flexibility of fuzzy controllers, but also it reveals the need for some guidelines for their practical design. Figure 5 FL controller structure and conventional design methodology. The FL controller regulates the dynamical system according to a collection set of rules . rule bas. in the form of linguistic IF-THEN rules. For example: IF error . is big and the rate of change of error . ei/d. is small. THEN the controller output . is medium, where: ei and dei/dt are the inputs and ui is the FL controllerAos rule fired output. Also, the big, medium and small are linguistic terms in the membership function . uzzy subset. of universe U of discourse. Traditionally, in the literature these sets of rules are presented in table form instead of as a cascaded IF-THEN statement. Since the quadcopter model being used is symmetric in the x and y directions, the roll and pitch movements present the same dynamic. Therefore, the same controller is capable of controlling both angles. The error in the roll and pitch angle input is divided into five regions in the membership function: negative large (NL), negative small (NS), zero (Z), positive small (PS) and positive large (PL). Also, the rate of change is divided into five regions in the membership function: negative large (NL), negative small (NS), zero (Z), positive small (PS) and positive large (PL). Figure 6 shows the finalized input membership functions. On-Line Optimal Tuning of Quadcopter Attitude Controller 751 Figure 6 Input membership functions. The controller output for the angle reference is divided into five membership functions: negative large (NL), negative small (NS), zero (Z), positive small (PS) and positive large (PL). Figure 7 shows the output membership function. Figure 7 Output membership function. Table 1 lists the used set of rules of knowledge base for the fuzzy inference system for the roll and pitch controllers, while Figure 8 depicts the FL generated control surface. Musa Abdalla & Salam Baradie Table 1 Fuzzy Rules for Attitude Control Figure 8 FL control surface. PID Controller Tuning Using Particle Swarm Optimization The literature shows that PID controllers have been applied successfully to quadrotors with some limitations . ,9,. However, the tuning of the PID controller may present challenges as it has to provide effective quadcopter dynamical behavior around the balance point. Several researchers have successfully used particle swarm optimization (PSO) based techniques to tune the PID controller parameters during the design stage or as an offline experimental interested readers can consult the following recent references . To achieve the desired performance in practice, an automated search technique that is based on PSO needs to be implemented for tuning the PID controllerAos On-Line Optimal Tuning of Quadcopter Attitude Controller 753 gains . The PSO search technique was first introduced by Kennedy and Eberhart in 1995, which was based on fish school and bird flock behaviors. Particle swarm optimization aims to find the minimum cost function in the search space according to a few simple dynamical formulas. A good metaphor for the PSO algorithm is to imagine a swarm of bees in a field searching for flowers. The objective of the swarm is to find the location with the most flowers. Basically, each bee conducts a random search and memorizes the densest location of flowers it encountered. Also, by assuming that all the individual bees may share the information about their best findings of locations, each bee will be guided by its own personal discovery and by the best location reported by the Consequently, by altering the direction of their trajectory to fly somewhere between the two locations, the bees will explore the fields by overflying locations with the highest concentrations and eventually will be drawn to the densest flower location . The following definitions and notes are needed to realize the PSO algorithm: A number n = 3 of particles is used in PSO. Every particle is identified by: current position Pi, velocity vi and Pi_Best in the searched solution space. All particles share their information about their best findings of locations. The individual particle best position Pi corresponds to its minimum evaluated cost function J. throughout its search journey. The global best position is the best of all the best particle positions. PGlobal. The solution space is explored by driving the particles to move according to their best findings and also influenced by the best locations reported by the other particles. The mathematical representation of the swarm iterative updates for all particles, n, is given by the following equations: A A A A A t A if J PAi ABest At A C J PAi ABest At A 1A EE E Ai A Best PA i A Best A t A 1A A E E PAi A Best A t A 1A if J PAi A Best A t A A J PAi A Best A t A 1A E A A A AP PGlobal A t A A min J PA i A Best A t A . Global A t A AA Figure 9 illustrates how the particles are moving and sweeping the solution space intelligently and it also summarizes the used pseudo-algorithm. Each particle in the swarm tracks its position by means of two vectors one accelerates the particle in the direction of its own best and another towards the global best for the whole swarm . est of the bes. The advancement of the particles in the solution space is controlled by a simple kinematic equation: Musa Abdalla & Salam Baradie Pi At A 1A A Pi At A A AEt A i At A . where it is the advancement in time . and Pi is the current location of the particle . the solutio. On the other hand, the particlesAo velocities are updated during the search with the following formula: A i At A 1A A AA i At A A c 1rand A A EE PAi ABest At A A PAi A At A EE A E c 2rand A A EE PAi AGlobal At A A PA i A At A EE where w is a scalar that generates some form of momentum for the particle taken from the previous iteration. The value that was used in this study was changed dynamically as well . n an adaptive fashio. Figure 9 Particle movement in solution space. The constants c1 and c2 represent the emphasis toward the particleAos best or toward the global swarmAos best, weighted by random terms. Typical values from the literature for these weights are within the interval . The local best is the best value of the solution attained by the particles and the global best is the best value of the solution attained by the whole swarm. The stochastic behavior of the PSO algorithm is realized by giving two random sequences. On-Line Optimal Tuning of Quadcopter Attitude Controller 755 Figure 10 PID tuning process. In this implementation, the objective is to find the minimum error in the fitness function, where the fitness of the particle is evaluated based on the systemAos step It is estimated using the sum square error (SSE). This will also act as a stopping criterion for the algorithm in conjunction with the maximum number of iterations allowed, i. once the iteration reaches the set maximum value the quadcopter stops the calibration process and the best result obtained is stored for further processing. The complete controllerAos tuning process is summarized and depicted in Figure 10 as a flowchart. This algorithm will be executed in real time as mentioned above. This poses some challenges but the produced results are worth the effort of getting them. Musa Abdalla & Salam Baradie Experimental Verification and Validation An in-house built quadcopter and testing platform was used to verify and validate the effectiveness of the proposed real-time PSO algorithm for tuning the PID controller parameters. Figures 11 and 12 depict an image of the quadcopter and the corresponding block diagram of the main units. The control algorithms were implemented on an STM32F4 - ARM Cortex-M4 board, where the board used different methods and protocols to communicate with the remaining hardware Each quadcopter motor was powered and controlled by its own electronic speed controller (ESC) that provided a 3-phase alternating current. The ESCs keep each motor rotating at an rpm value determined by a pulse width they receive from the MCU board. An inertial magneto unit (IMU) equipped with magnetometers, gyroscopes and accelerometers was used to provide all the needed measurements . filter algorithms, bias estimation and magnetometer calibratio. to operate the quadcopter. The IMU ran at a frequency of 400 Hz and the control loop at a rate of 250 Hz, which is the frequency of main loop. Figure 11 Quadcopter testing platform. Initially, the parameters i . , . , and O . were all set to zero Since the model used is symmetric in the x and y directions, the same controller is capable of controlling both angles. The quadcopter is started with a On-Line Optimal Tuning of Quadcopter Attitude Controller 757 stock PID value and when the PSO is activated by the user, the initialization of the PSO will start to set the maximum iteration fixed to 25 with three swarm After that the PSO starts updating the particle position and velocity every 16 seconds for pitch angle with a fixed desired angle . ero degree. After the iteration reaches the maximum number of iterations, the stop criterion is satisfied and the best gain is stored. Performance is satisfied around a constant set point . ero degree. , however, the user can select another state to optimize it. After achieving the optimized gain, the user can select the optimization under a variable desired angle, where the userAos desired value is changed every 1. seconds to find the optimal gains, which should improve the stabilization of the Figure 12 Quadcopter testing platform. Figure 13 depicts the tuned PID controller parameters and the corresponding cost The quadcopter roll controller performance was evaluated for a period of 16 seconds. The initial controller gains were taken as . p= 0. 85, ki = 0. 04, with fix kd = . After releasing 25 swarms searching the solution space, the algorithm reached the optimal gain, marked with white points in the top area, while the initial controller gain in the bottom area was taken from the previous global best swarm and the integration gain was fixed. The . p and k. was optimized after reaching the 25th iteration. the optimized gain is marked with white points in the bottom area. The quadcopter yaw controller performance was also evaluated for a period of 16 seconds with the initial controller gainstaken as . p = 1. 1, ki = After 25 swarms the algorithm reached the optimal gain, marked by white points in the surface, as shown in Figure 14. Musa Abdalla & Salam Baradie Finally, the quadrotor controller performance was evaluated for a period of 2. seconds while varying the desired angle. The initial controller . hown in blue in Figure . performed poorly but was stable. In contrast, the optimized controller . hown in re. showed an optimized, smooth, and fast response. The other controller parameters that were evaluated are shown in gray. Figure 13 Quadcopter iterating tuning using real-time PSO. On-Line Optimal Tuning of Quadcopter Attitude Controller 759 Figure 14 Quadcopter roll iterating tuning using real-time PSO. Figure 15 Quadcopter step responses for all swarms for pitch, yaw and roll. Musa Abdalla & Salam Baradie Figure 16 depicts a series of user-defined steps and the corresponding quadcopter angle responses that resulted from using the optimized real-time tuning using PSO. The figure shows the roll angle command response of the quadcopter in carrying out the user inputs. Such good performance would not be possible without real-time tuning. The figure also depicts the quadcopter roll angle response during a ten-second disturbance period generated by artificial wind produced by a fan. The curve illustrates how the quadcopter oscillated and represents the effectiveness of the tuned PID controller. The controller was able to compensate for the disturbance effect and preserved quadcopter stability. Figure 16 Roll, pitch and yaw angle step responses. Conclusions In this paper, a novel proportional, integral and derivative (PID) controller realtime tuning algorithm based on particle swarm optimization (PSO) search strategy was presented. The tuning strategy was tested on a laboratory experimental quadcopter platform with a fuzzy logic controller on board to On-Line Optimal Tuning of Quadcopter Attitude Controller 761 provide proper velocity reference signals to serve as tracking set points to be achieved by the PID controller. Optimum PID working-parameters were successfully produced in real time by the PSO algorithm. The quadcopter response enhancement due to utilizing the new tuned parameters was clear. This technique seems to be insensitive to errors in the mathematics or modeling errors of the system in contrast to offline tuning strategies but is a little riskier. References