Uavbook Supplement
Uavbook Supplement
Uavbook Supplement
Randal W. Beard
Timothy W. McLain
Contents
1. Introduction 1
1.1 System Architecture 1
1.2 Design Models 1
1.3 Design Project 1
2. Coordinate Frames 3
2.1 Rotation Matrices 3
2.2 MAV Coordinate Frames 3
2.3 Airspeed, Wind Speed, and Ground Speed 3
2.4 The Wind Triangle 3
2.5 Differentiation of a Vector 4
2.6 Chapter Summary 4
2.7 Design Project 4
6. Autopilot Design 33
6.1 Successive Loop Closure 33
6.2 Total Energy Control 49
6.3 LQR Control 51
6.4 Chapter Summary 54
6.5 Design Project 55
8. State Estimation 61
8.1 Benchmark Maneuver 61
8.2 Low-pass Filters 61
8.3 State Estimation by Inverting the Sensor Model 61
8.4 Complementary Filter 61
8.5 Dynamic-observer Theory 70
8.6 Derivation of the Continuous-discrete Kalman Filter 70
8.7 Covariance Update Equations 71
8.8 Measurement Gating 72
8.9 Attitude Estimation 75
8.10 GPS Smoothing 75
8.11 Full State EKF 75
8.12 Chapter Summary 84
8.13 Design Project 85
B. Quaternions 115
B.1 Another look at complex numbers 115
B.2 Quaternion Rotations 115
B.3 Conversion Between Euler Angles and Quaternions 115
B.4 Conversion Between Quaternions and
Rotation Matrices 115
B.5 Quaternion Kinematics 115
B.6 Aircraft Kinematic and Dynamic Equations 115
D. Animation 125
D.1 3D Animation Using Python 125
D.2 3D Animation Using Matlab 125
D.3 3D Animation Using Simulink 125
D.4 Handle Graphics in Matlab 125
D.5 Animation Example: Inverted Pendulum 125
D.6 Animation Example: Spacecraft using Lines 126
D.7 Animation Example: Spacecraft Using Vertices and Faces 128
Bibliography 145
Index 147
uavbook March 18, 2020
Chapter One
Introduction
Chapter Two
Coordinate Frames
where Va = kVa k. Under the assumption that the sideslip angle is zero, the
wind triangle can be expressed in inertial coordinates as
cos χ cos γ cos(ψ + β) cos γa wn
Vg sin χ cos γ = Va sin(ψ + β) cos γa + we . (2.1)
− sin γ − sin γa wd
Chapter Three
3.2 KINEMATICS
MODIFIED MATERIAL:
3.2 Verify that the equations of motion are correct by individually set-
ting the forces and moments along each axis to a nonzero value and
convincing yourself that the motion is appropriate.
3.3 Since Jxz is non-zero, there is gyroscopic coupling between roll and
yaw. To test your simulation, set Jxz to zero and place nonzero mo-
ments on l and n and verify that there is no coupling between the
roll and yaw axes. Verify that when Jxz is not zero, there is coupling
between the roll and yaw axes.
uavbook March 18, 2020
uavbook March 18, 2020
Chapter Four
NEW MATERIAL:
This section describes a model for the thrust and torque produced by a
motor/propeller pair. The inputs to the thrust and torque model will be the
airspeed of the aircraft Va and the throttle setting δt ∈ [0, 1]. We assume
that the thrust and torque vectors produced by the propeller/motor is aligned
with the rotation axes of the motor and denote the magnitude of the thrust
by Tp and the magnitude of the torque by Qp .
Based on propeller theory [], the standard model for the thrust and torque
produced by a propeller is given by
ρD4 2
Tp (Ωp , CT ) = Ω CT
4π 2 p
ρD5 2
Qp (Ωp , CQ ) = Ω CQ ,
4π 2 p
2πVa
J(Ωp , Va ) = .
Ωp D
CT (J) ≈ CT 2 J 2 + CT 1 J + CT 0
CQ (J) ≈ CQ2 J 2 + CQ1 J + CQ0 ,
where the coefficients CT ∗ and CQ∗ are unitless coefficients that are deter-
mined experimentally from data. The quadratic approximations are shown
as solid lines in figures 4.1 and 4.2. Combining these equations, the thrust
Forces and Moments 9
0.12
0.1
0.08
CT , data and 2nd-order curve fit
0.06
0.04
0.02
-0.02
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
advance ratio - J (1/rev)
Figure 4.1: Thrust coefficient versus advance ratio for APC Thin Electric 10x5
propeller [?].
10 -3
7
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
advance ratio - J (1/rev)
Figure 4.2: Torque coefficient versus advance ratio for APC Thin Electric 10x5
propeller [?].
!
2
KQ
ρD5 ρD4
2
C Q0 Ωp + CQ1 Va + Ωp
(2π)2 2π R
3 KQ
+ ρD CQ2 Va2 − Vin + KQ i0 = 0. (4.4)
R
1
We assume KQ has units of N-m/A and KV has units of V-sec/rad. In RC aircraft motor
datasheets, it is common for KV to be specified in units of rpm/V.
Forces and Moments 11
ρD5
a= CQ0
(2π)2
KQ2
ρD4
b= CQ1 Va +
2π R
KQ
c = ρD3 CQ2 Va2 − Vin + KQ i0 ,
R
the positive root given by
√
−b + b2 − 4ac
Ωp (Vin , Va ) = (4.5)
2a
defines the operating speed of the propeller as a function of airspeed Va and
motor voltage Vin .
Using the approach above to find the operating speed, the thrust and
torque characteristics of the motor/propeller combination over the full range
of voltage and airspeed inputs can be quantified. A family of curves, one for
each level of voltage input, is plotted versus airspeed and shows the thrust
and torque generated by a specific motor/propeller pair in figures 4.3 and
4.4. Although the voltages are plotted at discrete intervals, the voltage input
is assumed to be continuously variable. Figure 4.3 in particular illustrates
the full range of thrust performance for the selected motor/propeller pair.
As expected, the maximum thrust for a given voltage setting occurs at zero
airspeed and the thrust produced goes down as the airspeed increases.
Note that these plots model the windmilling effect that can occur at ex-
cessively high advance ratios, where both the thrust and torque become neg-
ative and the propeller produces drag instead of thrust. This condition can
occur when an aircraft is gliding and descending in a motor-off state and the
airspeed is being controlled using the pitch angle of the aircraft.
In this book, we will approximate the input voltage as a linear function of
the throttle command, which is roughly true for PWM commands applied to
an RC speed controller. Accordingly,
where Vmax is the maximum voltage that can be supplied by the battery.
In summary, the magnitude of the thrust and torque produced by a pro-
peller/motor pair is computed using Algorithm 4.1.
Assuming that the center of the propeller is on the body frame x-axis and
that the direction of the propeller is also aligned with the body frame x-axis,
12 FORCES AND MOMENTS
15
10
thrust (N)
12 V
10 V
5
8V
6V
4V
2V
0
0 5 10 15 20 25 30
airspeed (m/s)
Figure 4.3: Propeller thrust versus airspeed for various motor voltage settings.
0.2
12 V
0.15
10 V
torque (N-m)
0.1 8V
6V
0.05
4V
2V
0
0 5 10 15 20 25 30
airspeed (m/s)
Figure 4.4: Motor torque versus airspeed for various motor voltage settings.
then the force and torque vectors due to the propeller are given by
>
fp = Tp , 0, 0
>
mp = Qp , 0, 0 .
Vg = Va + Vw . (4.7)
For simulation purposes, we will assume that the total wind vector can be
represented as
Vw = Vws + Vwg ,
where Vws is a constant vector that represents a steady ambient wind, and
Vwg is a stochastic process that represents wind gusts and other atmospheric
disturbances. The ambient (steady) wind is typically expressed in the iner-
tial frame as
wns
i
Vw s
= wes ,
wds
where wns is the speed of the steady wind in the north direction, wes is
the speed of the steady wind in the east direction, and wds is the speed of
the steady wind in the down direction. The stochastic (gust) component
of the wind is typically expressed in the aircraft body frame because the
atmospheric effects experienced by the aircraft in the direction of its forward
motion occur at a higher frequency than do those in the lateral and down
directions. The gust portion of the wind can be written in terms of its body-
14 FORCES AND MOMENTS
altitude Lu = Lv Lw σu = σv σw
gust description (m) (m) (m) (m/s) (m/s)
low altitude, light turbulence 50 200 50 1.06 0.7
low altitude, moderate turbulence 50 200 50 2.12 1.4
medium altitude, light turbulence 600 533 533 1.5 1.5
medium altitude, moderate turbulence 600 533 533 3.0 3.0
frame components as
uwg
b
Vw g
= vwg .
wwg
Experimental results indicate that a good model for the non-steady gust
portion of the wind model is obtained by passing white noise through a
linear time-invariant filter given by the von Karmen turbulence spectrum
in [2]. Unfortunately, the von Karmen spectrum does not result in a rational
transfer function. A suitable approximation of the von Karmen model is
given by the Dryden transfer functions
r
2Va 1
Hu (s) = σu
πLu s + LVa
u
r s + √Va
3Va 3Lv
Hv (s) = σv 2
πLv
s + LVav
r s + √Va
3Va 3Lw
Hw (s) = σw 2 ,
πLw
s + LVwa
where σu , σv , and σw are the intensities of the turbulence along the vehi-
cle frame axes; and Lu , Lv , and Lw are spatial wavelengths; and Va is the
airspeed of the vehicle. The Dryden models are typically implemented as-
suming a constant nominal airspeed Va0 . The parameters for the Dryden
gust model are defined in MIL-F-8785C. Suitable parameters for low and
medium altitudes and light and moderate turbulence were presented in [?]
and are shown in Table 4.1.
Figure 4.5 shows how the steady wind and atmospheric disturbance com-
ponents enter into the equations of motion. White noise is passed
through the Dryden filters to produce the gust components expressed in the
vehicle frame. The steady components of the wind are rotated from the iner-
tial frame into the body frame and added to the gust components to produce
Forces and Moments 15
the total wind in the body frame. The combination of steady and gust terms
can be expressed mathematically as
uw wn s uwg
b
Vw = vw = Rbv (φ, θ, ψ) wes + vwg ,
ww wds wwg
where Rbv is the rotation matrix from the vehicle to the body frame given
in equation (??). From the components of the wind velocity Vw b and the
Figure 4.5: The wind is modeled as a constant wind field plus turbulence. The
turbulence is generated by filtering white noise with a Dryden model.
ur u − uw
Vab = vr = v − vw .
wr w − ww
to equation (??) as
p
Va = u2r + vr2 + wr2
−1 wr
α = tan
ur
!
vr
β = sin−1 p .
u2r + vr2 + wr2
For the Dryden model gust models, the input uk will be zero mean Gaussian
noise with unity variance.
Python code that implements the transfer function above is given as fol-
lows:
import numpy a s np
def init ( s e l f , Ts ) :
s e l f . t s = Ts
# set i n i t i a l conditions
s e l f . s t a t e = np . a r r a y ( [ [ 0 . 0 ] , [ 0 . 0 ] ] )
# d e f i n e s t a t e s p a c e model
s e l f . A = np . a r r a y ([[1 − Ts ∗c , −Ts ∗d ] , [ Ts , 1 ] ] )
s e l f . B = np . a r r a y ( [ [ Ts ] , [ 0 ] ] )
s e l f . C = np . a r r a y ( [ [ a , b ] ] )
def update ( s e l f , u ) :
’ ’ ’ Update s t a t e s p a c e model ’ ’ ’
self . state = self . A @ self . state + self . B ∗ u
y = self . C @ self . state
return y
# i n i t i a l i z e the system
Ts = 0 . 0 1 # s i m u l a t i o n s t e p s i z e
s y s t e m = t r a n s f e r f u n c t i o n ( Ts )
# main s i m u l a t i o n l o o p
sim time = 0.0
while sim time < 1 0 . 0 :
u=np . random . r a n d n ( ) # ( w h i t e n o i s e )
y = s y s t e m . u p d a t e ( u ) # u p d a t e b a s e d on c u r r e n t i n p u t
s i m t i m e += Ts # increment the simulation time
fx −mg sin θ Tp
fy = mg cos θ sin φ + 0
fz mg cos θ cos φ 0
CX (α) + CXq (α) 2Vc a q
1 2
+ ρVa S CY0 + CYβ β + CYp 2Vb a p + CYr 2Vb a r
2
CZ (α) + CZq (α) 2Vc a q
CXδe (α)δe
1
+ ρVa2 S CYδa δa + CYδr δr , (4.8)
2 C (α)δ Zδe e
18 FORCES AND MOMENTS
where
4
CX (α) = −CD (α) cos α + CL (α) sin α
4
CXq (α) = −CDq cos α + CLq sin α
4
CXδe (α) = −CDδe cos α + CLδe sin α (4.9)
4
CZ (α) = −CD (α) sin α − CL (α) cos α
4
CZq (α) = −CDq sin α − CLq cos α
4
CZδe (α) = −CDδe sin α − CLδe cos α,
and where CL (α) is given by equation (??) and CD (α) is given by equa-
tion (??). The subscripts X and Z denote that the forces act in the X and
Z directions in the body frame, which correspond to the directions of the ib
and the kb vectors.
The total torques on the MAV can be summarized as follows:
h i
b Cl0 + Clβ β + Clp 2Vb a p + Clr 2Vb a r
l
m = 1 ρVa2 S
h i
c Cm0 + Cmα α + Cmq 2Vc a q
2
n h i
b Cn0 + Cnβ β + Cnp 2Vb a p + Cnr 2Vb a r
b Clδa δa + Clδr δr Qp
1
+ ρVa2 S c Cmδe δe + 0 . (4.10)
2
0
b Cnδa δa + Cnδr δr
MODIFIED MATERIAL:
4.1 Add simulation of the wind to the mavsim simulator. The wind ele-
ment should produce wind gust along the body axes, and steady state
wind along the NED inertial axes.
4.2 Add forces and moments to the dynamics of the MAV. The inputs to
the MAV should now be elevator, throttle, aileron, and rudder. The
aerodynamic coefficients are given in Appendix E.
Forces and Moments 19
Chapter Five
ṗn = (cos θ cos ψ)u + (sin φ sin θ cos ψ − cos φ sin ψ)v
+ (cos φ sin θ cos ψ + sin φ sin ψ)w (5.1)
ṗe = (cos θ sin ψ)u + (sin φ sin θ sin ψ + cos φ cos ψ)v
+ (cos φ sin θ sin ψ − sin φ cos ψ)w (5.2)
ḣ = u sin θ − v sin φ cos θ − w cos φ cos θ (5.3)
ρV 2 S h cq
u̇ = rv − qw − g sin θ + a CX (α) + CXq (α)
2m 2Va
i T (δ , V )
p t a
+ CXδe (α)δe + (5.4)
m
ρV 2 S h
v̇ = pw − ru + g cos θ sin φ + a CY0 + CYβ β
2m
bp br i
+ C Yp + CYr + CYδa δa + CYδr δr (5.5)
2Va 2Va
ρV 2 S h
ẇ = qu − pv + g cos θ cos φ + a CZ (α)
2mi
cq
+ CZq (α) + CZδe (α)δe (5.6)
2Va
φ̇ = p + q sin φ tan θ + r cos φ tan θ (5.7)
θ̇ = q cos φ − r sin φ (5.8)
ψ̇ = q sin φ sec θ + r cos φ sec θ (5.9)
1 h bp
ṗ = Γ1 pq − Γ2 qr + ρVa2 Sb Cp0 + Cpβ β + Cpp
2 2Va
br i
+ Cp r + Cpδa δa + Cpδr δr (5.10)
2Va
ρV 2 Sc h
q̇ = Γ5 pr − Γ6 (p2 − r2 ) + a Cm 0 + Cm α α
2Jy
cq i
+ Cm q + Cmδe δe (5.11)
2Va
1 h bp
ṙ = Γ7 pq − Γ1 qr + ρVa2 Sb Cr0 + Crβ β + Crp
2 2Va
br i
+ Crr + Crδa δa + Crδr δr , (5.12)
2Va
where
(
V̇a = cos α rv − qw + r − g sin θ
ρVa2 S h cq
+ − CD (α) cos α + CL (α) sin α + (−CDq cos α + CLq sin α)
2m 2Va
)
i 1
+ (−CDδe cos α + CLδe sin α)δe + Tp (δt , Va )
m
(
+ sin α qur − pvr + g cos θ cos φ
ρVa2 S h cq
+ − CD (α) sin α − CL (α) cos α + (−CDq sin α − CLq cos α)
2m 2Va
)
i
+ (−CDδe sin α − CLδe cos α)δe + dV1
where Tp (δt , Va ) is the thrust produced by the motor. Using equations (??)
and the linear approximation CD (α) ≈ CD0 + CDα α, and simplifying, we
Linear Design Models 25
get
where
dV2 = (rVa cos α − pVa sin α) sin β − g sin α cos θ(1 − cos φ)
1
+ Tp (δt , Va )(cos α − 1) + dV1 .
m
where
ρVa∗ S 1 ∂Tp ∗ ∗
aV1 = CD0 + CDα α∗ + CDδe δe∗ − (δ , V )
m m ∂Va t a
1 ∂Tp ∗ ∗
aV2 = (δ , V ),
m ∂δt t a
aV3 = g cos(θ∗ − α∗ ),
5.5.1 Linearization
5.5.2 Lateral State-Space Equations
MODIFIED MATERIAL:
MODIFIED MATERIAL: Assuming that the lateral states are zero (i.e.,
φ = p = r = β = v = 0) and the windspeed is zero and substituting
w
α = tan−1
p u
Va = u + w 2
2
Linear Design Models 27
ρ(u2 + w2 )S h w i
u̇ = −qw − g sin θ + CX0 + CXα tan−1 + CXδe δe
√ 2m u
ρ u2 + w2 S p
+ CXq cq + Tp (δt , u2 + w2 ) (5.19)
4m
ρ(u2 + w2 )S h w i
ẇ = qu + g cos θ + CZ0 + CZα tan−1 + CZδe δe
√ 2m u
ρ u2 + w2 S
+ CZq cq (5.20)
4m
1 h w i
q̇ = ρ(u2 + w2 )cS Cm0 + Cmα tan−1 + Cmδe δe
2Jy u
1 p 2
+ ρ u + w2 SCmq c2 q (5.21)
4Jy
θ̇ = q (5.22)
ḣ = u sin θ − w cos θ. (5.23)
MODIFIED MATERIAL:
NEW MATERIAL: Using the fact that for the state-space equations
ẋ = Ax + Bu
y = Cx
∂Tp ∗ ∗
Xδt ∂δt (δt , Va )
∗
q ∗ + u mρS CZ0 + CZα α∗ + CZδe δe∗
Zu
ρSCZα w∗ u∗ ρSCZ cq ∗
− 2m + 4mV ∗q
a
w∗ ρS
CZ0 + CZα α∗ + CZδe δe∗
Zw m
ρSCZα u∗ ρw∗ ScCZq q ∗
+ 2m + 4mVa∗
∗ ρVa∗ SCZq c
Zq u + 4m
ρVa∗2 SCZδ
Zδ e 2m
e
u∗ ρSc
Cm0 + Cmα α∗ + Cmδe δe∗
Mu Jy
∗ ρSc2 Cmq q ∗ u∗
− ρScC2Jmyα w + 4Jy Va∗
w∗ ρSc
Cm0 + Cmα α + Cmδe δe∗
∗
Mw Jy
∗ ρSc2 Cmq q ∗ w∗
+ ρScC mα u
2Jy + 4Jy Va∗
ρVa∗ Sc2 Cmq
Mq 4Jy
ρVa∗2 ScCmδ
M δe 2Jy
e
30 LINEAR DESIGN MODELS
and letting C = 0, 1 , the transfer function from δ̄r to r̄ is given by
Yr −1 Yδr
!
Yv Va∗ cos β ∗ Va∗ cos β ∗
r̄(s) = 0 1 sI − δ̄r (s)
Nv Va∗ cos β ∗ Nr Nδr
Nδr s + (Yδr Nv − Nδr Yv )
= δ̄r (s). (5.24)
s2 − (Yv + Nr )s + (Yv Nr − Yr Nv )
MODIFIED MATERIAL:
5.1 Create a function that computes the trim state and the trim inputs for
a desired airspeed of Va and a desired flight path angle of ±γ. Set the
initial condition in your simulation to the trim state and trim input,
and verify that the aircraft maintains trim until numerical errors cause
it to drift.
5.2 Create a function that computes the transfer function models
described in this chapter, linearized about the trim state and trim in-
puts.
5.3 Create a function that computes the longitudinal and lateral state
space models described in this chapter, linearized around trim.
5.4 Compute eigenvalues of A lon and notice that one of the eigenvalues
will be zero and that there are two complex conjugate pairs. Using the
formula
(s + λ)(s + λ∗ ) = s2 + 2<λs + |λ|2 = s2 + 2ζωn s + ωn2 ,
extract ωn and ζ from the two complex conjugate pairs of poles. The
pair with the larger ωn correspond to the short-period mode, and
the pair with the smaller ωn correspond to the phugoid mode. The
phugoid and short-period modes can be excited by starting the simu-
lation in a wings-level, constant-altitude trim condition, and placing
an impulse on the elevator. By placing an impulse on the elevator,
convince yourself that the eigenvalues of A lon adequately predict
the short period and phugoid modes.
Linear Design Models 31
Chapter Six
Autopilot Design
Examining the inner loop shown in figure 6.2, the goal is to design a
closed-loop system from r1 to y1 having a bandwidth ωBW1 . The key as-
34 AUTOPILOT DESIGN
sumption we make is that for frequencies well below ωBW1 , the closed-loop
transfer function y1 (s)/r1 (s) can be modeled as a gain of 1. This is depicted
schematically in figure 6.3. With the inner-loop transfer function modeled
as a gain of 1, design of the second loop is simplified because it includes
only the plant transfer function P2 (s) and the compensator C2 (s). The crit-
ical step in closing the loops successively is to design the bandwidth of the
next loop so that it is a factor of W smaller than the preceding loop, where
1
S is typically in the range of 5-10. In this case, we require ωBW2 < W ωBW1
thus ensuring that the unity gain assumption on the inner loop is not violated
over the range of frequencies that the middle loop operates.
Figure 6.3: Successive loop closure design with inner loop modeled as a unity
gain.
With the two inner loops operating as designed, y2 (s)/r2 (s) ≈ 1 and the
transfer function from r2 (s) to y2 (s) can be replaced with a gain of 1 for
the design of the outermost loop, as shown in figure 6.4. Again, there is a
bandwidth constraint on the design of the outer loop: ωBW3 < W12 ωBW2 .
Because each of the plant models P1 (s), P2 (s), and P3 (s) is first or second
order, conventional PID or lead-lag compensators can be employed effec-
tively. Transfer-function-based design methods such as root-locus or loop-
shaping approaches are commonly used.
The following sections discuss the design of a lateral autopilot and a lon-
gitudinal autopilot. Transfer functions modeling the lateral and longitudinal
dynamics were developed in Section 5.4 and will be used to design the au-
topilots in this chapter.
Autopilot Design 35
MODIFIED MATERIAL:
Figure 6.5 shows the block diagram for a lateral autopilot using succes-
sive loop closure. There are five gains associated with the lateral autopilot.
The derivative gain kdφ provides roll rate damping for the innermost loop.
The roll attitude is regulated with the proportional gain kpφ . The course an-
gle is regulated with the proportional and integral gains kpχ and kiχ . And
the dutch-roll mode is effectively damped using the yaw damper with gain
kr . The idea with successive loop closure is that the gains are successively
chosen beginning with the inner loop and working outward. In particular,
kdφ and kpφ are usually selected first, and kpχ and kiχ are usually chosen
second. The gain kr is selected independently of the other gains.
<latexit sha1_base64="HfiHpXm+daNHKCHEUixBAvsqjhw=">AAACcnicbVHRTtswFHXCGNDBKEy8bNJmqJCKCijJC3tE4oVHkCggNSVy3JvWwnEi+wZRonwAv8fbvmIv+4A5JRoFdiVLx+f4XNvnxrkUBj3vl+MufFj8uLS80vq0uvZ5vb2xeWmyQnPo80xm+jpmBqRQ0EeBEq5zDSyNJVzFtye1fnUH2ohMXeA0h2HKxkokgjO0VNR+DBPNeHlwEmnaNTdBLwgfAFmYpTBmUakqQ3v0ZXcT7FVl1/TyKES4x9Lk1d6crWFHuvpneaFet5rj66a0FbU73qE3K/oe+A3okKbOovZTOMp4kYJCLpkxA9/LcVgyjYJLqFphYSBn/JaNYWChYimYYTmLrKK7lhnRJNN2KaQzdt5RstSYaRrbkynDiXmr1eT/tEGByc9hKVReICj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Wi8GO/GcNK6YExn9uCPjI9vEqebEg==</latexit>
Figure 6.5: Autopilot for lateral control using successive loop closure.
The following sections describe the design of the lateral autopilot using
successive loop closure.
36 AUTOPILOT DESIGN
The inner loop of the lateral autopilot is used to control roll angle and roll
rate, as shown in figure 6.6.
MODIFIED MATERIAL:
If the transfer function coefficients aφ1 and aφ2 are known, then there is
a systematic method for selecting the control gains kdφ and kpφ based on
the desired response of closed-loop dynamics. From figure 6.6, the transfer
d
ωn2 φ
Hφ/φc (s) = ,
s2 + 2ζφ ωnφ s + ωn2 φ
then equating denominator polynomial coefficients, we get
ωn2 φ = kpφ aφ2 (6.1)
2ζφ ωnφ = aφ1 + aφ2 kdφ . (6.2)
Accordingly, the proportional and derivative gains are given by
ωn2 φ
kpφ =
aφ2
2ζφ ωnφ − aφ1
kdφ = .
aφ2
where the natural frequency ωnφ and the damping ratio ζφ is a design pa-
rameter.
The output of the roll attitude hold loop is
δa (t) = kpφ (φc (t) − φ(t)) − kdφ p(t).
Autopilot Design 37
MODIFIED MATERIAL:
The next step in the successive-loop-closure design of the lateral autopilot
is to design the course-hold outer loop. If the inner loop from φc to φ has
been adequately tuned, then Hφ/φc ≈ 1 over the range of frequencies from
0 to ωnφ . Under this condition, the block diagram of figure 6.5 can be
simplified to the block diagram in figure 6.7 for the purposes of designing
the outer loop.
The objective of the course hold design is to select kpχ and kiχ in fig-
ure 6.5 so that the course χ asymptotically tracks steps in the commanded
course χc . From the simplified block diagram, the transfer functions from
the inputs χc and dχ to the output χ are given by
Note that if dχ and χc are constants, then the final value theorem implies
that χ → χc . The transfer function from χc to χ has the form
As with the inner feedback loops, we can choose the natural frequency and
damping of the outer loop and from those values calculate the feedback
gains kpχ and kiχ . Figure 6.8 shows the frequency response and the step
response for Hχ . Note that because of the numerator zero, the standard
intuition for the selection of ζ does not hold for this transfer function. Larger
ζ results in larger bandwidth and smaller overshoot.
Comparing coefficients in equations (6.3) and (6.4), we find
10 1.4
−10 1.2
magnitude (dB)
−20
−30 1
−40
−50 0.8
−60
0
0.6
phase (deg)
−30
0.4
−60 0.2
−90 0
−2 −1 0 1 2 3
10 10 10 10 10 10 0 2 4 6 8 10 12
frequency (rad/sec) (sec)
Figure 6.8: Frequency and step response for a second-order system with a transfer
function zero for ζ = 0.5, 0.7, 1, 2, 3, 5.
side-slip angle, this is impractical for small aircraft since the side-slip angle
is not measured directly. An alternative is to use the rudder to regulate the
yaw rate to zero. The difficulty with doing so, however, is that in a turn we
do not desire the yaw rate to be zero and so a direct control implementation
would create competing objectives between the course controller and the
yaw rate controller. The solution to this dilemma is to employ a so-called
washout filter to only allow feedback from yaw rate to the rudder for high
frequency yaw rate. A wash-out filter is simply a high-pass filter.
Recall from Equation (5.24) that the transfer function from the rudder to
the yaw rate is given by
frequency band below pwo and to pass with unity gain the feedback signal
for frequencies above pwo . The negative sign in the top path is due to the
fact that negative δr results in a postive yaw rate (i.e., Nδr < 0).
The selection of pwo and kr can be found from physical considerations.
As discussed in Chapter 5, the poles of the transfer function from δr to r
shown in Equation 6.7 correspond to the lightly-damped dutch roll mode.
Essentially, the objective of the yaw damper is damp out the dutch-roll
mode. Therefore, the pole of the washout filter should be selected to be be-
low the natural frequency of the dutch-roll mode. The canonical expression
s2 + 2ζdr ωndr s + ωn2 dr = s2 − (Yv + Nr )s + (Yv Nr − Yr Nv ) approximates
the natural frequency of the dutch-roll mode as
p
ωndr ≈ Yv Nr − Yr Nv .
For frequencies over pwo , when the washout filter is active, the closed-
loop transfer function from rc to r is given by
−(Nδr s + (Yδr Nv − Nδr Yv ))
r(s) = rc (s),
s2 + (−Yv − Nr − kr Nδr )s + (Yv Nr − Yr Nv − kr (Yδr Nv − Nδr Yv ))
Nr Nδr + Yδr Nv
kr = −
Nδ2r
v
u N N +Y N 2
u ! !
r δr δr v Yv2 + Nr2 + 2Yr Nv
+ t − .
Nδ2r Nδ2r
For the Aerosonde model given in the appendix, we get pwo = 0.45 and
kr = 0.196.
Figure 6.10 shows the lateral-directional performance of the Aerosonde
aircraft in response to a doublet roll command, both without the yaw damper
and with the yaw damper. The upper plot shows the roll response of the
aircraft to the doublet roll command. Without the yaw damper, the lightly
damped dutch-roll dynamics couple into the closed-loop roll dynamics caus-
ing the roll dynamics to be less-damped than anticipated. The lower plot
shows the yaw (heading) angle of the aircraft with and without the yaw
damper. The improved response resulting from the yaw damper is clear.
This is particularly true for the Aerosonde aircraft model used, which has
Autopilot Design 41
30
desired
w/o yaw damper
20 with yaw damper
roll angle (deg)
10
-10
-20
-30
0 1 2 3 4 5 6 7 8 9 10
time (s)
40
w/o yaw damper
with yaw damper
30
yaw angle (deg)
20
10
-10
0 1 2 3 4 5 6 7 8 9 10
time (s)
A final comment on the effect of the dutch-roll mode on the design of the
lateral-directional control of the aircraft is that it may be necessary to take
the speed of the dutch-roll mode into consideration when using successive-
loop closure to set the bandwidth of the outer-loop course control. Rather
than keeping the bandwidth of the outer course loop at least a factor of ten
below the bandwidth of the roll loop. Better performance may result from
setting the outer course-loop bandwidth at least a factor of ten slower than
the frequency of the dutch-roll mode.
42 AUTOPILOT DESIGN
NEW MATERIAL:
The yaw damper in the Laplace domain is given by
s
δr (s) = kr r(s).
s + pwo
Converting to the time domain results in the differential equation
δ̇r = −pwo δr + kr ṙ.
Integrating once gives
Z t
δr (t) = −pwo δr (σ)dσ + kr r(t). (6.8)
−∞
def update ( s e l f , u ) :
s e l f . xi = s e l f . xi
+ s e l f . Ts ∗ (− s e l f . p wo ∗ s e l f . x i
+ self . k r ∗ r )
d e l t a r = −p wo ∗ s e l f . x i + s e l f . k r ∗ r
return d e l t a r
MODIFIED MATERIAL: Figure 6.12 shows the block diagram for the lon-
gitudinal autopilot using successive loop closure. There are six gains associ-
ated with the longitudinal autopilot. The derivative gain kdθ provides pitch
rate damping for the innermost loop. The pitch attitude is regulated with the
proportional gain kpθ . The altitude is regulated with the proportional and
integral gains kph and kih . The airpseed is regulated using the proportional
and integral gains kpVa and kiVa . The idea with successive loop closure is
that the gains are successively chosen beginning with the inner loop and
working outward. In particular, kdθ and kpθ are usually selected first, and
kph and kih are usually chosen second. The gains kpVa and kiVa are selected
independently of the other gains.
kiV
s
V̄ac ¯t V̄a
kpV
Figure 6.12: Autopilot for longitudinal control using successive loop closure.
d KθDC ωn2 θ
Hθ/θ c = ,
s2 + 2ζθ ωnθ s + ωn2 θ
then, equating denominator coefficients, we get
ωn2 θ − aθ2
kpθ =
aθ3
2ζ ωn − aθ1
kdθ = θ θ
aθ3
kp aθ
KθDC = θ2 3 ,
ωnθ
where ωnθ and ζθ are design parameters.
An integral feedback term could be employed to ensure unity DC gain on
the inner loop. The addition of an integral term, however, can severely limit
the bandwidth of the inner loop, and therefore is not used. Note however,
that in the design project, the actual pitch angle will not converge to the com-
manded pitch angle. This fact will be taken into account in the development
of the altitude hold loop.
Autopilot Design 45
Figure 6.14: The altitude hold loop using the commanded pitch angle.
d ωn2 h
Hh/hc = ,
s2 + 2ζh ωnh s + ωn2 h
then, equating denominator coefficients, we get
ωn2 h = KθDC Va kih
2ζh ωnh = KθDC Va kph .
Solving these expressions for kih and kph , we get
ωn2 h
kih = (6.13)
KθDC Va
2ζ ωn
kph = h h. (6.14)
KθDC Va
Therefore, selecting the desired damping ratio ζh and the bandwidth sepa-
ration Wh fixes the value for kph and kih .
The commanded pitch angle is therefore
Z t
θc (t) = kph (hc (t) − h(t)) + kih (hc (τ ) − h(τ ))dτ.
−∞
kiV
s
V̄ac ¯t V̄a
kpV
control, then
aV2 kpV 1
V̄a (s) = V̄ac (s) + dV (s).
s + (aV1 + aV2 kpV ) s + (aV1 + aV2 kpV )
Autopilot Design 47
Note that the DC gain is not equal to one and that step disturbances are not
rejected. If, on the other hand, we use proportional-integral control, then
aV2 (kpV s + kiV )
V̄a = V̄ac
s2 + (aV1 + aV2 kpV )s + aV2 kiV
1
+ dV .
s2 + (aV1 + aV2 kpV )s + aV2 kiV
It is clear that using a PI controller results in a DC gain of one, with step dis-
turbance rejection. If aV1 and aV2 are known, then the gains kpV and kiV can
be determined using the same technique we have used previously. Equating
the closed-loop transfer function denominator coefficients with those of a
canonical second-order transfer function, we get
ωn2 V = aV2 kiV
2ζV ωnV = aV1 + aV2 kpV .
Inverting these expressions gives the control gains
ωn2 V
kiV = (6.15)
aV2
2ζV ωnV − aV1
kpV = . (6.16)
aV2
The design parameters for this loop are the damping coefficient ζV and the
natural frequency ωnV .
Note that since V̄ac = Vac − Va∗ and V̄a = Va − Va∗ , the error signal in
figure 6.15 is
e = V̄ac − V̄a = Vac − Va .
Therefore, the control loop shown in figure 6.15 can be implemented with-
out knowledge of the trim velocity Va∗ . If the throttle trim value δt∗ is known,
then the throttle command is
δt = δt∗ + δ̄t .
However, if δt∗ is not precisely known, then the error in δt∗ can be thought
of as a step disturbance, and the integrator will wind up to reject the distur-
bances.
The throttle command is therefore
Z t
δt (t) = kpV (Vac (t) − Va (t)) + kiV (Vac (τ ) − Va (τ ))dτ.
−∞
48 AUTOPILOT DESIGN
NEW MATERIAL:
A Python class that implements a general PID loop is shown below.
import numpy a s np
def u p d a t e w i t h r a t e ( s e l f , y r e f , y , ydot ,
r e s e t f l a g =False ) :
i f r e s e t f l a g == T r u e :
s e l f . i n t e g r a t o r = 0.0
s e l f . error delay 1 = 0.0
# compute t h e e r r o r
error = y ref − y
# update the i n t e g r a t o r using t r a p a z o i d a l rule
self . integrator = self . integrator \
+ ( s e l f . Ts / 2 ) ∗ ( e r r o r + s e l f . e r r o r d e l a y 1 )
# PID c o n t r o l
u = s e l f . kp ∗ e r r o r \
+ s e l f . ki ∗ s e l f . i n t e g r a t o r \
− s e l f . kd ∗ y d o t
# s a t u r a t e PID c o n t r o l a t l i m i t
u sat = self . saturate (u)
# i n t e g r a l a n t i −windup
# a d j u s t i n t e g r a t o r to keep u out of s a t u r a t i o n
i f np . abs ( s e l f . k i ) > 0 . 0 0 0 1 :
self . integrator = self . integrator \
+ (1.0 / s e l f . ki ) ∗ ( u sat − u )
self . error delay 1 = error
return u s a t
The longitudinal control system is complicated by the fact that both alti-
tude and airspeed need to be regulated, but that these quantities are strongly
coupled. If we assume a low level autopilot on the pitch angle, then the pri-
mary control signals are the throttle and the commanded pitch angle. Both
of these quantities have a significant effect on both altitude and airspeed.
Rather than attempt to decouple these effects by operating different loops in
different flight regimes, the total energy control method changes the regu-
lated outputs from altitude and airspeed to total energy and energy balance,
which produces a natural decoupling in the longitudinal motion.
The kinetic energy of a body in motion is given by K = 12 m kvk2 . If we
use the velocity of the aircraft relative to the air mass, then K = 21 mVa2 .
The reference kinetic energy is given by Kref = 12 m(Vac )2 . Therefore, the
error in kinetic energy is given by
4 1
Kerror = Kref − K = m((Vac )2 − Va2 ).
2
The potential energy of a body with mass m is given by U = U0 + mgh
where U0 is the potential of ground level when the altitude h = 0. The
reference potential energy is given by Uref = U0 + mghc . Therefore, the
error in potential energy is given by
Uerror = mg(hc − h). (6.17)
The total energy (error) is given by
E = Uerror + Kerror .
The energy (error) balance is given by
B = Uerror − Kerror .
As mentioned previously, the throttle is used to control the total energy using
a PI controller:
Z t
δt (t) = kpE E(t) + kiE E(τ ) dτ.
−∞
The pitch command is used to regulate the energy balance using a PI con-
troller:
Z t
c
θ (t) = kpB B(t) + kiB B(τ ) dτ.
−∞
where h̄e > 0 is the largest altitude error used to compute Uerror , and sat is
the saturation function.
NEW MATERIAL:
ẋ = Ax + Bu
and the symmetric positive semi-definite matrix Q, and the symmetric pos-
itive definite matrix R, the LQR problem is to minimize the cost index
Z ∞
J(x0 ) = min x> (τ )Qx(τ ) + u> (τ )Ru(τ )dτ.
u(t),t≥0 0
Note that Klqr are the optimal feedback gains given Q and R. The con-
troller is tuned by changing Q and R. Typically we choose Q and R to be
diagonal matrices
q1 0 . . . 0 r1 0 . . . 0
0 q2 . . . 0 0 r2 . . . 0
Q = .. R = .. .. ,
.. .. ..
. . . . . .
0 0 ... qn 0 0 ... rm
system
ẋ = Ax + Bu
z = Hx
ξ˙ = Āξ + B̄u,
where
A 0 B
Ā = B̄ = .
H 0 0
The LQR design process then proceeds as normal.
As derived in chapter 5, the state space equations for the lateral equation of
motion are given by
where xlat = (v, p, r, φ, ψ)> and ulat = (δa , δr )> . The objective of the
lateral autopilot is to drive the course χ to the commanded course χc . There-
fore, we augment the state with
Z
xI = (χ − χc )dt.
Since χ ≈ ψ, we approximate xI as
Z
xI = (Hlat xlat − χc )dt,
where
Alat 0 Blat
Ālat = B̄lat =
Hlat 0 0
The LQR controller is designed using
Q = diag ([qv , qp , qr , qφ , qχ , qI ])
R = diag ([rδa , rδr ]) .
As derived in chapter 5, the state space equations for the longitudinal equa-
tions of motion are given by
where xlon = (u, w, q, θ, h)> and ulat = (δe , δt )> . The objective of the
longitudinal autopilot is to drive the altitude h to the commanded altitude
hc , and the airspeed Va to commanded airspeed Vac . Therefore, we augment
the state with
c )dt
R
(h − h
xI = R
(Va − Vac )dt
Z c
h
= Hlon xlon − dt,
Vac
where
0 0 0 0 1
Hlon = u∗ w∗ .
Va Va 0 0 0
where
Alon 0 Blon
Ālon = B̄lon =
Hlon 0 0
The LQR controller is designed using
Q = diag ([qu , qw , qq , qθ , qh , qI ])
R = diag ([rδe , rδt ]) .
54 AUTOPILOT DESIGN
6.1 Implement the longitudinal autopilot and tune the gains. The input the
longitudinal autopilot is the commanded airspeed and the commanded
altitude. To make the process easier, you may want to initialize the
system to trim inputs and then tune airspeed control first, followed by
the pitch loop, and then the altitude loop.
6.2 Implement the lateral autopilot. The input to the lateral autopilot is
the commanded course angle.
6.3 Test the autopilot using a variety of different step inputs on the com-
manded airspeed, altitude, and course angle. Be sure to command
course angles that are greater than ±180 degrees.
uavbook March 18, 2020
uavbook March 18, 2020
Chapter Seven
7.1 ACCELEROMETERS
ρVa2 S
c̄q
yaccel,x = CX (α) + CXq (α) + CXδe (α)δe
2m 2Va
+ Tp (δt , Va ) + ηaccel,x
ρV S2 h bp br
yaccel,y = a CY0 + CYβ β + CYp + C Yr
2m 2Va 2Va
i
+ CYδa δa + CYδr δr + ηaccel,y (7.1)
ρV 2 S
c̄q
yaccel,z = a CZ (α) + CZq (α) + CZδe (α)δe + ηaccel,z .
2m 2Va
MODIFIED MATERIAL:
Because of clock synchronization errors between the satellites (whose
atomic clocks are almost perfectly synchronized) and the receiver, four in-
dependent pseudo-range measurements are required to trilaterate the posi-
tion of the receiver as depicted in figure 7.1. Why are four pseudo-range
58 SENSORS FOR MAVS
satellite 1 satellite 4
r2 r3
r4
r1
receiver
Figure 7.1: Pseudo-range measurements from four satellites used to trilaterate the
position of a receiver.
Chapter Eight
State Estimation
φ̇ ≈ p
θ̇ ≈ q
ψ̇ ≈ r,
62 STATE ESTIMATION
where ω bb/i = (p, q, r)> is the angular rate of the vehicle resolved in the
body frame. Resolving equation (??) along each body axes we get
ygyro,x = p + bp + ηp
ygyro,y = q + bq + ηq
ygyro,z = r + br + ηr ,
Z t Z t
4
φ̂gyro (t) = ygyro,x (τ )dτ = φ(t) + (bp (τ ) + ηp (τ )) dτ
−∞ −∞
= φ(t) + βφ (t)
Z t Z t
4
θ̂gyro (t) = ygyro,y (τ )dτ = θ(t) + (bq (τ ) + ηq (τ )) dτ
−∞ −∞
= θ(t) + βθ (t)
Z t Z t
4
ψ̂gyro (t) = ygyro,z (τ )dτ = ψ(t) + (br (τ ) + ηr (τ )) dτ
−∞ −∞
= ψ(t) + βψ (t),
where β∗ (t) are slowly varying signals, or signals with low frequency con-
tent.
The second measurement that will be used in the model-free complemen-
tary filter either comes from the accelerometers in the case of the roll and
pitch angles, or from a magnetometer, in the case of the yaw angle. Letting
vb = (u, v, w)> , using equation (??) for the rotation matrix in terms of the
Euler angles, and resolving equation (??) along each body axis, we get
yaccel,x = u̇ + qw − rv + g sin θ + bx + ηx
yaccel,y = v̇ + ru − pw + g cos θ sin φ + by + ηy
yaccel,z = ẇ + pv − qu + g cos θ cos φ + bz + ηz ,
where b∗ are slowly varying biases, and η∗ represent zero mean Gaussian
noise. If the bias terms are known, for example through pre-flight calibra-
State Estimation 63
−1 yaccel,y − by
4
φ̂accel (t) = tan
yaccel,z − bz
v̇ + ru − pw + g cos θ sin φ + ηy
−1
= tan
ẇ + pv − qu + g cos θ cos φ + ηz
= φ(t) + νφ (t) + ηφ
−1 yaccel,x − bx
4
θ̂accel (t) = sin
g
u̇ + qw − rv + g sin θ + ηx
= sin−1
g
= θ(t) + νθ (t) + ηθ .
The approximation of φ and θ given by the accelerometers will be most
accurate when the vehicle is not accelerating, i.e., when u̇ + qw − rv =
v̇+ru−pw = ẇ+pv−qu = 0. Since these terms are high frequency signals
that are linked through the dynamics to the true roll and pitch angles, φaccel
and θaccel are only good approximations at low frequencies. Therefore, we
assume that νφ and νθ are signals with high frequency content. We note that
this assumption is violated in many flight scenarios for fixed wing aircraft
like when the vehicle is in a fixed loiter configuration where νφ and νθ are
constant.
In the case of the magnetometer, the measurement is first processed by
subtracting any known biases, rotating to remove the inclination and decli-
nation angles, and then rotating to the body level frame as
mv1 = Rbv1 (φ, θ)Rz> (δ)Ry> (ι)(ymag − bmag ) (8.1)
= Rbv1 (φ, θ)Ry (ι)Rz (δ) mb + ν mag + η mag (8.2)
cθ sθ sφ sθ cφ cι 0 sι cδ sδ 0
= 0 cφ −sφ 0 1 0 −sδ cδ 0 (8.3)
−sθ cθ sφ cθ cφ −sι 0 cι 0 0 1
· mb + ν mag + η mag , (8.4)
We will assume that νψ is a high frequency signal, and therefore, that a low
pass filtered version of ψ̂mag is essentially ψ over low frequencies.
We will present the derivation of the simple complementary filter for the
roll angle φ. The derivation for the pitch and yaw angles is similar. The
intuitive idea of the complementary filter is to estimate the roll angle by
blending a high pass version of φ̂gyro and a low pass version of φ̂accel as
As mentioned above, the gyro measurement contains the true roll rate
p plus a nearly constant bias bφ . We can use the final value theorem to
determine the response of the feedback system shown above to a constant
bφ as the input disturbance. The relevant transfer function is
P
φ̂(s) = bφ (s).
1 + PC
The final value theorem gives
φ̂ss = lim φ̂(t)
t→∞
P b
= lim s
s→0 1 + PC s
bP
= lim .
s→0 1 + P C
1
When P = s and C = kp we get
b
s
φ̂ss = lim k
s→01 + sp
b
= lim
s→0 s + kp
b
= .
kp
State Estimation 67
Therefore, the effect of the bias can be reduced by increasing kp but cannot
be eliminated. However, using a PI structure for C(s) we can completely re-
move the effect of the bias. The resulting architecture is shown in figure 8.6.
When C(s) = kp + ki /s the steady state response to a constant bias is
b
s
φ̂ss = lim kp +ki /s
s→0 1+ s
bs
= lim
s→0 ss + kp s + ki
= 0.
From the block diagram, we see that the differential equations that describe
the complementary filter are given by
˙
b̂φ = −ki (φ̂accel − φ̂) (8.5)
˙
φ̂ = (ygyro,x − b̂φ ) + kp (φ̂accel − φ̂).
1 1
V = (φ − φ̂)2 + (bφ − b̂φ )2 .
2 2ki
68 STATE ESTIMATION
˙
b̂ψ = −ki (ψ̂mag − ψ̂) (8.7)
˙
ψ̂ = (ygyro,z − b̂ψ ) + kp (ψ̂mag − ψ̂).
Initialization:
• Initialize the estimate of the biases b̂φ [0], b̂θ [0], b̂ψ [0].
yaccel,x [n]−bx
• θ̂accel [n] = sin−1 g
MODIFIED MATERIAL:
where the 12 is because we only use half of the area inside the delta function.
Therefore, since Q is symmetric we have that P evolves between measure-
State Estimation 71
ments as
Ṗ = AP + P A> + Q.
8.6.0.2 At Measurements:
NEW MATERIAL:
Between measurements, the covariance evolves according to the equation
Ṗ = AP + P A> + Q.
One way to approximate this equation numerically is to use the Euler ap-
proximation
Pk+1 = Pk + Ts APk + Pk A> + Q .
Letting t = kTs and using the notation x̃k = x̃(kTs ), and assuming that
ξ(τ ) is held constant over each time interval and that ξk = ξ(kTs ), we get
Z Ts
ATs
x̃k+1 = e x̃k + ( eAτ dτ )ξk .
0
= A d Pk A > 2
d + Ts Q,
where we have made the assumption that the discrete estimation error and
the process noise are uncorrelated. Note that the discrete evolution equation
Pk+1 = Ad Pk A> 2
d + Ts Q
P + = (I − LC)P − . (8.8)
The difficulty with this form of the update equation is that numerical error
may cause (I − LC) to be such that P + is not positive definite, even if P −
is positive definite. To address this issue, we go back to the equation for
covariance update given in equation (??):
Rearranging we get
Note that since P − and R are positive definite, that P + will also be positive
definite. Therefore, rather than using equation (8.8), it is more numerically
stable to use the so-called Joseph’s Stabilized form:
or
self . accel threshold = chi2inv (0.99 , 3);
i f ( y−h ) ’ ∗ S i n v ∗ ( y−h ) < s e l f . a c c e l t h r e s h o l d
State Estimation 75
MODIFIED MATERIAL:
where yGP S = (yGP S,n , yGP S,e , yGP S,Vg , yGP S,χ , ywind,n , ywind,e ), u = V̂a ,
and
NEW MATERIAL: In this section we will expand upon the previous dis-
cussion to include the full aircraft state.
76 STATE ESTIMATION
The model for the dynamics of the aircraft are similar to that presented in
the book. If we define p = (pn , pe , pd )> , v = (u, v, w)> , Θ = (φ, θ, ψ)> ,
ω = (p, q, r)> , then we can write the dynamics as
ṗ = R(Θ)v
v̇ = v× ω + a + R> (Θ)g
Θ̇ = S(Θ)ω
ḃ = 03×1
ẇ = 02×1 ,
and where
cθ cψ cθ sψ −sθ
R(Θ) = sφ sθ cψ − cφ sψ sφ sθ sψ + cφ cψ sφ cθ
cφ sθ cψ + sφ sψ cφ sθ sψ − sφ cψ cφ cθ
1 sin φ tan θ cos φ tan θ
S(Θ) = 0 cos φ − sin φ ,
0 sin φ sec θ cos φ sec θ
and where we have used the model for the accelerometer in equation (7.1)
to get
1
f = a + R> (Θ)g,
m
yaccel = a + η accel
ygyro = ω + b + η gyro
yabs pres = ρghAGL + ηabs pres
ρVa2
ydiff pres = + ηdiff pres
2
yGPS,n = pn + νn [n]
yGPS,e = pe + νe [n]
p
yGPS,Vg = (Va cos ψ + wn )2 + (Va sin ψ + we )2 + ηV
yGPS,χ = atan2(Va sin ψ + we , Va cos ψ + wn ) + ηχ .
Using the gyro and accelerometer models, the equations of motion can be
written as
ṗ = R(Θ)v
v̇ = v× (ygyro − b − η gyro ) + (yaccel − η accel ) + R> (Θ)g
Ω̇ = S(Θ)(ygyro − b − η gyro )
ḃ = 03×1
ẇ = 02×1 .
Defining
we get
where
R(Θ)v
v× (ygyro − b) + yaccel + R> (Θ)g
f (x, y) =
S(Θ)(ygyro − b)
03×1
02×1 ,
03×3
−v×
Gg (x) = −S(Θ)
03×3
02×3
03×3
−I3×3
Ga = 03×3 ,
03×3
02×3
and where η is the general process noise associated with the model uncer-
tainty and assumed to have covariance Q.
The Jacobian of f is
4 ∂f
A(x, y) =
∂x
∂[R(Θ)v]
03×3 R(Θ) ∂Θ 03×3 03×2
∂ [R> (Θ)g]
03×3 −(ygyro − b)× −v×
∂Θ 03×2
= 0 ∂[S(Θ)(ygyro −b)] .
3×3 03×3 ∂Θ −S(Θ) 03×2
03×3 03×3 03×3 03×3 03×2
02×3 02×3 02×3 02×3 02×2
∂ [A(z)w] ∂A(z)
∂A(z)
∂A(z)
= ∂z1 w, ∂z2 w, ∂z3 w .
∂z
State Estimation 79
Therefore
∂ [R(Θ)v] ∂R(Θ) ∂R(Θ) ∂R(Θ)
= ∂φ v, ∂θ v, ∂ψ v
>∂Θ
∂ R (Θ)g > > >
= ∂R∂φ(Θ) g, ∂R∂θ(Θ) g, ∂R∂ψ(Θ) g
∂Θ
0 − cos θ 0
= g cos θ cos φ − sin θ sin φ 0
−cosθ sin φ − sin θ cos φ 0
∂S(Θ)
∂φ (ygyro − b)
∂ S(Θ)(ygyro − b)
= ∂S(Θ)
∂θ (ygyro − b)
,
∂Θ ∂S(Θ)
∂ψ (ygyro − b)
where ∂R(Θ)
∂φ is the matrix where each element of R(Θ) has been differenti-
ated by φ.
The covariance of the noise term Gg η gyro + Ga η accel + η is
where
2 2 2
Qgyro = diag([σgyro,x , σgyroy
, σgyroz
])
2 2 2
Qaccel = diag([σaccel,x , σaccely
, σaccelz
]),
and where
Therefore
1 >
hdiff (x) = ρ v − R> (Θ)w v − R> (Θ)w .
2
The associated Jacobian is given by
>
03×1
v − R> (Θ)w
>
Cdiff (x) = ρ
∂ [R> (Θ)w] >
.
− ∂Θ v − R (Θ)w
03×1
>
− I2×2 , 02×1 R(Θ) v − R (Θ)w
hGPS,n (x) = pn
hGPS,e (x) = pe
The inertial velocity in the world frame, projected onto the north-east plane
is given by
vg⊥ = I2×2 , 02×1 R(Θ)v. (8.9)
The ground-speed is given by
Vg (v, Θ) = kvg⊥ k .
The model for the sensor is therefore
hGPS,Vg (x) = kP R(Θ)vk ,
where P = I2×2 , 02×1 , and the associated Jacobian is given by
CGPS,Vg (x) = 01×3 , v> R> (Θ)P > P R(Θ), ∂Vg (v,Θ) >
∂Θ , 01×3 , 01×2 ,
The course angle is the direction of vg⊥ = (vg⊥n , vg⊥e )> given in equa-
tion (8.9). Therefore, the course angle is given by
χ(v, Θ) = atan2(vg⊥e , vg⊥n ).
The model for the sensor is therefore
hGPS,χ (x) = atan2(vg⊥e , vg⊥n ),
and the associated Jacobian is given by
> ∂χ(v,Θ) >
CGPS,χ (x) = 01×3 , ∂χ(v,v) , , 01×3 , 01×2 ,
∂v ∂Θ
With the given sensors, the side-slip angle, or side-to-side velocity is not
observable and can therefore drift. To help correct this situation, we can add
a pseudo measurement on the side-slip angle by assuming that it is zero.
The side slip angle is given by
vr
β= ,
Va
therefore an equivalent condition is that vr = 0. The airspeed vector is given
by
va = v − R(Θ)> w,
We assume that the gyro, accelerometers, and pressure sensors are sampled
at rate Ts , which is the same rate that state estimates are required by the
controller. We also assume that GPS is sampled at TGPS >> Ts .
The algorithm for the direct Kalman filter is given as follows.
0. Initialize Filter.
State Estimation 83
Set
x̂ = (pn (0), pe (0), pd (0), Va (0), 0, 0, 0, 0, ψ(0), 0, 0, 0, 0, 0)> ,
P = diag [e2pn , e2pe , e2pd , e2u , e2v , e2w , e2φ , e2θ , e2ψ , e2bx , e2by , e2bz , e2wn , e2we ] ,
L = P − CGPS,V
>
g
(x̂− )/(σGPS,V
2
g
+ CGPS,Vg (x̂− )P − CGPS,V
>
g
(x̂− ))
P + = (I − LCGPS,Vg (x̂− ))P −
x̂+ = x̂− + L(yGPS,Vg − hGPS,Vg (x̂− )).
L = P − CGPS,χ
>
(x̂− )/(σGPS,χ
2
+ CGPS,χ (x̂− )P − CGPS,χ
>
(x̂− ))
P + = (I − LCGPS,χ (x̂− ))P −
x̂+ = x̂− + L(yGPS,χ − hGPS,V χ (x̂− )).
MODIFIED MATERIAL:
8.1 Download the simulation files for this chapter from the web..
8.2 Implement the simple schemes described in Section 8.3 using low-
pass filters and model inversion to estimate the states pn , pe , h, Va , φ,
θ, χ, p, q, and r. Tune the bandwidth of the low-pass filter to observe
the effect. Different states may require a different filter bandwidth.
8.3 Modify the observer file to implement the extended Kalman filter for
roll and pitch angles described in Section 8.9. Tune the filter until you
are satisfied with the performance.
8.4 Modify the observer file to implement the extended Kalman filter for
position, heading, and wind described in Section 8.10. Tune the filter
until you are satisfied with the performance.
8.5 Change the simulation to use the estimated state in the autopilot as
opposed to the true states. Tune autopilot and estimator gains if nec-
essary. By changing the bandwidth of the low-pass filter, note that the
stability of the closed loop system is heavily influenced by this value.
uavbook March 18, 2020
uavbook March 18, 2020
Chapter Nine
Figure 9.1: Free-body diagram for a pull-up maneuver. The MAV is at a roll angle
of φ.
at an angle of φ, the projection of the lift vector onto P is Flift cos φ. The
centripetal force due to the pull-up maneuver is mVg γ̇. Therefore, summing
the forces in the ib -kb plane gives
Flift cos φ = mVg γ̇ + mg cos γ. (9.1)
88 DESIGN MODELS FOR GUIDANCE
NEW MATERIAL:
where V = kvk.
Design Models for Guidance 89
ii (north)
horizontal
component
of
airspeed
vector
ii
V cos
g
ψ̇ = tan φ,
V
MODIFIED MATERIAL:
The objective of the assignment in this chapter is to estimate the autopilot
constants b∗ and to develop a reduced-order design models that can be used
Design Models for Guidance 91
to test and debug the guidance algorithm discussed in later chapters, prior
to implementation on the full simulation model. We will focus primarily on
the models given in equations (??) and (??).
Chapter Ten
Figure 10.1: Desired altitude calculation for straight-line path following in longi-
tudinal direction.
tical plane containing the path shown in figure 10.1(b) and using similar
triangles, we have the relationship
h + rd −qd
pd =p .
2 2
sn + se qn2 + qe2
NEW MATERIAL:
The commanded course angle for orbit following is given in equation (10.13)
as
d−ρ
c π −1
χ (t) = ϕ + λ + tan korbit .
2 ρ
One of the disadvantages of this strategy is that if the roll angle is used
to command the course, and if the course angle is currently correct, then the
roll angle will be zero. The controller can be improved by using a feedfor-
ward term on the roll angle.
If the UAV is on the orbit and there is no wind, then the desired heading
rate is given by
Va
ψ̇ d = λ .
R
Assuming a coordinated turn condition, the kinematics of the UAV are given
by equation (9.14) as
g
ψ̇ = tan φ.
Va
Setting these expressions equal to each other, and solving for the roll angle,
gives the feedforward term
2
−1 Va
φf f = λ tan . (10.6)
gR
In other words, if the UAV is currently on the orbit and is banked at φf f , and
assuming that airspeed and altitude are being maintained by the autopilot,
then the UAV will continue to fly on the orbit.
the wind case, a stationary orbit of radius R relative the ground is described
by the expression
Vg (t)
χ̇d (t) = λ ,
R
where Vg is the time varying ground speed. From equation (9.10) in the
book, the coordinated turn condition in wind is given by
g
χ̇ = tan φ cos(χ − ψ).
Vg
Equating these expressions and solving for φ results in the feedforward term
!
−1
Vg2
φf f = λ tan .
gR cos(χ − ψ)
From the wind triangle expression given in equation (2.12) we have that
1
sin(χ − ψ) = (we cos χ − wn sin χ).
Va cos γa
Using a simple identity from trigonometry we get
s 2
1
cos(χ − ψ) = 1 − (we cos χ − wn sin χ) .
Va cos γa
In a constant altitude orbit, the flight path angle γ = 0, and therefore equa-
tion (2.11), which comes from the wind triangle, becomes
wd
sin γa = ,
Va
from which we get that
s 2
wd
cos γa = 1− ,
Va
which implies that
s
(we cos χ − wn sin χ)2
cos(χ − ψ) = 1− .
Va2 − wd2
The term under the square root will be positive when the airspeed is greater
than the windspeed, ensuring a positive groundspeed.
Therefore, the feedforward roll angle is given by
q 2
(w cos χ + w sin χ) + V 2 − (w sin χ − w cos χ)2 − w 2
n e a n e d
= λ tan−1
φf f r ,
2
Va2 −(wn sin χ−we cos χ)2 −wd
gR V 2 −w2
a d
(10.7)
which depends only on the wind speed, the current course angle, and the
airspeed. When the wind is zero, i.e., wn = we = wd = 0, then equa-
tion (10.7) simplifies to equation (10.6).
NEW MATERIAL:
This section shows how to develop guidance laws to ensure that the kine-
matic model (9.3) follows straight-line and helical paths. Section ?? shows
how straight-line and helical paths are combined to produce minimum dis-
tance paths between start and end configurations.
The guidance strategy will use the vector-field methodology proposed in [8],
and this section provides a brief overview. The path to be followed in R3
is specified as the intersection of two two-dimensional manifolds given by
α1 (r) = 0 and α2 (r) = 0 where α1 and α2 have bounded second partial
derivatives, and where r ∈ R3 . An underlying assumption is that the path
given by the intersection is connected and one-dimensional. Defining the
function
1 1
V (r) = α12 (r) + α22 (r),
2 2
gives
∂V ∂α1 ∂α2
= α1 (r) (r) + α2 (r) (r).
∂r ∂r ∂r
Straight-line and Orbit Following 97
Note that − ∂V
∂r is a vector that points toward the path. Therefore following
∂V
− ∂r will transition the Dubins airplane onto the path. However simply fol-
lowing − ∂V∂r is insufficient since the gradient is zero on the path. When the
Dubins airplane is on the path, its direction of motion should be perpendic-
ular to both ∂α ∂α2 0
∂r and ∂r . Following [8] the desired velocity vector u ∈ R
1 3
can be chosen as
∂V ∂α1 ∂α2
u0 = −K1 + K2 × , (10.8)
∂r ∂r ∂r
where K1 and K2 are symmetric tuning matrices. It is shown in [8] that the
dynamics ṙ = u0 where u0 is given by equation (10.8), results in r asymp-
totically converging to a trajectory that follows the intersection of α1 and α2
if K1 is positive definite, and where the definiteness of K2 determines the
direction of travel along the trajectory.
The problem with equation (10.8) is that the magnitude of the desired
velocity u0 may not equal V , the velocity of the Dubin’s airplane. Therefore
u0 is normalized as
u0
u=V . (10.9)
ku0 k
Fortunately, the stability proof in [8] is still valid when u0 is normalized as
in equation (10.9).
Setting the NED components of the velocity of the Dubins airplane model
given in equation (9.3) to u = (u1 , u2 , u3 )> gives
V cos ψ d cos γ c = u1
V sin ψ d cos γ c = u2
−V sin γ c = u3 .
Solving for the commanded flight-path angle γ c , and the desired heading
angle ψ d results in the expressions
h u i
3
γ c = −satγ̄ sin−1 (10.10)
V
ψ d = atan2(u2 , u1 ),
where atan2 is the four quadrant inverse tangent, and where the saturation
function is defined as
a
if x ≥ a
sata [x] = −a if x ≤ −a .
x otherwise
98 STRAIGHT-LINE AND ORBIT FOLLOWING
Figure 10.2 shows q` , c` , and the surfaces defined by αlon (r) = 0 and
αlat (r) = 0.
↵lon (r) = 0
nlat
c` q `
nlon
↵lat (r) = 0
Pline (r, q` )
Figure 10.2: This figure shows how the straight-line path Pline (c` , ψ` , γ` ) is de-
fined by the intersection of the two surfaces given by αlon (r) = 0 and αlat (r) = 0.
where
∂αcyl ∂αpl 2 re −ce >
× = Rh , − rnR−c n
, λh tan γh .
∂r ∂r Rh h
Chapter Eleven
Path Manager
Figure 11.1: The geometry associated with inserting a fillet between waypoint
segments.
be defined as the length of the waypoint path W. Define |W|F as the path
length of the fillet-corrected waypoint path that will be obtained using Al-
gorithm ??. From figure 11.1 we see that the length of the fillet traversed
104 PATH MANAGER
MODIFIED MATERIAL:
Chapter Twelve
Path Planning
and
s
2
((v1 − p)> (v1 − v2 ))
D(v1 , v2 , p) = kp − v1 k2 − .
kv1 − v2 k2
If we define
D(v1 , v2 , p)
if σ ∗ ∈ [0, 1]
0 4
D (v1 , v2 , p) = kp − v1 k if σ ∗ < 0
if σ ∗ > 1,
kp − v2 k
then the distance between the point set Q and the line segment v1 v2 is given
by
0
D(v1 , v2 , Q) = min D (v1 , v2 , p).
p∈Q
108 PATH PLANNING
Chapter Thirteen
Vision-guided Navigation
MODIFIED MATERIAL:
Figure 13.1: A graphic showing the relationship between the gimbal and camera
frames and the vehicle and body frames.
13.3 GEOLOCATION
Appendix A
NOMENCLATURE
NOTATION
uavbook March 18, 2020
uavbook March 18, 2020
Appendix B
Quaternions
Appendix C
C.1 INTRODUCTION
destination, map
obstacles
state estimates
path planner
waypoints
status
path manager
path definition
tracking error
NEW MATERIAL:
This section provides a brief overview of techniques for numerically solv-
ing ordinary differential equations, when the initial value is specified. In
118 SIMULATION USING OBJECT ORIENTED PROGRAMMING
The difficulty with solving equation (C.2) is that x(t) appears on both sides
of the equation, and cannot therefore be solved explicitly for x(t). Nu-
merical solutions techniques for ordinary differential equations attempt to
approximate the solution by approximating the integral in equation (C.2).
Most techniques break the solution into small time increments, usually equal
to the sample rate, which we denote by Ts . Accordingly we write equa-
tion (C.2) as
Z t−Ts Z t
x(t) = x(t0 ) + f (x(τ ), u(τ )) dτ + f (x(τ ), u(τ )) dτ
t0 t−Ts
Z t
= x(t − Ts ) + f (x(τ ), x(τ )) dτ. (C.3)
t−Ts
4
Using the notation xk = x(t0 + kTs ) we get the numerical approximation
to the differential equation in equation (C.1) as
Equation (C.4) is called the Euler method, or the Runge-Kutta first order
method (RK1).
While the RK1 method is often effective for numerically solving ODEs, it
typically requires a small sample size Ts . The advantage of the RK1 method
is that it only requires one evaluation of f (·, ·).
Simulation Using Object Oriented Programming 119
Figure C.2: Approximation of integral using the left endpoint method results in
Runge-Kutta first order method (RK1).
Accordingly,
Figure C.3: Approximation of integral using the trapezoidal rule results in Runge-
Kutta second order method (RK2).
t
Ts
Z
f (x(τ ), u(τ ))dτ ≈ f (x(t − Ts ), u(t − Ts )) + f (x(t), u(t)) .
t−Ts 2
120 SIMULATION USING OBJECT ORIENTED PROGRAMMING
c l a s s dynamics :
def init ( s e l f , Ts ) :
s e l f . t s = Ts
# set i n i t i a l conditions
s e l f . s t a t e = np . a r r a y ( [ [ 0 . 0 ] , [ 0 . 0 ] ] )
def update ( s e l f , u ) :
’ ’ ’ I n t e g r a t e ODE u s i n g Runge−K u t t a RK4 a l g o r i t h m ’ ’ ’
ts = self . ts
X1 = s e l f . d e r i v a t i v e s ( s e l f . s t a t e , u )
X2 = s e l f . d e r i v a t i v e s ( s e l f . s t a t e + t s / 2 ∗ X1 , u )
X3 = s e l f . d e r i v a t i v e s ( s e l f . s t a t e + t s / 2 ∗ X2 , u )
X4 = s e l f . d e r i v a t i v e s ( s e l f . s t a t e + t s ∗ X3 , u )
s e l f . s t a t e += t s / 6 ∗ ( X1 + 2∗X2 + 2∗X3 + X4 )
def output ( s e l f ) :
’ ’ ’ Returns system output ’ ’ ’
y = s e l f . s t a t e . item (0)
return y
# i n i t i a l i z e the system
Ts = 0 . 0 1 # s i m u l a t i o n s t e p s i z e
s y s t e m = d y n a m i c s ( Ts )
# i n i t i a l i z e t h e s i m u l a t i o n t i m e and p l o t d a t a
sim time = 0.0
time = [ sim time ]
y = [ system . output ( ) ]
# main s i m u l a t i o n l o o p
while sim time < 1 0 . 0 :
u=np . s i n ( s i m t i m e ) # s e t i n p u t t o u= s i n ( t )
system . update ( u ) # propagate the system dynamics
s i m t i m e += Ts # increment the simulation time
time . append ( s i m t i m e )
y . append ( system . o u t p u t ( ) )
# plot output y
p l t . p l o t ( time , y )
p l t . x l a b e l ( ’ time ( s ) ’ )
plt . ylabel ( ’ output y ’ )
p l t . show ( )
uavbook March 18, 2020
uavbook March 18, 2020
Appendix D
Animation
>> p l o t h a n d l e = p l o t ( t , s i n ( t ) )
>> s e t ( p l o t h a n d l e , ’ YData ’ , c o s ( t ) )
>> p l o t h a n d l e 1 = p l o t ( t , s i n ( t ) )
>> h o l d on
>> p l o t h a n d l e 2 = p l o t ( t , c o s ( t ) )
>> s e t ( p l o t h a n d l e 2 , ’ YData ’ , c o s ( 2 ∗ t ) )
f u n c t i o n drawPendulum ( u )
% process inputs to function
y = u(1);
theta = u(2);
t = u(3);
% drawing parameters
L = 1;
gap = 0 . 0 1 ;
width = 1 . 0 ;
height = 0.1;
% a t e v e r y o t h e r t i m e s t e p , r e d r a w b a s e and r o d
else
drawBase ( y , w i d t h , h e i g h t , gap , b a s e h a n d l e ) ;
drawRod ( y , t h e t a , L , gap , h e i g h t , r o d h a n d l e ) ;
end
f u n c t i o n XYZ= s p a c e c r a f t P o i n t s
% d e f i n e p o i n t s on t h e s p a c e c r a f t i n l o c a l NED c o o r d i n a t e s
Animation 127
XYZ = [ . . .
1 1 0;... % point 1
1 −1 0;... % point 2
−1 −1 0;... % point 3
−1 1 0;... % point 4
1 1 0;... % point 1
1 1 −2;... % point 5
1 −1 −2;... % point 6
1 −1 0;... % point 2
1 −1 −2;... % point 6
−1 −1 −2;... % point 7
−1 −1 0;... % point 3
−1 −1 −2;... % point 7
−1 1 −2;... % point 8
−1 1 0;... % point 4
−1 1 −2;... % point 8
1 1 −2;... % point 5
1 1 0;... % point 1
1.5 1.5 0;... % point 9
1.5 −1.5 0;... % point 10
1 −1 0;... % point 2
1.5 −1.5 0;... % point 10
−1.5 −1.5 0;... % point 11
−1 −1 0;... % point 3
−1.5 −1.5 0;... % point 11
−1.5 1.5 0;... % point 12
−1 1 0;... % point 4
−1.5 1.5 0;... % point 12
1.5 1.5 0;... % point 9
] ’;
f u n c t i o n XYZ= r o t a t e (XYZ, p h i , t h e t a , p s i )
% define rotation matrix
R roll = [ . . .
1, 0, 0;...
0 , c o s ( p h i ) , −s i n ( p h i ) ; . . .
0 , sin ( phi ) , cos ( phi ) ] ;
R pitch = [ . . .
cos ( t h e t a ) , 0 , sin ( t h e t a ) ; . . .
0, 1, 0;...
−s i n ( t h e t a ) , 0 , c o s ( t h e t a ) ] ;
R yaw = [ . . .
c o s ( p s i ) , −s i n ( p s i ) , 0 ; . . .
sin ( p s i ) , cos ( p s i ) , 0 ; . . .
0 , 0 , 1];
R = R r o l l ∗ R p i t c h ∗R yaw ;
% rotate vertices
XYZ = R∗XYZ;
128 ANIMATION
f u n c t i o n XYZ = t r a n s l a t e (XYZ, pn , pe , pd )
XYZ = XYZ + r e p m a t ( [ pn ; pe ; pd ] , 1 , s i z e (XYZ , 2 ) ) ;
f u n c t i o n [V, F , p a t c h c o l o r s ] = s p a c e c r a f t
% Define the v e r t i c e s ( physical location of v e r t i c e s )
V = [...
1 1 0 ; . . . % point 1
1 −1 0 ; . . . % point 2
−1 −1 0 ; . . . % point 3
−1 1 0 ; . . . % point 4
1 1 −2;... % point 5
1 −1 −2;... % point 6
−1 −1 −2;... % point 7
−1 1 −2;... % point 8
1.5 1.5 0 ; . . . % point 9
1 . 5 −1.5 0 ; . . . % p o i n t 10
−1.5 −1.5 0 ; . . . % p o i n t 11
−1.5 1 . 5 0 ; . . . % p o i n t 12
];
% d e f i n e f a c e s a s a l i s t o f v e r t i c e s numbered a b o v e
F = [...
1, 2, 6, 5 ; . . . % front
Animation 129
4, 3, 7, 8 ; . . . % back
1, 5, 8, 4 ; . . . % right
2, 6, 7, 3;... % left
5, 6, 7, 8 ; . . . % top
9 , 10 , 11 , 1 2 ; . . . % bottom
];
% d e f i n e c o l o r s f o r each f a c e
myred = [1 , 0 , 0];
mygreen = [ 0 , 1 , 0 ] ;
myblue = [0 , 0 , 1];
myyellow = [ 1 , 1 , 0 ] ;
mycyan = [0 , 1 , 1];
patchcolors = [ . . .
myred ; . . . % front
mygreen ; . . . % b a c k
myblue ; . . . % right
myyellow ; . . . % l e f t
mycyan ; . . . % top
mycyan ; . . . % bottom
];
end
The vertices are shown in figure ?? and are defined in Lines 3–16. The
faces are defined by listing the indices of the points that define the face.
For example, the front face, defined in Line 19, consists of points 1 − 2 −
6 − 5. Faces can be defined by N -points, where the matrix that defines the
faces has N columns, and the number of rows is the number of faces. The
color for each face is defined in Lines 32–39. Matlab code that draws the
spacecraft body is listed below.
f u n c t i o n h a n d l e = d r a w S p a c e c r a f t B o d y ( pn , pe , pd ,
phi , t h e t a , psi ,
h a n d l e , mode )
% d e f i n e p o i n t s on s p a c e c r a f t
[V, F , p a t c h c o l o r s ] = s p a c e c r a f t ;
% r o t a t e and t h e n t r a n s l a t e s p a c e c r a f t
V = r o t a t e (V’ , p h i , t h e t a , p s i ) ’ ;
V = t r a n s l a t e (V’ , pn , pe , pd ) ’ ;
% t r a n s f o r m NED t o ENU f o r r e n d e r i n g
R = [...
0, 1, 0;...
1, 0, 0;...
0 , 0 , −1;...
];
V = V∗R ;
i f isempty ( handle )
h a n d l e = p a t c h ( ’ V e r t i c e s ’ , V, ’ F a c e s ’ , F , . . .
’ FaceVertexCData ’ , p a t c h c o l o r s , . . .
’ FaceColor ’ , ’ f l a t ’ , . . .
130 ANIMATION
’ EraseMode ’ , mode ) ;
else
s e t ( h a n d l e , ’ V e r t i c e s ’ ,V, ’ F a c e s ’ , F ) ;
end
end
uavbook March 18, 2020
Appendix E
Airframe Parameters
Appendix F
NEW MATERIAL:
The MAV dynamics can be described at a high level by the dynamics
ẋ = f (x, u),
∂f
∂f ∂f ∂f
= ∂x ∂x2 ... ∂xn ,
∂x 1
where
∂f
1
∂xi
∂f
∂x2i
∂f
= .
..
∂xi
∂fn
∂xi
A = np . z e r o s ( ( 1 2 , 1 2 ) ) # J a c o b i a n o f f w r t x
f at x = f (x , u)
f o r i i n range ( 0 , 1 2 ) :
x e p s = np . copy ( x )
x e p s [ i ] [ 0 ] += e p s # add e p s t o i t h s t a t e
f a t x e p s = f ( x eps , u )
d f d x i = ( f a t x e p s − f a t x ) / eps
A[ : , i ] = df dxi [ : , 0 ]
return A
NEW MATERIAL:
The simulation developed in the book can be done using either Euler an-
gles or a unit quaternion to represent the attitude of the MAV. The state space
and transfer function models are all with respect to Euler angles. Therefore,
if unit quaternions are used instead of Euler angles, then we need a tech-
nique to compute the Jacobians with respect to Euler angles. Let
represent the state using unit quaternions for attitude. Let T : R13 → R12
be the mapping that converts quaternion representation so that xe = T (xq ).
Specifically,
pn
pn
pe
pe
pd
pd
u
u
v
v
w
w
T e0 = ,
Θφ (e0 , ex , ey , ez )
ex
Θθ (e0 , ex , ey , ez )
e
y
e Θψ (e0 , ex , ey , ez )
z p
p
q q
r
r
[A, B , C , D] = l i n m o d ( f i l e n a m e , x t r i m , u t r i m )
A l a t = A( [ 5 , 10 , 12 , 7 , 9 ] , [ 5 , 10 , 12 , 7 , 9 ] ) ;
B l a t = B( [ 5 , 10 , 12 , 7 , 9 ] , [ 3 , 4 ] ) ;
NEW MATERIAL:
If your Simulink implementation uses quaternions for the state, then
linmod returns state space equations with respect to xq , whereas the stan-
dard state space equations require the state space equations with respect to
xe . Suppose that the quaternion state space equations are given by
and recall from the discussion above that xe = T (xq ). Differentiating with
respect to time we get
∂T
ẋe = ẋq
∂xq
∂T
= fq (xq , u)
∂xq
∂T
= fq (T −1 (xe ), u)
∂xq
= fe (xe , u).
∂fe
∂T
∂ ∂x q
fq (T −1 (xe ), u)
=
∂xe ∂xe
∂T ∂fq ∂T −1
= ,
∂xq ∂xq ∂xe
∂T
where ∂xq given in equation (F.1) and where
I3×3 03×3 03×3 03×3
∂T −1 03×3 I3×3 03×3 03×3
=
04×3 ∂Q
(F.2)
∂xq 04×3 ∂Θ 04×3
03×3 03×3 03×3 I3×3 ,
∂Q
and where Q(Θ) is given by equation (??) and where ∂Θ can be computed
numerically.
Trim and Linearization 137
NEW MATERIAL:
In Matlab, trim can be computed using the built in optimization function
fmincon. In general fmincon can be configured to minimize nonlinear
functions with general constraints. For example, to minimize the function
J(x) = x>x − γ subject to the constraints that x1 = x2 and sin(x3 ) ≤
−0.5, the appropriate Matlab code is as follows:
x0 = [ 1 0 ; 5 ; −20; 8 ] ; % i n i t i a l g u e s s f o r t h e optimum
gam = 3 ; % p a r a m e t e r p a s s e d i n t o o b j e c t i v e f u n c t i o n
x o p t = f m i n c o n ( @ o b j e c t i v e , x0 , [ ] , [ ] , [ ] , [ ]
[ ] , [ ] , @ c o n s t r a i n t s , [ ] , gam ) ;
% o b j e c t i v e f u n c t i o n t o be m i n i m i z e d
f u n c t i o n J = o b j e c t i v e ( x , gam )
J = x∗x ’ − gam ;
end
NEW MATERIAL:
In Python, trim can be computed using the scipy optimize library. For
example, to minimize the function J(x) = x>x − γ subject to the con-
straints that x1 = x2 and sin(x3 ) ≤ −0.5, the appropriate Python code is as
follows: import numpy as np from scipy.optimize import minimize
# i n i t i a l g u e s s f o r t h e optimum
x0 = np . a r r a y ( [ [ 1 0 ; 5 ; −20; 8 ] ] ) . T ;
gam = 3 ; # p a r a m e t e r p a s s e d i n t o o b j e c t i v e f u n c t i o n
# f i r s t c o n s t r a i n t i s e q u a l i t y c o n s t r a i n t x1==x2
# s e c o n d c o n s t r a i n t i s i n e q u a l i t y c o n s t r a i n t s i n ( x3 )<=−0.5
c o n s = ( { ’ t y p e ’ : ’ eq ’ , ’ f u n ’ : lambda x : x [0] − x [ 1 ] , } ,
138 TRIM AND LINEARIZATION
{ ’ t y p e ’ : ’ i n e q ’ , ’ f u n ’ : lambda x : np . s i n ( x [ 2 ] ) + 0 . 5 } )
# s o l v e t h e m i n i m i z a t i o n problem
r e s = m i n i m i z e ( o b j e c t i v e , x0 ,
method = ’SLSQP ’ ,
a r g s = ( gam ) ,
c o n s t r a i n t s = cons ,
o p t i o n s ={ ’ f t o l ’ : 1 e −10 , ’ d i s p ’ : T r u e } )
# extract optimal st ate
x o p t = np . a r r a y ( [ r e s . x ] ) . T
# o b j e c t i v e f u n c t i o n t o be m i n i m i z e d
d e f o b j e c t i v e ( x , gam ) :
J = np . d o t ( x . T , x ) − gam
return J
uavbook March 18, 2020
Appendix G
Appendix H
Sensor Parameters
H.2 ACCELEROMETERS
H.5 GPS
uavbook March 18, 2020
uavbook March 18, 2020
Appendix I
Bibliography
Index
Short-period Mode, 28
Side Slip Angle, 16
Simulation Model, 1, 22, 133
Spiral-divergence Mode, 28
State-Space Models
Longitudinal, 26
State-space Models
Lateral, 26
straight-line path following, 98
Successive Loop Closure, 33
Transfer Functions
Elevator to Pitch, 43
Pitch to Altitude, 45
Roll to Course, 37
Throttle to Airspeed, 46
Trim, 23
Wind Gusts, 13
Dryden Model, 14
WIND SPEED, 3
Wind Speed, 4, 13
Wind Triangle, 3, 4