## 2 Materials and Methods
### Optimal Gain Tuning of a Two-Parameter Controller Based on Bootstrapping Mechanism  
In a two-dimensional space of parameters, the vector of parameters \(\underline{x}= \begin{bmatrix}x_{1},&x_{2}\end{bmatrix} ^{T}\) for the cost function \(f(\underline{x})\) (calculated from in-flight measurements) can be interpreted as controller gains (here: \(k_{P}\) and \(k_{D}\)). For fast exploration of this space and to give a global character the GLD extremum-seeking procedure, Algorithm 2 is proposed. It is based on the bootstrapping mechanism (see Table 2), for the predefined bootstrap cycles \(N_{b}\). In considered two-parameter controller tuning, in every single bootstrap, two launch of GLD algorithm (for each of controller gains) are executed to obtain expected value of the \(\epsilon\). Firstly, the gain no.1 is tuned (while the gain no. 2 is fixed), and then, the gain no. 2 (for fixed value of the no. 1). Step 0. Put the bootstrap cycles counter to \(l=0\); for initial \(\mathcal{D}_{i}^{(l)}\) (\(i=1,2\)) define \(\epsilon\), \(N_{b}\), and initial value of the second parameter \(x_{2}^{(l)}\) (take \(\hat{x}_{2}^{(l)^{*}}=x_{2}^{(l)}\)), set \(l:=l+1\). Step 1. Find the optimal \(\hat{x}_{1}^{(l)^{*}}\) using the GLD algorithm, with the second parameter fixed at \(\hat{x}_{2}^{(l-1)^{*}}\). Step 2. Calculate the optimal \(\hat{x}_{2}^{(l)^{*}}\) analogously to the method from the Step 1, keeping the first parameter fixed at \(\hat{x}_{1}^{(l)^{*}}\). Step 3. If \(l<N_{b}\), increase the bootstrap cycles counter \(l:=l+1\), and proceed to Step 1, otherwise stop the algorithm--the optimal solution \(\hat{x}^{*}= \begin{bmatrix}\hat{x}_{1}^{(l)^{*}},&\hat{x}_{2}^{(l)^{*}}\end{bmatrix} ^ {T}\) has been obtained after \(N_{b}\) bootstrap cycles, as desired. To ensure high effectiveness of the proposed method of auto-tuning, one should remember about several important aspects (in configuration and implementation):  
* The proposed method requires predefining the initial, admissible ranges for \(\underline{x}\), i.e., \(\mathcal{Q}_{i}^{(0)}=\left[x_{i}^{(0^{-})},\quad x_{i}^{(0^{+})}\right]\) for \(i=1,2\). It is a crucial choice from the perspective of ensuring the safety of autonomous flight. If there is a such a possibility, it is strongly recommended to use the expert knowledge about the controller gains (from initial flights on the base of analysis of a rise time and the maximum overshoot, prototyping in virtual environment, default settings of on-board controller, detailed analysis of the UAV feedback control system, etc. ),
* For the expected tolerance \(\epsilon\), the number \(N\) is calculated. \(2N\) calculations of \(f\) are needed in the tuning of a pair of controller parameters of a single bootstrap,
* The algorithm's execution time depends on: \(N_{b}\), \(N\), and the time of a single reference primitive, which must be correlated with the expected UAV dynamics and its natural inertia,
* Recalling the most important principles of the zero-optimization method from [26], one needs to have in mind that the proposed method _\"(...) is iterative-based and collects information about the performance index (on incremental cost function value) at sampling time instants, equally spaced every \(T_{p}\) seconds\"_ during the tuning experiments. Thus, for sampling period \(T_{p}\), a single evaluation of \(f\) value according to Step 2 of Algorithm 1 with a change of a single parameter of controller is performed using Procedure 1 (for symbols from the Table 1). * The performance index is calculated as \[\Delta J^{(n)}=J^{(n+1)}+\Delta J^{(n)},\] (11) where \(\Delta J^{(n)}\) can be obtained from the discrete-time version of Equation (3), which for \(n\)-th sample (tracking error and control signal) at time \(t=nT_{p}\) is given by \[\Delta J^{(n)}=\alpha\left|e_{n}\right|+\beta\left|u_{n}\right|.\] (12) ```  
**Algorithm 3** Evaluation of performance index (with single change of controller parameter) [26]  
Recalling defined \(N_{c}\), \(N_{max}\), and \(n\) for \(f(\cdot)\).