*3.3. Tracking the Mobile Platform*

Two variants for the tracking algorithm were explored. The first one uses the currently estimated 3D position of the landing platform's centroid relative to the UAV's body frame as the input cue for a height-adaptive PID controller. The required 3D position is computed by transforming the output of the detection-localization algorithm presented in Section 3.2 to the UAV's body frame, as detailed in the following subsection. Note that by height-adaptive we refer to the fact that the PID gains are modified continuously depending on the UAV's flight altitude at every instant.

The second variant extends this height-adaptive PID with a Kalman filter to predict the future position of the landing platform. This prediction is then used as the target position for the same height-adaptive PID controller. The implementation of the Kalman filter is based on a previous work by the authors [22] where the prediction was used for tracking pedestrians.

Additionally, embedded in the tracking module, a *height control system* ensures that a proper descent speed is set in every instant depending on the current UAV's flight altitude. Furthermore, as mentioned above, this height-adaptive control system updates the PID gains depending on the current altitude: essentially, the goal is to have a faster response the closer the UAV is to the landing platform along the vertical axis (perpendicular to the ground).

After having presented the general scheme of both algorithms, i.e., with (w/) and without (w/o) the prediction of the future position of the moving platform, each variant is explained with more detail in Sections 3.3.1 and 3.3.2, respectively.

#### 3.3.1. Height-Adaptive, Non-Predictive PID Controller

A PID controller is a control loop feedback mechanism to compute the necessary control variable *u*(*t*) that makes the error *e*(*t*) between the desired process value or setpoint *r*(*t*) and the measured process value *y*(*t*) converge to zero as fast as possible. To do so, it uses three different actions, namely a proportional, an integral, and a derivative action, each contributing differently to the control action. The mathematical expression of a PID controller is given by:

