## 2 Materials and Methods
### Iterative Learning Method for In-Flight Tuning of UAV Controllers--General Idea  
Bearing in mind that the search space for the \(J_{min}\) for all combinations of controller gains \(\underline{k}=(k_{1},k_{2},...,k_{N})^{T}\) in predefined intervals (ranges) of gains, in the problem outlined in (5) is huge,  
Figure 4: Flowchart for the proposed tuning strategy of the UAV controllers.  
Figure 5: Following steps to obtain optimal gains of controllers.  
one needs a fast, effective mechanism for search space exploration. It should be characterized by low computational complexity, and after checking the value of \(J(t)\) in a maximum of dozen or several dozen of gain combinations, should be able to provide the value of \(J_{min}\) (locally best variant) or a significant improvement compared to the controller's original gains (expressed using e.g., the expected accuracy of the \(\epsilon\)).  
Recalling the publications cited in Section 1.3, iterative learning algorithms are characterized by fast convergence towards the minimum value--especially the region elimination methods (REMs). To be able to use them, one needs to refer to the general idea of iterative learning approaches (proposed by [PERSON] et al. in [45]), i.e., minimization of the norm of error (here: cost function) in order to tune particular controller using the periodical repeitiveness of the trials (here: repetitions of the same, predefined trajectory primitives--see Figure 6). Then, to find locally best gains of a particular controller based on a given reference of \(x_{d}\), \(y_{d}\), \(z_{d}\) or \(\psi_{d}\) primitive, and corresponding measured value, the performance index \(J(t)\) calculated during the flight with given safe ranges of controller parameters, enables the minimum-seeking procedure to find controller gains with respect to the preferred dynamics, and for a given tolerance of the solution.  
**Remark 4**.: _Since the method is based solely on the cyclic collection of measurement data to determine \(J(t)\), the need to use the UAV model is reduced. However, its knowledge is advantageous when in the simulation conditions it is possible to roughly estimate/determine the maximum values of the elements of the \(\underline{k}\) vector, for which the UAV does not lose its stability._  
For every single primitive being used in the optimization procedure, three phases can be distinguished (see Figure 6):  
1. Acquisition of measurement data (current, sampled values: \(x_{m}\), \(y_{m}\), \(z_{m}\) or \(\psi_{m}\)) for set controller gains with the assumed \(T_{p}\) and the assumed form of the \(J(t)\) function,
2. Determination of new controller gains based on the estimated value of the cost function from the phase no. 1,
3. Adjusting the controller according to iteratively corrected gains and waiting for the time necessary to stop the transient processes caused by it.  
Determining the sequence of controller gains is possible by systematically narrowing the search space. For this purpose, the use of region elimination method based on the zero-order deterministic optimization algorithm (GLD), is proposed.  
Figure 6: Following steps in iterative learning mechanism for altitude controller tuning.