## 3 PID Controller  
Due to the increasing number of applications and complexity of the quadcopter on a daily basis, approved control algorithms also need to progress so that they can deliver better performance and boost flexibility [38]. In the past, modest linear control methods were accepted, due to their lower computational requirements and stable behavior. However, with advanced modeling methods and faster on-board computational power, a wide-range of nonlinear methods have been used to run in real time. The proposed nonlinear control methodologies have grown rapidly, and they provide high performance, making the quadcopter more powerful [39; 40]. In this paper we explore one of the well-recognized controllers in industry, called the PID controller [34; 41]. The PID controller has many merits, such as reducing the downtime, rise time, and peak error, and smoothing the movement of the output in addition to the overshoot of the system. Meanwhile, this type of controller has many difficulties in adjusting its parameters. For example, its low ability to tune P, I and D parameters may result in poor performance, slow control and, in some cases, system instability. Consequently, many types of tuning methods for the PID controller demand considerable attention from the operator to identify the optimal set of values for those parameters to reach a reasonable gain. One of the conventional methods widely used to fine-tune the parameters of the PID controller is the Zeigler-Nichols method [12]. However, in a few past cases, this method did not produce sensible results in reducing the time response of the signal as reported in the literature. Based on the developed mathematical model for the quadcopter, the four inputs of the PID controller of the quadcopter's motors were tuned to control the altitude, attitude, heading and position of the quadrotor in space. In this work, GAs, PSO and CSA are presented to optimize the gain of the PID controller in order to improve the system's dynamic response. \[P=K_{p}\times e(t) \tag{21}\]  
\[I=K_{i}\times\int_{0}^{t}e(t) \tag{22}\]  
\[D=K_{d}\times\frac{de(t)}{dt} \tag{23}\]  
The control function can be expressed mathematically as given in Equation (24). \[u(t)=K_{p}e(t)+K_{i}\int_{0}^{t}e(t)+K_{d}\frac{de(t)}{dt} \tag{24}\]  
The transfer function of the PID controller is defined as presented in Equation (25). \[U(S)=K_{p}+K_{i}\times\frac{1}{s}+K_{d}\times s \tag{25}\]  
The transfer function is capable of capturing the dynamics of the quadcopter's movements [42]. Furthermore, the transfer function is utilized to demonstrate the effectiveness of the presented method. The transfer functions for the inputs of the PID controller, \(\phi\), \(\theta\), \(\psi\) and \(z\) are defined in Equations (26)-(29), respectively [42]. \[G(s) = \frac{65\times s+4560}{s^{3}+109\times s^{2}+1023\times s+2935} \tag{26}\] \[G(s) = \frac{56.95\times s+4391}{s^{3}+105\times s^{2}+870\times s+4430}\] (27) \[G(s) = \frac{105}{s^{2}+413\times s}\] (28) \[G(s) = \frac{1.63}{s^{2}+5\times s} \tag{29}\]  
The PID controller was designed using closed-loop feedback control in order to stabilize the closed-loop system based on pre-defined equality characteristics. The PID controller can be described by a discrete transfer function as that given in Equation (30). \[U(s)=\frac{K_{d}\times s^{2}+K_{p}\times s+K_{i}}{s} \tag{30}\]  
At each generation, the error is recomputed for the closed-loop system, where the resulting error is corrected by the PID controller and passed as inputs to the motors of the quadcopter. In short, flight control systems for UAVs are mostly carried out using PID control systems. A PID controller is typically used to stabilize the rotational and translational motion of an UAV quadrotor system and enforce it to follow a specific path with minimum energy and error. It is evident that a fast response speed and high control capacity can be obtained by implementing adequate PID parameters.