$$u(t) = K\_p e(t) + K\_i \int\_0^t e(t') \, dt' + K\_d \, \frac{\mathrm{d}c(t)}{\mathrm{d}t},\tag{4}$$

where *e*(*t*) = *r*(*t*) − *y*(*t*). In our system, the desired process value, *r*(*t*), is the 2D zero vector, i.e., the origin of the UAV's coordinate frame relative to the coordinate frame itself. The measured process value, *y*(*t*), is the two-vector containing the x and y coordinates from the 3D position of the landing platform's centroid relative to the UAV's body frame. Thus, *e*(*t*) in our system is the distance in the xy-plane (parallel to the ground) between the UAV's frame and the centroid of the landing platform at time *t*.

Recall now that in the localization stage we compute the three-space coordinates of the landing platform in the drone's camera frame, which we denote by *Pcam*. If we are to use this position as a target value for the PID controller, the first step is to transform its coordinates to the UAV's body frame, *Pbody*, since what we want is for the center of the UAV—and not for the center of its downward-looking camera—to get closer to the centroid of the landing platform. The transformation *Tbody*\_*cam* that maps a point from the camera frame to the body frame of the UAV is known from design and gives us:

$$P\_{body} = T\_{body\\_cam} \, P\_{cam} \, \tag{5}$$

We can then compute the position error *e*(*t*) using the expression:

$$
\sigma(t) = \sqrt{(P\_{\text{body}\_x})^2 + (P\_{\text{body}\_y})^2} \tag{6}
$$

and finally, calculate the control variable *u*(*t*).

**Tuning.** Finding the optimal PID gains (proportional gain *Kp*, integral gain *Ki*, and derivative gain *Kd*) was carried out through heuristic rules, i.e., looking first for the *Kp* that provided the desired response while keeping *Ki* and *Kd* at zero; then gradually increasing *Ki* to cancel the position error (and slightly decreasing the *Kp* so that the system did not become unstable); and, finally, increasing *Kd* so that the response of the system was faster while fixing the values of *Kp* and *Ki* obtained in the former steps. In practice, we found a PI controller, i.e., without the derivative action, to work better than a complete PID.

**Height-adaptive PI controller.** We also found a height-adaptive PI controller to perform better than a fixed-gain PI, since different responses are needed when the drone is hovering at 4 m above the landing platform than moments before landing. In particular, the UAV needs to react faster the closer it is to the landing platform along the vertical axis.

An initial tuning of the PI gains for an altitude of 4 and 2 m in the simulation is shown in Table 1. Note that no distinction has been made between the x and y axes of the UAV, since we can disregard the different dynamics of the UAV with respect to each of these axes.


**Table 1.** Height-dependent PI gains.

We noticed that an exponential function of the form:

$$\mathcal{K}\_x = \mathcal{Q} \, e^{-T \, p\_z} \tag{7}$$

could nicely fit the values we had obtained manually, where *Q* and *T* are the parameters of the function, *pz* the drone's altitude, and *Kx* the height-dependent PID gain we want to model. After further fine-tuning, the final expressions for both the proportional and integral gains are the following:

$$\begin{aligned} K\_{\mathcal{P}} &= 0.\mathcal{T} \, e^{-0.002 \, p\_z} , \\ K\_i &= 0.2 \, e^{-0.002 \, p\_z} .\end{aligned}$$

**Landing.** The descent speed during landing remains at a constant value of 0.3 m s−<sup>1</sup> when flying 0.7 m above the landing platform, i.e., when the sonar indicates more than 0.7 m. Below 0.7 m, the UAV increases its downward speed notably to 2.0 m s−1. The intuition behind this design choice is that, when too close to the landing platform, the latter is not viewed completely by the UAV's downward-looking camera, and in turn the computed centroid might not represent the real center position of the platform. It is therefore a better option to rely on the correct measurements taken at altitudes higher than 0.7 m and then perform the final approach stages faster.

To determine whether the drone has successfully landed on the landing platform, we use the sonar measurements and the linear acceleration provided by the IMU. If there exists some linear acceleration, either in the x or y direction, that means the drone is moving. Moreover, if the sonar indicates a value smaller than a threshold for a certain period of time, the drone is assumed to have landed; this is not, however, a sufficient condition, since it might as well have landed on the ground. Therefore, to be certain that the UAV has actually landed on the moving platform and not on the ground, both conditions must be met, namely (1) the sonar measurement must be smaller than a threshold persistently and (2) the IMU must indicate a non-zero linear acceleration. Note that these assumptions are valid because the landing platform is assumed to be moving constantly.

In practice, the UAV mostly lands smoothly without major rebounds after the first contact with the landing platform, as we could verify in a set of preliminary experiments. After all, given that the height-adaptive PID controller ensures that the landing platform's centroid and the UAV's body frame are aligned along the vertical axis at all times, landing mostly occurs very close to the center of the platform. Therefore, in all experiments (Section 4) we can safely use the initial touch point between the landing platform and the UAV as stop signal for data recording.

3.3.2. Height-Adaptive, Predictive PID Controller

In this section, we describe how we integrated the pedestrian trajectory prediction algorithm developed in a previous work by the authors [22] into the height-adaptive PID controller described in the previous section. The resulting pipeline looks as follows:

1. The detection-localization algorithm (Section 3.2) outputs the centroid of the landing platform in the UAV's camera frame. The prediction algorithm requires as input a 3D point relative to an *inertial* reference system. Therefore, we must transform the centroid of the landing platform from the drone's camera frame into the the world's frame:

$$P\_{\text{uvrold}} = T\_{\text{uvrold\\_cam}} P\_{\text{cam}}.\tag{8}$$


$$
\mathcal{P}\_{body} = T\_{body\\_world\\_up} \mathcal{P}\_{world\\_up} \tag{9}
$$

4. Finally, the x and y coordinates of *P*ˆ *body* are used to calculate the controller's error, i.e., the distance in the xy-plane between the UAV and the predicted position of the landing platform. Using this error we can now calculate the speed commands in x and y, i.e., *u*(*t*) in (4), that make this error converge to zero.

**Configuration of the Kalman filter.** We use a value of 0.1 s as the time step for our predictions and a path time of 0.1 s, thus obtaining a vector of future predictions of size two, where the element with index one corresponds to the predicted position of the landing platform. (Recall that the element with index zero corresponds to the *current* position of the landing platform's centroid.) We studied the effect of using different path times and then accessing different future positions within this vector of predictions depending on the altitude, but in a set of preliminary experiments, we found that the performance improvement of this design choice was minor or even negative.

By using the time step and path time defined above, if the landing platform were to move, for instance, linearly at a speed of 0.5 m s−1, the prediction algorithm would estimate an increment of 0.05 m along the current trajectory of the moving target. We found that such a minor prediction (in this example, the predicted position differs only in 5 cm from the current position) benefits the landing accuracy notably, as presented in Section 4, when compared to the non-predictive system.

For completeness, we detail the co-variance matrices of the process noise, *Q*, and the observation noise, *R*, both diagonal matrices of the form:

$$Q = \begin{pmatrix} 2 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 2 \end{pmatrix}, \qquad R = \begin{pmatrix} 2 & 0 \\ 0 & 2 \end{pmatrix}. \tag{10}$$

which were obtained empirically.

As will become apparent in Section 4, employing a Kalman filter to predict the future positions of the landing platform not only provided the system with knowledge about the trajectory described by the UGV, but also helped further stabilize the measurements from the detection-localization algorithm (Section 3.2).

In this section, we described a system for the autonomous takeoff, tracking, and landing of a small UAV on a moving landing platform. We presented two variants for the tracking module: a non-predictive height-adaptive PID controller and its predictive counterpart, which leverages a Kalman filter to predict the future position of the landing platform. By doing so, not only do we filter out noise in the measured relative 3D position of the landing platform with respect to the UAV, but also allow the UAV itself to stay slightly ahead of the UGV by directly feeding this virtual future position to the height-adaptive PID. This approach will prove to be crucial to accomplish successful landings, especially when the landing platform describes non-linear trajectories.
