Tesi
Tesi
Supervisors Candidate
Prof. Alessandro RIZZO Alessandro PAGLIANO
Dr. Stefano PRIMATESTA
December 2020
Summary
Trajectory planning is an essential element in robotics applications. The quality of
the planned trajectory strongly influences the robot behavior, particularly when an
autonomous robot operates in complex and structured environments.
This thesis focuses on the study, deployment and testing of a trajectory planning
algorithm for autonomous Unmanned Aerial Vehicles (UAVs), exploiting the Model
Predictive Control (MPC) theory and the Rapidly-Exploring Random Tree "Star"
(RRT*) algorithm. The developed logic makes use of the RRT* algorithm to explore
the search space and, then, construct an incremental optimal tree to connect a
given start and a goal pose in the search space. During the exploration phase,
whenever two states are attempted to be connected, the deployed Model Predictive
Control logic computes a "cost-to-go" cost of moving between two adjacent states
in the graph by predicting the motion of the UAV, exploiting its dynamic model.
At the end of the search phase, RRT* returns the asymptotically optimal path in
the graph with the lowest cost. The resulting path consists in a sequence of states
connected through the optimal motion computed by the MPC logic.
One of the drawback of the implemented logic is its complexity due to the MPC
optimization that requires huge computational resources and time. Hence, some
assumptions and heuristics are deployed for improving the quality of the algorithm.
Finally, simulation results in realistic environments validate the implemented
approach, proving how the proposed trajectory planner is able to compute an
effective trajectory to be executed by the UAV.
This thesis is carried out within the activities of the Amazon Research Award "From
Shortest to Safest Path Navigation: An AI-Powered Framework for Risk-Aware
Autonomous Navigation of UASes" granted to Prof. Rizzo.
ii
Acknowledgements
Last months have been the toughest of my life, because of the pandemic and the
several difficulties I encountered. Nevertheless, I have never stopped smiling, thanks
to all the people around me.
First of all, I want say thanks to my family for all the sacrifices they did for me
and for the values and love they have always shared with me. Particularly, I want
to spend some words for my sister. You are the most important person in my life,
the person that, with her simplicity, always manages to pull a smile out of my
face. Please, do not change, because, even if you are young, you are an example to
follow. Thanks to my great-grandparents, that I know they are happy for me. I
want to say that I gave my all to finish this thesis as soon as possible, in order to
share this joy with Grammy, but unfortunately I didn’t make it. What I want to
say is that, if someone asked me to imagine the perfect family, I would not be able
to imagine a better family than the one I have.
Thanks to all my friends that are always willing to help me and that always
encourage me in what I do. Thanks to all my university friends with whom I shared
beautiful and though moments, spending entire days at the Politecnico. Thank
you all my friends for all the moments you shared with me, hoping to see you again
and again in this life.
I want to thank Professor Alessandro Rizzo for having given me the opportunity of
developing this thesis. A really big thanks to my supervisor Stefano Primatesta
that has always helped me, replying to my stressful messages and supporting me
at every stage of this project.
During this course of study I had beautiful experiences that I will never forget.
Therefore, I dedicate this thesis to all the people I love; thank you for having
accompanied me on this beautiful journey. I will be forever grateful to all of you.
Alessandro
iii
Table of Contents
Acronyms xi
1 Introduction 1
1.1 State of the Art . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Dijkstra’s Algorithm . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 A* Search Algorithm . . . . . . . . . . . . . . . . . . . . . . 4
1.1.3 Genetic Algorithm . . . . . . . . . . . . . . . . . . . . . . . 5
1.1.4 Ant Colony Optimization . . . . . . . . . . . . . . . . . . . 6
1.1.5 Probabilistic Roadmap Planner . . . . . . . . . . . . . . . . 8
1.1.6 Rapidly-Exploring Random Tree . . . . . . . . . . . . . . . 9
1.1.7 Rapidly-Exploring Random Tree "Star" . . . . . . . . . . . . 10
1.2 Outline of the Thesis . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 Background 13
2.1 Robot Operating System (ROS) . . . . . . . . . . . . . . . . . . . . 13
2.1.1 ROS Resources Hierarchy . . . . . . . . . . . . . . . . . . . 14
2.1.2 ROS Computation Graph Level . . . . . . . . . . . . . . . . 15
2.2 Open Motion Planning Library (OMPL) . . . . . . . . . . . . . . . 18
2.2.1 Problem Statement Definition . . . . . . . . . . . . . . . . . 18
2.2.2 OMPL Foundations . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Model Predictive Control (MPC) . . . . . . . . . . . . . . . . . . . 21
2.3.1 MPC Theory . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4 Multi-Rotor System Notation . . . . . . . . . . . . . . . . . . . . . 24
2.5 Multi-Rotor System Model . . . . . . . . . . . . . . . . . . . . . . . 27
2.5.1 Linearization and Discretization . . . . . . . . . . . . . . . . 28
v
3 Software Implementation 32
3.1 Code Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.1.1 RRT* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 33
3.1.2 MPCOptimizationObjective . . . . . . . . . . . . . . . . . . 38
3.2 ROS-PX4 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5 Conclusions 79
A CVXGEN Code 82
B text.launch File 83
C CVXGEN Statistics 85
D Euclidean Distance 86
E mavros_msgs/Waypoint Message 87
Bibliography 88
vi
List of Tables
vii
List of Figures
C.1 Computation time for finding the solution to the same problem by
different solvers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
ix
Acronyms
ACO
Ant Colony Optimization
MPC
Model Predictive Control
OMPL
Open Motion Planning Library
PRM
Probabilistic Roadmap
ROS
Robot Operating System
RRT
Rapidly-Exploring Random Tree
RRT*
Rapidly-Exploring Random Tree "Star"
SITL
Software In The Loop
UAS
Unmanned Aerial System
UAV
Unmanned Aerial Vehicle
xi
Chapter 1
Introduction
Some of the most challenging issues in the Robotics field are related to motion
planning. New generation robots are suppose to work with high speed, low con-
sumption movements, in order to perform high number of actions for long periods
of time. For the already mentioned reasons, motion planning plays a fundamental
role in this sense. In fact, the quality of the planning strongly influences the quality
of the actions performed by robots. When robots execute harsh maneuvers, it is
necessary to avoid to damage their components because of the excessive forces and
accelerations necessary for performing desired movements, so these precautions are
intrinsically defined by the planner.
A popular motion planning problem often used as an example to explain a practical
motion planning is the so called Piano Mover’s Problem [1], where a piano is
supposed to be moved in a known house, from a room to another, without hitting
obstacles and walls. Going deeper inside the motion planning theory, it is possible
to distinguish between path planning and trajectory planning, two central topics
in the Robotics industry, particularly when automation is requested.
Differences between these two planning theories need to be presented. Path plan-
ning algorithms are able to return a continuous path between two given robot
configurations; trajectory planning algorithms, instead, return a continuous path
between two robot configurations marked with a timing law. In this sense, tra-
jectory planning algorithms affect robot kinematics and dynamics. As properly
presented in [2], path planning algorithms are usually divided according to the
methodologies used for generating the geometric path:
• Roadmap Techniques;
• Cell Decomposition Algorithms;
• Artificial Potential Methods.
1
Introduction
Trajectory planning algorithms are named on the basis of the function that the
algorithm tries to minimize:
• Minimum Time;
• Minimum Energy;
• Minimum Jerk.
At the end of this section, one algorithm is chosen as candidate algorithm for the
thesis.
Explanation
The aim of the algorithm is to find the shortest path between any two vertices in
a graph. Given a set of vertices, Dijkstra’s Algorithm first reports the shortest
distance from a previous vertex (i.e. the lowest cost for connecting the current
vertex to another vertex). In this way, it is possible to easily find out the lowest
cost path for reaching the goal vertex. Defined a starting vertex, the algorithm
iteratively repeats the following phases until all vertices are visited:
• Visit the nearest unvisited vertex to the start one;
• Examine the current vertex unvisited neighbour vertices;
• Calculate the distance (cost) of each neighbour from the starting vertex;
• Update the shortest distance whenever it is shorter than the known distance;
• Update the previous vertex for each of the updated distances;
• Mark the current vertex as visited;
• Move to the next unvisited vertex.
1
Image courtesy from Geeksforgeeks website.
3
Introduction
Limitations
Even if it is very fast and computationally simple, Dijkstra’s Algorithm wastes time
by performing a "blind" research, computing unnecessary calculations. Moreover,
Dijkstra’s Algorithm is able to return the global optimal solution with respect to
a quantifiable variable, like length or another cost. However, in several problems,
multivariable functions are asked to be minimized. Because of these impediments,
this algorithm is modified by adding some heuristics to speed up the algorithm.
Explanation
Consider a square grid having many obstacles. It is desired to plan the optimal
trajectory from a starting cell to a target one as quick as possible. A* Search
Algorithm, at each computational step, picks a node x computing the cost f(x),
equal the sum of two functions, g(x) and h(x). At each iteration step, the node/cell
with the lowest f(x) value is chosen.
g(x) and h(x) values are defined as follow:
g(x): The cost to move from the starting point to a given cell on the grid, following
the path generated to get there, the same used in the Dijkstra’s Algorithm.
2
Image courtesy from 101computing website.
4
Introduction
h(x): The estimated cost to move from a given node on the grid to the final
destination. In order to guarantee the optimal solution in the graph, the
heuristic must be admissible, i.e. it must never overestimate the cost of
moving toward the goal node.
The main advantage of this algorithm is that the distances used as a criterion
can be accepted, modified or another distance can be added. This allows a wide
range of modifications of this basic principle, so that time, energy consumption or
safety can be also included in function f(x). Moreover, because of the introduced
heuristic, world information can be taken into account [5].
Limitations
A* Search Algorithm doesn’t produce always the shortest path because it heavily
relies on heuristics/approximations to calculate h(x). Moreover, as explained in [6],
this algorithm provides a solution that is a sequence of vertices to be followed in
order to move from a starting position to a target one.
Explanation
The process of natural selection starts with the selection of fittest individuals from
a population. The results of this population are offspring that inherit parents’
characteristics. Better fitness parents produce better offspring with higher chances
to survive. The process iteratively repeats until the best offspring is found. Same
iterative approach can be used for finding best problem solutions.
Genetic algorithm can be described with five phases3 :
Initial Population: The process begins with a set of individuals which is called a
Population. Each member of this Population is a solution to the problem. An
individual is characterized by a set of parameters (variables) known as Genes.
A set of Genes is joined into a string to form a Chromosome (solution). Often,
Genes are described by alphanumerical characters.
3
Definition courtesy from Towardsdatascience website.
5
Introduction
Fitness Function: The fitness function represents a way for quantifying the
quality of a solution, relative to the problem to be solved. Thanks to this
function, each individual receives a score, called fitness score. Higher the
fitness score, higher the probability of an individual to be chosen for the future
generations.
Selection: The idea of selection phase is to select the fittest individuals and let
them pass their Genes to the next generation. Depending on their fitness
scores, two pairs of individuals, called parents, are selected.
Crossover: The crossover phase is very significant. Parents pair Genes are mixed
until a predefined crossover point is reached. This point is randomly chosen,
with the aim of increasing the probability of finding a solution to the problem.
The algorithm ends when it results in saturation, i.e. new generations are very
similar to parents. In this way, a solution to the problem is found.
A three-dimensional trajectory planning based on genetic algorithm, as reported
in [7], is done by randomly generating a route from the initial three-dimensional
position (xi , yi , zi ) to the final one (xf , yf , zf ), and finding out an optimized
trajectory by minimizing the sum of the Euclidean distances between couples of
points in the 3D space.
Limitations
This method is efficient for trajectory planning where the obstacles are static.
Moreover, it is really effective in minimizing the distance from a start to a goal,
but it is not able consider dynamic and kinematic constraints of the UAV.
Moreover, as shown in [8], a successful solution depends on the success in encoding
or representing Chromosomes.
4
Definition courtesy from Towardsdatascience website.
6
Introduction
deposit pheromone on the ground in order to mark some favorable path that should
be followed by other members of the colony. Similar mechanism is used for solving
optimization problems.
Explanation
This algorithm is introduced based on the foraging behavior of ants for seeking a
path between their colony and food source. While searching, ants roaming around
their colonies. While moving, they deposit an organic compound called pheromone
on the ground. Ants communicate with each other via pheromone trails. When an
ant finds some amount of food, it carries as much as it can carry. When returning
to the colony, it deposits pheromone on the paths based on the quantity and quality
of the discovered food. Ant can smell pheromone, so, other ants can follow that
path. Higher the pheromone level, higher the probability of choosing that path
and the more ants follow the path, higher the amount of pheromone deposited on
the pathway, that results in higher probability of choosing it as preferential route
by other ants.
Limitations
As properly explained in [9], ACO can fall into local minima during the path
research, so it is not popular to be used for trajectory planning, while it is widely
used for problems optimization.
5
Image courtesy from Towardsdatascience website.
7
Introduction
Explanation
The concept behind PRM is to take random samples from the robot configuration
space, ensuring that they are in the free space and, then, trying to connect them
to nearby configurations. Then, starting and goal configurations are added in, and
a graph search algorithm is applied to the resulting graph in order to determine
a path between the starting and goal configurations. PRM works by uniformly
sampling the free space, trying to connect the samples to form a roadmap of the
free space. PRM has two main phases:
Query Phase: In this phase, start and goal are added to the graph, and the
shortest length roadmap is found.
6
Image courtesy from Mathworks website.
8
Introduction
Limitations
Because of the random nature of the samples, it is not sure that a solution is
found, particularly inside environments with narrow passages. Furthermore, this
algorithm is provably probabilistically complete: it means that the probability of
finding a solution increases with the increasing number of samples.
Explanation
After having defined a start and a goal position in the robot free space, a set of
samples is generated. Commonly, a single tree is constructed starting from the
initial position. At each sample, the sampled state is attempted to be connected
to the nearest state in tree. If the connection is feasible, the sample is added to
the tree. Whenever the nearest sample in the tree is farther to the sampled state
7
Image courtesy from Mathworks website.
9
Introduction
than a predefined distance called growth factor, this sample is substituted with
another one on the same line of the original one, but at a distance equal to the
growth factor. The probability of finding a solution depends on the number of
samples, as well as on the sampling strategy. Higher the number of samples, higher
the probability to find a path. In the same way, it is possible to grow two trees
starting from initial and final state, with the aim to try to connect them, finding a
suitable path with a higher probability; this variation is called Bidirectional RRT.
Limitations
Even if the probability of finding a solution is high also with a small number of
samples, the obtained solution is not supposed to be optimal. In fact, RRT is not
able to find a path that minimizes the distance between start and goal.
10
Introduction
Explanation
The sampling theory used by RRT* is the same used by RRT: robot configurations
are sampled in the robot free space. The main difference is the introduction of a
minimization function. RRT* algorithm adds to the grown tree robot configurations
whenever connection to parent node is collision free and with a minimum cost. In
fact, new sample nodes are not connected to the nearest node, but to the node
with the minimum cost. For each added node, the cost of the connection, defined
by a cost function c(t), is computed. Each node of the graph is marked with a cost
relative to the connection to the parent node. In this way, for each new connection,
the overall cost of the graph (i.e. the summation of each node cost) is updated.
The algorithm ends after a predefined solve time or after a predefined number of
nodes are sampled, and the returned graph is the one joining the start and the goal
pose with the lowest cost according to the cost function c(t).
Limitations
The limit of this algorithm is that, ideally, it converges to the optimal solution
with an infinite number of iterations, meaning that the convergence to the optimal
requires an infinite amount of time. However, this algorithm is able to provide a
sub-optimal path solution in a limited period of time. For the mentioned reasons,
together with the fact of being able to consider dynamic and kinematic constraints,
RRT* is used as path-finding algorithm in this thesis, with an ad-hoc extension
that allows to characterise the path with a timing law.
11
Chapter 2
Background
1
Guide courtesy from ROS website.
13
Background
Thin: ROS environment is designed so that code written for this platform can be
used on other software frameworks. This is possible thanks to the lightness of
ROS. In order to fully exploit this characteristic, the drivers and algorithms
development should be done using standalone libraries, without ROS depen-
dencies. The ROS build system performs modular builds inside the source
code tree;
Free and Open-Source: ROS has been developed with the aim of being open-
source. In fact, the entire ROS source code is public. The ROS distribution
is performed under the terms of BSD license, allowing commercial and non-
commercial project development.
Packages: Packages are the key units in which ROS software is organized. Pack-
ages can carry different entities, like ROS run-time processes (Nodes), a
ROS-dependent library, data sets, configuration files, or anything else that is
usefully organized together. Packages aim to provide their useful functionalities
in an easy-to-consume manner, in order to exploit software reusability;
15
Background
ROS Nodes: Nodes are executable files inside ROS Packages. Nodes exchange
information through message passing, using Topics for identifying message
contents. In order to maintain the modularity principle on which ROS is
based, a single robot process, like a control system, can be composed of several
Nodes. In this way, errors can be restricted to a single Node, improving code
readability, debugging and decreasing the probability of error spread up to
the entire system.
Master: The ROS Master is the main actor of the Computation Graph for the
Nodes peer-to-peer communication. Its main action is to store Topics and
Services registration information for ROS Nodes. In this way, Master allows
the ROS Nodes to locate each other, enabling peer-to-peer communication
and direct Nodes connections. ROS Master provides an XMLRPC-based
API, called by ROS client libraries, such as roscpp and rospy, for storing and
retrieving information.
2
Image courtesy from Introduction to ROS, Clearpath Robotics, 2015.
16
Background
Bags: Bags are important ROS tools used for storing data published on a defined
Topic. A Bag file, in fact, subscribes to desired ROS Topics and stores message
data in the order they are received.
3
Image courtesy from ROS website.
17
Background
StateSampler: This class implements methods for uniform and Gaussian sam-
pling robot configurations in the available state space;
18
Background
19
Background
4
Image courtesy from OMPL website.
20
Background
21
Background
The discrete time finite horizon LQ design procedure considers the minimization
of a cost function J of the input and state over a finite time horizon:
1 2
min J x(k|k), U (k|k) (2.1)
U (k|k)
where J is the cost function, x(k|k) the state vector at time k and U (k|k) =
[u(k|k) u(k + 1|k) . . . u(k + HP − 1)]T is the control sequence computed at time k
over the prediction horizon HP , subjected to the following model constraint:
x(k + 1) = Ax(k) + Bu(k) x(k) ∈ Rn , u(k) ∈ Rp (2.2)
with A ∈ Rn×n the state matrix and B ∈ Rn×p the input matrix.
The optimal input sequence, marked with U ∗ (k|k), is the input argument that
minimizes the cost function J:
1 2
U ∗ (k|k) = arg min J x(k|k), U (k|k) (2.3)
U (k|k)
This input sequence is computed optimizing the predicted state response, given
the system information at time k:
x(k + 1|k), x(k + 2|k), . . . , x(k + HP |k)
On the basis of the measured state x(k|k) = x(k) at time k, in fact, exploiting
system model, it is possible to calculate the ith -step ahead prediction:
x(k+i|k) = Ai x(k|k)+Ai−1 Bu(k|k)+Ai−2 Bu(k+1|k)+· · ·+Bu(k+i−1|k) (2.4)
In order to take into account input saturation, the following constraints are
added in the optimization problem:
umin ≤ u(k|k) ≤ umax
umin ≤ u(k + 1|k) ≤ umax
..
.
After this introduction, it possible to present the Model Predictive Control (MPC)
methodology. MPC is a control strategy that exploits a dynamical model of the
plant to predict the future behaviour of the variables of interest to compute an
optimal control action. MPC control input is computed by solving at each sampling
time k the following Quadratic Problem:
P −1 1
HØ 2
min xT (k + 1|k)Qx(k + 1|k) + uT (k + 1|k)Ru(k + 1|k) + xT (HP |k)Sx(HP |k)
U (k|k)
i=0
On the other hand, MPC presents several disadvantages that must be taken
into account:
• MPC strongly relies on the plant mathematical model used for the states
prediction. Most of the cases where MPC results infeasible are due to modelling
errors, neglected disturbances or dynamics. For these reasons, it is very
important to use a precise system model, in order to carefully take into
account system dynamics;
• The biggest limit of the MPC approach is the computational effort that
computers spend in order to solve the control problems. Moreover, better
system performances can be obtained with longer prediction horizon, but
higher the prediction horizon, higher the number of degrees of freedom in the
optimization, so the problem complexity. A possible solution to this problem
is reducing the number of variables to be optimized over a shorter time horizon
named control horizon HC . In this way, the system is predicted over the entire
prediction horizon, but only the first HC input variables are optimized, while
the remaining HP − HC control values may be set in different ways, reducing
computational effort.
• Multicopters;
24
Background
• Fixed-wing.
The main difference between these two categories of UAVs is the mechanics adopted
for generating lift, that influences the way wings and rotors are arranged in the
UAV body. After this short introduction and before presenting the UAV model
that is used in this thesis, it is necessary to explain several notations and terms
that are used in the following parts.
It is important to precise that the developed project does not focus on the UAV
model, while focusing on the trajectory planning strategy. Anyway, it is decided
to use a multi-rotor system model. For the following explanations, a quadcopter
drone will be considered. Moreover, the following considerations will be treated for
a three-dimensional frame, while this thesis is developed in a two-dimensional one.
Following the approach used in [14], the vehicle position and speed are defined
with respect to a world inertial frame W. Defined a vehicle body frame B, the
position vector is computed as the relative position of the drone body frame B
origin, fixed in the vehicle center of mass, expressed in the world inertial frame W.
Both frames are right-handed reference frames. The model speed vector is defined
as the derivative of the position vector in the given instant of time. Geometrically
speaking, given a point in the 3D space, the following relationship can be defined:
xB vAB,x xA
pB = y
B
= vAB · t + p A =
v
AB,y
· t + yA
(2.8)
zB vAB,z zA
Being the system working in discrete time, for a matter of notation and completeness,
the previous equation can be rewritten as follows:
where p(t + 1) and p(t) are the positions at time t + 1 and t, v(t) is the vehicle
speed at time t, and TS is the sampling time.
UAV orientation in the space is described with Cardan angles convention, a
particular representation of the Euler angles.
Remembering that the vehicle is described in a three-dimensional right-handed
reference frame, it is possible to name the rotations as follows:
Roll φ: Rotation around the drone longitudinal axis;
Pitch θ: Rotation around the drone transverse axis;
Yaw ψ: Rotation around the drone vertical axis passing for its center of mass.
These rotations are considered in the vehicle body frame, so, in order to correctly
translate information from the inertial world frame to the vehicle body frame it is
25
Background
direction). It is important to point out that, in order to not affect drone yaw,
the rotor on the same axis are coupled in the sense that whenever the speed
of a drone rotor is augmented for performing the desired maneuver, the one of
the opposite rotor is decreased;
Pitch: Similarly to how the roll maneuver is done, the pitch is performed by
increasing or decreasing the rotational speeds of the rotors of longitudinal axis
(i.e. the drone forward direction);
Yaw: This movement is performed by increasing the rotational speeds of a couple
of opposite rotors, while decreasing the ones of the other two rotors. In this
way, an overall imbalance of moments causes a rotation around the vertical
axis.
T −g 0 0 Az
27
Background
1
φ̇(t) = (Kφ φd (t) − φ(t)) (2.12)
τφ
1
θ̇(t) = (Kθ θd (t) − θ(t)) (2.13)
τθ
where the vehicle speed v is expressed as the derivative of the position vector
p, T is the mass normalized thrust, g represents the gravitational acceleration,
Ax ,Ay ,Az are the mass normalized drag coefficients, d is the external disturbance
vector, while τφ , Kφ , τθ , Kθ are the time constants and gains of the inner-loop
behavior for roll angle and pitch angle respectively, and R(φ, θ, ψ) is the rotation
matrix from W to B presented in Equation 2.14 (cosine and sine are marked with
c and s letters).
c(ψ)c(θ) c(ψ)s(φ)s(θ) − c(φ)s(ψ) s(φ)s(ψ) + c(φ)c(ψ)s(θ)
R(φ, θ, ψ) = c(θ)s(ψ) c(φ)c(ψ) + s(φ)s(ψ)s(θ) c(φ)s(ψ)s(θ) − c(ψ)s(φ)
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 −Ax 0 0 g 0
Ac = 0
0 0 0 −Ay 0 0 −g
0 0 0 0 0 −Az 0 0
0
0 0 0 0 0 − τ1φ 0
1
0 0 0 0 0 0 0 − τθ
28
Background
x is the state vector [pT , v T ,W φ,W θ]T , u is the input vector equal to [W φd ,W θd , T ]T
and d is the disturbance vector equal to [dx , dy , dz ]T . Entities marked with subscript
c are continuous time models.
Being the controller implemented in discrete time, system dynamics is discretized
as follows:
A = eAc Ts (2.16)
Ú Ts
B= Bc dτ (2.17)
0
Ú Ts
Bd = Bd,c dτ (2.18)
0
As advised by Kamel, Stastny, Alexis and Siegwart, control input should undergo
a feed-forward compensation before being applied to the system, in order to
compensate coupling and achieve better tracking performances [14].
30
Chapter 3
Software Implementation
In fact, whenever a new state is sampled as candidate child node in the chosen
state space, the node and its parent node are passed to the optimization class that
computes the trajectory for moving from the parent node to the sampled child. If
the sampled child satisfies specific characteristics, both states are transformed in
ROS poses and the MPC implemented logic is called for predicting the intermediate
poses and computing the relative cost of moving. If child pose does not match
particular characteristics, the class returns an infinite "cost-to-go", marking the
trajectory as unfeasible.
After the defined search time, the sub-optimal path (i.e. the path with the lowest
cost) is chosen as candidate path and then, exploiting again the MPC approach,
an optimized trajectory is returned. The proposed algorithm contains function for
simplifying the resulting sub-optimal path.
This thesis is developed using a two-dimensional state space, configuring OMPL for
sampling 2D poses in the the Special Euclidean Group with dimension two (SE(2)).
The implemented software is able to detect the presence of obstacles during the
path cost computation by exploiting the predictive capability of the MPC tool.
contains an important improvement for the path computation, that is the research
of an optimal path with respect to a given cost function c(t). The optimal motion
planning problem targets the minimization of a cost function c(t) for the feasible
path computation. In fact, each admissible trajectory is tagged with a real number
representing the relative cost for performing the desired motion. In solving the
optimal motion planning problem, the RRT* algorithm builds and maintains a tree
G = (V ; E) comprised of a vertex set V of state from Xf ree connected by directed
edges E ⊆ V × V [16].
In the following, a set of basic procedures is listed for introducing the RRT*
logic[17]:
Sampling : The first function to be introduced is the one devoted to the sampling
of states in the space. This function randomly samples a state zrand in the
robotic free space Xf ree ;
MPC Logic: motionCost X × X → R+ is the function that solves the optimiza-
tion problem defined in the MPC logic, given an initial and a final state, and
returns the cost of the optimized trajectory. If an obstacle is encountered
during the optimal trajectory computation or the final state does not satisfy
certain characteristics, this function returns an infinite cost, marking the
trajectory as unfeasible;
Nearest Neighbor: Given a state z ∈ X and a tree G = (V ; E), v = N earest(G, z)
is the function used for returning the nearest node in the tree G, in terms of
Euclidean distance, to the passed state z;
Collision Check: ObstacleF ree(x) function checks whether a path x : [0, T ] → X
lies within the obstacle-free region of state space. The previous sentence means
that each state of the resulting path belongs to the obstacles free state space
Xf ree : x(t) ∈ Xf ree , ∀t ∈ [0, T ];
Distance Computation: A function called computeDistance(x1 , x2 ), X × X →
R+ is the function that returns the Euclidean distance between two states in
the state space.
Node Insertion: InsertN ode(zcurrent , znew , G) is the function that adds the new
sampled node znew to V and creates an edge to connect the new state to the
current node zcurrent ∈ V as its parent. The already generated edge is added
to E and the cost of the trajectory for reaching the newer state is added to
the cost of the whole path up to znew . Whenever the trajectory for joining a
state has an infinite cost, the corresponding node is discarded.
The functioning of the RRT* algorithm is the same of RRT, with the only
difference that whenever a node is added as vertex, the "cost-to-go" from the start
34
Software Implementation
state up to the added node znew is increased by the cost of the trajectory for
reaching znew form its lowest cost near state in the vertex space V . In fact, it
is important to highlight the choice of the parent made by the algorithm. The
parent of a sampled state, according to RRT logic, is the nearest node in the graph,
instead, RRT* chooses the lowest cost parent according to the defined cost function,
from a set of near parent nodes. Initially, the sample is attempted to be connected
to its nearest vertex in the graph in the circular area of radius equal to ρ around its
nearest node, with ρ the Planner Range. Samples are performed in the whole robot
free space, but, whenever a state is randomly sampled in this space, if the sampled
state is farther to its nearest node than ρ, the parent nearest node connection is
attempted with a state on the same line joining the sampled node and its parent,
but at a distance equal to ρ.
Then, being Znear the set of near nodes to the sampled one, for each node znear in
this set, the motion cost between it and the sample is computed. Discovered the
near parent with the lowest cost of moving, the sample is connected to it and a
rewiring action is performed. For each sample znear ∈ Znear in the vicinity of znew ,
a connection check is done to see whether reaching znear via znew would achieve
lower cost than doing so view its current parent [16]. If this connection reduces
the total cost associated with znear , the tree is modified to make znew the parent of
znear .
An example of this state connection is shown in Figure 3.2.
35
Software Implementation
• f loat64 x position;
• f loat64 y position;
OMPL sampled states need to be translated from their native data structure to
the ROS Pose2D one. For doing that, a function, named SE2ToROSPose2D, is
developed. It exploits OMPL SE(2) state space methods that are automatically
able to transform states characteristics into double quantities, saved in the Pose2D
attributes:
Explaining and showing the translation form OMPL states to ROS Pose2D is
important because it is the first action performed by MPCOptimizationObjective
class.
37
Software Implementation
3.1.2 MPCOptimizationObjective
The novel feature of the proposed algorithm that differs from those presented in
the literature is the path cost computation, that exploits the MPC logic. For
accomplishing this task, a class named MPCOptimizationObjective is created.
This class, sets as default class for performing the RRT* optimization through
OMPL default setOptimizationObjective function, contains some methods needed
for properly solving the MPC optimization problem and for generating the desired
trajectory. OMPL automatically recalls two default functions for evaluating a
cost in the motion query. These functions must be defined in the optimization
class, and are named stateCost and motionCost. The former, evaluates the cost
of a state, while the latter evaluates the cost for moving from am initial state
to a final one arbitrarily defined in the state space. stateCost function does not
perform any computation and it always returns a null cost; for the purpose of this
thesis, in fact, it is not necessary to compute the cost of a single state, but it is
necessary to compute the cost of moving from a certain pose to another one in the
two-dimensional plan.
Particular attention is paid to the implementation of the motionCost function
devoted to compute the cost for approaching a final pose from an initial one,
exploiting the MPC logic. Moreover, this function is also exploited to define the
optimal trajectory for moving between two poses. Before presenting the functions
created for properly setting the MPC for the thesis purposes, it is mandatory to
introduce an important tool used for generating the MPC desired code.
As treated in Section 2.3, the biggest limit of the MPC approach is the computational
effort requested for solving the optimization problem, and higher the problem
complexity (i.e. the number of optimization variables), higher the computational
effort. This limit causes big time delays that are undesired in sample-based motion
planner. In fact, higher the speed of the cost computation, higher the number of
samples that the planner is able to analyze in a fixed amount of time and, concerning
the RRT* algorithm, higher the probability of obtaining a better solution.
For the already mentioned problems, it is decided to use CVXGEN for the MPC
code generation.
CVXGEN stands for Code Generation for Convex optimization. It is an online
interface used for generating fast custom code for small, QP-representable convex
optimization problems. As treated in [19], CVXGEN interface allows to describe
the problem to be optimized with a simple and powerful language, to automatically
create library-free C code for custom, high-speed solver that can be directly
downloaded from the CVXGEN website.
Additionally, for same optimization problems, the solution provided by CVXGEN is
twelve to one thousand-times faster than the solution offered by the most common
optimizers [20] (further details at Appendix C).
38
Software Implementation
Before showing the CVXGEN description of the problem, the optimization problem
is presented. The MPC problem is defined by inspiring to [14], where a MPC-based
trajectory tracking is developed using CVXGEN.
Assuming a disturbance free system model (i.e. d(t) = 0 ∀t ∈ [0, HP ]), the
optimization problem can be defined as:
P −1
1 HØ 2
min (xk − xref,k )T Qx (xk − xref,k ) + (uk − uk−1 )T R∆ (uk − uk−1 ) +
U,X
k=0 (3.1)
T
+ (xHP − xref,HP ) Qf inal (xHP − xref,HP )
spaces, but the reference trajectory is only computed for a x-y plan, being z position
and z speed assumed to be equal to zero.
In the following, the way state matrix A and input matrix B are filled is presented:
Listing 3.2: Drone model matrices definition.
1 Eigen : : MatrixXd A_continuous_time ( S t a t e S i z e , S t a t e S i z e ) ;
2 A_continuous_time = Eigen : : MatrixXd : : Zero ( S t a t e S i z e , S t a t e S i z e ) ;
3 Eigen : : MatrixXd B_continuous_time ( S t a t e S i z e , I n p u t S i z e ) ;
4 B_continuous_time = Eigen : : MatrixXd : : Zero ( S t a t e S i z e , I n p u t S i z e ) ;
5
9 s t d : : v e c t o r <double> d r a g _ c o e f f i c i e n t s _ ;
10
11 const double kGravity = 9 . 8 0 6 6 ;
12 d r a g _ c o e f f i c i e n t s _ . push_back ( 0 . 0 1 ) ;
13 d r a g _ c o e f f i c i e n t s _ . push_back ( 0 . 0 1 ) ;
14 d r a g _ c o e f f i c i e n t s _ . push_back ( 0 . 0 ) ;
15 A_continuous_time ( 0 , 3 ) = 1 ;
16 A_continuous_time ( 1 , 4 ) = 1 ;
17 A_continuous_time ( 2 , 5 ) = 1 ;
18 A_continuous_time ( 3 , 3 ) = −d r a g _ c o e f f i c i e n t s _ . a t ( 0 ) ;
19 A_continuous_time ( 3 , 7 ) = kGravity ;
20 A_continuous_time ( 4 , 4 ) = −d r a g _ c o e f f i c i e n t s _ . a t ( 1 ) ;
21 A_continuous_time ( 4 , 6 ) = −kGravity ;
22 A_continuous_time ( 5 , 5 ) = −d r a g _ c o e f f i c i e n t s _ . a t ( 2 ) ;
23 A_continuous_time ( 6 , 6 ) = −1.0 / r o l l _ t i m e _ c o n s t a n t _ ;
24 A_continuous_time ( 7 , 7 ) = −1.0 / pitch_time_constant_ ;
25
26 model_A_ = ( prediction_sampling_time_ ∗ A_continuous_time ) . exp ( ) ;
27
28 Eigen : : MatrixXd integral_exp_A ;
29 integral_exp_A = Eigen : : MatrixXd : : Zero ( S t a t e S i z e , S t a t e S i z e ) ;
30 const int count_integral_A = 1 0 0 ;
31
32 B_continuous_time ( 5 , 2 ) = 1 . 0 ;
33 B_continuous_time ( 6 , 0 ) = r o l l _ g a i n _ / r o l l _ t i m e _ c o n s t a n t _ ;
34 B_continuous_time ( 7 , 1 ) = pitch_gain_ / pitch_time_constant_ ;
35 for ( int i = 0 ; i < count_integral_A ; i ++)
36 {
37 integral_exp_A += ( A_continuous_time ∗
prediction_sampling_time_ ∗ i / count_integral_A ) . exp ( ) ∗
prediction_sampling_time_ / count_integral_A ;
38 }
39 model_B_ = integral_exp_A ∗ B_continuous_time ;
13 Q. s e t Z e r o ( ) ;
14 Q_final . s e t Z e r o ( ) ;
15 R. s e t Z e r o ( ) ;
16 R_delta . s e t Z e r o ( ) ;
17
18 Q. b l o c k ( 0 , 0 , 3 , 3 ) = q_position_ . a s D i a g o n a l ( ) ;
19 Q. b l o c k ( 3 , 3 , 3 , 3 ) = q_velocity_ . a s D i a g o n a l ( ) ;
20 Q. b l o c k ( 6 , 6 , 2 , 2 ) = q_attitude_ . a s D i a g o n a l ( ) ;
21 R = r_command_ . a s D i a g o n a l ( ) ;
22 R_delta = r_delta_command_ . a s D i a g o n a l ( ) ;
23 Q_final = Q;
24 for ( int i = 0 ; i < 1 0 0 0 ; i ++)
25 {
26 Eigen : : MatrixXd temp = ( model_B_ . t r a n s p o s e ( ) ∗ Q_final ∗
model_B_ + R) ;
27 Q_final = model_A_ . t r a n s p o s e ( ) ∗ Q_final ∗ model_A_ − (
model_A_ . t r a n s p o s e ( ) ∗ Q_final ∗ model_B_ ) ∗ temp . i n v e r s e ( ) ∗ (
model_B_ . t r a n s p o s e ( ) ∗ Q_final ∗ model_A_) + Q;
28 }
All the matrices in the implemented code are defined as Eigen matrices of double
quantities, but CVXGEN corresponding parameters must be passed as attributes
of an object in vector form. For doing that, cast operations are performed:
41
Software Implementation
After having initialized the necessary parameters and having transformed the
sampled states in ROS Pose2D, the samples evaluation can be performed.
Points sampled in the plan portion defined by the perpendicular to the initial pose
yaw angle in the opposite direction to the initial pose orientation are marked with
an infinite cost. The same happens for the final sampled poses with orientations
offset more than sixty degrees with respect to the line joining initial and final
poses. This samples selection is done to exclude non-promising samples and, then,
avoiding to spend time computing unnecessary MPC problem solutions, considering
that it is a-priori known that initial and final poses with opposite directions may
cause bad trajectories in terms of cost. This is a sort of heuristic used to speed-up
the algorithm.
For doing that, a function inside MPCOptimizationObjective class named motion-
CostHeuristic2D is implemented. This function is unprecedented named heuristic.
"Heuristics are problem-solving methods that use shortcuts to produce good-enough
solutions given a limited time frame or deadline. Heuristics are flexibility tech-
niques for quick decisions, particularly when working with complex data", this is
the definition given by James Chen on Investopedia website, so our function aims
to speed-up the optimal solution computation, avoiding to evaluate non-optimal
trajectories, but it indirectly increases the quality of the computed solution; in
fact, motionCostHeuristic2D allows to sample and evaluate an higher number of
possible "good trajectories" states, while neglecting those causing "bad trajectories".
The result of this function is a Boolean variable sets as true whenever a goal pose
does not satisfy predefined characteristics, and cost computation is immediately
stopped returning an infinite cost; otherwise, if false, the MPC solver, the input
limits, the initial position and the reference states are set and the optimization
problem solution is computed.
It is decided not to limit the states, being the sampled child nodes quite close to
parent nodes, so short motions are supposed to be predicted by the MPC.
Concerning the setting of the solver characteristics and of the limits, two functions
are created:
42
Software Implementation
7 s e t t i n g s . verbose = dont_print_solver_output ;
setSolver function performs a default configuration of the MPC, but the de-
sired CVXGEN generated solver parameters could be customized. settings.eps is
used for setting the solver duality gap for returning the MPC problem solution:
solver will not declare a problem converged until the duality gap is known to be
bounded by eps; settings.resid_tol command sets the residue tolerance value for
returning the solver solution: solver will not declare a problem converged until
the norm of the equality and inequality residuals are both less than resid_tol.
settings.max_iters is used for setting the maximum number of iterations the
MPC solver is allowed to run before returning a solution if eps and resid_tol are
not reached. settings.verbose is used for making the solver able to output or not
output information about each iteration, including residual norms, duality gap
bounds and step sizes. By properly adjusting the setting parameters of the MPC
solver, solution computation can be speeded-up considerably (further information
available on CVXGEN website). For the purpose of this thesis, it is decided to
keep these parameters at their default values. setLimits function defines the input
values bounds. Limits are set according to [14].
Of particular interest is the reference trajectory xref,k used by the MPC opti-
mization with k ∈ [0, HP ], defined by line-circumference interpolations, with an
iterative process. Given an initial and a final pose, defined a line joining the two
poses, interceptions line-circumferences centred in the initial pose are calculated,
by increasing the circumference radius iteration after iteration, finding out newer
reference positions farther to the initial pose. When the interpolated pose is near
to the final pose, the successive references are calculated with interceptions cir-
cumferences centred in the start pose-final speed direction line, along the speed
direction.
The reference speeds are set by multiplying the speed module, constant and a-priori
defined, for sine and cosine of an angle that could be the joining line inclination
angle, in case of reference points on the poses joining line, or the final pose orienta-
tion in the other case.
Setting as initial states the initial position and as initial speed the speed vector
with predefined module and direction given by the initial pose orientation, the
43
Software Implementation
44
Software Implementation
45
Software Implementation
matrices cells product. These products are added to an incremental double variable,
representing the cost.
Listing 3.12: computeCost3 function code fragment.
1 double c o s t = 0 . 0 ;
2 for ( unsigned i =1; i <i t ; i ++)
3 {
4 for ( unsigned j =0; j <I n p u t S i z e ; j ++)
5 {
6 c o s t=c o s t+pow ( ( matrix_u ( i , j )−matrix_u ( i −1, j ) ) , 2 ) ∗ R_delta (
j ,j);
7 }
8 }
9
This cost computation process is performed many times for each sampled state of
RRT*, so it is logical to expect that the cost computation is continuously performed
until the solve time. If, after this period of time, a path joining the desired start
and goal poses in the two-dimensional plan is found, it is the one that minimizes
the "cost-to-go" function for reaching the desired pose in the space, according to the
motion cost definition. Being the MPC optimization computationally expensive,
the algorithm computes few states in the defined search time, so the path will not
be the global optimal one, while the one with the lowest cost between the evaluated
paths for reaching the goal. This limit is always present in RRT* logic; in fact, the
global optimal solution is obtained only when search time approaches infinite. The
limitation is emphasized in the deployed algorithm because of the time needed for
evaluating a single trajectory through MPC approach.
After the computation of the path using RRT*, the returned path consists in a
sequence of motions defined by the MPC. However, these motions are not perfectly
aligned due to uncertainties in the MPC optimization. In order to have a continuous
trajectory between the start and the goal pose, the MPC optimization is used to
define the whole trajectory.
47
Software Implementation
Differently of what is done for the motion cost computation, the trajectory compu-
tation function, named trajectoryGenerator, introduces a little modification with
respect to the previous function. These function receives as inputs two states that
are successively transformed into ROS Pose2D data for performing the desired
operations, and a vector of ROS Pose elements. The MPC logic is initialized in
the same way it is done for the motionCost method; the only difference is that,
at each iteration successive the first one, the initial pose to be connected to the
corresponding goal pose is the one calculated by the MPC logic at the previous
iteration. In this way, possible orientation errors as well as position errors are
corrected by the MPC tool, returning a continuous final path. trajectoryGenerator
and motionCost are structured in the same way; for a single couple of poses, MPC
problem is solved since the Euclidean distance between the first optimized state and
the goal pose is greater than a predefined quantity or since a predefined maximum
number of iterations is not reached.
However, at the end of each optimization phase, the first optimized pose x1 ∈ R8 is
saved into the vector of poses passed as input. Trajectory generation is performed
after that the lowest cost path is obtained. The sets of states passed by the planner
are assumed to be trajectory feasible, being the unfeasible nodes discarded in the
cost computation phase. After that each of the couples is passed to trajectoryGener-
ator, the optimized trajectory and the whole tree constructed by this algorithm are
published on the corresponding Topics and visualized with RViz tool. An example
of the obtained trajectory is presented in Figure 3.3
48
Software Implementation
The search tree is marked with a blue colour, while the optimized trajectory is
represented by a set of pink arrows. As clearly shown in Figure 3.3, the algorithm
samples states only in the robotic free space. The constructed tree never enters the
obstacle region, highlighted with the black colour, and it never exceeds the map
outline.
Another important aspect to be highlighted is the fact that the computed trajectory
is not straight. This is due to the random orientation of the sampled states. The
algorithm computes the cost for reaching a state that could have any orientation in
the space. It is important to remember that wrong samples in terms of orientation
are discarded, but those with an acceptable orientation are always taken into
consideration, even if they are not optimal for reaching the goal pose of the motion
query. These states are marked with an higher cost because of their distance from
the desired reference, designed as a straight line, and for their longer distance and
bigger overall rotation. By increasing the number of samples, the probability of
sampling lower cost states is higher, but it is not sure that the solution obtained in
the given search time is perfectly straight. It could happen that an intermediate
state in the graph has an high cost, so its trajectory is not "optimal", but in the
given solve time, no other solution with lower cost is found.
It must not be forgotten that, even if the final graph contains high cost nodes, the
resulting trajectory is supposed to be kinematically and dynamically "optimal" for
the UAV, being computed by an MPC that exploits the vehicle dynamic model
with constraints in terms of UAV input signals. Being more precise, the resulting
trajectory is always the optimal one between any couple of states in the resulting
graph.
For all the mentioned reasons, timing is a crucial topic for this algorithm. The
quality of the resulting trajectory strongly depends on the sampled states orienta-
tions.
With the aim of improving the quality of the planner, some simplifications are
done exploiting default OMPL functions. In particular, reduceVertices function
is applied after the optimal path computation and before the MPC trajectory
generation. This function attempts to remove vertices from the passed path while
keeping it valid by creating connection between non-consecutive way-points for
"short-cutting" the path when possible. Other simplifications are offered by OMPL,
but it is important to say that the simplifications compromise the quality of the
algorithm; some nodes, that are optimally oriented, may be deleted for achieving a
simpler resulting path, but not optimal in terms of trajectory regularity. Anyway,
simulation results are reported in the Section 4.
49
Software Implementation
It is decided to use PX4 for the final simulation because of its capability of in-
terfacing with ROS. In fact, PX4 communicates with external frameworks using
the MAVLink communication protocol [22]. In order to enable the communication
between PX4 and ROS, the ROS community developed the mavros package, that
converts ROS messages into MAVLink messages, and the opposite.
In particular, as showed in Figure 3.4, UDP port 14540 allows the communication
1
Definition courtesy from PX4 Autopilot website.
2
Image courtesy from PX4 Autopilot website.
50
Software Implementation
with ROS. Exploiting the mavros Topics and the ROS services offered by MAVLink,
it is possible to publish missions described by a set of points in the space on PX4
to perform realistic simulations. In order to publish trajectory states with a proper
syntax on the mavros corresponding Topic, a ROS Node is implemented.
This node, named drone_node contains a ROS Service and a ROS Subscriber. The
subscriber subscribes to the optimized trajectory Topic and a callback to that Topic
is implemented for making the node able to react to any trajectory publication.
It is decided to publish data in the form of UAV Waypoints list. MAVLink exploits
a mavros/mission/waypoints Topic for receiving data of this type. Each element of
this list is a Waypoints message containing attributes for position and other pa-
rameters to be passed to PX4 for configuring the autopilot (for further information
referring to Appendix E). Callback function is intended for translating ROS Pose
in Waypoints. Waypoints are set for performing UAV arming, takeoff, trajectory
following and landing, depending on the passed pose set.
Mavlink Waypoints interface needs global GPS coordinates for working properly, so
local positions in meter are translated into GPS data. The function that performs
this operation translates Cartesian coordinates in GPS ones referring to a fixed
origin position.
51
Chapter 4
53
Simulation and Testing
length in meters, Cost2 is the weight cost of the total rotation in degrees necessary
for performing the motion, while Cost3 is the weight of the cost obtained computing
the optimization function used by the MPC, solved with the trajectory set of state,
reference and input.
Before proceeding with testing, it is necessary to introduce two parameters that
have not been taken into consideration yet, but that are really important for
obtaining good planning results. The first one is the Planner Range; it is the radius
of the circle centered in the states in which RRT* connects newer states; whenever
a sample is randomly sampled at a distance greater than the Planner Range, it
is substituted with a newer sample along the line joining the initial sample, but
Planner Range far from its nearest node in the graph. This radius decreases with
the increasing of the sampled states, as properly explained by Frazzoli and Karaman
in [17], to converge to the sub-optimal path solution, so, for this reason, it is fixed
equal to five meters, but decreases while the planning proceeds. Another important
parameter to introduce is the Planner Goal Bias, that represents the probability of
sampling the goal state in the whole Solve Time. Its value is fixed equal to 5%,
meaning the goal state is sampled five out of one hundred times during the graph
construction phase; higher value are counterproductive in terms of planner quality.
For the way the proposed algorithm is designed, RRT* Solve Time does not
represent the total time it searches for a solution. In fact, for analyzing the
evolution of the graph constructed by the planner, the solving phase is divided in
ten phases with the same duration equal to the Solve Time. At the end of each
phase, the cost of the path up to that time is printed for seeing it diminishes cycle
after cycle.
Because of the probabilistic nature of RRT* algorithm, each test is performed
five times and the different path costs and path lengths are reported on a single
label, while only the most significant trajectory out of five is figured out (i.e. the
trajectory that best represents the limitations or advantages introduced by the
55
Simulation and Testing
Test 1
The first test is performed with the parameters set labelled at Table 4.1.
Parameter Set
Cost1 1.0
Cost2 1.0
Cost3 0.1
Prediction Sampling Time 0.1s
Planner Range 5m
Solve Time 6s
Total Solve Time 60s
UAV Speed Module 3.0m/s
This value is too high for the imposed input constraints, so bad trajectories are
expected.
Simulation Results
Simulation Number Path Cost Path Length
First Simulation 1287.763 46.380m
Second Simulation 1250.149 42.837m
Third Simulation 1276.167 42.800m
Fourth Simulation 1155.827 54.519m
Fifth Simulation 1307.899 40.382m
Average 1255.561 45.384m
56
Simulation and Testing
As clearly shown in Figure 4.2, this configuration of the planner is not effective.
The UAV Speed Module, assumed constant for the whole motion, is too high with
respect to the imposed input constraints: the goal pose orientation is never obtained
and long trajectories are planned. Adopting a set of constraints that is optimal for
the used trajectory tracking logic on which the designed MPC tool is based, it is
decided to decrease the speed of the UAV during the planning instead of changing
the input constraints. Another possible approach is adding state limits directly
in the MPC optimization problem, but this addiction increases the complexity of
the problem, slowing down the solution computation and the overall algorithm
performances.
Test 2
For the previously explained reasons, this test is performed by decreasing the UAV
Speed Module from 3.0m/s to 2.0m/s.
The quality of the planner increases a lot with the new UAV Speed Module; the
costs of the new trajectories are less than half of those obtained from the previous
parameter set, and as a consequence, the total lengths of the computed paths are
reduced. Decreasing again UAV Speed Module is counterproductive because the
planner has to guarantee good motion performances, so lower values of speed are
not taken into consideration.
The trajectories computed by the proposed algorithm in this test set are quite
good; however, they are quite far from the optimal; the length of the path is high
and several useless curves are performed.
57
Simulation and Testing
Parameter Set
Cost1 1.0
Cost2 1.0
Cost3 0.1
Prediction Sampling Time 0.1s
Planner Range 5m
Solve Time 6s
Total Solve Time 60s
UAV Speed Module 2.0m/s
Simulation Results
Simulation Number Path Cost Path Length
First Simulation 570.945 24.079m
Second Simulation 799.445 28.477m
Third Simulation 565.249 29.308m
Fourth Simulation 690.262 24.998m
Fifth Simulation 572.070 25.230m
Average 639.594 26.418m
58
Simulation and Testing
Test 1
For the previously explained reasons, taking into consideration the rotation of the
UAV seems useless. Indeed, the presence of this cost contribution is ineffective for
the optimal solution computation. Sharp corners are marked with high cost in
terms of MPC function because of the smooth reaction due to input limitations that
causes "slow" maneuvers for riding the corner; so, higher the number of rotations in
the trajectory, higher the cost in terms of MPC function due to state errors with
respect to the reference as well as the input variations.
So, the first test is done with a null weight of the cost function that takes into
consideration the UAV rotation during the motion.
Parameters Set
Cost1 1.0
Cost2 0.0
Cost3 0.1
Prediction Sampling time 0.1s
Planner Range 5m
Solve Time 6s
Total Solve Time 60s
UAV Speed Module 2.0m/s
The performances of the algorithm following the first modification of the weights
look quite interesting, as clearly shown in Figure 4.4. The generated trajectories
are smooth, but another limit is met: being the MPC relative cost dominant with
respect to the length cost, it could happen, and it is clearly observable in Table 4.6,
59
Simulation and Testing
Simulation Results
Simulation Number Path Cost Path length
First Simulation 281.131 28.495m
Second Simulation 277.422 20.413m
Third Simulation 336.692 22.967m
Fourth Simulation 275.649 26.753m
Fifth Simulation 327.581 25.707m
Average 299.695 24.867m
that the lowest cost trajectory is the longest one, being the quality of the motion
the predominant parameter in the optimization problem.
Test 2
In this test, the best relative weights between the MPC optimization function and
the path length in the cost computation are discussed.
For giving bigger importance to the path length, its cost is augmented of ten times
with respect to the previous test sets. Having the weighted MPC cost a dimension in
the order of hundreds, multiplying by 10 the path makes the two costs comparable
for the final cost value. Higher values in terms of cost are expected, but they do not
have to be compared with the ones of the previous test sets: another cost function
is introduced whenever the relative weights in the cost function change.
The new test parameters set is showed in Table 4.7
60
Simulation and Testing
Parameters Set
Cost1 10.0
Cost2 0.0
Cost3 0.1
Prediction Sampling time 0.1s
Planner Range 5m
Solve Time 6s
Total Solve Time 60s
UAV Speed Module 2.0m/s
Simulation Results
Simulation Number Path Cost Path length
First Simulation 543.601 23.201m
Second Simulation 509.132 22.436m
Third Simulation 528.185 23.662m
Fourth Simulation 422.044 23.590m
Fifth Simulation 454.620 22.418m
Average 491.516 23.061m
At the end of this test it is clear that, with the current parameter set, the
algorithm discovers shorter good shape trajectories. The aspect that could be
61
Simulation and Testing
Test 1
This test set aims to demonstrate that, doubling the RRT* Solve Time, the trajec-
tories discovered by the planning algorithm converges to the optimal in terms of
cost function. The cost weights remain unchanged with respect to the previous
test set, while the only parameter that is changed is the Solve Time, that becomes
of 12.0s.
Initial Parameters
Cost1 10.0
Cost2 0.0
Cost3 0.1
Prediction Sampling time 0.1s
Planner Range 5.0m
Solve Time 12.0s
Total Solve Time 120.0s
UAV Speed Module 2.0m/s
This test set does not present unexpected results. With higher Solve Time value,
the probability of obtaining an optimal solution is higher. For the whole test set,
in fact, low cost and short trajectories are planned, showing the convergence of the
resulting path to the optimal one with the time increasing.
62
Simulation and Testing
Simulation Results
Simulation Number Path Cost Path length
First Simulation 503.885 21.204m
Second Simulation 470.008 23.184m
Third Simulation 421.392 22.485m
Fourth Simulation 449.071 21.206m
Fifth Simulation 433.744 22.388m
Average 455.62 22.093m
Test 2
In order to test the effectiveness of the proposed algorithm, the second test of
this section shows the trajectory-find capability of the implemented logic in small
amount of time. The algorithm configuration parameters of this test are reported
in Table 4.11.
By inspecting the results labelled in Table 4.12, it could be seen that the used set
of cost function weights allows to plan good trajectories even with few Solve Time.
The overall length and cost of the motion paths are similar to the ones obtained
in the previous test set. This fact demonstrates that, with the proper trade-off of
the algorithm parameters, good solutions can be found even in small amount of
time. Moreover, until now, the effects of the path simplifier have not been taken
into account, so it is interesting to understand if this kind of simplification could
be useful in terms of final solution.
63
Simulation and Testing
Initial Parameters
Cost1 10.0
Cost2 0.0
Cost3 0.1
Prediction Sampling time 0.1s
Planner Range 5m
Solve Time 1s
Total Solve Time 10s
UAV Speed Module 2.0m/s
Simulation Results
Simulation Number Path Cost Path length
First Simulation 433.859 22.936m
Second Simulation 421.449 23.607m
Third Simulation 635.237 27.800m
Fourth Simulation 570.987 24.222m
Fifth Simulation 452.389 25.166m
Average 502.784 24.746m
64
Simulation and Testing
Simulation Results
Simulation Number Path Cost Path length
First Simulation 430.465 22.973m
Second Simulation 528.295 26.021m
Third Simulation 562.702 22.536m
Fourth Simulation 535.964 22.402m
Fifth Simulation 580.709 22.154m
Average 527.627 23.217m
Table 4.13: Solve Time test 3: simulation results with path simplifier.
As clearly shown in Table 4.13, the main advantage of applying a path simplifi-
cation in the presence of few samples in the search space is the fact that shorter
65
Simulation and Testing
paths can be obtained, being longer trajectories "cut" by the path simplifier. In fact,
it could happen that, with few samples, the algorithm returns a long trajectory; the
probabilistic nature of the algorithm does not ensure to discover always a smooth
and short path in a small search time. Removing non-optimum vertices in terms of
trajectory length solves this problem. Moreover, RRT* discovered path is passed
to the MPC logic for computing the final trajectory, ensuring a good shape final
solution. However, even if this solution looks pretty good for solving local motion
queries, it is decided to plan for one minute, and, then, applying the path simplifier.
Parameters Set
Cost1 10.0
Cost2 0.0
Cost3 0.1
Prediction Sampling time 0.1s
Planner Range 5m
Solve Time 6s
Total Solve Time 60s
UAV Speed Module 2.0m/s
Simulation Results
Simulation Number Path Cost Path length
First Simulation 534.707 21.191m
Second Simulation 544.864 22.346m
Third Simulation 543.272 20.680m
Fourth Simulation 470.754 22.212m
Fifth Simulation 505.283 20.935m
Average 519.776 21.473m
The application of the path simplifier to a good discovered path does not produce
excessive changes in terms of quality. Nevertheless, applying a path simplification is
helpful for reducing the length of the final trajectory when the algorithm discovers
relative high cost solutions. Because of the probabilistic nature of the algorithm,
66
Simulation and Testing
the final solution strongly depends on the quality of the sampled states, so, in order
to force the final trajectory to be straight, the use of path simplifier is appreciable
in this sense.
Summarising, after this first testing phase, the overall best solution with a Solve
Time of sixty seconds, where the rotation cost is neglected and the MPC cost and
the length cost are comparable in terms of relative values, is the one analyzed in this
last section. In addiction, for the already explained reasons, the path simplification
is kept valid for planning the final trajectory.
The analyses performed in this section are quite different from those of the previous
test sets.
Here, the convergence of the cost function to the optimal is showed with a chart
where each of its points represents the average path cost over the five tests in a
precise instant of time. This chart is important for figuring out the diminishing of
the path cost over time, proving that the algorithm tries to minimize the defined
cost function. Moreover, another chart is introduced; it shows the average over
the five tests of the number of samples in the constructed graph in a precise time
instant in order to show that the addiction of vertices to the graph constructed
by RRT* slows down while time passing. So, each point in the charts represents
the average over the five tests of the costs and of the number of samples in that
precise time instant.
It could happen that, being the analyzed map quite big, the saturation of the
vertices number is not reached in the imposed Solve Time.
950
900
Path Cost
850
800
750
700
650
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
68
Simulation and Testing
1,400
Number of Vertices
1,200
1,000
800
600
400
200
0
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
Figure 4.11: Example of solution in the first narrow and constrained environment.
Nothing unexpected is observed in this test; as clearly shown in Figure 4.11, the
goal pose is reached while properly moving inside the narrow passage.
orientation of the goal, the algorithm may return the best route for reaching that
desired pose in the space.
950
900
850
800
750
700
650
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
Evolution over time of the average number of vertices in the graph.
1,600
Number of Vertices
1,400
1,200
1,000
800
600
400
200
0
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
The algorithm behaves exactly as expected. As can be seen in Figure 4.13, the
70
Simulation and Testing
Figure 4.13: Example of solution in the second narrow and constrained environ-
ment.
logic privileges the trajectories that approach the final pose in the right direction,
and not those passing from the other pathway that need a final rotation.
Simulation Results
Simulation Number Path Cost Path Length Number of Vertices
First Simulation 407.838 22.63m 1680
Second Simulation 493.952 22.63m 1837
Third Simulation 422.915 22.63m 1877
Fourth Simulation 434.476 22.63m 1856
Fifth Simulation 430.796 22.63m 1800
Average 437.995 22.63m 1810
state if there are not obstacles along the straight line joining them.
Another interesting test that is useful to be performed is the test in a map with
two obstacles. This test aims to demonstrate the effectiveness of the planner in
open environments where the path is imposed. In fact, in the map used for this
test, reported at Figure 4.15, the motion of the UAV is forced to be through two
obstacles after having turned around one of them. Experimental results considering
the same data as before are plotted in the following.
72
Simulation and Testing
850
800
750
700
650
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
Evolution over time of the average number of vertices in the graph.
1,800
Number of Vertices
1,600
1,400
1,200
1,000
800
600
400
200
0
0 6 12 18 24 30 36 42 48 54 60
Instant of Time [s]
73
Simulation and Testing
Figure 4.16: Example of a solution in the two obstacles avoidance test map.
This test does not present peculiarities to be mentioned. The algorithm behaves
exactly as expected, trying to minimize the distance for approaching the goal while
avoiding the obstacles encountered during the motion. Analyzing Figure 4.16, it is
possible to appreciate the work of the path simplifier; when no turning action is
requested, the simplifier directly joins states for obtaining a "short-cut" of the path.
In this way, perfectly straight trajectories can be obtained. For the path sections
close to a corner, it is possible to see that no simplification in terms of motion is
done and the trajectory is that planned by the RRT* algorithm exploiting the UAV
dynamic model.
Figure 4.17b, reporting an example of SITL testing, the trajectory planned by the
proposed logic can be handled and performed by PX4 autopilot, resulting in the
vary same path computed by the algorithm. In this way, it is possible to state that
the implemented trajectory planner can be used for real UAVs.
Figure 4.17: Comparison between the trajectory planned on RViz and the one
performed by PX4 autopilot for the SITL testing.
75
Simulation and Testing
Figure 4.18: Example of the orientation error. The green arrow represents the
goal pose that is not reached in terms of heading.
77
Chapter 5
Conclusions
The main contribution of this thesis focuses on the development of a trajectory
planning algorithm. The proposed logic, based on the RRT* planning algorithm,
provides good performances in terms of quality of the final solution.
The MPC logic developed for accomplishing the desired tasks is really useful for the
path computation; even if this prediction is really expensive in terms of computer
resources and time, exploiting the system model, each sampled state is inserted as
vertex in the constructed graph and labelled with a cost only if the predicted motion
for reaching it is feasible. In this way, the resulting optimal path is composed by
states whose connections are previously checked by the MPC logic. The application
of the MPC tool after the optimal path computation performed by the RRT*
algorithm allows to obtain a resulting smooth and continuous trajectory that is
optimal for the UAV, being calculated on the basis of its dynamical model together
with the imposed input constraints.
As already explained in Section 4.5, this trajectory planner is designed for working
locally and performing small motions; this logic is supposed to be run several times
for performing small sequential moves between the desired starts and goals, so,
even the presence of small final orientation errors with respect to the desired goal
poses are accepted, being completely compensated by the successive trajectory.
Furthermore, the SITL testing phase shows that this planning algorithm can be
applied to real UAV. The computed trajectories are not only marked as a sequence
of states in the space with a given speed, but they are also marked with a set of
input that could be passed to a real UAV. It is important to point out that the
input sets returned by the algorithm need some arrangements for being applied in
a real world; gravity and accelerations need to be compensate for achieving precise
trajectories.
79
Conclusions
• The first possible improvement refers to the space dimension. This thesis
project is designed for working in a two-dimensional space; so the variables
sampled by the RRT* algorithm in each sample are three, two positions and
one orientation in the space. Changing the state space from SE(2) to SE(3)
allows to extend the planning capabilities to the three-dimensional space,
but it means adding one positional contribution and two orientations at each
sample data-structure, increasing considerably the complexity of the algorithm.
Moreover, the presence of a third positional coordinate makes a bigger amount
of samples necessary for obtaining a good final trajectory, so timing limitations
have to be taken into consideration in order to provide planning effectiveness;
• Another possible improvement is the use of Dubins path for the reference
trajectories definition. This different kind of approach, that could be used
even in SE(3) state space, allows to obtain better curvatures with respect to
the line-circumference interpolation. However, this different reference is not
sure to be better than the implemented interpolation technique; close start
and goal states with very different orientations that are attempted to be joined
in the space may need long curvatures for approaching the final orientation.
• Concerning the time performances of the planner, it is possible to change the
MPC logic. Instead of returning only the first state calculated by the MPC, it
is possible to return more than one state from each optimization cycle. In this
way, the number of solving iterations can be considerably decreased, making
the algorithm able to sample an higher number of states. On the contrary,
the quality of the planning may decrease and this different approach cannot
be considered an MPC anymore.
• The last improvement that is proposed is about the possibility of improving the
quality of the planning procedure by inserting disturbances directly inside the
UAV state space representation. By using an Extended Kalman Filter (EKF),
disturbances prediction can be done, increasing the overall quality of the
planner. Even if the estimation phase is quite heavy in terms of computational
effort, it is the best possible way of modelling the UAV dynamics.
In conclusion, the proposed planner represents an efficient way of planning
the UAV trajectory inside an unknown two-dimensional environment. The use
of the MPC logic together with the RRT* algorithm turned out to be a good
planning strategy, even with its timing limitations. This technology presents several
limitations and possible improvements that need to be considered step-by-step
during the developing phase for preserving the planning effectiveness.
80
Appendix A
CVXGEN Code
82
Appendix B
text.launch File
83
text.launch File
84
Appendix C
CVXGEN Statistics
Figure C.1 shows the time needed by several optimization methods for solving the
same Model Predictive Control problem presented in [19], where m is the number
of input, n is the number of state variables and T is the prediction horizon.
Figure C.1: Computation time for finding the solution to the same problem by
different solvers.
85
Appendix D
Euclidean Distance
The Euclidean distance between two points is the length of the straight line joining
the points.
In Cartesian coordinates, given two points p = [p1 , p2 , . . . , pn ] and q = [q1 , q2 , . . . , qn ]
belonging to the Euclidean n-space, the Euclidean distance of the points can be
computed exploiting the Pythagorean theorem:
ñ
d(p, q) = (q1 − p1 )2 + (q2 − p2 )2 + · · · + (qn − pn )2
For the purpose of this thesis, being developed in 2-D space, the previous formula
can be re-written for n = 2:
ñ
d(p, q) = (q1 − p1 )2 + (q2 − p2 )2
86
Appendix E
mavros_msgs/Waypoint
Message
87
Bibliography
[1] Jacob T Schwartz and Micha Sharir. «On the “piano movers’” problem I.
The case of a two-dimensional rigid polygonal body moving amidst polygonal
barriers». In: Communications on pure and applied mathematics 36.3 (1983),
pp. 345–398 (cit. on p. 1).
[2] Alessandro Gasparetto, Paolo Boscariol, Albano Lanzutti, and Renato Vidoni.
«Path Planning and Trajectory Planning Algorithms: A General Overview».
In: Mechanisms and Machine Science 29 (Mar. 2015), pp. 3–27. doi: 10.
1007/978-3-319-14705-5_1 (cit. on p. 1).
[3] Chad Goerzen, Zhaodan Kong, and Bernard Mettler. «A survey of motion
planning algorithms from the perspective of autonomous UAV guidance». In:
Journal of Intelligent and Robotic Systems 57.1-4 (2010), p. 65 (cit. on p. 2).
[4] Yoshiaki Kuwata, Gaston A Fiore, Justin Teo, Emilio Frazzoli, and Jonathan
P How. «Motion planning for urban driving using RRT». In: 2008 IEEE/RSJ
International Conference on Intelligent Robots and Systems. IEEE. 2008,
pp. 1681–1686 (cit. on p. 2).
[5] František Duchoň, Andrej Babinec, Martin Kajan, Peter Beňo, Martin Florek,
Tomáš Fico, and Ladislav Jurišica. «Path planning with modified a star
algorithm for a mobile robot». In: Procedia Engineering 96 (2014), pp. 59–69
(cit. on p. 5).
[6] Emilio Frazzoli, Munther A Dahleh, and Eric Feron. «Real-time motion
planning for agile autonomous vehicles». In: Journal of guidance, control, and
dynamics 25.1 (2002), pp. 116–129 (cit. on p. 5).
[7] Reagan L Galvez, Elmer P Dadios, and Argel A Bandala. «Path planning for
quadrotor UAV using genetic algorithm». In: 2014 International Conference
on Humanoid, Nanotechnology, Information Technology, Communication and
Control, Environment and Management (HNICEM). IEEE. 2014, pp. 1–6
(cit. on p. 6).
88
BIBLIOGRAPHY
[8] Safaa H Shwail and Alia Karim. «Probabilistic roadmap, A*, and GA for
proposed decoupled multi-robot path planning». In: Iraqi Journal of Applied
Physics 10.2 (2014), pp. 3–9 (cit. on p. 6).
[9] Guanjun Ma, Haibin Duan, and Senqi Liu. «Improved ant colony algorithm
for global optimal trajectory planning of UAV under complex environment.»
In: IJCSA 4.3 (2007), pp. 57–68 (cit. on p. 7).
[10] Sertac Karaman and Emilio Frazzoli. «Sampling-based algorithms for optimal
motion planning». In: The international journal of robotics research 30.7
(2011), pp. 846–894 (cit. on p. 10).
[11] Morgan Quigley, Josh Faust, Tully Foote, and Jeremy Leibs. «ROS: an
open-source Robot Operating System». In: (cit. on p. 13).
[12] Yu-Geng XI, Dewei Li, and Shu Lin. «Model Predictive Control — Status
and Challenges». In: Acta Automatica Sinica 39 (Mar. 2013), pp. 222–236.
doi: 10.1016/S1874-1029(13)60024-5 (cit. on p. 21).
[13] John F Keane and Stephen S Carr. «A brief history of early unmanned
aircraft». In: Johns Hopkins APL Technical Digest 32.3 (2013), pp. 558–571
(cit. on p. 24).
[14] Mina Kamel, Thomas Stastny, Kostas Alexis, and Roland Siegwart. «Model
predictive control for trajectory tracking of unmanned aerial vehicles using
robot operating system». In: Robot operating system (ROS). Springer, 2017,
pp. 3–39 (cit. on pp. 25, 27, 30, 39, 43).
[15] Jung Cheon, Han Kyoohyung, Seong-Min Hong, Junsoo Kim, Suseong Kim,
Hoseong Seo, Hyungbo Shim, and Yongsoo Song. «Toward a Secure Drone
System: Flying with Real-time Homomorphic Authenticated Encryption». In:
IEEE Access PP (Mar. 2018), pp. 1–1. doi: 10.1109/ACCESS.2018.2819189
(cit. on p. 27).
[16] Sertac Karaman, Matthew R Walter, Alejandro Perez, Emilio Frazzoli, and
Seth Teller. «Anytime motion planning using the RRT». In: 2011 IEEE
International Conference on Robotics and Automation. IEEE. 2011, pp. 1478–
1483 (cit. on pp. 33–35).
[17] Sertac Karaman and Emilio Frazzoli. «Optimal kinodynamic motion planning
using incremental sampling-based methods». In: 49th IEEE conference on
decision and control (CDC). IEEE. 2010, pp. 7681–7687 (cit. on pp. 34, 55).
[18] Juan Cortés, Léonard Jaillet, and Thierry Siméon. «Disassembly Path Plan-
ning for Complex Articulated Objects». In: Robotics, IEEE Transactions on
24 (May 2008), pp. 475–481. doi: 10.1109/TRO.2008.915464 (cit. on p. 35).
89
BIBLIOGRAPHY
[19] Jacob Mattingley and Stephen Boyd. «CVXGEN: A code generator for em-
bedded convex optimization». In: Optimization and Engineering 13.1 (2012),
pp. 1–27 (cit. on pp. 38, 85).
[20] Michael Grant and Stephen Boyd. CVX: Matlab software for disciplined
convex programming, version 2.1. 2014 (cit. on p. 38).
[21] Francesco Borrelli, Alberto Bemporad, and Manfred Morari. Predictive control
for linear and hybrid systems. Cambridge University Press, 2017 (cit. on p. 39).
[22] Joseph A Marty. Vulnerability analysis of the mavlink protocol for command
and control of unmanned aircraft. Tech. rep. AIR FORCE INSTITUTE OF
TECHNOLOGY WRIGHT-PATTERSON AFB OH GRADUATE SCHOOL
OF . . ., 2013 (cit. on p. 50).
90