## 3 Hierarchical Controllers for Trajectory Tracking
### Genetic Algorithm-Based Hierarchical Controller (GAHC)  
As mentioned above and as shown in Figure 2, the PD/PID parameters in the inner loop for attitude stabilization and the PD/PID gains for the outer loop are optimized using the GA. GAs use a direct analogy of natural evolution. They work with a population of \"individuals\"; each one representing a potential solution to a given issue. Each individual is assigned a fitness score according to how suited it is to the problem.  
Before a GA can be turned, an appropriate representation for the problem must be designed. In our case, the PD/PID gains are represented to the GA as a vector of size 12 for PD and 18 for PID. Each element is used to refer to a particular controller gain. Accordingly, the population is defined as a collection of those vectors.  
The initial population is randomly generated within predetermined limits in order to reduce AG convergence time. The search regions \(R_{SPD}/R_{SPiD}\) of the optimal solutions are noted as follows in (22) and (23):  
\[R_{SPD}=[k_{p_{min}};k_{p_{max}}]\times[k_{d_{min}};k_{d_{max}}] \tag{22}\]  
\[R_{SPiD}=[k_{p_{min}};k_{p_{max}}]\times[k_{i_{min}};k_{i_{max}}]\times[k_{d_{ min}};k_{d_{max}}]. \tag{23}\]  
Indeed, from some knowledge about the system, search region limits are defined as follows in (24) and (25):  
* For attitude \[\left\{\begin{array}{l}k_{p}\in[0;50]\\ k_{i}\in[0;50]\\ k_{d}\in[0;10].\end{array}\right.\] (24)
* For position: \[\left\{\begin{array}{l}k_{p}\in[0;200]\\ k_{i}\in[0;20]\\ k_{d}\in[0;50].\end{array}\right.\] (25)  
Once the initial population is created, the evolutionary process starts. Each individual (solution) is evaluated using a fitness function in order to rate it in terms of its adaptation to the objective.  
We desire a behavior without overshoot and zero error with minimal settling time. The fitness function which takes into account all this performance is given by the Equation (26):  
\[f=\frac{8D+4E_{ss}+2T_{s}}{14} \tag{26}\]  
where \(D\) is the overshoot, \(E_{ss}\) steady-state error, and \(T_{s}\) the settling time.  
\begin{table}
\begin{tabular}{l c c c c c c c} \hline \hline \multirow{2}{*}{**RMHC Method**} & \multicolumn{6}{c}{**Controllers**} \\ \cline{2-9}  & \(C_{\phi}(s)\) & \(C_{\theta}(s)\) & \(C_{\psi}(s)\) & \(C_{x}(s)\) & \(C_{y}(s)\) & \(C_{z}(s)\) \\ \hline PD & \(k_{p}\) & 16.67 & 16.67 & 16.67 & 0.10 & 0.10 & 190.8 \\ \cline{2-9} Parameters & \(k_{d}\) & 1.21 & 1.21 & 1.21 & 0.20 & 0.20 & 34.98 \\ \hline PID & \(k_{p}\) & 37.17 & 37.17 & 33.34 & 18.34 & 37.17 & 6.60 \\ \cline{2-9} Parameters & \(k_{i}\) & 65.22 & 65.22 & 7.28 & 0.25 & 65.22 & 0.05 \\ \cline{2-9}  & \(k_{d}\) & 2.35 & 2.35 & 1.4 & 10.41 & 2.35 & 6.24 \\ \hline \hline \end{tabular}
\end{table}
Table 1: Proportional-derivative (PD) and proportional-integral-derivative (PID) parameters values of the reference model-based hierarchical control (RMHC).  
To determine which parents should be considered in generating a new population, a selection procedure is indispensable and can take many forms. We have chosen to use tournament selection. The new population is gated by selecting the more adaptive individuals, according to their fitness from the parent population. The selected individuals are subjected to random mutations and crossover operations.  
The type and implementation of these operators depend on the problem being studied. The mutation operation is applied with a rate of 0.2, corresponding to the probability of being mutated. This evolutionary process is repeated until the algorithm convergence criterion is met, generally a pre-defined number of generations. This was 500 generations in our case.  
The optimal solutions turned by the GA code for the PD and PID controllers are shown in Table 2.  
The simulation results of the quadcopter represented by the non-linear model (1)-(6) and controlled using the GA-based hierarchical controllers (GAHC) are discussed in Section 5.