2.1. Hardware Platform
All the experiments carried out in this work were performed on the DART platform [
17,
18,
19,
20] produced by Florence Robotics; see
Figure 1. The system consists of a quadcopter with a multilevel architecture able to process computationally expensive algorithms on board without the use of mocap techniques. In particular, the architecture is organized into two levels: (i) a low-level one that consists of the standard electronics available on a multicopter (flight controller and electronic speed controller); and (ii) a high-level one that is characterized by the NVIDIA Jetson Xavier NX board on which the embedded Linux
Operating System (OS) runs. The latter is then interfaced via a custom
Application Programming Interface (API) with the low-level electronics.
Thanks to the DART platform APIs, it is possible to receive real-time telemetry from all sensors on board the drone at a frequency of 200 Hz. Furthermore, it is possible to send autonomous commands from the high-level system to the flight controller (still with a frequency of 200 Hz), replacing those normally issued by the pilot during manual flight.
Since all signals passing through the DART platform are managed by specific intermediate hardware, which always ensures the correct fail-safe mode handling, the use of this drone significantly simplifies the experimentation of new algorithms and software for autonomous navigation. In fact, in the event of a failure in the software under test, the intermediate hardware can detect it and return the control to the pilot or, if configured, it automatically manages the switch between available flight modes on the flight controller, which may include auto-landing and return to home.
All of this allowed the abstraction of the software implementation of the trajectory planning. In fact, thanks to this approach, it was possible to test the trajectory planning algorithm in a more realistic way compared to the usual mocap techniques, which can only work in controlled environments. Obviously, since the present work is focused on testing a trajectory optimization algorithm on board an autonomous vehicle in a real scenario, the DART platform was equipped with an advanced optical sensor to accurately detect the targets. In particular, the Intel RealSense T265 camera was used for this purpose. This camera can provide a faithful 3D estimate of position and online speed. In
Figure 2b, it is possible to see it mounted on the DART platform.
2.2. Scenario
To validate the effectiveness of the trajectory planner, which will be discussed in detail in
Section 2.3, it is crucial to conduct a flight demonstration serving as a practical assessment for the planner. Specifically, the drone is assigned the task of reaching specific points within the space. Aruco environmental markers [
21,
22,
23], in conjunction with the associated OpenCV libraries, are used for this purpose.
The markers are strategically positioned in the environment, with their locations intentionally undisclosed to the drone. Leveraging optical flow data from the stereoscopic camera, the drone must adeptly identify the markers and accurately estimate the 3D position of each.
At the mission’s initiation, the drone possesses only the identification (ID) codes of the markers, devoid of any knowledge about their physical locations in the environment. Therefore, to fulfill the mission objectives, the drone must first locate the markers and then autonomously generate a trajectory so that it traverses over each marker in the precise order dictated by the provided sequence of IDs. This emphasizes the drone’s reliance on its onboard capabilities, particularly in terms of the optical flow processed from the stereoscopic camera, which is needed for detecting and navigating to each marker without any external information about the marker positions. An example of a frame obtained from the on-board optical flow during a test mission is shown in
Figure 3. Note that, in this position, just two waypoints are visible and then are passed together with the drone’s current position as inputs to the planning module. In fact, the trajectory will be calculated starting from the drone position.
For the sake of completeness, we report in
Figure 4 the block diagram of the embedded software designed for the execution of the test missions. Within block (a), the module responsible for estimating the position of Aruco markers is depicted. This module takes the optical flow data from the stereoscopic camera as its input. Once new markers are detected, the mission supervisor module (block (b)), housing the optimal trajectory generation algorithm, is activated, and the desired trajectory is provided as a sequence of points.
Subsequently, the computed trajectory is relayed point by point to the module responsible for implementing the control strategy, block (c). This module also takes as input the estimated acceleration, speed, and position data from the Intel T265 stereoscopic camera, which are essential for accurate trajectory tracking.
2.3. Trajectory Generation
Let us state the problem for trajectory planning as follows. Assume we have a set of waypoints that each defines the desired position in the world frame, where the drone must be at specific time instants. Having this set, we want to establish the optimal trajectory with respect to some functional cost, so that all the constraints (such as smoothness and safety passages) are satisfied. Of course, it is important to guarantee the feasibility of the computed trajectory. In other words, during the flight, we must ensure that both velocities and accelerations required for carrying out the mission never exceed the maximum allowable values. If this happens, then we must relax some constraints (like time allocation with which the drone must move from a waypoint to the subsequent one) and recompute the trajectory to have a less aggressive behavior.
In the following, the bold font notation will be used for both vectors and matrices of matrices.
The position of the quadcopter’s center of mass between one waypoint and the subsequent one can be described by three independent
N-order polynomials (one for each
,
, and
), as follows:
Therefore, computing an optimal trajectory means finding the optimal coefficients of these polynomials along the whole path. Consider that here, unlike [
6,
24], the yaw angle
is not optimized along with the trajectory. In fact, thanks to the differential flatness property of a multicopter, it can be demonstrated that, in principle, the vehicle is capable of following a desired trajectory regardless of the heading angle. Therefore, we prefer to compute it afterwards, once the optimal trajectory is available, so that the drone is always forced to head forward.
Assuming a one-dimensional single-segment trajectory, the objective function is simply
with
T being the flight time, while the weights
are penalties chosen by the user. However, Equation (
2) can be rewritten in matrix fashion, which is more convenient for implementation, as
where
is the vector of the
N coefficients, and where matrix
(see [
24]) is defined as
with
As stated previously, penalties
can be arbitrarily chosen; nevertheless, in [
25], it is proved that the minimization with respect to the snap (
) leads to minor stress on the rotors. Therefore, in the continuation, we will assume
, while all the other weights will be set to zero.
Given Equations (
2)–(5), we can easily extend the problem from the case of a one-dimensional single-segment to a three-dimensional multi-segment path. In this case, the joint functional cost becomes
In Equation (
6), every
is the flight time for moving from the
i-th waypoint to the
-th waypoint, and
is the vector of the (unknown) coefficients of each polynomial composing the trajectory, whose structure is as follows:
Again, the three states
, and
are actually independent, and thus three independent cost functions can be written and solved separately [
6]. However, we prefer to use a joint cost function since requirements on passages through oriented windows couple together more state variables [
24]. Therefore, the current formulation can be more easily extended in the future for allowing acrobatic maneuvers.
Given the cost function of Equation (
6), the Quadratic Problem (QP) can be finally formulated as follows:
where
and
are matrices defining the constraint set over the trajectory.
Equation (
8) is particularly useful for the implementation, since standard functions available on MATLAB (such as
quadprog) can be used for solving the optimization problem. Furthermore, since MATLAB 2021, the C++ Coder toolbox allows for the export of C++ code, simplifying notably the work [
16].
Finally, we can address the problem of constraint formulation. They can be sorted into three categories:
Position constraints;
Derivative constraints;
Corridor constraints.
2.5. Derivative Constraints
Derivative constraints are necessary for defining the dynamics of the drone, for example, if the mission is started/finished from rest or not, but also for guaranteeing a smooth enough trajectory. We define derivative constraints up to the second-order derivative, since it is a good compromise between accuracy and computation time for our purposes. In fact, higher-order derivative constraints improve the smoothness, but the computation time for solving the optimization problem increases, and hence it is not suitable for real-time applications.
If velocities and accelerations are known at every endpoint, these constraints can then be written similarly to Equation (
9), with appropriate substitution in
and
.
In our application, we assume that just the derivatives of the first and last detected waypoints were known, while the others were left free. However, some continuity constraints over those halfway points have to be imposed to guarantee a smooth trajectory. This problem can be overcome by requiring that the derivatives at the end of the
i-th segment match the derivatives at the beginning of the
-th segment, i.e.,:
which can be stored as a matrix as follows:
2.6. Corridor Constraints
Corridor constraints were first introduced in [
6] because, sometimes, especially in indoor environments, the available space for a drone’s maneuvers is very tight. In these situations, additional constraints are needed for avoiding possible collisions with the surroundings. Let
be the unit vector along the direction of the
i-th segment and
be the position of the drone center of mass expressed in the world frame. The perpendicular distance vector
from segment
i is therefore
A corridor constraint on segment
i can be translated as requiring that
does not exceed a maximum value
, i.e.,:
Then, Equation (
13) must be rearranged in a matrix structure to be inserted in the QP, Equation (
8). By introducing
additional intermediate points and projecting vector
on the three-world axis
, and
, Equation (
13) becomes
Equivalent expressions can be derived for
and
as well. Finally, Equation (
14) can be split into two linear constraints by removing the absolute value. This last step yields an equation that can be finally added as a constraint in the original problem.
2.7. Time Allocation
The reader should have noticed that, in the formulation of the optimization problem described by Equation (
8), both the cost function and the constraints depend explicitly on vector
. Hence,
must be fixed prior to the optimization.
A common approach is to use the steepest descent method, which allows for smart allocation of the times for every segment [
5,
24]. Concerning our algorithm, we proceeded differently, since the steepest descent method remarkably increases the computation time. The algorithm that we derived simply checks that, for every segment, both velocity and acceleration are kept within the desired ranges for each component. In the eventuality that the requirements are not satisfied, a new augmented time is imposed over just those segments violating the constraints. Then, a new optimal trajectory using Equation (
8) is computed. Therefore, our method does not aim to find an optimal time allocation; rather, it finds the first feasible configuration. It is also clear that the speed with which the algorithm converges to a feasible solution depends on how much each violating segment time is increased. However, this approach guarantees that it always converges to a solution, since all maneuvers are possible for a long enough travel time. Concerning the experimental results and our bounds—
m/s and
m/s
2—an increase of
s is enough for converging to a solution within 10 iterations.
2.8. Experimental Setup
Our experiments have been conducted in an indoor environment where we defined two different possible scenarios: (i) a known environment with a priori knowledge of the mission, and (ii) an unknown environment where the location of each marker must be uncovered on the go. The former scenario is less interesting from a practical point of view, since it does not reflect the common conditions in which a UAV must work. On the contrary, the latter requires efficient algorithms so that a trajectory can be computed in real time using the current available information. Therefore, the last scenario is important for testing the goodness of our proposed algorithm, while those tests in a known environment are relevant just for comparing the discrepancies between the predicted trajectories in the two scenarios. In the following, we refer to the known environment as the “one-step” approach, since all the computations are done altogether, while with “iterative”, we refer to the second scenario, in which the trajectory is iteratively computed as new data become available.
Before moving to the next section, we would like to give further details about the experimental setup and implementation for the iterative approach. At every iteration, module (a) in
Figure 4 outputs a vector containing the coordinates of those markers detected in the current frame. The dimension of this vector is dynamic since the number of markers seen may differ from frame to frame. The vector is then fed to the Mission Supervisor, module (b), in which a refinement of the markers’ locations and trajectory planning are carried out. Specifically, whenever a new coordinate vector is provided by (a), the Map Generator (b1) checks whether those coordinates refer to new markers or not. If a new marker is seen, then it is saved and added to the map (memory); otherwise, the Map Generator decides whether to update the marker’s estimated position or not given the following Equation (
15):
where
represents the difference between the current
and the old
estimated position vectors of marker
l, respectively. Therefore, the position of marker
l in the map is updated if and only if
, with
defined by the user. This logic has been implemented to avoid excessive calls to the trajectory planning algorithm (b2). In fact, every time new estimated positions are available, the trajectory must be recomputed, but this requires a lot of computational effort.
Finally, we would like to make the readers aware that our markers have to be imagined at the center of gates, and the drone must cross these passages as perpendicular as possible for safety reasons. Hence, in addition to corridor constraints, for every detected marker, two additional points are generated along the perpendicular line of the gate plane, one before and the other after the passage; see
Figure 5. Therefore, the actual waypoints with which the new trajectory is computed are the last point of the current trajectory and the pair of additional points for each detected marker.