Design and Implementation of an Autopilot for UAV
____________________________________________________________
Salvatore Norcaro P44/01 Marco Donnarumma P44/03
1. Introduction
The goal of this project is to design and implement an autopilot for small unmanned aerial vehicle
and simulate it using Matlab/Simulink environment in order to test the autopilot against a generic
scenario for an autonomous mission.
1.1 Equations of Motion
To design an autopilot is necessary to represent the UAV as a dynamic system, so the state variables
of the system are defined in a way in which all the possible motion and attitude of the aircraft are
modelled. The aircraft is assumed as a rigid body. Thus, the model of the aircraft is represented by
12 non-linear equations of motion, 3 for position, 3 for velocities, 3 for the attitude and 3 for angular
rates:
Figure 1. Equations of Motion
These equations depend on different parameters of the vehicle, such as mass, matrix of inertia, lift
coefficient, drag coefficient, propeller coefficient and others structural parameters. Some of these are
variable in time and depend on airspeed or angle of attack or sideslip angle. This model also includes
the effect of the wind and is also modelled the stall condition. Finally, a model that represents the
1
evolution of the aircraft motion, with in input 4 variables: 3 for the angle of the control surfaces
(aileron, elevator and rudder) and 1 for the throttle.
For this project the parameters of the Aerosonde UAV represented in the following tables are
considered:
Figure 2. Tables of Aerosonde UAV parameters
2
1.2 Equation of Motion in Matlab
These equations are used in Matlab to simulate the evolution of the dynamic system. These are
implemented using a Matlab function with input the angle of the control surfaces and the throttle and
output the derivative of the state that is integrated in Simulink to obtain the state vector.
Figure 3.a Matlab code for Non-linear equations
3
Figure 4.b Matlab code for Non-linear equations
2. Linear Design Model
The previous non-linear equations of motion are too complex to design an autopilot, so the equations
of motion are linearized and decoupled to produce reduced order transfer function and to obtain a
state space models more suitable for control system design. The dynamics for a fixed-wings aircraft
can be decomposed into lateral and longitudinal motion.
2.1 Lateral Design Model
For the lateral dynamics, the variables of interest are the roll angle, the roll rate, the heading angle,
and the yaw rate. The control surfaces used to influence the lateral dynamics are the ailerons, and the
rudder. The ailerons are primarily used to influence the roll rate, while the rudder is primarily used to
control the yaw of the aircraft.
2.1.1 Transfer function – Roll and Course
For roll the simplified transfer function is obtained from the linearization of the equation of motion
of roll rate. It is obtained a simple transfer function relationship between roll (Φ) and aileron
command (𝛿𝑎 ). It is considered a small pitch angle to simplify the equation. The final transfer
function is the follow on:
4
Then it is obtained the transfer function from roll to course as follow:
5
2.1.2 Transfer function – Sideslip
It is designed the transfer function from rudder to sideslip considering the assumption of absence of
wind, for a constant airspeed and small sideslip angle.
2.2 Longitudinal Design Model
In the longitudinal dynamics, the variables of interest are the pitch angle, the pitch rate, the altitude,
and the airspeed. The control signals used to influence the longitudinal dynamics are the elevator, and
the throttle. The elevator will be used to directly influence the pitch angle. The pitch angle can be
used to manipulate both the altitude and the airspeed. The airspeed can be used to manipulate the
altitude, and the throttle is used to influence the airspeed.
2.2.1 Transfer function – Pitch
The transfer function obtained from relationship between pitch (𝜃) and elevator command (𝛿𝑒 ) under
the assumption of straight and level flight is:
6
2.2.2 Transfer function – Altitude from Pitch
For a constant airspeed the pitch angle directly influences the climb rate of the aircraft, hence a
transfer function can be derived from pitch angle to altitude:
2.2.3 Transfer function – Airspeed
The airspeed is regulated using both the throttle setting and the pitch angle. When the pitch angle is
constant, increasing the throttle will increase the thrust which increases the airspeed of the vehicle. If
the throttle is held constant, then pitching the nose down will decrease the lift causing the aircraft to
accelerate downward under the influence of gravity, thereby increasing its airspeed.
Also in this case, under assumption of level flight and wings level, to obtain the simplified transfer
functions a linearization is performed about trim condition:
7
In general, it is relatively hard to find trim value from UAV, because in most of the cases the motion
of UAV is to irregular. The idea is to use the untrimmed variables, thus it is not used variation with
respect to trim, but the actual angle is used and trim values are considered as a disturbance.
3 Autopilot Design
The autopilot is the portion of the control system that resides onboard the aircraft. In general terms,
an autopilot is a system used to guide an aircraft without the assistance of a pilot. For manned aircraft,
the autopilot can be as simple as a single-axis wing levelling autopilot or complicated enough to
control position and attitude during the various phases of flight.
The method called successive loop closure is used herein to design both lateral and longitudinal
autopilots. Saturation of commands is considered because the lifting surfaces of aircraft have limited
range, and this imposes limits on the performance.
For most flight manoeuvres of interest, decoupled dynamics still allow the autopilot to yield good
performance. Longitudinal dynamics (forward speed, pitching, climbing/descending motions) are
decoupled from the lateral dynamics (rolling, yawing motions).
The basic idea behind successive loop closure is to close several simple feedback loops in sequence
around the open-loop plant dynamics rather than designing a single control system.
Bandwidth separations among different loops is mandatory for successive loop closure. For aircraft
systems, the bandwidth of the inner-most loop is often limited by saturation constraints. For example,
in the design of the lateral autopilot, the ailerons have physical limits on their angular deflections that
is the roll rate is limited.
The goal is to design the bandwidth of the inner loop to be as large as possible without violating the
saturation constraints and then to design the outer loops (slower dynamics) to ensure bandwidth
separation of successive loops. A practical condition to satisfy is to have a ratio between inner loop
bandwidth and outer loop bandwidth larger than 5.
8
3.1 Lateral Autopilot Design
3.1.1 Roll attitude and Course Loop Design
Being the most outer loop the goal is to set the course angle so to realize the desired path or trajectory
in the horizontal plane. Based on linearized dynamic equations for lateral motion, the course angle
depends on the roll. There are five gains associated with the lateral autopilot. The derivative gain
𝑘𝑑,Φ provides roll rate damping at the innermost loop. The roll attitude is regulated with the
proportional and integral gains 𝑘𝑝,Φ and 𝑘𝑖,Φ . The yaw attitude is regulated with the proportional and
integral gains 𝑘𝑝,χ and 𝑘𝑖,χ . The idea with successive loop closure is that the gains are successively
chosen beginning with the inner loop and working outward.
Figure 4. Course and Roll Loops
In general, the PD controller is preferred in the inner loops, because integrators introduce delays and
instabilities.
The control gains for roll loop can be set introducing the maximum expected input error and the
expected damping ratio:
As a result of the design the bandwidth of the inner loop is also set:
So, the maximum input error and the damping ratio are the only two parameters that can be tuned to
optimize the control system of the roll loop.
For the course loop (outer loop) a PI controller is considered, in which the gain are computed using
the following formulas:
9
In this case, the damping ratio and the bandwidth separation are the parameters to tune the outer loop
control. Generally, more bandwidth separation is better. More bandwidth separation requires either
slower response in the outer loop, or faster response in the inner loop. Faster response usually comes
at the cost of requiring more actuator control authority, which may not be possible given the physical
constraints of the actuators.
The implementation in Simulink is based considering the above discussed model (figure 4), the main
differenced being that:
1) an additional saturator is introduced to limit the roll angle command.
2) to avoid wind-up effect, for the outer-loop is used directly a PI block on Simulink, that applies a
saturation and an anti-wind-up method (clamping method).
Figure 5. Course and Roll Loop implemented in Simulink
Figure 6. Control gains and parameters for Roll and Course Loops
10
Figure 7. Simulation of Roll Loop
Figure 8. Simulation of Course Loop
11
3.1.2 Sideslip Hold Loop Design
If the aircraft is equipped with a rudder, then the rudder can be used to maintain zero sideslip angle.
Based on rudder to sideslip dynamics the following sideslip hold loop can be used:
Figure 9. Sideslip Hold Loop
Design parameters are the maximum expected input error and the damping ratio:
In Simulink, the implementation is the same, but also in this case the PI block is used, that performs
saturation for deflection of rudder and the anti-wind-up. In the linear simulation, for simplicity, the
initial condition of beta is zero and is put as beta command a value of 5 degrees to evaluate the
performance of the control of the sideslip angle loop.
Figure 10. Sideslip Loop in Simulink with code for control gains and result
12
3.2 Longitudinal Autopilot Design
The goal is to regulate airspeed and altitude using the throttle and the elevator as actuators. The
method used to regulate altitude and airspeed depends on the flight regime:
Figure 11. Longitudinal flight regimes
3.2.1 Pitch Attitude Hold Design
To design the pitch attitude hold loop, it is considered an approach like the one applied in roll loop
design. In this loop an elevator is used to control pitch dynamics. This is implemented using a PD
control. Standard approach can be used to set the proportional and the derivative gain: knowing the
actuator saturation limit and selecting the desired damping ratio and the maximum anticipated pitch
error determine the bandwidth of the pitch loop and set the gain values.
Figure 12. Pitch Loop
13
The steady state error of this loop is not zero, the steady state pitch angle will be very
small independently of the commanded pitch. The design of the outer loops shall use the DC gain
(<<1) to represent the gain of the inner loop over its full bandwidth (instead of 1).
3.2.2 Altitude Hold Design using commanded Pitch
The altitude hold loop uses the above described pitch hold loop as inner loop and in the outer loop
there is a PI controller to calculate the correct pitch command to reach the desired altitude. The PI
control on altitude ensures that altitude tracks the commanded one with zero steady state
error, and rejects low frequency disturbances.
Figure 13. Altitude Hold Loop using commanded Pitch
Design parameters are the bandwidth separation and the damping ratio, so equations for gain
calculations are:
In general,𝐾𝜃,𝐷𝐶 = 𝜃𝑐 /𝜃, but for this design is considered as constant value that is much less than 1.
In the Simulink implementation there is PI block with a saturation for the pitch angle and anti-wind-
up method.
Figure 14. Altitude Hold Loop using commanded Pitch in Simulink
14
Figure 15. Controls gains and parameters for Altitude and Pitch Loop
Figure 16. Pitch and Altitude Results
15
3.2.3 Airspeed Hold Design using commanded Pitch
This loop uses pitch command to control the airspeed. Considering the throttle constant, if aircraft
pitching the nose down will decrease the lift causing the aircraft to accelerate downward under the
influence of gravity, thereby increasing its airspeed. To control a PI controller is used as a the outer
loop whereas the pitch loop is the inner loop
Figure 17. Airspeed Hold Loop using commanded Pitch
Design parameters are the bandwidth separation and the damping ratio, so equations for gain
calculations are:
The implementation in Simulink uses, like the others loops, the PI block to perform saturation and
anti-wind-up.
Figure 18. Airspeed loop using commanded pitch in Simulink
16
Figure 19. Airspeed commanded Pitch Loop control gains and parameters
Figure 20. Pitch and Airspeed Results
17
3.2.4 Airspeed Hold Design using commanded Throttle
The goal of this loop is to control airspeed dynamics using throttle. The PI control is used on the
throttle to airspeed loop ensures that airspeed tracks a constant commanded airspeed with zero steady
state error and rejects low frequency disturbances.
Figure 21. Airspeed commanded throttle loop
Design parameters are the natural frequency and the dumping ratio:
Also in this case the simulation in Simulink follow the upper scheme with the difference that uses PI
block for the saturation of the throttle and the anti-wind-up.
Figure 22. Airspeed commanded throttle control gains and results
18
4 Autopilot in non-linear model.
To validate the design of the autopilot is necessary to simulate it using the non-linear model of the
aircraft. It used the non-linear model wrote in section 1.2. In Simulink it is implemented using the
block “Matlab function” with in input the values of the 3 control surfaces (aileron, elevator and
rudder) and the throttle percentage. In output there is the derivative of the state, that is integrated to
obtain the state vector of the aircraft which is used in feedback as previous state.
Figure 23. Non-linear model in Simulink
The output “x_state” represent the 12 states of the aircraft, so describes the position, attitude, velocity
and angular rates on the three axes in NED frame. There are also others dynamic parameters such as
airspeed, angle of attack, sideslip angle, course angle, relative velocities in body frame, that are
necessary in the autopilot, but are not directly present in the state. So, they are calculated on Simulink
using these formulas:
Figure 24. Estimation of airspeed, alpha and beta angles and course angle
19
The 4 inputs are the output of the autopilot. The aileron command and the rudder command are related
to lateral autopilot, otherwise elevator command and throttle are related to longitudinal one.
Figure 25. Lateral Autopilot
Figure 26. Longitudinal Autopilot
In the next sections different simulations are shown, first without wind and then the wind model suis
designed and implemented in order to observe the difference behaviour of UAV under different
environmental conditions.
20
4.1 Lateral Autopilot
As already mentioned, the lateral autopilot is responsible to tracks the course angle to desired one and
to maintain the sideslip angle to zero. Thus, it uses the course loop to calculate aileron command and
the sideslip loop to calculate rudder command. In Simulink in the subsystem “Lateral Autopilot” the
two control loops are implemented:
Figure 27. The two loops inside lateral autopilot
The course loop takes in input the desired course, the actual course, the roll angle and the roll rate,
instead the sideslip loop take in input only the sideslip angle.
For the simulation, the value of all control gains are the same already defined in section 3.1.1. Thus,
the follow gains are used for Course loop of this aircraft:
𝑘𝑑,Φ = 0.559; 𝑘𝑝,Φ = 5.2; 𝑘𝑝,χ = 1.4119 ; 𝑘𝑖,χ = 0.2173;
In the following simulation, it is considered a course command as a step at time 35 second with a
value of 90 degrees, to simulate a left turn. The UAV reach the desired course in about 15 seconds,
with an overshoot that is about 5.5%. The overshoot is due to the sharp turn obtained from the step
input.
Figure 28. Course Loop result
21
If the damping ratio increases from 1.5 of the previous simulation to 2.5, also the 𝑘𝑝,χ value increases.
So, it’s obtained a different behaviour because the settling time reduces to 5 seconds, but the
overshoot increases to 19% and the oscillations also increases.
Figure 29. Course Loop with greater damping ratio
The roll angle tracks very well the commanded one, obliviously it has a response time faster than the
course loop.
Figure 30. Roll loop simulation
22
For the sideslip loop, the control gains are the follow:
𝑘𝑝,𝛽 = −2.0333; 𝑘𝑖,𝛽 = −3.3577;
The sideslip loop correctly maintains the sideslip angle to zero. In this simulation, the wind is zero,
thus the beta angle is influenced only by the turn:
Figure 31. Sideslip result
4.2 Longitudinal Autopilot
As mentioned in paragraph 3.2, the longitudinal autopilot depends on the flight regime, that are: take-
off zone, climb zone, altitude hold zone and descend zone. The flight regime depends on the altitude
error.
4.2.1 Take-off zone
In the take-off zone, full throttle is commanded and the pitch attitude is regulated to a fixed pitch
angle using the elevator. The loop that is considered in this step is the pitch hold loop to reach and
maintain the pitch commanded. In this flight regime, the elevator is commanded by the pitch loop
and the throttle is set at maximum value. As an input the loop has the commanded pitch for take-off,
the pitch angle and the pitch rate. As output the loop has “delta_e_1” and “delta_t_1”.
Figure 32. Take-off zone loop
23
For this simulation it is considered a commanded pitch of 30 degrees. The control gains are the same
of the linear simulation. The take-off phase has a duration about 3.5 seconds. The pitch angle reaches
the commanded one with a steady-error due to the absence of integral gain. The control gain are the
same of the linear case:
𝑘𝑝,𝜃 = −2.15; 𝑘𝑑,𝜃 = −0.3288
Figure 33. Pitch result during take-off
4.2.2 Climb Zone
The objective in the climb zone is to maximize the climb rate. To maximize the climb rate, full throttle
is commanded and the airspeed is regulated using the pitch angle. If the airspeed increases above its
nominal value, then the aircraft is caused to pitch up which results in an increased climb rate and a
decrease in airspeed. Similarly, if the airspeed drops below the nominal value, the aircraft is pitched
down thereby increasing the airspeed but also decreasing the climb rate. Regulating the airspeed using
pitch attitude effectively keeps the aircraft away from stall conditions. The climb zone subsystem
has as input the commanded airspeed, airspeed and also in this case, pitch and pitch rate. As output
there are “delta_e_2” and “delta_t_2”.
Figure 34. Pitch result during take-off
24
Figure 35. Climb zone loop
The climb zone start from 3.5 seconds and end at 14 seconds of simulation. The settling time to the
airspeed is about 4.5 seconds. It regulates its airspeed using pitch. The value of the controls gains are
the same shown before in linear case:
Figure 36. Airspeed and Altitude results during climbing
𝑘𝑝,𝑉2 = −0.072; 𝑘𝑖,𝑉2 = −0.0689;
If the damping ratio value decreases, (more negative) the proportional gain increase (𝑘𝑝,𝑉2 =
−0.2841), in this case, it is obtained a reduction of the overshoot, but an increasing of the settling
time.
25
Figure 37. Airspeed in climb zone with a greater damping ratio
In the climb zone, the altitude is not directly controlled, so it is very important the airspeed command
chosen to guarantee a correct climb rate.
4.2.3 Altitude Hold Zone
In the altitude hold zone, the airspeed is regulated by adjusting the throttle, and the altitude is
regulated by commanding the pitch attitude. Thus, for this flight regime, two loops are used, one that
is altitude hold using commanded pitch and the other one that is airspeed hold commanded throttle
that calculate respectively elevator command (“delta_e_3”) and throttle command (“delta_t_3”).
Figure 38. Altitude Hold Zone loop
26
In the simulation the altitude hold zone start at 14 seconds and end at 50 seconds. The altitude is
correctly tracked by the altitude hold loop, using only the elevator. The airspeed is commanded using
throttle and the airspeed commanded throttle loop quickly reachs the desired value. For the simulation
the control gains of the linear case are used:
𝑘𝑝,h = 0.2925; 𝑘𝑖,h = 0.0856; 𝑘𝑝,v = 0.1191 ; 𝑘𝑖,v = 0.1530;
Figure 39. Altitude and Airspeed results during altitude hold zone
At 36 second, it is possible to observe a little oscillation in both loop due to the presence of the turn.
It cause a loss of altitude and consequently a little increases of the airspeed that are quickly retrieved
by the control.
4.2.4 Descend Zone
The descend zone is similar to the climb zone except that the throttle is commanded to zero. Again,
stall conditions are avoided by regulating airspeed using the pitch angle thus maximizing the descent
rate at a given airspeed. The control loop is the same of the climb zone loop. The output are
“delta_e_4” and “delta_t_4”.
27
Figure 40. Descend zone loop
Obviously also the controls gains are the same of the climb loop. The airspeed set is greater with
respect to the previous value, to guarantee a maximum descend rate. The descend zone start at 50
seconds and end at 76 seconds of the simulation. To avoid negative pitch angle and to have smoother
flight, it is imposed a minimum value for commanded pitch to 0 degrees. So, in the descend zone, the
airspeed does not reach the desired value, but this means that it is maximized the descend rate in a
smooth condition.
28
Figure 41. Airspeed and Altitude results in descend zone
4.2.5 Flight Regime Switch
The flight regime depends by the altitude error. To design the transition to the different zones of the
flight regime, the following state-machine is used:
29
Figure 42. Longitudinal state-machine
To implement the state-machine in Simulink, a Matlab function is used that takes in input the altitude
command, the altitude and all the elevator and throttle command calculated from all longitudinal
loops.
Figure 43. Simulink implementation of state-machine
30
In the Matlab function “switch_case_zone” a switch/case is implemented to transit from a flight
regime to another. Each case is responsible to send in output the correct elevator and throttle
commands.
Figure 44. Matlab code of switch/case for flight regime
31
5. Wind Model and Final Results
The previous results are in absence of wind. To obtain a more realistic simulation and to study the
behaviour of the aircraft under atmospheric disturbances, it is considered to design a model to
simulate the wind. Wind and atmospheric effects enter the calculation of the aerodynamic forces and
moments and influence the motion of the aircraft.
5.1 Wind Model Design
The wind is modelled considering the sum of a steady ambient wind (𝑉𝑤,𝑠 ) and the wind gust and
other disturbances (𝑉𝑤,𝑔 ).
The 𝑉𝑤,𝑠 is in inertial frame, otherwise 𝑉𝑤,𝑔 is in body frame. So, 𝑉𝑤,𝑠 is converted in body frame
using the relevant rotation matrix. A good model for wind gust is obtained by passing white noise
through a linear-time-invariant filter given by the Dryden transfer functions.
32
In the simulation the parameters are used of the first two rows, for low altitude. But in a general
simulation, if the altitude is greater than 50 meters, the parameters for medium altitude can also be
considered. The final wind model is:
Figure 45. Wind Model using Dryden transfer functions
In Simulink the implementation of the wind uses a Matlab function to perform the conversion of the
steady wind in body frame and then uses the Dryden transfer function to simulate the wind gust.
Figure 46. Simulink implementation of wind model
33
In the Matlab function there is the following code:
Figure 47. Matlab code for wind model
5.2 Final Results
Three different simulations with different wind conditions are performed and their results are show
in the following. The mission for the three simulations is the same: the aircraft take-off and reach an
altitude of 40 meters, then at time 35s a course command is imposed as step value of 90 degrees (left
turn) and successively at time 45s a ramp input start with value -27 of a duration 10 seconds (right
turn), thus the aircraft reach a course of 180 degrees. Then at time 65 seconds the altitude command
is imposed to 20 meters to show a descend of the aircraft.
The first simulation has zero wind. The second simulation has the three components of the steady
wind as following: 𝑤𝑛,𝑠 = 0.5 (𝑚/𝑠), 𝑤𝑒,𝑠 = 0.2 (𝑚/𝑠), 𝑤𝑑,𝑠 = 0.1 (𝑚/𝑠) and use the parameters
to model wind gust corresponding to a light turbulence.
The third simulation uses the same three components for steady wind, but uses the parameters to
model wind gust corresponding to a moderate turbulence.
34
5.2.1 Zero Wind Simulation
Figure 48. Results of Zero Wind simulation
35
Without wind, the aircraft follow the desired command with accuracy and with good response time.
The airspeed is influenced by the two turns, but the control at the end of the turn correctly retrieves
the desired value. The course is correctly tracked with a little overshoot.
In this simulation the sideslip angle is only affected by aircraft manoeuvres, as we have zero wind. In
fact, we can see an increase in sideslip from 35 seconds in the simulation which is immediately
corrected to zero thanks to the control.
5.2.2 Light Turbulence Simulation
Figure 49. Results of light turbulence simulation
36
With light turbulence, the behaviour of the aircraft does not change very much with respect to
simulation without wind. This means that control correctly rejects the wind disturbances. It is possible
to note a little noise on airspeed added respect previous simulation.
In the latter case the sideslip angle is influenced not only by the manoeuvring of the aircraft but also
by the presence of the light wind. Also in this case we can see that the control manages to keep the
sideslip angle at zero.
5.2.3 Moderate Turbulence Simulation
Figure 50. Results of moderate turbulence simulation
37
With moderate turbulence, the longitudinal behaviour is very similar to the previous simulations, but
it is possible to see an in important difference in the lateral dynamic. The course angle is characterized
by an increased overshoot, but it is quickly retrieved by the control to the desired value.
In the last simulation where a moderate wind is considered, we have a higher error in the sideslip
angle, the control has more difficulty in maintaining the value at zero, especially at 50 seconds, when
the second turn to the right occurs with a course of 180 degrees.
38