Principles of Drone Design
Principles of Drone Design
ISBN: 978-1-7366303-0-3
Introduction
Chapter 1 - Physical models
Objectives
Modeling physical systems
Quadcopter physical model
Example 1
Example 2
Summary
Problems
Chapter 2 - Concepts of control systems
Objectives
System diagrams
Proportional controller
Steady state (t -> ∞)
Exponential terms
Derivative controller
Integral controller
Summary
Problems
Chapter 3 - Flight controller and sensors
Objectives
Reference flight controller - Pixhawk
Software implementation of a PID
Core sensors
Accelerometer
Altimeter
Magnetometer (compass)
Hall effect [14]
Anisotropic magnetoresistance (AMR)
Gyroscope
GNSS+RTK
Physical interfaces
General
UART (Universal Asynchronous Receiver Transmitter)[29]
I2C (Inter-Integrated Circuit)
SPI (Serial Peripheral Interface)[31]
CAN (Controller Area Network)[30]
Device drivers
Code analysis (optional)
Supplemental sensors
Sonars
Lidars
Optical flow cameras
Infra-red
Summary
Problems
Chapter 4 - Copter tuning and calibration
Objectives
Accelerometer
Magnetometer (compass)
Gyroscope
Electronic Speed Controller (ESC)
About Oneshot protocol
PID controllers
Summary
Problems
Chapter 5 - On-board computing
Objectives
Extending the UAV functionality
Computer selection
Weight
Size
Voltage and current
Computing power
Memory and storage
Peripherals
On-board computer and flight controller interface - MAVLINK
Messages and commands
Messages
NAV and DO commands
Connecting to the flight controller
Message types
Flying the multi-propeller copter
Frames of reference and modes of operation
Core flight commands
Parameters and settings
Available libraries
Summary
Problems
Chapter 6 - Designing a multi-propeller copter
Objectives
Formulas and definitions
Payload and weight ratio
Thrust, power and motor specification
Battery
Electronic Speed Controller (ESC) current
Flight duration
Calculation procedure
Frame size
Battery position and arrangement
Battery holder or plate
Battery straps
Arms length
Legs
Head
Body
Foot
UAV Body
Propellers
Flight controller selection
Sensor tuning/calibration
PID tuning
Physical model
Closed-loop system with proportional controller
Resolve the equation
Apply constraints and calculate K
Parameters
MAVLINK
Serial ports
Multicopter position control
PWM outputs
Sensor position
Additional components
GNSS antenna/receiver
Real-Time Kinematics (RTK) board
Radio control receiver
Cellular modem
USB powered hub
Voltage regulators
Power distribution
5V distribution
Battery connectors
Battery charger
Power module
Power cables
Summary
Problems
Chapter 7 - Command and control software
Objectives
Software description
Setup
Chapter 8 - UAV Project
Objectives
Process
Weight estimate
Propeller and motor parameters
Propeller selection
Motor selection
Frame dimensions and materials
Landing gear/legs
Wiring
Bill of materials
UAV components
Other materials and tools
Blueprint and instructions
Instructions
Work area
Preparation
ESC configuration
Step 1: Download the BLHeli Suite
Step 2: Connect the ESC, programmer and PC
Step 3: ESC flashing and programming
ESC connection to motors
Mounting motors and ESCs
Step 1: Label the motor wires and ESC taps
Step 2: Mount the foldable joints
Step 3: Mount the motors and arms
Step 4: Mount the ESCs
Mounting and connecting batteries and power
Mounting and connecting remaining components
Calibration and configuration
Testing the configuration
Attaching propellers and flight
Chapter 9 - Final considerations
Objectives
Rules and regulations
14 CFR Part 107 - SMALL UNMANNED AIRCRAFT SYSTEMS
Remote pilot certification
Aircraft registration
Waivers
Remote ID
Limitations of using the mobile network
References
Appendix
A - Linearization
B - MAVLINK generated libraries
C language
Folder content
minimal/mavlink_msg_protocol_version.h
Java
Folder content
Messages
common
C - Radio controller setup (PX4/Pixhawk 4)
Smart-Bus protocol (S-BUS)
S-BUS cable
Telemetry data (optional)
D - GroundControl communication link setup
E - Propeller thrust and power calculation - momentum method
F - Raspberry Pi 4 serial port configuration
Pin address
Configuring the primary UART for use with Pixhawk
Configuring a secondary serial port
G - Launching an app on startup on RPi 4
Introduction
This book started as a textbook for the EET-112 Sensors for Drones
class at Union Community College; along the course, it evolved into a guide
for designing drones, specifically multi-propeller copters.
This book is intended to be a practical manual; any theoretical
material presented here is used as background to justify the calculations and
design presented in the final chapters; it would be difficult to understand the
numbers and design decisions without this foundation.
Since it is an undergraduate, college level work, the text does require
some knowledge of Calculus and Mathematics in general; some parts will
require understanding of software programming and a basic knowledge of
electricity and physics.
The mathematics will be kept quite informal, it is just a tool for
understanding some of the concepts presented along the book. The same can
be said for the physical models used throughout the text.
The content tries to aggregate in one single place all the information
needed to design and build multi-propeller copters - information that is
scattered all over the Internet - as well as data our team gathered from the
years spent building and flying custom made, mobile network connected
drones; some of the information in this book will not be found anywhere else;
this is, however, a rapidly evolving field and some of the information and
links here may become obsolete. As the author, I will try my best to keep the
information up-to-date.
This book is only published in electronic format; it contains links to
both online reference material and auxiliary files that complement its content.
Although readers can, in principle, obtain a printed copy, it will not be as
useful as the electronic version.
Chapter 1 will present key mathematical concepts used when
modeling physical systems. Physical models are the starting point for all the
calculations associated with UAV design. It will then cover the concept of
automatic control using PID controllers and its implementation.
Chapter 2 introduces the concepts and mathematics of control
systems, including system diagrams, open and closed loop systems and PID
controllers.
Chapter 3 introduces the flight controller as the core unit responsible
for allowing controlled flight of the UAV by implementing the controllers
studied in . The chapter then introduces sensors, the functional components
responsible for providing measurements used by the PID controllers.
Chapter 4 focuses on tuning and calibration of the core sensors used
for flight control, as well as the parameters that must be manually configured
by the user in order to guarantee safe, controlled flight.
Chapter 5 introduces the on-board computer, used for extending the
UAV functionality beyond flight. It will describe how the on-board computer
communicates with the flight controller as well as the network.
Chapter 6 covers the practical use of the concepts covered by the
previous chapters, introducing a systematic procedure for calculating the
dimensions of all essential parts of an UAV.
Chapter 7 presents a reference client/server application that allows
controlling the UAV over the mobile network using ground control system
software.
Chapter 8 presents the full design of an UAV, including costs, bill of
materials, blueprints and instructions on how to install and configure each
component. Although intended to be used as an educational tool, this design
can be used by the reader to build a fully operational UAV.
Chapter 9 covers some use cases and legal aspects of flying and
operating a UAV, including the latest regulation published by FAA,
certification requirements and rules related to flight beyond line of sight
(BLOS). The chapter also covers the limitations associated with using the
mobile network for command and control of remote UAVs.
Chapter 1 - Physical models
Objectives
This chapter the reader will learn:
● The concept of physical models
● The physical model for for the forces acting in a quadcopter
● System diagrams and concepts of system control
● The concept of proportional, integral and derivative (PID) controllers
Figure 1 shows the forces applied to the mass at the end of the string
in the simple pendulum.
Using Newton’s Second Law of Motion and relationships between
angular and linear velocity in a circular trajectory one can write the
following equation describing the motion of the pendulum:
(1.1)
In this model the inputs are the forces acting on the mass at the end of
the string.
This equation is nonlinear because the sine is a function of the variable of
interest and it is a nonlinear function. The analytical solution for this
nonlinear equation is complicated [1]
This equation is a mathematical model for the behavior of the simple
pendulum. Difficult as it is to resolve it in this form, it is still a simplified
model; many assumptions are implied in this formula:
1. The string’s length (l) is assumed to stay constant under tension; in reality
the string may change length while the pendulum swings and forces
change, due to elastic properties
2. This string is assumed massless with all the mass in the system
concentrated at the weight at the end of the string; in reality that is not true
3. Gravity’s acceleration (g) is additionally assumed to be constant but it
does have a small variation as the pendulum changes its height
4. Air resistance, the friction at the end of the string, Coriolis effects
associated with Earth’s rotation, etc. were not included
Moreover, more simplifications are necessary to eliminate the no-
linearity; if the angle of oscillation is sufficiently small then:
(1.2)
Replacing (1.2) in (1.1) the much simpler linear differential equation
is obtained:
(1.3)
The general solution for this equation is:
(1.4)
where:
θ0 = initial, sufficiently small angle (rad)
In the next section, physical models for a quad copter drone will be
derived following the same strategies described in this section.
Altitude
From Newton’s Second Law the sum of all vertical forces must be
equal to the drone’s mass multiplied by the vertical acceleration so the
differential equation for the altitude is:
(1.5)
But since vy is the time derivative of the altitude then (1.5) can be
rewritten as after rearranging the terms:
(1.6)
Notice that this is a nonlinear equation due to the term with the square
of the vertical speed.
Horizontal velocity
Following the same principle, the non-linear equation for the
horizontal velocity is:
(1.7)
Heading
Before deriving the heading equation, it is important to define the
concept of heading. When it comes to flight it is important to distinguish
between heading and course over ground.
Heading is the direction the aircraft is pointing to; in other words,
once the front of the aircraft is defined, heading is the clockwise angle
between the main axis of the aircraft and the magnetic (or real) North.
(1.9)
where:
ID = drones’s total moment of inertia
𝛼 = drone’s heading angle
Ii = moment of inertia of each motor-propeller pairs
𝜔i = rotation speed of each motor-propeller pair
The different signs for the terms in ωi emphasize the fact that
propellers are counter-rotating
Here are some examples of how these equations can be used.
Example 1
From equation (1.7) this means that the term on the left must be 0;
since it is known that the lift forces are not 0 by definition - the aircraft is
airborne after all - then the sine of the pitch must be 0 or, equivalent, the
pitch must be 00.
Similarly, from equation (1.6), all terms on the left are 0; since the
pitch angle is 0, the conclusion is that the combined forces of all motor-
propeller pairs must be equal to the UAV weight.
Example 2
(1.10)
where:
vh = is the steady, constant horizontal velocity
𝜃 = pitch angle
Rearranging the terms of the equation:
(1.11)
Notice that the pitch can no longer be 0. Based on this equation alone
there is an infinite combination of lift forces and pitch angles that can achieve
the desired speed. Let’s now add the second constraint.
From equation (1.6) and Example 1 it is known that, for the aircraft to
maintain a constant altitude, the terms on the right of equation (1.6) must be
equal to the weight. Explicitly:
(1.12)
Equating (1.11) and (1.12) and rearranging:
(1.13)
Equations (1.11), (1.12) and (1.13) provide some interesting insights:
1. Equation (1.13) tells us that the higher the desired speed, the
higher the pitch; however, Equation (1.12) tells us a higher pitch
means a lower cosine; in other words, more thrust is required to
keep the altitude. Therefore, there is a well-defined maximum
speed attainable by the aircraft, limited by the maximum thrust that
can be provided by the motor-propeller pairs.
2. Equation (1.13) also tells us that the higher the total aircraft mass,
the lower the pitch required to reach the desired speed. This may
sound counterintuitive, but keep in mind the higher mass requires
higher vertical thrust so a smaller pitch is enough to redirect
enough thrust for the aircraft to move horizontally.
Summary
At this point it must be clear that:
1. Flying a multi-propeller copter requires simultaneously adjusting
the spin of multiple independent motors to obtain a desired effect
(yaw, fly horizontally, keep altitude, etc.)
2. Even something apparently as simple as flying a multi-propeller
copter at a constant speed and altitude requires manipulation of the
lift forces of each individual motor
Problems
1. Using the simplified model for the pendulum, show that the angular
velocity is
2. Explain, in layman terms, why the higher the total mass of UAV, the
lower the pitch angle for a desired speed.
3. Write and resolve the force ODE for a system comprised of a mass
M, a spring with elastic constant K and a shock absorber with
damping constant B.
Assume the following:
where:
FE = elastic force applied by the spring
FB = damping force applied by the shock absorber
System diagrams
When designing a system, it is useful to represent the relationship between
its components using a system diagram.
System diagrams are just a graphical representation of the inputs, physical
models and outputs using block diagrams.
Figure 4 shows the simplest possible representation of a system.
Proportional controller
Figure 7: Block diagram for the controlled model for altitude using
proportional controller
In order to make the calculations simpler, assume the multi-propeller copter
is flying vertically - therefore the pitch is 00 - and the total lift - FT(t) - is equally
distributed to all four motors. In addition assume the desired altitude is a constant
hD.
A linearized drag term is used in the differential equation to simplify the
calculations.
The proportional controller is the simplest controller that can be designed; it
simply multiplies the input by a constant K. The constant is known as the gain of the
controller.
Let us rewrite (1.6) with the simplifications defined in the previous section:
(1.14)
where:
cd = drag coefficient for linearized drag
FT = total lift
where:
hD = desired altitude AGL
where:
K = gain of the proportional controller
Finally, replacing this expression in (1.14) and rearranging the terms, the close-loop
equation of for the system is:
(1.15)
Since there are two possible values for 𝜆, the general solution for the
homogeneous equation is:
(1.16)
For the complete solution all is needed is one solution for the non-
homogeneous equation.
The right hand side of the equation is a constant; therefore, the solution for
the non-homogeneous equation is:
(1.17)
Since the aircraft is assumed landed, the initial value for the AGL altitude is
0; in other words, . Replacing this condition in (1.17) results:
(1.18)
A couple of conclusions regarding the behavior of the altitude can be
derived from this general form of the solution for the altitude.
Exponential terms
The second thing to be noticed are the exponential terms and their
dependency on K.
Depending on the value of K there are three possibilities for the value of the
exponents:
Condition 1:
Under this condition both terms in A and B vanish over time but the term in
B vanishes slower than A and is the dominant term.
The conclusion here is that a lower value for K guarantees a smooth
ascension to the drone, at the price of a longer time to reach steady-state and a final
altitude with a larger steady-state error.
Condition 2:
Under this condition both terms A and B vanish at the same rate; the rate
depends only on the drag coefficient and the mass and is independent of the gain; in
other words the time it takes for the UAV to reach steady-state doesn't depend on the
gain.
Substituting K in equation (1.17) and making time infinite, an expression for
the steady-state altitude can be written:
This is a curious result where the steady-state error depends only on the
aircraft characteristics (drag and weight).
Condition 3:
In this case the square root will produce a complex number of the form ejb.
From Euler's formula:
where:
j = imaginary unit
Applying this result to equation (1.17), ignoring the imaginary terms
(imaginary terms don’t have any physical meaning in this case) and taking into
account that results:
(1.19)
Finally, applying (1.18) to (1.19) and rearranging the terms results:
(1.20)
Equation (1.20) models the case where the altitude has an attenuated
oscillatory profile; the term inside the cosine is proportional to the natural
oscillation frequency of the system.
If K is made large enough so that the error becomes negligible and the term
in 4mK becomes much larger than the drag constant, (1.20) can be re-written as:
(1.21)
Equation (1.21) shows that the altitude can be temporarily higher than the
desired altitude at a certain point in time; all that is needed is for the cosine to turn
negative. The earlier this happens is when:
Derivative controller
Let’s start with re-drawing the block diagram and adding the derivative
controller. The derivative controller is added in parallel to the proportional
controller and its output is combined with the proportional controller output as the
multi-propeller copter input.
Figure 8: Block diagram for a proportional-derivative controller
The lift will then be given by:
where:
Kd = gain of the derivative controller
Replacing the input lift forces with the output of the controllers in Equation
(1.14) and rearranging the terms results:
(1.22)
This equation is identical to equation (1.15) with the only difference in the
constant multiplied to the time derivative of the altitude, which means all results
from the proportional controller can be reused, just replacing cd occurrences with
(cd+Kd).
From the steady-state analysis:
Clearly the derivative controller has no effect on the steady-state error. On
the other hand, replacing the constants in Equation (1.20) (attenuated oscillation
case) results:
(1.23)
Like with the proportional controller, if the cosine becomes negative, the
altitude may overshoot the setpoint; however, now the gain from the derivative
controller can be used as follows:
1. Increase the dampening effect, by increasing Kd; in other words, the
system can reach steady-state faster
2. At the same time, reduce the overshoot when compared to the
proportional controller
3. Control the time to reach the desired altitude
Integral controller
The same way as the derivative control, the integral control goes in parallel
to the other two controllers and it contributes to the physical system's input.
Figure 9: Block diagram for the proportional-derivative-integral controller
The lift will then be given by:
where:
Ki = gain of the integral controller
D = arbitrary constant, dependent on boundary conditions
Replacing in (1.14) and rearranging the terms:
(1.25)
This is called a linear integro-differential equation. This particular
equation is solved the same way an ODE is resolved, by finding the general
solution for the homogeneous equation and one solution for the non-homogeneous
equation, then applying boundary conditions to calculate the other factors.
The homogeneous equation is:
Just like before, the solution is in the form:
(1.26)
Therefore,
(1.27)
This is a quite important result. Assume the exponential terms all vanish
over time; in that case, the steady-state altitude is:
Summary
The controller that combines the proportional, integral and derivative
controls is called a PID controller [7].
In summary:
●
Proportional controllers use the difference between the setpoint and output to
control the system input; there’s always a steady-state error.
●
Derivative controllers improve dampening of any oscillatory behavior and
maximum overshoot but it does not help removing the steady-state error
●
Integral controllers remove any steady-state error but the gain must be
carefully calculated since it may cause the exponential terms to grow and
make the system unstable
The objective of control systems design is to use the physical models to
calculate suitable values for each controller gain. Once the gains are calculated, the
PID controller is expected to force the system to behave as desired.
There are several techniques to calculate the values for the gains, but they
are all based on a suitable physical model of the system to be controlled.
Finally, the gains calculated for a UAV with certain characteristics -
particularly drag and weight - most likely will not work for another model. In order
to re-use the same flight controller in different models, it is impractical to
implement the controllers in hardware; therefore, it must be clear now why flight
controllers rely on software implementation of such control systems.
Problems
1. Write and resolve the ODE for the horizontal speed of a UAV in a closed
loop proportional-integral control system. Assume the following:
Chapter 3 - Flight controller and sensors
Objectives
This chapter covers:
● A reference flight controller - Pixhawk
● How a PID is implemented in software
● How sensors measure variable of interest
● Study the physical interfaces exposed by the flight controller and device drivers to sensors
Pins in each connector are numbered from left to right, where PIN 1 is the leftmost pin in the
connector.
The reference software for the Pixhawk is the PX4[9]. The firmware is extensive and covers a
variety of vehicles besides copters (rovers, fixed-wing aircrafts, boats, etc.) as well as a long list of
external devices and sensors.
This chapter highlights two aspects of the software: 1) the code that implements the PID
controller; 2) the code that implements drivers for the peripheral and embedded devices
In the previous section it was stated that the PID controller in the multi-propeller copter is
responsible for varying the lift provided by the motors to accomplish a certain result for example,
ascending and hovering at a certain desired altitude. Figure 12 diagram depicts the way this is done in
practice.
Figure 12: Block diagram of a flight controller connected to ESCs (electronic speed controllers) and
motors in a multi-propeller copter
In Figure 12 each ESC - electronic speed controller - is connected to an output pair of pins in
the flight controller and connected to the power input of a motor. The flight controller provides to the
ESC the percentage of total voltage that must be applied to the motor and the ESC converts that into the
appropriate amount of power that it allows to go from the power supply to the motor, indirectly changing
the motor RPM and therefore the lift as described in Equation (10).
In the particular case of Pixhawk and PX4, PWM - pulse width modulation - ESCs are
commonly used along with brushless motors.
/*
* Generic PID controller algorithm
* *pid: pointer to memory storing the previous values
* sp: set point or the desired value for the variable of interest
* val: current value for the variable of interest
* val_dot: first derivative for the variable of interest
* dt: time interval between calculations
* */
__EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt)
{
if (!PX4_ISFINITE(sp) || !PX4_ISFINITE(val) || !PX4_ISFINITE(val_dot) ||
!PX4_ISFINITE(dt)) {
return pid->last_output;
}
float i, d;
/* current error value */
float error = sp - val;
/* current error derivative */
if (pid->mode == PID_MODE_DERIVATIV_CALC) {
d = (error - pid->error_previous) / fmaxf(dt, pid->dt_min);
pid->error_previous = error;
} else if (pid->mode == PID_MODE_DERIVATIV_CALC_NO_SP) {
d = (-val - pid->error_previous) / fmaxf(dt, pid->dt_min);
pid->error_previous = -val;
} else if (pid->mode == PID_MODE_DERIVATIV_SET) {
d = -val_dot;
} else {
d = 0.0f;
}
if (!PX4_ISFINITE(d)) {
d = 0.0f;
}
/* calculate PD output */
float output = (error * pid->kp) + (d * pid->kd);
if (pid->ki > SIGMA) {
// Calculate the error integral and check for saturation
i = pid->integral + (error * dt);
/* check for saturation */
if (PX4_ISFINITE(i)) {
if ((pid->output_limit < SIGMA || (fabsf(output + (i * pid->ki)) <= pid->output_limit)) &&
fabsf(i) <= pid->integral_limit) {
/* not saturated, use new integral value */
pid->integral = i;
}
}
/* add I component to output */
output += pid->integral * pid->ki;
}
/* limit output */
if (PX4_ISFINITE(output)) {
if (pid->output_limit > SIGMA) {
if (output > pid->output_limit) {
output = pid->output_limit;
} else if (output < -pid->output_limit) {
output = -pid->output_limit;
}
}
pid->last_output = output;
}
return pid->last_output;
}
The output of the function is the throttle value to be applied to the motors (to be precise, the
percentage of the full throttle to be applied). This function is used by the main application running in the
PX4 to determine the power output to be applied to the motors, given a certain value for a variable of
interest.
Multiple instances of this type of controller, in different combinations and measuring different
variables of interest, can be used for all operations of a UAV: take-off, hover, landing, flying
horizontally, etc.
There are two important arguments as the input arguments for this function: the current value and
the first derivative of the variable of interest. Let's take a closer look at these for two variables of
interest that were studied earlier: horizontal speed and altitude.
Variable of interest: horizontal speed
If the variable of interest is horizontal speed, the software can provide two arguments: current
velocity (val) and current acceleration (val_dot); both can be measured directly and provided to the
controller.
Variable of interest: altitude
In this case the software can provide the current altitude (val) and, optionally, vertical or
ascension velocity (val_dot). In general only the current altitude is needed; it can be measured directly
and provided to the PID.
Notice that the algorithm requires measuring at least the current value of the variables of interest
and feeding those back into the loop; these variables are measured using sensors.
Sensors can be classified in two main categories: core and supplemental. Core sensors are
those essential for flying the aircraft; lacking one of them can drastically increase the risk of losing
control of the aircraft or even making controlled flight impossible.
Supplemental sensors are those that can be used for additional functionality (e.g. collision
avoidance) or as backup for a core sensor (e.g. position indoors when GPS is not available); they can
even provide extra accuracy to the core sensors when present.
The next section describes the core sensors, how they work and how they are used.
Core sensors
Core sensors are those sensors fundamental for both manual and autonomous flight. They are
used directly by the controllers within the flight controller, providing the current values for the variable
of interest and allowing the controllers to stabilize the aircraft during flight. These sensors are usually
built into the flight controller and are accessible via either SPI and I2C bus, although other buses can be
used.
Accelerometer
Accelerometers are used to measure acceleration. Accelerometers can come in a variety of
types: 1) gravimeters, used to measure gravity; 2) linear accelerometers, measure the vehicle's
acceleration without gravity; 3) pure accelerometers, measure the raw acceleration of the vehicle
including gravity.
Accelerometers used in drones must measure acceleration according to some predefined 3-D
coordinate system, usually relative to the device; it measures acceleration in directions x, y and z.
The flight controller must be mounted in such a way that the three axis assumed by the sensor are
aligned with the drone's axis: x points" to the "front” or the normal forward direction of flight of the
drone, y points to the "side" and z points "upwards".
Accelerometers as well as some of the other sensors will study here, use a technology called
MEMS - Micro Electro-Mechanical Systems[10] - which allows adding tiny mechanical systems that
interact with electrical circuitry.
Examples of MEMS technologies used in accelerometers are: 1) piezoelectric crystals, which
generate an electric charge when under a force; 2) thermal MEMS, which use variations in temperature
of a heated gas sealed in a chamber inside the chip[11]
Pixhawk 4 comes with two accelerometer/gyroscope combos: 1 x ICM-20689 and 1 x BMI055
in the IMU (Integrated Measurement Unit).
The acceleration measured by the accelerometer is one of the inputs to the PID controller when
controlling for example horizontal speed.
The Pixhawk 4 comes equipped with accelerometer/gyroscope combos, a ICM-20689 and a
BMI055.
Altimeter
Altitude is usually measured in two ways, depending on the application: 1) relative to the ground
(AGL); 2) relative to the mean sea level (AMSL)
Altitude is a fundamental measurement when it comes to flying drones. Drones are not allowed
to fly above 400 feet relative to the ground or a structure nearby and only in certain air spaces with
limited maximum altitudes[12].
Altitude can be measured in a few ways: 1) electronic air pressure sensors (barometric
altimeters); 2) GPS; 3) distance sensors (lidars, sonars)
Barometric altimeters in general use a piezoresistive component that changes electric resistance
with pressure. The chip has a pressurized chamber - the reference pressure - and a small inlet for the
external air to enter; the pressure difference between the external air pressure and the reference pressure
deforms the piezoresistive component, changing its resistance; the change in current allows for the chip
to measure the pressure difference and calculate the altitude.
Pixhawk 4 comes equipped with 1 x MS5611 in the IMU. This altimeter is a type of MEMS that
uses piezo-resistive components that change electric resistance depending on the applied pressure[13].
The current altitude measured by the altimeter is input to the PID controller.
Magnetometer (compass)
Magnetometers are used to determine the direction of the Earth’s magnetic field and,
consequently, the orientation of the aircraft relative to the Earth’s magnetic North.
Magnetometers are important for drone flight depending on the mode of operation. Symmetric
multi-propeller copters are quite flexible when it comes to flight, being able to fly in any direction while
never changing heading; if however the operation requires the drone to always fly along the heading or
that the drone is pointed to specific directions (e.g. when filming during flight) then compass becomes
important.
Magnetometers use different methods to determine the direction of the magnetic field.
Hall effect [14]
If one assembles a circuit in such a way that a well-defined electric current travels across a
metallic surface it is generally expected that the flow of electrons is uniformly distributed across the
whole surface and therefore the electric potential between the opposite sides of the surface will be zero.
However, if a magnetic field is applied to the surface, it will disturb the electron flow, causing it
to be skewed and concentrate in one of the sides of the metallic surface; that unbalanced distribution of
electrons generate a voltage between the opposite sides of the surface; this voltage can be measured and
used to calculate the magnetic field being applied.
Anisotropic magnetoresistance (AMR)
Certain materials change electric resistance depending on the angle of the magnetic field
applied to it.
By measuring the change in terminal voltage or current and calculating the resistance the device
can determine the angle of incidence of the magnetic field.
Pixhawk 4 comes with a IST8310 AMR magnetometer; however, using Pixhawk’s internal
compass alone is not recommended, due to the device's proximity to multiple sources of magnetic fields
(wires and other electronics). As it will be discussed later, the GPS receivers used with drones also
come equipped with a compass and it is highly recommended to also use this compass.
Gyroscope
Traditional mechanical gyroscopes are machines built in such a way that, when all the elements
are spinning, it does not matter how it is moved, the axis of the center spinning piece is always pointing
in the same direction. This happens due to the conservation of angular momentum.
Electro-mechanical gyroscopes can be used for very precise positioning. In three-dimensional
space, it is possible to determine the position of any point if one has the direction from that point to six
known reference points (it is the equivalent, 3-D space, of triangulation in 2-D space); hence, if an
aircraft has six gyros on board, pointing to six reference points, as the vehicle moves it measures the
angle of the spinning axis relative to the board and can precisely triangulate the vehicle position.
The technique was used in the Apollo program where the gyros pointed to known stars -
considered fixed points in space - and therefore the on-board computer could determine its position at
all times.
Another use for gyroscopes is measuring angular velocity; since the spin axis is always pointing
to the same direction as the vehicle moves, it can measure the angular velocity by measuring the angular
velocity of the spin axis relative to the board.
Electronic gyroscopes are used in that capacity.
Electronic gyros use a number of different techniques to measure angular speed: 1) ring laser
gyros use the frequency difference between 2 lasers sent into a circular route in opposite directions
when rotation is present, due to Dopler effect; 2) vibrating structure gyros uses a quartz crystal vibrating
at a very precise frequency; when rotation is present the crystal tends to continue vibrating in the same
plane (Coriolis effect) so the chip can measure the forces of the crystal on its support; etc.
The Pixhawk 4 comes equipped with accelerometer/gyroscope combos, a ICM-20689 and a
BMI055.
GNSS+RTK
Of all the sensors discussed here so far the GNSS receiver is the only core sensor that is external
to the flight controller.
There are several GNSS - Global Navigation Satellite System - systems: USA's GPS, Russia's
GLONASS, Europe's Galileo and China's BeiDou, among others.
GNSS receivers calculate their positions using the known position of some satellites in a
constellation and the travel time of a message from the satellite to the receiver (the travel time is the
difference between the time a message is received and the time it was sent; the send time is recorded in
the message, along with the satellite position).
Assuming the receiver's clock is not synchronized with the satellites' clocks, one can write the
equations for the receiver position as a system of equations as follows:
where:
c = speed of light
xi, yi, zi, ti = satellite i coordinates and time message was sent
x, y, z = unknown position of the receiver
treceiver = time at the receiver
terror = unknown error in the time measurement (lack of synchronization, atmospheric effects, etc.)
Since there are four unknowns, a minimum of four equations are needed in our system of
equations and therefore a minimum of four satellites; more satellites will help make the calculations
more accurate.
Pixhawk 4 and PX4 support several GNSS receivers using a variety of protocols. It is usual to
select a receiver that also has a compass but it is not mandatory.
GNSS position information is mostly used when the aircraft is flying autonomously executing a
mission; PX4 uses the data in a few ways:
Position could theoretically be also used within a PID controller but in practice it's not; the logic
is usually very simple, by simply checking if the vehicle is within a certain radius of the target position
and using that condition to trigger the next step in the flight.
RTK (Real-Time Kinematic)[15] is a technique to improve the accuracy of GNSS-based
positioning. It uses a fixed base station at a known position that can measure errors in the location and
broadcast correction information to GNSS receivers within a certain range (around 6 miles); correction
data is commonly sent using NTRIP (Networked Transport of RTCM via Internet Protocol) where the
messages content and format are defined by RTCM (Radio Technical Commission for Maritime
Services)[16]. RTK can provide accuracies under 3 cm.
Now that our review of core sensors is completed, let’s look into supplemental sensors; but
before that it is important to take a look at the physical interfaces the Pixhawk offers for connecting these
supplemental sensors.
Physical interfaces
Pixhawk 4 offers a number of external physical interfaces that allow attaching peripherals and
sensors to expand both the functionality and safety of the drone.
General
Some of the interfaces about to be studied have one characteristic in common: all devices in the
bus share the same wire to send and receive data. Therefore, they all implement some mechanism that
allows one of the devices (e.g. a master device) to take control over the bus.
This is normally done by changing the voltage level in the wire to a level that is standardized and
agreed with the chipset manufacturers.
This is accomplished using a circuit like the one below:
As it can be seen, if no voltage is applied to the base of the transistor, the transistor is not
conducting any current between the collector and emitter and therefore the voltage in the line will be at
the "high" level.
Once a suitable voltage is applied to the base, the transistor conducts and the voltage drop in the
collector resistor causes the voltage to drop to the "low" level.
Observe that in this scheme the collector resistor is passively keeping the voltage high, simply
because no current is flowing through it; this type of state is called passive pull-up.
Conversely, the low level in the line is forcefully set by creating a current through the transistor;
this state is called active pull-down.
In general, if a port has an active pull-down it will have a passive pull-up and vice-versa.
Peripheral addresses are usually programmed into the device using a mechanism provided by the
manufacturer; devices must be set with an address before they can be connected to the bus.
The protocol is defined as follows[17]:
1. The master indicates a communication start by making the SDA level low while the SCL is
high (start sequence)
2. The master writes the 7 bit for the device address then adds an 8th bit to indicate if it is a
write operation (low) - the master is sending data to the peripheral - or read operation
(high) - the master is reading data from the peripheral. Each bit of the address is written by
the master by lowering the SCL level, raising the SCL level for the clock pulse duration and
lowering it again.
3. Either the master or the peripheral writes data to the SDA, depending on the operation being
performed; the data must be written while the SCL line is low.
4. The master then pulses the SCL to indicate the operation is done. Once 1 byte is transmitted,
the receiver adds an ACK bit to indicate to the sender data is received and another byte can
be sent.
5. When the data transmission is finished, the master sends a stop sequence by making the SDA
line high while SCL is also high.
The amount of data to be sent by master and peripheral is peripheral-dependent and is controlled
by software; in the Pixhawk the communication protocol for each peripheral is implemented by device
drivers.
Some devices for example may provide access to registers that are individually addressable by
the master; in this case the protocol involves the master first doing a write procedure to provide the
register address to be used by the peripheral, a stop sequence then a new start sequence to actually
read/write data; the peripheral will "know" it is supposed to read/write from/to the register previously
set by the master.
The SPI interface was developed by Motorola in the 1980s as a short-range communication
interface for peripherals like LCD displays.
Similar to the I2C interface, the SPI is a synchronous serial interface that uses a master-slave
architecture where the master is responsible for controlling the clock. However, it has several
differences when compared to I2C.
The main difference is that SPI allows for full-duplex communication; that comes with the price
of a more complex hardware that requires 2 wires for data (MOSI and MISO) and 1 wire for clock
(SCLK). If the system requires multiple SPI peripherals to share the bus - called 4-wire configuration -
then more hardware is required because SPI does not have an address system like I2C and uses a
traditional chip select signal granting the chip access to the bus.
The SPI specification defines a set of registers that allow configuring the SPI interface
functionality and work as buffers for data to be sent/received.
Among other features the registers allow configuring the character length (between 2 and 16 bits)
and the clock polarity and phase.
Polar Ph Description
ity ase
0 0 Output in the rising edge of clock; input latched in the falling edge
0 1 Output first half-cycle before first rising edge, then falling edge subsequent cycles; input
in the rising edge
1 0 Output in falling edge; input latched in rising edge
1 1 Output first half-cycle before first falling edge, then rising edge subsequent cycles; input
in the falling edge
Device drivers
In the previous section it must have become clear that physical interfaces specifications only
define how data is sent and received; it makes no assumptions about the meaning of the data and its
content.
Therefore, for a specific device to be able to function using a certain physical interface it is
necessary to write software that allows data to be sent, received and interpreted.
There are two ways this can be accomplished: 1) each application interested in interfacing with
a certain device implements the code to do so or 2) the system provides a device driver that implements
such communication protocols.
The second approach is the standard way for communicating with physical interfaces, for a few
reasons:
1. Reusability: the device driver is implemented once and used by any application interested
in it. Also if there is an issue with the device driver code, there is only one source to fix.
2. Abstraction: by implementing a common interface, device drivers allow applications to
interact with any sensor the same way, without having to worry about the underlying details
of the physical communication interface and protocols.
3. Privilege separation: it is common for device drivers to require a higher privilege level
for accessing the hardware than the level needed by an application; by separating the
device driver from the application, the 2 components can run at their appropriate
privilege level.
Here is the device driver code for the I2C interface of the MS5611 barometric pressure sensor:
/****************************************************************************
*
* Copyright (c) 2013 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file ms5611_i2c.cpp
*
* I2C interface for MS5611
*/
#include "ms5611.h"
#define MS5611_ADDRESS_1 0x76 /* address select pins pulled high (PX4FMU
series v1.6+) */
#define MS5611_ADDRESS_2 0x77 /* address select pins pulled low (PX4FMU
prototypes) */
1. This driver extends class device::I2C, this way, it is guaranteed it will expose the same I2C
common interface to all applications.
2. The code overrides methods read() and ioctl(), the 2 methods exposed to applications. This
is done so the driver implements the specific functionality for the MS5611 while
guaranteeing that these implementation details are hidden form the applications
3. The driver defines the addresses for writing and reading from the device. Since these are
hardcoded, any developer adding a device I2C device driver must be aware of these
predefined addresses, in order to avoid conflicts in the bus.
4. Most of the code is just formatting data to be sent to the device, as well as data sent back to
the application.
The actual reading and writing into the physical bus is done by method transfer(), which is
not implemented by this device driver but by the underlying I2C driver, which in turn relies
on a lower driver that actually communicates with the physical bus.
This shows how even device drivers are also implemented in layers and rely on lower level
functionality provided by other drivers.
Supplemental sensors
Sonars
Sonars are used in multi-propeller copters and drones in general as a
distance sensor. Collision Avoidance is one of the main applications for
this kind of sensor.
Sonars measure distance by echolocation: sonar emits a short pulse
and measures the time it takes for the pulse to return (time of flight).
Sonars are cheap compared to other types of distance sensors but are
not as precise; they cannot be used for high accuracy measurements and
safety purposes.
Since the time of flight is dependent on the speed of sound, which in
turn is dependent on air density and temperature, measurement accuracy will
be affected under different weather conditions.
Sonars are small and lightweight so it is common to install multiple
units pointing in different directions to provide wide coverage for obstacles.
Some sonars allow for connection in "daisy chain" so the master sonar only
has to trigger the first sonar measurement; after that each sonar triggers the
next in the chain once it is done with the distance measurement.
Sonar's maximum range is dependent on the size of the obstacle; the
larger the obstacle the further it can be detected. A good sonar datasheet will
provide graphs with bean shape and distance detection for obstacles of
different sizes and at different positions.
One example of such a device is the I2CXL-MaxSonar - EZ series of
devices [39]. This series of sonars is supported by PX4.
Lidars
Lidars are also distance sensors. Lidars use laser or focused light
pulses to measure distance and direction of an obstacle by measuring the time
of flight of a light pulse.
Prices for lidars can vary widely, depending on the application.
Lidars used to construct precise point maps of an environment can cost tens
of thousands of dollars. Even lidars used only as range finders can be quite
expensive, in the hundreds of dollars range.
Lidar's maximum range is affected by the obstacle's material; the
more reflective the surface the higher the range. The maximum range is also
affected by the width of the field of view; a wider field of view reduces the
maximum range.
Depending on the obstacle reflective properties and the field of view,
the range of a lidar can go from over 150 meters to only 6 meters.
Some lidars are connected to the flight controller using one of the
serial ports; therefore, the aircraft can be equipped with only one device;
others use I2C.
As a rule of thumb the lidar will be installed facing forward along the
main axis of the aircraft (assuming this is the usual direction of flight).
Lidar datasheets will normally provide a chart showing the amplitude
of the reflected laser signal versus the obstacle distance for different
materials with different reflective properties; the lowest signal level in the
chart will generally match the maximum distance for obstacle detection.
LeddarOne is an example of a relatively cheap, lightweight lidar for
drones [40]. It is currently supported by PX4.
Optical flow cameras
Optical flow cameras are specialized cameras mounted at the bottom
of a copter, facing down in a vertical direction. The cameras can be also
equipped with a rangefinder as well as a gyroscope.
The range finder is used to determine distance from the ground; the
gyroscope is used to determine the drone's rotation angle (rotation affects the
displacement calculation).
These cameras are used as a mechanism to keep the aircraft hovering
in place but can also be used for navigation. It is useful when flying a drone
in regions where GPS signal is inaccurate or absent (e.g. indoors flight).
The camera compares frames from the ground to measure the aircraft
displacement and provide that information to the controllers for correction
and control.
Optical flow cameras typically capture images at a high rate - around
400 Hz - and produce optical flow data to be used by the flight controller at
about 100 Hz, depending on the physical connection.
The main caveat when using optical flow cameras is that very
homogeneous ground patterns will reduce the camera's accuracy (e.g. flying
over grass).
Infra-red
Infra-red sensors are specialized cameras mounted at the bottom of
the copter, facing down in a vertical direction.
These sensors are used in conjunction with an infra-red light emitter,
normally positioned in areas where the copter must perform precise landing.
The copter flies to the general area where the emitter is and once it detects
the infra-red bean it can use the small displacements of the bean relative to
the camera to feed the controller and keep the copter aligned to the landing
point.
The main caveat with this type of sensor is the real estate they take
from the copter and the need for additional infra-structure at the landing site.
Another issue is infra-red emitted from the ground that can mask the bean
coming from the infra-red emitter.
Summary
For PID controllers to work, they must constantly compare the
current value of the variable of interest and setpoint for the variable.
Sensors are used to measure the current values for the variable of
interest.
Device drivers are software specifically designed to interact with
different sensors. device drivers abstract the details of the communication
protocol via a common software interface.
Core sensors are those necessary for controlled flight.
Supplemental sensors are those that provide additional functionality to the
UAV and may or may not be related to flight control.
Sensors interface with the flight controller via different physical
interfaces, typically I2C, SPI, CAN, USB and UART.
Actual software implementation of PID controllers can use
strategies that make calculations more efficient and less CPU intensive. For
example, by using direct measurements from sensors corresponding to the
derivative and integral values for the variable of interest, and manipulating
the setpoint for a convenient model.
Problems
1. Research for other examples of sensors that use I2C, SPI and CAN
interfaces and could be useful as either core or supplemental
sensors.
2. Regarding the device driver for the MS5611:
a. What do the following functions do?
i. read()
ii. ioctl()
b. What is the function transfer() used for?
3. Using the datasheet from the MB1030 LV-MaxSonar-EZ3, explain
how to use the bean pattern charts.
4. In the reference implementation of a PID controller, 2 of the inputs
are the variable of interest and its derivative. If the variable of
interest is horizontal speed, what would be its derivative? How
can it be measured?
Chapter 4 - Copter tuning and
calibration
Objectives
This chapter covers:
● Why sensors and ESCs must be calibrated
● How each sensor is calibrated
● The calibration procedure for the Pixhawk 4
Before a multi-propeller copter - and any drone for that matter - can
safely fly its core sensors must be calibrated. Flight controller software will
implement fail safes that prevent the aircraft from taking-off if it detects
uncalibrated sensors.
Sensor calibration is performed using specialized software classified
as Ground Control Systems (GCS). For PX4 running in the Pixhawk the
official ground control system is QGroundControl[18].
QGroundControl runs on a PC connected to the aircraft via a direct
connection using a USB cable, via WiFi or via a radio link with the
transmitter connected to a USB port in the PC.
When connected using the USB cable the flight controller
automatically prevents the drone from flying; this connection is normally
used for calibration or software debugging.
Finally, when connected using the RC radio link, QGroundControl
can be used for both calibration and flight.
Accelerometer
Accelerometer calibration is performed by connecting the aircraft to
the PC and positioning the aircraft in different orientations; since the
application knows where the drone is pointing to and that only gravity's
acceleration is applied it can determine measurement errors and flight
controller position relative to the drone and use these values to compensate
for measurement errors.
Magnetometer (compass)
Magnetometer calibration is the most difficult and unreliable.
Magnetic fields can be affected by so many factors - electric currents,
aircraft frame, environment, location, etc. - that it will be very difficult to
make precise and accurate compass heading measurements.
Magnetometer calibration is designed to remove hard-iron and soft-
iron magnetic offsets generated by components in the aircraft electronics
itself. Hard-iron interference is generated from permanently magnetized
components in the device while soft-iron offset is generated by temporarily
magnetized components (e.g. batteries, frame).
Calibration is accomplished by rotating the copter around all 3 axes
and assuming the hard and soft iron offsets are constant and move with the
aircraft, while the geomagnetic field does not. Therefore, by measuring the
field variation in every axis over time and applying a low-pass filter to the
signal, the DC component (or zero-frequency component) corresponds to the
hard and soft iron offsets and can therefore be subtracted from the
measurements; moving the aircraft quickly results in higher frequencies and
more accurate filtering of the DC component.
Calibration does not remove effects of the surrounding environment
to the geomagnetic field; buildings, minerals on the ground, electric wires,
etc. will still introduce errors to the compass measurements.
Because the calibration requires rotating the aircraft around its axis
in multiple orientations it is very difficult to execute with the drone
connected to the PC using the USB cable; it is much easier to perform using
the radio link.
Gyroscope
Gyroscope calibration is simple. Since this sensor is used to measure
rotational speed the calibration simply requires the aircraft to be placed on a
level surface without moving. The software can then calibrate the gyroscope
to reduce measurement errors.
where:
T = period in seconds
f = pulse frequency in Hz
One aspect to be considered is that the pulse is not really a perfect
rectangle; in real life it takes a few microseconds for the signal to go from 0
to the maximum voltage. This is called slew rate.
For Pixhawk with PX4 it is typical to use a frequency of 400 Hz,
corresponding to a period of 2,500 µs so normally the maximum pulse is set
to 2,000 µs for 100% duty cycle and leaving 250 µs for the slew rate.
For the minimum value, the industry standard is 1000 µs.
As a rule, ESCs must be calibrated. Calibration is the process of
programming the ESCs with the maximum and minimum pulse width that will
be provided by the flight controller, as well as other parameters associated
with the ESC functionality. Calibration guarantees all ESCs will respond the
same way to a certain pulse width.
For the Pixhawk running PX4, calibration is performed by
QGroundControl. The software will set the maximum and minimum values
for the PWM pulse, safety features, etc. For a detailed description on how to
calibrate ESCs see [19].
About Oneshot protocol
It is worth mentioning that some ESCs support the Oneshot
protocol, which is also supported by Pixhawk 4 running on PX4. One of the
drawbacks of standard PWM is the 400 Hz frequency; it means that there’s
always a 1 - 2 ms delay between the flight controller and ESC before the
motor receives the new values for the voltage. For most applications this is
quite tolerable, but some applications - for example, racing - may require
faster reaction times.
Oneshot125 uses a higher frequency and shorter pulses to reduce the
delay. Oneshot125 uses pulses from 125 µs to 250 µs (maximum of 4 kHz).
When using Oneshot125, PX4 automatically converts the values set to
PWM_MAX to the proper pulse width.
PID controllers
As we've seen in the earlier chapters of this text, the PID controllers
are used for automatic management of the power supplied to the motors,
based on the setpoints for certain variables of interest.
PX4 implements several PID controllers that can be classified into
rate controllers and attitude controllers. These controllers work together in
order to provide the final throttle to each motor in the multi-propeller copter
so it can achieve the desired attitude.
The flight controller software implements multiple PID controllers
that monitor pitch, yaw, roll - both current values and rate of change -, both
vertical and horizontal speed and acceleration, trajectory, distance to
waypoint, altitude, etc.. All these PIDs contribute to the thrust of each
individual motor to achieve the behavior requested by the pilot.
Also the setpoint for several of these controllers is not fixed, but is
also the output of another PID controller. For example, the desired horizontal
speed is the output of a proportional controller that uses the distance between
the current position and the target position.
PX4 sets default values for the gains of these controllers; in general,
the derivative and integral controllers can be left alone, and only the
proportional controllers need to be adjusted by the designer.
As it can be seen, the implementation of PID controllers and their use
can be quite sophisticated and complex. Further study of the PX4 software is
recommended for a deeper understanding on how the software controls the
UAV flight.
Summary
Before safely flying the UAV, all sensors must be calibrated. In
fact, PX4, as a safety precaution, will not allow take-off until all calibration
is finished.
Each sensor must be calibrated to compensate for potential errors
inserted by the environment.
ESCs must also be calibrated so the flight controller can learn how
to regulate the PWM signals used to control the motors.
Finally, PID controllers must have their gains properly set.
Problems
1. Assuming a quadcopter in a “X” configuration, where the red
arrow indicates the front of the aircraft:
The pilot commands the UAV to fly at angle θ from North (Northeast
direction), at speed setpoint vd, while maintaining altitude and heading 00
(North).
Both horizontal speed and altitude are regulated by a proportional
controller, with gains Ks and Kh, respectively.
where:
Fxi = horizontal forces from each motor
b. What will be the total thrust applied to each motor in order to also
maintain the desired altitude hd?
Computer selection
When selecting the on-board computer that will be integrated with the flight controller several
aspects must be taken into account.
1. Weight
2. Size
3. Voltage and current
4. Computing power
5. Memory and storage
6. Peripherals
Weight
This one is quite obvious: heavier on-board computers will reduce the maximum payload that
can be carried by the aircraft. So favor systems that are a few grams and can operate for long periods of
time without refrigeration (e.g. electric fans).
Size
Real estate in the multi-copter is limited. An industrial multicopter that will carry several
pounds of payload, there is probably enough space for large motherboards equipped with powerful
CPUs.
If however this is a small drone there are several credit card sized computers available in the
market that are suitable for this type of application.
Voltage and current
Most CPUs are powered by a DC charger that provides 3.3, 5 or 12 volts, depending on the
power requirements of the computer. Be careful here: the batteries used in drones provide voltages as
integer multiples of 3.7 volts. In order to properly power the on-board computer a voltage regulator is
required.
When selecting a regulator, pay close attention to the input and output currents to make sure
they match the needs of the on-board computer and electronics used in the UAV.
Computing power
A relatively easy way to assess the computing power of an on-board computer is the clock: in
general, the higher the clock the faster the computer.
Other things to look at are: number of cores, number of threads per core and bus speeds.
Operating systems, programming languages and types of applications running in the on-board
computer are the main drivers for more or less computer power.
Applications written in C, running in a Real-Time Operating System (RTOS) like FreeRTOS or
QNX require much less computing power than a machine learning application written in Python and
running in a Linux-based OS like Ubuntu.
Applications that use AI or require processing large amounts of graphic content (e.g. video from
a camera) may require Graphics Processing Units (GPU) on top of the CPU.
Some research on board benchmarks using applications with similar functionality to the ones
running in the on-board computer will help.
As a rule of thumb, overestimate the specification: more computing power than needed doesn’t
hurt; less may cause catastrophic failure to the aircraft.
Memory and storage
Long gone are the days where memory and storage were prohibitively expensive and had to be
used with much care. Today one can buy 1 terabyte of storage for 150 bucks.
So when it comes to storage and memory there’s no reason to save; just go for the maximum
the on-board computer can use.
Peripherals
Here again the peripherals will be dependent on the application. In general a good general
purpose I/O (GPIO) interface with support for SPI, I2C and UART pins is a must; a few USB ports; an
Ethernet port; WiFi.
Other interfaces needed are video input and output, preferably HDMI, allowing interaction
with the computer for software installation and configuration.
The serial interface in the GPIO is the main interface with the flight controller; SPI and I2C
external interfaces are useful for additional sensors not connected to or supported by the flight
controller.
USB and Ethernet ports are needed for connecting WiFi and/or cellular modems.
Below is a list with characteristics of credit card sized on-board computers with high-end
specifications:
Name CPU/GPU Size Peripherals Volta Operatin
(Compa memory/ (mm)/ ge g
ny) storage weight /curr system
(g) ent
RPi 4 CPU: BCM2711, Quad core Cortex-A72 (ARM Size: 2 x USB 2.0 type-A 5V Raspberry Pi
(Raspberry v8) 64-bit SoC @ 1.5GHz 85.6mm × 2 x USB 3.0 type-A 3A OS
PI RAM: 8 GB 56.5mm 1 x Gigabit Ethernet
Foundation Disk: SD card (128 GB) Weight: 45 2 x mini HDMI out
) GPU: VideoCore VI g 40-pin GPIO (UART,
SPI, I2C)
WiFi
Bluetooth LE
BeagleBon CPU: AM5729 w/ 2 x Cortex-A15 @ 1,5 GHz Size: 1 x USB 3.0 type-C 5V Linux
eA RAM: 1 GB 89mm x 1 x USB 2.0 type-A 3A
(BeagleBoa Disk: eMMC 16 GB 54mm 2 x 46-pin headers with
rd GPU: 2 x SGX544 Weight: 48 PRU support
Foundation g
)
ROCKPro6 CPU: RK3399 w/ 1 x dual-core Cortex-A72 @ Size: 1x USB 3.0 type C Host 12 V Linux
4 2 GHz + 1 x quad-core Cortex-A53 @ 1.5 GHz 133mm x with DP 1.2 5A Android
(PINE64) RAM: 2 and 4 GB 80mm 1x USB 3.0 type A Host Unix
Disk: SD card/eMMC 256 GB Weight 2 x USB 2.0 Host
GPU: Mali-T860MP4 @ 650 MHz (w/ Gigabit Ethernet
RAM: heatsink): PI-2 GPIO Bus
136 g MiPi DSI
eDP
touch Panel stereo MiPi
CSI
PCIe
WiFi/BT
HDMI out
Coral CPU: NXP iMX 8M w/ 1 x Cortex-A53 @ 1,5 Size: 1 x USB Type-C power 5V Mendel Linux
(Google) GHz + 1 x Cortex-M4 microcontroller @ 120 85mm x port (5 V DC) 3A
MHz 56mm 1 x USB 3.0 Type-C
GPU: Vivante GC7000Lite Weight: OTG port
H/W codecs 138 g (w/ x USB 3.0 Type-A host
TPU: Edge TPU coprocessor (TensorFlow) fan) port
RAM: 4 GB 1 x USB 2.0 Micro-B
Disk: serial console port
eMMC 8GB HDMI out
SD card: - 40-pin GPIO
Gigabit Ethernet
WiFi/BT
ODYSSEY CPU: Intel® Celeron® J4105 @ 1.5 GHz Size: 1 × 40-Pin (Raspberry 12 V Windows 10
X86J41058 GPU: Intel® UHD Graphics 600 @ 750 MHz 110mm x Pi) 5A
00 RAM: 8 GB 110mm 1 × 28-Pin
(Seed) Disk: eMMC 64 GB Weight: 1 × 4-Pin UART
600 g (w/ 3 × 4-Pin SATA Power
heatsink) Connector
1 × 4-Pin Power and
Switch
2 x USB 2.0 Type-A
1 x USB 3.1 Type-A
1 x USB 3.1 Type-C
HDMI
2 x Gigabit Ethernet
4 x PCIe
WiFi
Jetson CPU: Quad-core ARM A57 @ 1.43 GHz Size: 69 4 x USB 3.0 Type-A 5V NVIDIA L4T
Nano GPU: 128-core Maxwell mm x 45 1 x USB 2.0 Micro-B 6A (derived from
(NVIDIA) RAM: 4 GB mm Gigabit Ethernet Ubuntu
Disk: SD card (> 16 GB) Weight: HDMI 18.04)
240 g DisplayPort
40-pin GPIO
Hikey 970 CPU: HiSilicon Kirin 970 w/ Quad-core Cortex- Size: 1 x 40-pin low-speed 12 V Android
(96Boards) A73 2.36GHz + Quad-core Cortex-A53 105.26mm header 2A Linux
@1.8GHz x 100mm 1 x 60-pin high speed
GPU: Mali-G72 MP12 Weight: header
RAM: 6 GB 150 g (UART, I2C, USB, etc.
Disk: SD card 64 GB
through the extension
headers)
WiFi
Bluetooth
GPS
Figure 11 shows the terminals in the Pixhawk. Terminals TELEM 1 and TELEM 2 are UARTs
that allow an on-board computer to transmit commands and receive messages from the flight controller.
In general the on-board computer must be connected only to TELEM 1 to transmit commands to
and receive messages from the flight controller.
TELEM 1 uses a serial UART interface that must be configured with the same attributes as the
on-board computer serial interface; the configuration parameter depends on the software running in the
flight controller as well as the flight controller hardware.
For PX4, use QGroundControl to change the following parameters:
Set it to
2
Table 1: Configuration parameters for serial port TELEM 1
Message types
There are 2 types of messages that can be received over TELEM 1: responses to commands and
unsolicited messages.
Response to commands are normally messages containing data requested by the on-board
computer (e.g. HOME_POSITION message as response to a MAV_CMD_GET_HOME_POSITION
command).
Unsolicited messages are messages sent by the flight controller, either periodically or as a
response to an event (e.g. periodic message GPS_RAW_INT). Which messages and how often these
messages are sent depends on the software running in the Pixhawk.
For PX4 running MAVLINK in on-board mode the unsolicited messages are listed in Table 2.
Not all messages in Table 2 are available - or useful - to a multi-propeller copter; the ones
important for controlling the multi-propeller copter from an on-board computer are marked in bold and
italic.
Rate
Message
(messages/second)
TIMESYNC 10.0f
CAMERA_TRIGGER unlimited_rate
HIGHRES_IMU 50.0f
LOCAL_POSITION_NED 30.0f
ATTITUDE 100.0f
ALTITUDE 10.0f
DISTANCE_SENSOR 10.0f
MOUNT_ORIENTATION 10.0f
OBSTACLE_DISTANCE 10.0f
ODOMETRY 30.0f
ACTUATOR_CONTROL_TARGET0 10.0f
ADSB_VEHICLE unlimited_rate
ATTITUDE_QUATERNION 50.0f
ATTITUDE_TARGET 10.0f
BATTERY_STATUS 0.5f
CAMERA_CAPTURE 2.0f
CAMERA_IMAGE_CAPTURED unlimited_rate
COLLISION unlimited_rate
DEBUG 10.0f
DEBUG_FLOAT_ARRAY 10.0f
DEBUG_VECT 10.0f
ESTIMATOR_STATUS 1.0f
EXTENDED_SYS_STATE 5.0f
GLOBAL_POSITION_INT 50.0f
GPS2_RAW unlimited_rate
GPS_RAW_INT unlimited_rate
HOME_POSITION 0.5f
NAMED_VALUE_FLOAT 10.0f
NAV_CONTROLLER_OUTPUT 10.0f
OPTICAL_FLOW_RAD 10.0f
ORBIT_EXECUTION_STATUS 5.0f
PING 1.0f
POSITION_TARGET_GLOBAL_INT 10.0f
POSITION_TARGET_LOCAL_NED 10.0f
RAW_RPM 5.0f
RC_CHANNELS 20.0f
SERVO_OUTPUT_RAW_0 10.0f
SYS_STATUS 5.0f
SYSTEM_TIME 1.0f
TRAJECTORY_REPRESENTATION_WAYPOINTS 5.0f
UTM_GLOBAL_POSITION 1.0f
VFR_HUD 10.0f
VIBRATION 0.5f
WIND_COV 10.0f
HEARTBEAT 1.0f
Table 2: List of unsolicited MAVLINK messages in on-board mode
Flying the multi-propeller copter
There are 2 basic mechanisms for flying the multi-propeller copter using MAVLINK: MIssion
Protocol and the Command Protocol.
The Mission Protocol allows the operator to push a complete set of commands to the flight
controller and let it take care of the whole mission. This is a case where the on-board computer is used
for other activities that are not related to the flight itself (e.g. capturing and transmitting real-time video).
The Command Protocol all allows the on-board computer to send single commands to the flight
controller as required by the current situation. In this work, we’ll focus on the Command Protocol, since
that’s where the power of an on-board computer is more relevant.
Frames of reference and modes of operation
Val
Field Name
ue
128 MAV_MODE_FLAG_SAFETY_ARMED
64 MAV_MODE_FLAG_MANUAL_INPUT_ENABLED
32 MAV_MODE_FLAG_HIL_ENABLED
16 MAV_MODE_FLAG_STABILIZE_ENABLED
8 MAV_MODE_FLAG_GUIDED_ENABLED
4 MAV_MODE_FLAG_AUTO_ENABLED
2 MAV_MODE_FLAG_TEST_ENABLED
1 MAV_MODE_FLAG_CUSTOM_MODE_ENABLED
But the modes of operation are not restricted to these; on top of that, MAVLINK allows for
additional custom flags that are implementation-dependent (e.g.
PX4_CUSTOM_MAIN_MODE_AUTO) and not always well documented.
Core flight commands
Despite the complexity of the protocol, the fact is that, in order to fly a multi-propeller copter,
only a handful of commands is required.
Flying a multi-propeller copter can be summarized in 7 operations:
Flight Description
operations
Turn on the motors; propellers are spinning but not fast enough for the
1. Arm copter to start flying
motor
s
Hover in place
5. Hover
Stop motors
7. Disar
m
motor
s
These steps can be accomplished with different combinations of commands. This is how
QGroundControl does it:
Operation Message
Arm motor COMMAND_LONG (76)
Command: 400 (MAV_CMD_COMPONENT_ARM_DISARM)
Param1: 1 (arm)
Param2: 0 (does not bypass safety checks)
Take-off SET_MODE (11)
Base_mode: 157 (bitmask 10011101) = safety_armed, stabilize_enabled,
1. Set the guided_enabled, auto_enabled, custom_mode_enabled)
required Custom main mode: 4 = PX4_CUSTOM_MAIN_MODE_AUTO
flags Custom sub mode: 3 = PX4_CUSTOM_SUB_MODE_AUTO_LOITER (will
2. Send hover once take-off altitude is reached)
command COMMAND_LONG (78)
to take-off Command: 22 (MAV_CMD_NAV_TAKEOFF)
Param1: -1 (pitch, not applicable for copter)
Param7: AMSL
Go to waypoint COMMAND_LONG
Command: 192 (MAV_CMD_DO_REPOSITION)
Param1: -1 (default speed)
Param2: 1 (aircraft immediately transition to guided mode)
Param4: NaN (yaw = uses current yaw setting)
Param5: <destination latitude>
Param6: <destination longitude>
Param7: <destination AMSL>
Change altitude COMMAND_LONG
Command: 192 (MAV_CMD_DO_REPOSITION)
Param1: -1 (default speed)
Param2: 1 (aircraft immediately transition to guided mode)
Param4: NaN (yaw = uses current system yaw, for example yaw towards next
waypoint)
Param5:NaN
Param6: NaN
Param7: <destination AMSL>
Hover COMMAND_LONG
Command: 192 (MAV_CMD_DO_REPOSITION)
Param1: -1 (default speed)
Param2: 1 (aircraft immediately transition to guided mode)
Param4: NaN (yaw = uses current yaw setting)
Param5:NaN
Param6: NaN
Param7: NaN
Land SET_MODE (11)
Base_mode: 157 (bitmask 10011101) = safety_armed, stabilize_enabled,
guided_enabled, auto_enabled, custom_mode_enabled)
Custom main mode: 4 = PX4_CUSTOM_MAIN_MODE_AUTO
Custom sub mode: 6 = PX4_CUSTOM_SUB_MODE_AUTO_LAND
Disarm COMMAND_LONG (76)
Command: 400 (MAV_CMD_COMPONENT_ARM_DISARM)
Param1: 0 (disarm)
Param2: 0 (does not bypass safety checks)
So it is clear that, despite the fact that MAVLINK provides a large set of navigation commands
for all these operations, the multi-propeller copter can be fully operated using only 2 commands and 1
message - MAV_CMD_COMPONENT_ARM_DISARM, SET_MODE and
MAV_CMD_DO_REPOSITION - for all flight operations.
Parameters and settings
PX4 provides over 600 parameters that can be configured by the aircraft operator.
For the commands described in the previous section just a few parameters are relevant,
especially for the ones that explicitly used the default value or current settings:
Available libraries
When developing software for the onboard computer that will take advantage of MAVLINK,
using pre-existing tested libraries implementing the protocol makes life much easier.
mavgenerate[27] is the de-facto standard tool for developers that need to build a MAVLINK
library for their application. mavgenerate provides a graphic user interface for the developer to use
when generating the source code.
mavgenerate currently supports C, CS-4, JavaScript, TypeScript, Python, Lua, WLua, ObjC,
Swift, Java and C++-11.
In order to use mavgenerate the developer must do the following (these are commands for
machines running some flavor of Linux)
1. Install Python 3
2. Install the future module: pip3 install future
3. If using Linux to run the tool, install TkInter: sudo apt-get install python3-tk
4. Create a folder and download the tool in it: git clone
https://github.com/mavlink/mavlink.git --recursive
<?xml version="1.0"?>
<mavlink>
<include>common.xml</include>
<version>3</version>
<dialect>0</dialect>
<enums>
<enum name="PX4_CUSTOM_MAIN_MODE">
<entry value="1" name="PX4_CUSTOM_MAIN_MODE_MANUAL"/>
<entry value="2" name="PX4_CUSTOM_MAIN_MODE_ALTCTL"/>
<entry value="3" name="PX4_CUSTOM_MAIN_MODE_POSCTL"/>
<entry value="4" name="PX4_CUSTOM_MAIN_MODE_AUTO"/>
<entry value="5" name="PX4_CUSTOM_MAIN_MODE_ACRO"/>
<entry value="6" name="PX4_CUSTOM_MAIN_MODE_OFFBOARD"/>
<entry value="7" name="PX4_CUSTOM_MAIN_MODE_STABILIZED"/>
<entry value="8" name="PX4_CUSTOM_MAIN_MODE_RATTITUDE"/>
<entry value="9" name="PX4_CUSTOM_MAIN_MODE_SIMPLE"/>
</enum>
<enum name="PX4_CUSTOM_SUB_MODE_AUTO">
<entry value="1" name="PX4_CUSTOM_SUB_MODE_AUTO_READY"/>
<entry value="2" name="PX4_CUSTOM_SUB_MODE_AUTO_TAKEOFF"/>
<entry value="3" name="PX4_CUSTOM_SUB_MODE_AUTO_LOITER"/>
<entry value="4" name="PX4_CUSTOM_SUB_MODE_AUTO_MISSION"/>
<entry value="5" name="PX4_CUSTOM_SUB_MODE_AUTO_RTL"/>
<entry value="6" name="PX4_CUSTOM_SUB_MODE_AUTO_LAND"/>
<entry value="7"
name="PX4_CUSTOM_SUB_MODE_AUTO_RESERVED_DO_NOT_USE"/>
<entry value="8" name="PX4_CUSTOM_SUB_MODE_AUTO_FOLLOW_TARGET"/>
<entry value="9" name="PX4_CUSTOM_SUB_MODE_AUTO_PRECLAND"/>
</enum>
<enum name="PX4_CUSTOM_SUB_MODE_POSCTL">
<entry value="0" name="PX4_CUSTOM_SUB_MODE_POSCTL_POSCTL"/>
<entry value="1" name="PX4_CUSTOM_SUB_MODE_POSCTL_ORBIT"/>
</enum>
</enums>
<messages/>
</mavlink>
Summary
On-board computing is useful for adding functionality to the UAV beyond simply flying.
On-board computers can be used to:
● Run applications to control and interact with on-board equipment (e.g. cameras, scientific
instruments, etc.)
● Run applications to interact with the web
● Run AI software that will control the UAV autonomously (e.g. power line inspection UAV)
The appropriate size for the on-board computer will depend on the payload capacity,
application and size of the aircraft. It can go from small microcontrollers to powerful, full-size
computers running multiple CPUs and GPUs.
Problems
1. (Requires knowledge of computer programming) Using the generated source code for one
of the programming languages (examples here), write a small program for RPi 4 that
generates the MAVLINK messages used for flying the UAV
Chapter 6 - Designing a multi-
propeller copter
Objectives
This chapter covers:
● Propeller thrust and consumed electrical and mechanical power
● Propeller and motor key parameters
● Batteries, ESCs and power distribution
● Electronic components on board of the UAV
● UAV parts and mechanical structure
● Systematic calculation procedure for propellers, motors, power and
frame parts
(6.1)
where:
TT = maximum total thrust from all motor-propeller pairs in Newtons
WB = weight of one battery
WP = maximum weight of payload
WFM = estimated weight of frame + motors
n = number of batteries
As indicated above, at maximum thrust, the motor-propeller pairs
are consuming the maximum available electrical power, given by:
(6.2)
where:
PE = available electrical power per motor-propeller pair
IM AX = maximum safe current provided by batteries (limited by wiring and
battery connectors)
VE = voltage applied to the on-board electronics (typically 5 V)
IE = current consumed by the on-board electronics (depends on the UAV
configuration)
Thrust, power and motor specification
In this chapter only DC electric brushless motors, by far the most popular motors for copters, are
considered. These motors are compact, durable, precise, lightweight and affordable.
A brushless electric motor is characterized by its kV rating, the motor’s constant velocity. This
number conveys the RPM per volt applied to the motor.
Propellers are characterized by 3 parameters: diameter, number of blades and pitch. In this
analysis the propeller is assumed to have 2 blades.
The ideal static thrust generated by one motor-propeller pair is given by: [22]
(6.3)
(6.4)
where:
TM = thrust per motor-propeller pair in Newtons
D = diameter of the propeller in meters
p = propeller pitch in meters
RPM = revolutions per minute of the motor-propeller pair
ρ = air density (1.225 kg/m3)
N = number of motor-propeller pairs
The mechanical power transmitted by the motor to the propeller is given by [22]:
(6.5)
(6.6)
where:
PEM = electrical power consumed by each motor-propeller pair in watts
PM M = useful power provided by the motor to the propeller
N = number of motor-propeller pairs
The kV rating of the motor is given by:
(6.7)
where:
kV = motor’s constant velocity or kV rating
RPM = rotations per minute of the motor-propeller pair
V = voltage applied to the motor’s terminals
The thrust and power formulas work for a pitch-to-diameter ratio up to 1:2; after that the
propeller efficiency is reduced due to several aerodynamic factors and further increases in pitch only
provide marginal increase in thrust.
Battery
Copters typically use lithium-polymer (LiPo) batteries for power.
LiPo batteries are built using 3.7 V cells connected in series and.or parallel to provide the
total voltage output and capacity of the battery; cells with different sizes have different capacities.
There are a few characteristics that must be considered when selecting the batteries:
● Capacity (mAh): the maximum charge a battery can hold.
○ The higher the capacity, the longer the copter can fly
● Discharge rating “C”: maximum safe current divided by the capacity
○ Use this to make sure the maximum current required by the UAV is below this absolute
upper limit
● Voltage (V): the maximum total voltage that can be supplied by the battery.
○ The higher the voltage, the higher the maximum RPM delivered by the motor; also some
motors are designed to work with a range of voltages
● Weight (g): the battery weight
○ Batteries within the same classification can have different weights
● Connector type and wire gauge: the connector type and wire gauge constrain the actual maximum
current that can be output by the battery
○ For example, an XT60 connector type allows for 60 A maximum current but a typical 12
AWG terminal wire allows only for a maximum of 40 A (more than that and the wire will
overheat).
There’s no explicit equation correlating the battery parameters with its weight, we’ll have to
rely on tables mapping these values; in any case it can be considered the battery weight as a function -
albeit unknown - of the capacity.
Here is a chart for weight x capacity:
(6.8)
where:
IESC = minimum ESC current
PEM = electrical power consumed by each motor-propeller pair in watts
V = batteries voltage
Flight duration
By definition, the flight duration depends on the number of batteries and the total current drained
by the UAV:
(6.9)
where:
FD = flight duration
C = capacity of each battery
ID = total current consumed by the drone
n = number of batteries
However, as it was mentioned before, there are constraints on the maximum current a LiPo
battery can effectively provide, from both the connector type and the wire gauge.
So, in reality, the total current consumed by the UAV must be:
where:
IM AX = maximum safe current per battery
(6.10)
In other words, the minimum flight duration does not depend on how many batteries are
installed. This is an important result, since it helps to eliminate configurations that do not meet the
minimum flight duration requirements right away.
For example, if a minimum flight duration of 30 minutes is required and the maximum current
that can be safely provided by the battery is 30 A (due to connector size and wire gauge), then only
batteries with capacity above 15000 mAh must be considered.
Calculation procedure
Before proceeding with the calculations, a word of advice: as it was studied in the first
chapters, the equations and formulas used here are models for the behavior of the components; as such,
they are approximations and many variables and factors are left out.
In general, the values calculated here will have a 25% error when compared with the numbers
provided by the manufacturer, and will be valid up to about 10000 revolutions per minute and a pitch-to-
diameter ratio of about 1:2; after that, other losses and inefficiencies become more relevant and affect
the available power and thrust.
The calculations also assume a 2-blade propeller; using a 3 or 4 blades propeller requires
adjustments to the equations.
The variables in our system of equations are:
V, C, IM AX and ID = voltage and current parameters
D, p = propeller’s diameter and pitch
kV = motor parameter
PM M . PEM , TM and RPM = power - both mechanical and electrical - , thrust and RPM per motor-
propeller pair
n, N = number of batteries and motor-propeller pairs
WP, WFM , WB= weights of the payload, frame and batteries, respectively
It’s clear that there are way more variables than equations, so it is not possible to resolve the
system of equations without postulating arbitrary values or constraints for some of the variables.
Besides, because the system is composed of nonlinear equations, it is difficult to resolve it
analytically. Therefore, a numeric approach is used.
The spreadsheet with these formulas and calculations is downloadable from [24]; the chart with
battery parameters used for the calculations can be found here [25].
Repeat the calculations using different numbers for the payload, frame weight and number of
propellers and batteries, until a suitable configuration shows up.
It’s not a problem to overestimate the numbers and end up with a UAV with more capacity than
required. An overdimensioned UAV is safe; in the best case, an underdimensioned aircraft will not fly;
in the worst it will fly haphazardly and be a danger to its surroundings. Do not underestimate the damage
a fiberglass blade, spinning at 7000 RPM, can make.
Step 1: Define the design constraints
In this step, enough variables must be set so that it is possible to calculate the remaining
parameters from these constraints.
There are no set rules for which variables must be set. For this procedure it is assumed that
the following variables are selected:
1. WP = the maximum payload to be carried by the UAV
2. WFM = estimated weight of the frame, including electronics and motors. A good rule of
thumb for an initial estimate is to make the frame’s weight 2 times the payload.
3. IE = estimate for the current consumed by the on-board electronic components
4. IM AX = maximum safe current; it will depend on the battery connectors and wires and
number of batteries. For batteries using an XT60 connector and 12 AWG wires, 30 A per
battery is safe; for XT90 with 10 AWG wires 50 A per battery is fine.
5. VE = voltage applied to the electronics. It is usually 5 V, depending on the electronics on
board.
6. n = number of batteries; 2 batteries is common. Some heavy lifting UAVs can carry up to 6
batteries.
Observe that equation (6.5) shows an exponential relationship between mechanical power and
thrust.
This relationship is one of the reasons why adding more batteries to the UAV does not
necessarily increase the flight duration significantly, especially if the batteries are a major contributor to
the overall aircraft weight.
Just as an example, let’s say one battery represents 50% of the total weight; adding a new
battery means increasing the required thrust by 50%; the corresponding increase in required power will
be 80%. So the capacity is doubled, but the power requirement is also almost doubled; the gain in flight
duration will be about 10%.
On the other hand, if the batteries represent only 10% of the total weight, adding a new battery
can increase flight duration by about 75%.
It is important to keep these in mind when selecting the battery type and number of batteries for
the UAV.
The next steps are repeated for each battery and different number of motor-propeller pairs.
● 4, 6 and 8 motor-propeller pairs are common configurations, but others are possible. In order to
expedite the calculations, using the spreadsheet is recommended.
● The following variables come from the batteries specifications: V, C and WB. Use then in the
calculations described in the next steps
Step 2: Calculate F D, TT and TM
Use Equations (6.1) for TT , (6.4) for TM . Use each battery weight for WB.
Use Equation (6.10) for FD. As stated before, if the flight duration is a constraint, its value can
be used to eliminate unsuitable configurations. Use each battery capacity for the value of C.
Step 3: Calculate P E, P EM and P MM
From (6.2), calculate PE. This is the maximum electrical power available for the motors,
running at full thrust. Use each battery voltage for the value of V.
From (6.6) calculate PEM . This is the maximum electrical power available per motor-
propeller pair.
From (6.5) calculate PM M as a fraction of PEM . As indicated in the expression, make PM M
about 85% of PE.
where:
PM M = available mechanical power from step 3
TM = thrust per motor from step 2
Make the pitch half of the diameter. As indicated before, beyond that the models do not stand
since other aerodynamic effects become more relevant.
The next sections will use the propeller dimensions to calculate the size of the frame - arms,
body and landing gear/legs - and kV to find a suitable motor.
Frame size
In this section it is assumed a symmetric geometry will be used for the calculations.
As mentioned in previous sections, using pairs of counter-rotating propellers, mounted
symmetrically opposite to each other, makes it easier to compensate for the angular momentum and better
control the copter’s yaw.
Therefore, an even number of motor-propeller pairs is typical when designing copters. If an
odd number of motor-propeller pairs is a hard requirement, one solution is to use 2 counter rotating
propellers on each arm of the copter; another, more complicated approach from a system control
perspective, is to have the motors turning at different RPMs.
The calculations from the previous section provided the following information:
From these numbers the size of the copter’s body, as well as the length of each arm, can be
calculated.
Arms length
The length of each arm will depend on the size and number propellers as well as the copter
shape. and structure.
Assuming the N propellers are distributed symmetrically and radially around the copter’s
center body, then the center of each propeller corresponds to the vertex of a regular polygon with N
sides.
The length of the side of a regular polygon is related to the distance between the vertex and the
center of the polygon by this formula:
where:
L = distance between center of motor-propellers pairs
R = length of each arm
N = number of sides of the polygon
Therefore:
where:
L = distance between centers of the propellers
rP = radius of the propeller
D = diameter of the propeller
Therefore:
One disadvantage of the hashtag design is that, if the diameter for the actual propeller ends up
to be larger than calculated, it affects the size of the whole UAV frame; in the traditional radial
configuration it only affects the length of the arms.
Finally, aircraft storage and transportation is also a factor to consider. Rigid arms will work,
but storage and shipping may get difficult. One common solution is to use folding arm connectors.
Example: JMT Z16 DIY Aluminum Folding Arm
Legs
Multi-propeller copters usually rely on legs as landing gear. Landing gear can be fixed or
retractable. Retractable landing gear will normally be mounted to retract outwards to avoid physical
contact with the batteries and payload, usually placed under the copter’s body.
Each leg can be divided into 3 core parts: head, body and foot.
Head
The head is the part connected to the copter; the legs can be connected to the copter’s body, to
the copter’s arm or under the motor itself.
The leg can also be retractable, with a folding joint at or near the head equipped with a servo
motor that allows the landing gear to be folded during flight.
Example: powerday Tarot TL65B44 Retractable Landing
Body
The body is the structure of the leg itself; it can come in different shapes, materials and
configurations.
Example: ShareGoo Universal Tall Landing Gear, Mallofusa Universal Landing Gear
Foot
The foot is the part of the leg that touches the ground.
The criteria to select the proper landing gear are:
1. The vertical distance between the head and the foot must be greater than the height of
batteries plus payload
2. The horizontal distance between the head and the foot and mounting position must be such
that the foot is located as far from the body as possible, to improve stability on take-off and
landing
3. The material and structure must be able to support the weight of the UAV
In reality, most - if not all - landing gear and drone legs available in the market are designed for
specific commercial drones. In general, when working with custom drones, custom made legs will often
be required.
This doesn’t mean the legs must be difficult to build and install or expensive; the chapters
dedicated to the UAV design will show a simple, cheap, lightweight and strong way to build a landing
gear for the UAV.
UAV Body
The body is the central part of the aircraft. Here is where the electronics are placed, as well
as batteries and cables connecting the various components among themselves.
Despite the fact that there are hundreds of pre-fabricated form factors for the UAV body
available for a builder to choose from, when building a custom aircraft it may not be possible to find a
suitable one. For example, one will be hard pressed to find an off-the-shelf body that fits the 8 propeller
using the hashtag frame shape.
When selecting the body, the designer must take into account the following aspects:
1. Strength: The material must be hard enough to resist crashes but pliable enough to be
drilled and cut to shape
2. Weight: the material must be as light as possible so it does not compromise the payload
capacity or flight time
3. Surface area: it must provide enough space for mounting all the components in a suitable
distribution.
Propellers
UAV propellers can be made of composite polymeric materials like nylon, fiberglass and
carbon fiber. Carbon fiber propellers are more rigid and lighter, but may be less stable in windy
conditions. It is recommended to use cheaper plastic or fiberglass propellers for testing and validation
of the UAV parameters and functionality and then switch to carbon fiber only if needed.
Propellers can be manufactured to rotate either in clockwise or counterclockwise direction,
when looked from above, with the standard direction being counterclockwise. In general, copters will
use an even number of propellers, half rotating clockwise and half counterclockwise.
Diameter in a 2-bladed propeller is the length of the propeller from tip to tip, while pitch is
defined as the distance traveled by the propeller at one complete rotation.
Cont Description
rolle
r
mRo Popular general purpose flight controller (this is a slightly updated version of the
Pixha discontinued 3DR Pixhawk 1).
wk
Pixra Very small/light autopilot optimized for FPV racers. It is suited to any small frame that
cer requires no more than 6 PWM outputs.
Pixha Small general purpose autopilot that has been optimized for ease of setup.
wk The controller has internal vibration damping and only 8 main outputs (no AUX ports),
Mini making it much less daunting to install and connect. It is not suitable for
vehicles/functions that require AUX ports.
The following subsections are specific to the Pixhawk 4 running PX4 but all flight controllers
follow similar procedures
Sensor tuning/calibration
PID tuning
There are 3 PID controllers implemented in the PX4 code: roll rate, pitch rate and yaw rate.
The gains for these controllers are:
As it was studied in the first sections, to properly estimate the gains, follow these steps:
1. Write approximate equations for the physical model for the variable of interest
2. Determine closed loop system and add PID controller
3. Resolve the equation
4. Determine the gains for the desired behavior (fast climb to steady state, low overshoot, etc.)
As an example, let’s resolve for MPC_XY_VEL_P assuming only the proportional controller
Physical model
where:
K = MPC_XY_VEL_P
vD = desired horizontal velocity
v = current horizontal velocity
T = maximum thrust expected from the motors = 2mg (in PX4 the PID gains are used to calculate
percentages of the maxim thrust); maximum thrust is 2x the UAV weight
Here is a table with some gains selected from the allowed range and the corresponding vD and
time:
The values for the integral and derivative gains can be calculated following a similar
procedure.
Parameters
This section lists a set of parameters that must be set by hand with values appropriate to the
operation parameters of the application.
MAVLINK
Serial ports
Parameter Value Description
SER_GPS1_BAUD 0: auto (GPS driver discover baud rate Baud rate for the GPS port.
automatically) Pixhawk provides 2 but normally
1 GPS receiver is used
SER_TEL1_BAUD 115200: 115200 8N1; recommended Baud rate for the TELEM 1 Serial
baud rate for sensing telemetry from Port
PX4 as well as receiving MAVLINK Pixhawk provides several serial
messages ports; for interaction with an on-
board computer TELEM 1 is
sufficient
GPS_1_CONFIG 201: GPS 1 port Serial Configuration for Main GPS
Default value, keep it
MAV_0_CONFIG 101: TELEM 1 Serial Configuration for MAVLink
Default value, keep it (instance 0)
TEL_FRSKY_CONF 102: TELEM 2 This is the telemetry port
IG connected to the RC receiver.
No need to setup the baud rate, that
is done automatically by the PX4
driver
Multicopter position control
The parameters described here are relevant for autonomous mode. For the complete list see [28].
Name Description M D U
i ef n
n au it
> lt s
M
a
x
(
I
n
c
r
.
)
Name Description M D U
in ef n
> au i
M lt t
a s
x
MOT_ORDERI Motor Ordering 0 0
NG (INT32) Specific for certain UAVs that use 1-to-4 ESCs >
Keep the default 0 1
Name Description M D U
i ef n
n au i
> lt t
M s
a
x
SENS_BOARD_ Board rotation 0 0
ROT (INT32) This parameter defines the rotation of the FMU board >
relative to the platform; rotation is clockwise when 3
looking from above. 4
Each possible value maps to a different combination of
yaw, pitch and row.
0: No rotation
1: Yaw 45°
2: Yaw 90°
3: Yaw 135°
4: Yaw 180°
5: Yaw 225°
6: Yaw 270°
7: Yaw 315°
8: Roll 180°
9: Roll 180°, Yaw 45°
10: Roll 180°, Yaw 90°
11: Roll 180°, Yaw 135°
12: Pitch 180°
13: Roll 180°, Yaw 225°
14: Roll 180°, Yaw 270°
15: Roll 180°, Yaw 315°
16: Roll 90°
17: Roll 90°, Yaw 45°
18: Roll 90°, Yaw 90°
19: Roll 90°, Yaw 135°
20: Roll 270°
21: Roll 270°, Yaw 45°
22: Roll 270°, Yaw 90°
23: Roll 270°, Yaw 135°
24: Pitch 90°
25: Pitch 270°
26: Roll 270°, Yaw 270°
27: Roll 180°, Pitch 270°
28: Pitch 90°, Yaw 180
29: Pitch 90°, Roll 90°
30: Yaw 293°, Pitch 68°, Roll 90° (Solo)
31: Pitch 90°, Roll 270°
32: Pitch 9°, Yaw 180°
33: Pitch 45°
34: Pitch 315°
Additional components
This session covers the electronic components that, although not directly involved with flight,
are however fundamental for the proper functioning of the aircraft.
GNSS antenna/receiver
The UAV will not be able to maintain stable autonomous flight without a precise way to
determine its location. Without using optical flow cameras, stereoscopic cameras, lidars, sonars or other
sensors that allow the UAV to determine its position, stable flight is not possible.
Obviously, the simplest and most cost effective way to do so, at least for outdoor applications,
is via GNSS.
It is highly recommended to place the GNSS receiver away from the propellers and other
electronics to avoid radio-frequency and mechanical interference (signal multipath, reflection, etc.). For
that the builder will want to use a GPS antenna mount holder for the receiver; one usually comes with
the GPS receiver.
Ideally the holder is mounted as close to the center of the aircraft since the position is always
calculated relative to the antenna/receiver. This arrangement is, however, prone to damage in case of an
accident.
Alternatively, the developer can also cover the electronics with an RF blocking hard top and
then mount the receiver directly on top of it.
The GPS output is connected to the GPS 1 port in the Pixhawk.
Example: Holybro Pixhawk 4 GPS receiver (Ublox M8N), Ublox Neo-M8N GPS with
Compass, mRo GPS u-Blox Neo-M8N Dual Compass LIS3MDL+ IST8310, Drotek uBlox
GPS/Compasses, Holybro Micro M8N GPS Module, Holybro Ublox NEO-M8N GPS Module, Here
GNSS GPS (M8N), Zubax GNSS 2
In this configuration:
1. The on-board computer gets RTCM data via mobile network
2. The on-board computer pushes RTCM data to the RTK receiver via UART
3. The RTK receiver calculates the location using the correction data
4. The RTK board pushes location to the flight controller via UART output/GPS 1 input
This configuration is extremely flexible since it is very loosely coupled - in terms of hardware -
to the RTK service and RTK receiver providers the work is almost 100% done by software. Most, if not
all, RTK receivers can be configured to receive RTCM data via UART interface.
Cellular modem
The cellular network - in particular 4G and 5G technologies - is a suitable option for
telemetry and command/control of UAVs; it has excellent coverage, high throughput, low latency and
lower cost if compared to other forms of communication (e.g. satellite).
USB powered hub
All cellular modems - with rare exceptions that use the Ethernet port - will connect to the on
board computer using a USB port and be powered by it. Depending on the selected model, the modem
can pull a relatively high current and there is a good chance the USB port in the on-board computer will
not be able to supply it.
One possible solution is to use a USB hub with external power input. The power is supplied
to the modem via the hub.
Another option is to use a WiFi mobile hotspot that provides WiFi connectivity to the mobile
network; the hotspot can be powered directly by the voltage regulator and the on-board computer can
connect to it using a WiFi USB dongle. A mobile carrier data plan will be required to use a mobile
hotspot.
Some hobbyists use an actual cell phone for connectivity. There are many options in the market
that can be used to tether the on-board computer to the Internet. However, phones are quite expensive
and fragile; in a crash they can be permanently damaged.
Voltage regulators
As it was mentioned before, the voltage provided by the LiPo batteries commonly used in
UAVs are integer multiples of 3.7 V; this means that, in almost all cases, it is not possible to provide the
correct voltage to the electronic components on board of the aircraft.
Electronics commonly work under a few well-defined voltages: 3.3 V, 5 V and 12 V. In order
to obtain these voltages from the LiPO batteries one needs to resort to voltage regulators.
A voltage regulator will take a range of input voltages and provide a stable output voltage at a
level defined by the developer.
Here is a list of regulators that will provide the necessary power for the on-board computer,
the flight controller, the RC receiver and the GPS/RTK receiver as needed.
In order to reduce the hardware on board of the aircraft, a step-down voltage regulator that
covers a wide range of input voltages as well as providing enough current for all components is
recommended. The YEP 20A HV (2~12S) SBEC w/Selectable Voltage Output is an example of such a
regulator.
Power distribution
After all calculations are done, the size of the UAV is defined, the materials and components
selected, it is time to place them on the UAV and connect them. And this is more complicated than it
looks.
Providing power to all the components requires some careful planning. In the 8 propeller
design, the 2 batteries must provide power to the voltage regulator and 8 ESCs.
A convenient way of doing this is to use a power distribution board (PDB) or a power
management board (PMB).
PDBs and PMBs designed specifically for UAVs provide connectors that are conveniently
positioned to optimize the wiring and can withstand the high current levels associated with copter
operation.
It is also recommended installing a pair of power distribution bars as a way to organize the
wires coming from the battery into the power modules and electronics, for live power and ground.
Power distribution bars can handle over 150A and are commonly used in the automotive and maritime
industry.
5V distribution
For distribution of the 5 V power to some of the electronics, using splice wire terminals is a
good, inexpensive solution for connecting the power cables to the power terminals. The Nilight -
50004R 120 Pcs/60 Pairs Quick Splice Wire Terminals T-Tap Self-striping Kit is a very convenient
solution for currents up to 20 A, within the ranges used by ESCs and electronics.
Battery connectors
Batteries come with different types of connectors, specified for different current levels.
Here is a list of battery connector types and their specifications:
1 - 10 A 30 - 70 A 70+ A
Molex Deans or T Plug EC5
JST EC3 XT90
Deans XT60 Anderson Power Pole
Servo TRX Bullet Style
XT30 XT150
EC2 AS150
Batteries sporting either the XT60, XT90 or XT150 connectors are recommended for the
currents expected to be drained from each battery.
Battery charger
A good battery charger is an essential piece of equipment. TheEV-Peak CQ3 Multi Charger
4x 100W NiMH / LiPO with Built-in Balance is a good model, it supports different battery sizes and
types and can charge up to 4 batteries simultaneously.
Normally LiPo charges require a balance cable or board, so it can read status from the
battery. The HobbyStar JST-XH Balance Board Adapter is an example.
A set of banana plugs for the selected connector size is also needed for connecting the
batteries to the charger. Make sure the cables have the connectors with the right size for the battery
connectors.
Power module
It is highly recommended to have a power module installed in the UAV and connected to the
flight controller. In fact, it is not possible to do automatic ESC calibration without one connected to the
flight controller.
It is important to note that the power module is not a replacement for the voltage regulator; for
example the PM07 has a 3A limit in the 5V output so it can only power the Pixhawk through that output.
The voltage regulator is still needed for power to the on-board computer and other electronics on board
the UAV.
Details on the use and operation of the PM07 can be found here [32]
Power cables
Connecting power to the various electronic devices on board of the UAV can be challenging.
Many of the off-the-shelf devices are designed to be powered by bulky wall chargers not suitable for
this application.
Fortunately, if the reader uses the electronic components recommended in this book, all
electronics - except for the flight controller, powered by its own cable through the power module - are
powered using micro-USB or USB-C cables. It is relatively easy to find USB-C and micro-USB portal
cables for power only in the market; if not any USB cable can be cut and trimmed to serve this purpose.
When selecting the cables that connect the batteries to the power modules, pay close attention
to the currents expected to be consumed by the UAV For each current level and wire length, a cable with
the appropriate gauge is required in order to avoid overheating and even fire.
The table below summarizes the current limits for typical wire gauges used in UAVs.
Summary
There are many variables that affect the design of a UAV.
A systematic procedure was presented for determining the size of all required parts.
Nevertheless, sound estimates for several variables are required to make the calculations
possible; in that case, always try to overestimate the parameters. Overpowered drones are safe;
underpowered are a menace.
Be wary of the limits of physical models; they must be used to calculate a ballpark for the
necessary values. Always refine the calculations, once more data is available, in particular using
propeller and motor data from manufacturers.
Problems
1. Using the drone calculations spreadsheet, find a configuration that can fly for 30 minutes,
using the following constraints:
Software description
This section describes in detail the simplest client/server
application that can be implemented in the on-board computer that allows
command and control of a UAV over mobile cellular networks.
As is, this system is not feasible for a practical commercial
application since it requires several manual setup steps, only supports one
UAV at a time and provides no security or privacy features; however, it can
be used as a basis for one.
The source code is open source and available here, along with the
executable binaries.
The client application assumes that the on-board computer is an RPi4
running the Raspberry OS; this constraint is due to dependencies on the GPIO
configuration for the serial port; if a different on-board computer is used the
client must be modified and recompiled accordingly.
The functionality described here is not even close to everything
that can be done with software in an on-board computer. That software can
be as complex as an UAV with a powerful, AI enabled, on-board computer
using machine learning and computer vision to determine damage in a house
after a storm and autonomously deciding where to go next.
The system described here requires the following:
1. Laptop or tablet connected to the Internet (cable, WiFI, mobile)
2. Pixhawk with the latest PX4 firmware
a. Firmware can be updated by connecting Pixhawk to the
PC via USB and using QGroudControl to update the
firmware
b. The laptop/desktop must be connected to the Internet so
the new firmware can be downloaded.
c. Pixhawk must be powered solely by the PC’s USB port.
3. UAV with on-board computer connected to the flight controller
a. Again, the implementation assumes RPi 4 for the on-
board computer and Pixhawk running PX4; if a different
on-board computer is used the software must be modified
and re-compiled as needed.
4. QGroundControl installed in the laptop
a. QGroundControl will be used to send commands to the
UAV and receive telemetry
b. Use version 4.1.1 or later.
5. A free account with a hosting service like Amazon’s’ AWS or
RedHat’s OpenShift
a. Must allow running standalone software, not only web
pages
b. Must support running programs in Java
6. The server software running in the hosting server (need a Java
Runtime installed)
7. The client software running in the on-board computer (need a Java
Runtime installed)
Setup
1. Upload and run the server software in the server
Process
In order to use the algorithm previously described, one of the first
steps is to estimate the weight of the aircraft, without payload.
This is a little tricky because the weight depends on how many and
size of motors and propellers, but the motors cannot be determined until the
weight is known.
On top of that, the calculated diameter and RPM for the required
thrust and power will not match exactly the numbers from the manufacturer.
Here is the general flow:
1. Start with an initial educated guess for the weight of the UAV
(without batteries)
2. Using the drone selection spreadsheet [24], calculate the
propeller’s diameter and pitch, and the motor’s kV, using an
arbitrary number of batteries and propellers
3. Select a suitable configuration (e.g., based on flight duration or
propeller size)
4. Find a propeller with diameter and pitch around the calculated
values, and obtain the actual power, thrust and RPM combination
that match the required constraints for the UAV
5. Find a motor with kV around the the calculated value
6. Re-calculate the total weight of the UAV using the actual weight of
motors and propellers
7. Use the values from the selected propeller, motor and final weight
in with the drone calculation spreadsheet [24] and determine if the
results are still acceptable
8. If the results are not acceptable, start again using the new weight
estimates.
Weight estimate
The weight estimate will be an educated guess. In the bill of
materials provided in the next section, the weight of the components to be
used in the project is provided. From that table:
1. Electronics: 500 g
2. Arms, body, joints, landing gear: 1200 g
3. Motors: 1200 g (150 g per motor; assuming 8 motors)
In total, about 3 kg for the UAV without any payload and batteries.
As a rule of thumb, assume the payload to be no more than 50% of
the UAV weight. Remember, the battery’s weight is not taken into account in
this initial estimate so it is necessary to leave some room for it.
Propeller and motor parameters
Using the drone selection spreadsheet [24] with the following
constraints:
● 2 batteries
● 8 motors
● 3,000 g for frame weight
● 0 g fo payload
● 50 A per battery (WT90 connectors with 10 AWG wiring)
The design will use the output in row 20 of the spreadsheet as the
basis for the next steps:
● 2x Battery:
○ 6S1P
○ 10000 mAh of capacity
○ 1319 g of weight
○ 185 x 70 x 47 mm
○ 20 C discharge rate (444 A)
● 8 x Propeller:
○ 2 blades
○ 13 inches diameter
○ 6.5 inches pitch
○ At least 3.09 lbf (1310 g) of thrust at 6000 RPM
○ Maximum 0.350 HP of power @ 6000 RPM
● 8 x Motor:
○ 278 kV
○ Maximum 6154 RPM at full throttle
○ Maximum 260 W of electrical power at full throttle
● ESC
○ 12 A or more @ 22.2 V
Using this configuration, the uAV is predicted to hover for about 20
minutes, using about 1.3 kW of power at 4400 RPM.
Propeller selection
The design will use APC propellers. These are cost-effective,
good quality fiberglass composite propellers, designed specifically for
electrical motors.
The design spreadsheet recommends a 13 x 6.5 propeller, but
looking at the APC propeller specification the 12x6 seems to provide the
necessary thrust within the power limits, if a motor with a somewhat higher
kV is used. From the APC performance data [33] for these propellers:
● APC 12x6E (standard rotation, counterclockwise)
○ Thrust
■ 3.184 lbf @ 7000 RPM
■ 1.615 lbf @ 5000 RPM
○ Power
■ 0.240 HP @ 7000 RPM
■ 0.091 HP @ 5000 RPM
● APX 12x6EP (reverse rotation, clockwise)
○ Thrust
■ 3.186 lbf @ 7000 RPM
■ 1.616 lbf @ 5000 RPM
○ Power
■ 0.240 @ 7000 RPM
■ 0.091 HP @ 5000 RPM
The shaft diameter is 1/4”; with an adapter ring it will fit motors
with 1/8", 4mm, 5mm, 6mm and 5/16" shaft diameter. The center hub is 23.32
mm (0.8”) in diameter and 10.4 mm (0.41”) high.
Motor selection
Motor selection is more complicated than propeller:
1. Low kV motors are designed to provide high torque, and therefore
are heavier, larger motors, potentially outside the range assumed in
the design
2. High kV motors are lighter and can provide very high RPM, but
will pull more current to provide the RPM and power required by
the design, potentially going over the safety constraints.
Wiring
The UAV may consume around 100 A during flight, while each motor may consume about 7 A
each.
Therefore, here is the wiring gauge required for powering the motors:
● Batteries:
○ Connector: XT90
○ Wire: 10 AWG
● ESC
○ Wire: 18 AWG
It is a good idea to avoid loose cables in an UAV, considering that they can interfere with the
propellers during flight. It is recommended the use of self-adhesive wire clips to route the cables and
keep them in place, flush to the aircraft body.
Bill of materials
At this point all required elements for building the UAV are defined and calculated.
Below is a list of all components needed to build the octocopter designed in this text, along with
prices from specific providers and weight for each component.
A blueprint for the UAV assembly is also provided, with the suggested position of each
component and the associated wiring.
All components are attached to the UAV using heavy duty hook-and-loop fasteners (e.g.
Velcro) so they can be easily replaced if needed but will still be firmly positioned during flight.
UAV components
Component Price (USD) Weight Dimensions
(g) (mm)
(W x L x H)
The final weight is about 500 g higher than estimated, with a corresponding decrease in flight
time, now expected to be 17 minutes instead of the original 20 minutes. For this design, this reduction is
acceptable and the calculations are considered complete at this point.
If this reduction in flight time is not acceptable, the designer must then go back to the
spreadsheet, put the new weight and recalculate; as indicated before, the process is iterative and it may
take a few rounds before an acceptable configuration is found.
Other materials and tools
This section list the extra materials and tools required for building the UAV:
● Soldering iron, wire and flux
● Wire cutter/stripper
● Cable crimper for wire lugs
● Voltmeter/amperemeter/resistometer (for checking wire connections)
● XT90/10 AWG pigtail cables
● 6, 10 and 18 AWG wires
● Power drill
● Drill bits for acrylic
● Electric saw (handheld or table)
● Mask (due to toxic fumes/particles created when cutting carbon fiber tubes)
● Heavy duty hook-and-loop fasteners
● Taranis X9D RC controller
● Mouse, keyboard, monitor, HDMI cables, etc. (for interaction with RPi 4)
● Screwdrivers, Allen keys, wrenches (different sizes)
● Zip ties of different lengths and sizes (15”, 5”, 3”)
● 2 x 50 amp toggle switch (optional)
● 1 x Nilight - 50004R 120 Pcs/60 Pairs Quick Splice Wire Terminals T-Tap Self-stripping
● Wire lugs for 10 and 6 AWG wires (sizes M4 and M6)
● Wire connectors (multiple gauges)
● Copter landing pad (optional)
● Male JR plug wire extensions (12”)
● EV-Peak CQ3 Multi Charger 4x 100W NiMH / LiPO with Built-in Balance
● Little Bee ESC USB Linker Programming Tool (Silabs)
Blueprint and instructions
This section presents the blueprint [35] for the UAV calculated in
the previous sections.
The blueprint indicates where each component is positioned, as
well as the wiring routes. Some drilling will be required for mounting the
battery holder and arm joints.
When following the blueprint, pay close attention to the position
and wiring of ESCs and motors; the position and corresponding PWM output
of each motor is essential for the proper operation of the UAV. Each ESC
must be properly connected to the motor, so it will rotate in the correct
direction, according to the indications in the blueprint. Remember, the
normal direction is counterclockwise (CCW).
The components are located where they are to facilitate connection
between components and to balance the weight distribution.
Instructions
Work area
One more comment before moving to the next section. The BLHeli
Setup tool offers a tab called Motors, which allows testing if the ESCs are
properly programmed. The builder can connect motors to the ESCs, power
them up with the battery, and use the slides to see if they are spinning
properly and as expected.
This step is optional, but recommended. Finding out the ESCs are
not properly configured after mounted in the drone, along with the motors,
will be a major hurdle to the assembly process.
ESC connection to motors
Connection to the motors is both straightforward and tricky.
The 3 wires from the motor must be connected to the 3 plates in the
ESC, in the exact same order, as indicated in the figure below.
1. Using a label maker or tape, label each motor’s wires “A”. “B”
and “C” at the naked end
2. Mark the corresponding taps in the ESC with the same letters
a. A color code can also be used; important here is that the
taps are properly identified so they are connected to the
right cables
3. Using a label maker or tape, label the red cable on the battery side
with the corresponding motor code (“M1”, “M2”, etc.)
a. Refer to the blueprint for the position and direction of
rotation for each motor. Remember, “N” means
counterclockwise.
Step 2: Mount the foldable joints
1. Attach the motor mount plate to one end of a carbon fiber tube
2. Mount the motor on the mount plate, with the wires facing the ube;
no need to tight the screws yet, since the position may be changed
after all components are in place
3. Pass the motor wires through the carbon fiber tube
4. Pass the wire through the hole at the end of the carbon fiber holder
in the foldable joint
5. Insert the other end of the carbon fiber tube in the foldable joint
holder; make sure the motor mount plate is horizontal; fasten the
tube in place
6. Adjust the motor position so its axis is 9.2” away from the
corresponding yellow ⊗ symbol marked in the blueprint and
13” from axis to axis.
7. Fasten the motor to the motor mount plate using the screws
provided by the motor manufacturer
a. ATTENTION: Be extra careful when using the screws
provided by the motor’s manufacturer; if they go too far
up they will push the motor windings and severely affect
the motor’s performance; if the screws are too long for
the mount plate use shorter M2.5 screws.
1. Mount the ESCs in the proper positions under the frame body per
the blueprint
a. Make sure the ESCs marked “N” are mounted to the
“CCW” positions, while the ones marked “R” are
assigned to the “CW” positions
2. Mount the PM07 power module in the proper position per the
blueprint
3. Solder the 18 AWG wires to the motor power out terminals of the
PM07
a. Use red wires for the live terminal and black wires for
ground
4. Solder the JR plug extensions to the PWM outputs of PM07
a. Solder the black wire to ground and the other wire to the
corresponding PWM output (terminal marked with M1,
M2, M3, etc.)
5. Pass the 18 AWG wires and JR plug wires through the 1” wiring
hole in the frame’s body
6. Connect the 18 AWG wires from the PM07 to the battery wires
from the ESCs, paying attention to connect each cable to the
corresponding ESC
a. Using terminal connectors instead of soldering will make
it easier to disconnect the ESCs if needed
7. Connect the JR plug extensions coming from the PM07 to the JR
plug wire from the ESC
Mounting and connecting batteries and power
As the heaviest components in the UAV, the batteries require
special care when mounted.
1. Mount the power distribution bars as indicated in the blueprint.
a. Hook and loop tape can be used but, if preferred, the
power distribution bars can be screwed in place.
2. Mount the batteries in the positions indicated in the blueprint, with
the XT90 connectors facing towards the power distribution bars
a. If using a heavy duty hook-and-loop tape/strip, make sure
it can firmly attach to plastics like polycarbonate and can
hold the battery’s weight; tapes that can hold 10 lbs or
more are recommended
b. If using a battery mount plate:
i. Make sure they are positioned in the correct
location, so the batteries are centered.
ii. Make sure they do not cover the wiring hole
iii. The blueprint does not provide hole marks for
the mount plate because different plates have
mounting holes in different positions and with
different diameters
3. Solder the 6 AWG wires to the battery terminals in the PM07 and
connect them to the power distribution bars
a. Make sure the red wire goes to the positive terminal in
the PM07 and to live power distribution bar; the black
wire goes to the ground power bar
b. It is highly recommended to use lugs clamped to the
naked end of the 6 AWG wire to make the connection to
the power distribution bar more secure.
c. Do not connect the 6 AWG wires to the main posts of the
power distribution bars, use one of the other connections
4. Connect the XT90 pigtails to the power distribution bars
a. It is highly recommended to use lug connectors clamped
to the naked end of the XT90 pigtails
b. Use the 2 main posts in the power distribution bar to
connect the XT90 pigtails
c. Connect the red wire to the live power bar and the black
wire to the ground power bar
d. IMPORTANT: Do not connect the pigtails to the
batteries until all the work is done
Mounting and connecting remaining components
Waivers
Flying the aircraft outside of Part 107 requires the FAA to issue
waivers for the exception requested by the operation.
Here are some cases that require waivers:
● Operation from a moving vehicle or aircraft
● Night time operation
● Beyond visual line of sight aircraft operation
● Operation without a visual observer
● Operation of multiple small unmanned aircraft systems
● Yielding the right of way
● Operation over people
● Operation in certain airspace
● Operating limitations for small unmanned aircraft
This FAA page explains all the details regarding the process to
request a waiver.
Remote ID
As of December, 23rd, 2020, UAVs are required to fly carrying a
Remote Identification Broadcast Module, which broadcasts information
about the aircraft from take-off to shutdown.
The information broadcasted includes an aircraft unique identifier
and its location (latitude, longitude, etc.).
The broadcast is done over unlicensed radio spectrum regulated by
the Federal Communications Committee (FCC).
However, by the time this book was written, the actual
frequency/band used for the broadcast and if using the mobile cellular
network would be allowed were still under discussion.
The final rule from the FAA regarding Remote ID can be found here.
(A.1)
valid for x in the vicinity of x0.
Equation (A.1) represents a straight line and therefore is the linearized function in the vicinity of
x0. Expanding the terms and regrouping results in the linearized function:
For example:
The range of acceptable values for x will depend on the linearization error tolerance.
For the example above:
minimal/mavlink_msg_protocol_version.h
#pragma once
// MESSAGE PROTOCOL_VERSION PACKING
#define MAVLINK_MSG_ID_PROTOCOL_VERSION 300
/**
* @brief Get field version from protocol_version message
*
* @return Currently active MAVLink version number * 100: v1.0 is 100, v2.0 is 200, etc.
*/
static inline uint16_t mavlink_msg_protocol_version_get_version(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint16_t(msg, 0);
}
/**
* @brief Get field min_version from protocol_version message
*
* @return Minimum MAVLink version supported
*/
static inline uint16_t mavlink_msg_protocol_version_get_min_version(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint16_t(msg, 2);
}
/**
* @brief Get field max_version from protocol_version message
*
* @return Maximum MAVLink version supported (set to the same value as version by default)
*/
static inline uint16_t mavlink_msg_protocol_version_get_max_version(const mavlink_message_t* msg)
{
return _MAV_RETURN_uint16_t(msg, 4);
}
/**
* @brief Get field spec_version_hash from protocol_version message
*
* @return The first 8 bytes (not characters printed in hex!) of the git hash.
*/
static inline uint16_t mavlink_msg_protocol_version_get_spec_version_hash(const mavlink_message_t* msg, uint8_t
*spec_version_hash)
{
return _MAV_RETURN_uint8_t_array(msg, spec_version_hash, 8, 6);
}
/**
* @brief Get field library_version_hash from protocol_version message
*
* @return The first 8 bytes (not characters printed in hex!) of the git hash.
*/
static inline uint16_t mavlink_msg_protocol_version_get_library_version_hash(const mavlink_message_t* msg, uint8_t
*library_version_hash)
{
return _MAV_RETURN_uint8_t_array(msg, library_version_hash, 8, 14);
}
/**
* @brief Decode a protocol_version message into a struct
*
* @param msg The message to decode
* @param protocol_version C-struct to decode the message contents into
*/
static inline void mavlink_msg_protocol_version_decode(const mavlink_message_t* msg, mavlink_protocol_version_t* protocol_version)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
protocol_version->version = mavlink_msg_protocol_version_get_version(msg);
protocol_version->min_version = mavlink_msg_protocol_version_get_min_version(msg);
protocol_version->max_version = mavlink_msg_protocol_version_get_max_version(msg);
mavlink_msg_protocol_version_get_spec_version_hash(msg, protocol_version->spec_version_hash);
mavlink_msg_protocol_version_get_library_version_hash(msg, protocol_version->library_version_hash);
#else
uint8_t len = msg->len < MAVLINK_MSG_ID_PROTOCOL_VERSION_LEN? msg->len :
MAVLINK_MSG_ID_PROTOCOL_VERSION_LEN;
memset(protocol_version, 0, MAVLINK_MSG_ID_PROTOCOL_VERSION_LEN);
memcpy(protocol_version, _MAV_PAYLOAD(msg), len);
#endif
}
Java
Folder content
Messages
/**
* Simply a common interface for all MAVLink Messages
*/
Folder with the implementation of the encoding and decoding of each MAVLINK message.
C - Radio controller setup (PX4/Pixhawk 4)
The Pixhawk 4 provides multiple interfaces - Smart-Bus (S-BUS),
PPM and DSM - for connecting radio controller receivers.
This section describes how to use the S-BUS interface.
S-BUS cable
Use an S-BUS cable to connect the Pixhawk 4 to a S-BUS capable
receiver, like the FrSky X8R.
Telemetry data (optional)
If using the FrSky X8R receiver with the Taranis X9D transmitter, it
is possible to connect one of the telemetry ports in the Pixhawk 4 to the X8R
receiver so the transmitter can display useful telemetry information from the
flight controller.
In order to do so, connect the TELEM 2 port to the Smart Port in the
X8R using the appropriate specialized cable or adapter, like the FrSky Yaapu
Telemetry Converter Cable.
(D.1)
where:
⍴ = density of air
V = volume of the cylinder
A = effective area of the propeller
Therefore,
(D.2)
where:
vp = velocity of air flowing through the propeller
(D.3)
where:
ve = escape velocity of the mass of air, considered constant for the
calculation
vi = intake velocity of the mass air at the propeller, considered constant for
the calculation
This is known as the thrust equation..
Replacing (D.2) in (D.3), results:
(D.4)
On the other hand, Bernoulli’s equation relates pressure over a
surface to the fluid speed.
The pressure differential between the 2 surfaces of the disk
representing the propeller, assuming the static pressure is the same on both
sides, is the difference between the dynamic pressure on each side of the
disk:
(D.5)
(D.6)
Equating (D.4) and (D.6), the value for vp can be calculated:
(D.7)
Replacing (D.7) in (D.4) and assuming vi = 0 (the UAV is hovering
in place):
(D.8)
Replacing (D.7) in (D.2):
(D.9)
The propeller’s pitch is the distance traveled by the propeller in
one full rotation. Therefore:
(D.10)
where:
Rs = rotations per second
p = pitch (m)
Replacing (D.10) in (D.8) and the area by the area of the circle
results:
(D.11)
where:
D = diameter of the propeller
The power associated with moving the air mass at a speed ve is:
(D.12)
Replacing (D.8I) in (D.12):
(D.13)
Combing (D.13) and (D.8) and resolving for ve, the expression relating thrust
and power is:
(D.14)
Replacing the area with the the area of the circle in (D.14) results:
(D.15)
Again, these equations are ideal and many physical effects are left
out. They are useful as a means to provide a ballpark for the actual values.
Once in possession of the numbers generated by these equations,
the designer must rely on power and thrust tables provided by the propeller
and motor manufacturers to refine the calculations.
F - Raspberry Pi 4 serial port configuration
The Raspberry Pi comes with a 40-pin General Purpose I/O - GPIO - and each pin can be
configured with different functions. In fact, it comes out of the box with a number of pins pre-configured
with different interfaces.
Pin address
The diagram below shows the pin-out configuration of the GPIO bus, indicating the physical
position of each pin and its address.
TX RX
UART
PIN GPIO PIN GPIO
2 27 0 28 1
3 7 4 29 5
4 24 8 21 9
5 32 12 33 13
By looking at the RPi 4 pinout, it’s clear that some of these pins are allocated for other
functionality by default:
PINs 27 - 28: allocated to EEPROM ID
PINs 21 - 24: SPI functionality (MISO and clock)
PIN 7: General purpose clock
PINs 32-33: PWM 0 and 1
From this list of functions, the one unlikely to be used in the UAV is the PWM signal, so
UART5 is recommended if a secondary serial port is needed (e.g., for communication with the RTK
component).
Configuring the UART is relatively easy.
1. Connect the RPi 4 to a monitor and keyboard
2. Open a terminal window
3. Open file /boot/config.txt using a text editor (e.g. Vim)
a. Caution: the editor must be executed with root privileges, for example, using the
sudo command (e.g. sudo vim /boot/config.txt)
4. Go to the end of the file and add this line: dtoverlay = uart5
5. Save the modification and reboot
sudo nano
/etc/rc.local
java -jar <path/to/proxy_client/JAR/file> -i obc -h <IP address or URL for the AWS
server>
Once the RPi 4 is connected to the network, the client will automatically start interacting with
the server and the PIxhawk.
The server will display logs on the terminal indicating when connection to the OBC is
successfully completed.