Skip to the lesson
FixTheRobot Explore Robotics / Guidance, Navigation and Control / M2 Modelling a Vehicle for GNC / M2-T4

Guidance, Navigation and Control · Theory · M2

M2-T4 — Trim and Linearization

A nonlinear model is accurate and hard to analyse. A linear model is easy to analyse and true only near one operating point. Trim and linearization are how the two meet.

  • Lesson 4 of 5
  • Intermediate
  • Module 2: Modelling a Vehicle for GNC
  • Theory
  • About 17 minutes to read

The tools of the next two modules, poles, margins, regulators, observers, all work on linear models. Hopper's model is not linear: it has sines, products and a mass that changes. The step between them is standard and short. Choose a steady condition about which the vehicle can sit, which is called its trim, and expand the equations to first order around it. This lesson does both for Hopper, with a numerical Jacobian, and then asks the question that decides whether the linear model can be used: how far from the trim does it stop being true?

Learning objectives

After this lesson, you should be able to:

  • Find a trim of a nonlinear model by solving the steady-state equations numerically.
  • Linearize the model about a trim to state-space form with a Jacobian.
  • Read the poles of the linear model and relate them to the behaviour of the vehicle.
  • Estimate the range of the linear model's validity, and name the couplings it leaves out.

The intuition

Hopper's nonlinear model, from the last two lessons, has seven states and two inputs. Its lateral acceleration is (T/m)sin⁡(θ+δ)(T/m)\sin(\theta + \delta), which is not a linear function of anything. The methods of the next modules (poles, frequency response, linear-quadratic regulators) need a model of the form x˙=Ax+Bu\dot{\mathbf{x}} = \mathbf{A}\mathbf{x} + \mathbf{B}\mathbf{u}. The way to get one is to look at the vehicle close up, near one steady condition, where the curved relations are nearly straight.

Trim: a condition the vehicle can hold

A trim is a steady operating condition: the inputs are constant and the accelerations that matter are constant too. Every vehicle has its own.

  • A multirotor in hover: zero velocity, zero tilt, rotor thrusts that add up to the weight.
  • An aircraft in level flight at a given airspeed: an angle of attack, an elevator angle and a throttle setting at which lift equals weight and thrust equals drag.
  • A satellite spinning at a constant rate about a principal axis.
  • Hopper in hover (zero tilt, thrust equal to weight) or in a steady acceleration (a constant lateral acceleration, with the thrust tilted to give it).

Finding a trim is solving equations: set the derivatives that must vanish to zero, and solve for the inputs and the states that remain. For hover the answer is obvious. For a steady acceleration it is not: the thrust, the pitch and the gimbal angle have to be found together, because the aerodynamic moment and the gimbal moment have to cancel at the same time as the forces balance. A numerical solver (Newton's method, with a numerical Jacobian) does it for any model.

Linearize: the straight line that touches the curve

Around a trim, small deviations from it obey equations that are linear in the deviations. The figure shows the idea for one term: the straight line gθg\theta touches the curve gsin⁡θg\sin\theta at the origin and stays close for a while. The slope of that line is a partial derivative, and the collection of such slopes for every state and every input is a pair of matrices, A\mathbf{A} and B\mathbf{B}.

Lateral acceleration of a pitched Hopper: nonlinear and linearizedA plot of lateral acceleration against pitch from 0 to 60 degrees. The nonlinear curve, g sine theta, bends below the straight line g theta of the linear model. The two agree near zero. They differ by 5 percent at 31 degrees and 10 percent at 43 degrees, marked by dots on the linear line, and by 21 percent at 60 degrees.010203040506002.24.46.68.811pitch θ (degrees)lateral acceleration (m/s²) linear model: g θ true: g sin θ 5% off at 31°10% off at 43°
The true lateral acceleration of a pitched Hopper (curve) and its linear model (dashed line). They agree near hover and drift apart as the tilt grows.

What the linear model tells you

The poles of A\mathbf{A}, its eigenvalues, say how the vehicle behaves near the trim: which modes grow, which decay, which neither. For Hopper in hover they are 0, 0, +0.7 and −0.7 per second: two integrators (position and velocity) and the unstable pair of the pitch axis. The same four numbers were already in the model; the linearization exposes them and makes them computable for a model whose structure is not obvious by inspection.

What it leaves out

A linear model is true at one point and an approximation near it. Two things go wrong as the vehicle moves away. The curvature of each term shows up, as in the figure. And couplings that vanished at the trim come back: at hover, the lateral and vertical motions are independent to first order, but a Hopper tilted by 40° has lost 2.3 m/s² of vertical acceleration that the lateral model knows nothing of.

Trim finds the condition. Linearization gives the model around it. The range of validity, which the linear model cannot tell you about itself, is something you compute separately.

Definitions

Nonlinear model
x˙=f(x,u)\dot{\mathbf{x}} = \mathbf{f}(\mathbf{x}, \mathbf{u}) with state x\mathbf{x} and input u\mathbf{u}.
Equilibrium or trim (x0,u0)(\mathbf{x}_0, \mathbf{u}_0)
A state and input at which the part of the motion that must be steady has no acceleration. For a true equilibrium, f(x0,u0)=0\mathbf{f}(\mathbf{x}_0, \mathbf{u}_0) = 0. For a steady acceleration the equations are solved for the states and inputs that make the other derivatives vanish.
Deviations δx,δu\delta\mathbf{x}, \delta\mathbf{u}
The difference from the trim: δx=x−x0\delta\mathbf{x} = \mathbf{x} - \mathbf{x}_0, δu=u−u0\delta\mathbf{u} = \mathbf{u} - \mathbf{u}_0.
Jacobian
The matrix of partial derivatives of a vector function: its entry (i,j)(i, j) is how output ii changes with input jj.
Pole
An eigenvalue of A\mathbf{A}. A mode with eigenvalue λ\lambda behaves as eλte^{\lambda t} (M1-T3: One Block Diagram, Four Vehicles explains why).

The linearization is the first-order expansion of the model about the trim:

Linearization
δx˙=A δx+B δu,A=∂f∂x∣0,B=∂f∂u∣0\delta\dot{\mathbf{x}} = \mathbf{A}\,\delta\mathbf{x} + \mathbf{B}\,\delta\mathbf{u}, \qquad \mathbf{A} = \left.\frac{\partial\mathbf{f}}{\partial\mathbf{x}}\right|_{0}, \quad \mathbf{B} = \left.\frac{\partial\mathbf{f}}{\partial\mathbf{u}}\right|_{0}
The subscript 0 says that the derivatives are evaluated at the trim. A and B are constant matrices.

For a steady lateral acceleration aa, the trim of Hopper has no vertical or pitch acceleration. Its three unknowns, the thrust TT, the pitch θ\theta and the gimbal δ\delta, satisfy three equations:

Trim of Hopper at a steady acceleration a
Tmsin⁡(θ+δ)=a,Tmcos⁡(θ+δ)=g,λ2θ+T lJsin⁡δ=0\frac{T}{m}\sin(\theta + \delta) = a, \qquad \frac{T}{m}\cos(\theta + \delta) = g, \qquad \lambda^2\theta + \frac{T\,l}{J}\sin\delta = 0
The first two fix the direction and size of the thrust; the third balances the aerodynamic and gimbal moments. For a = 0 the solution is the hover: T = m g, θ = δ = 0.

Linearizing the lateral channel, with states (x,vx,θ,q)(x, v_x, \theta, q) and input δ\delta, gives:

Lateral channel of Hopper
A=(010000g0000100λ20),B=(0g0b),b=T lcos⁡δ0J\mathbf{A} = \begin{pmatrix} 0 & 1 & 0 & 0 \\ 0 & 0 & g & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & \lambda^2 & 0 \end{pmatrix}, \qquad \mathbf{B} = \begin{pmatrix} 0 \\ g \\ 0 \\ b \end{pmatrix}, \qquad b = \frac{T\,l\cos\delta_0}{J}
gg is gravity, λ\lambda the divergence rate and bb the pitch authority at the trim. The next two lessons and module 3 use this model.

Derivation: the Jacobian of Hopper, its poles, and how far it can be trusted

The linearization follows from one expansion. Then the entries of A\mathbf{A} and B\mathbf{B} for Hopper can be written down by hand, and the model's range of validity estimated.

  1. f(x0+δx, u0+δu)=f(x0,u0)+A δx+B δu+(second order)\mathbf{f}(\mathbf{x}_0 + \delta\mathbf{x},\,\mathbf{u}_0 + \delta\mathbf{u}) = \mathbf{f}(\mathbf{x}_0, \mathbf{u}_0) + \mathbf{A}\,\delta\mathbf{x} + \mathbf{B}\,\delta\mathbf{u} + \text{(second order)}

    Expand each component of f\mathbf{f} in a Taylor series about the trim. The first-order coefficients are the partial derivatives, collected into the Jacobians A\mathbf{A} and B\mathbf{B}.

  2. δx˙=x˙−x˙0≈A δx+B δu\delta\dot{\mathbf{x}} = \dot{\mathbf{x}} - \dot{\mathbf{x}}_0 \approx \mathbf{A}\,\delta\mathbf{x} + \mathbf{B}\,\delta\mathbf{u}

    At a trim the derivative of the part of the state that must stay steady is zero (or constant), so it drops out of the difference. Neglecting the second-order terms leaves the linear model.

The entries for Hopper

  1. ∂∂θ ⁣[Tmsin⁡(θ+δ)]=Tmcos⁡(θ0+δ0)=g\frac{\partial}{\partial\theta}\!\left[\frac{T}{m}\sin(\theta + \delta)\right] = \frac{T}{m}\cos(\theta_0 + \delta_0) = g

    Differentiate the lateral acceleration with respect to pitch. At the trim the vertical balance of the trim equations says (T/m)cos⁡(θ0+δ0)=g(T/m)\cos(\theta_0 + \delta_0) = g, so the entry is exactly gg at every steady acceleration, not just in hover. The same holds for the derivative with respect to δ\delta.

  2. ∂∂θ ⁣[λ2θ+TlJsin⁡δ]=λ2,∂∂δ ⁣[⋯ ]=T lJcos⁡δ0\frac{\partial}{\partial\theta}\!\left[\lambda^2\theta + \frac{T l}{J}\sin\delta\right] = \lambda^2, \qquad \frac{\partial}{\partial\delta}\!\left[\cdots\right] = \frac{T\,l}{J}\cos\delta_0

    Differentiate the pitch acceleration. The aerodynamic term is already linear. The gimbal term has slope b=Tlcos⁡δ0/Jb = T l\cos\delta_0/J, the authority at the trim.

  3. det⁡(sI−A)=s2 (s2−λ2)\det(s\mathbf{I} - \mathbf{A}) = s^2\,(s^2 - \lambda^2)

    Expand the determinant. The chain x,vxx, v_x is two integrators driven by the pitch, and the pitch pair is θ¨=λ2θ\ddot\theta = \lambda^2\theta. The characteristic polynomial factors into s2s^2 and s2−λ2s^2 - \lambda^2.

  4. s=0, 0, +λ, −λs = 0,\ 0,\ +\lambda,\ -\lambda

    The poles: two integrators and a divergent and a convergent pitch mode. They do not depend on the trim, and they do not depend on the pitch authority. Only B\mathbf{B} changes with the thrust.

How far can it be trusted?

  1. sin⁡θ=θ−θ36+⋯  ⇒  gθ−gsin⁡θgsin⁡θ≈θ26\sin\theta = \theta - \frac{\theta^3}{6} + \cdots \;\Rightarrow\; \frac{g\theta - g\sin\theta}{g\sin\theta} \approx \frac{\theta^2}{6}

    The first neglected term of the series for the sine. The relative error of the linear lateral acceleration grows as the square of the tilt.

  2. θ26=0.05⇒θ=0.55 rad=31∘,θ26=0.10⇒θ=0.77 rad=44∘\frac{\theta^2}{6} = 0.05 \Rightarrow \theta = 0.55\ \text{rad} = 31^\circ, \qquad \frac{\theta^2}{6} = 0.10 \Rightarrow \theta = 0.77\ \text{rad} = 44^\circ

    Choose an acceptable error and solve for the tilt. Both numbers match the figure (the 10% point, at 43°, is a little lower because the next term of the series matters there).

  3. Δaz=g (cos⁡θ−1)≈−g θ22\Delta a_z = g\,(\cos\theta - 1) \approx -\frac{g\,\theta^2}{2}

    The vertical acceleration that the lateral model leaves out when thrust is held at the hover value. It is a second-order effect that is missing from the linear model of the lateral channel.

The linearization is exact only at the trim. Near it the error is second order in the distance, and the question is never "is the model linear?" but "how far from the trim will the vehicle go?".

A worked example

Find the trim of Hopper for a lateral acceleration of 2 m/s² at liftoff mass, linearize its lateral channel about hover and about that trim, and measure where the hover model stops being accurate.

  1. Trim. Newton's method on the three equations of the definitions, with a numerical Jacobian, starting from the weight and small angles, finds a thrust of 1201.4 N (1.0206 times the weight), a pitch of 11.81° and a gimbal angle of −0.289°. The thrust direction θ+δ\theta + \delta is 11.52°, which is arctan⁡(2/9.81)\arctan(2/9.81): the direction of the vector sum of weight and the required acceleration.
  2. Linearize. A central-difference Jacobian of the nonlinear model gives the matrices at both operating points. At hover A\mathbf{A} has the entries g=9.81g = 9.81 and λ2=0.49\lambda^2 = 0.49 and B\mathbf{B} has (g,b)=(9.81,19.62)(g, b) = (9.81, 19.62). At the trim A\mathbf{A} is identical, as the derivation says, and bb is 20.02.
  3. Poles. The eigenvalues are −0.7, 0, 0 and +0.7 per second at both operating points.
  4. Validity. The linear lateral acceleration gθg\theta is 0.5% too high at 10° of tilt, 2.1% at 20°, 4.7% at 30°, 8.6% at 40° and 20.9% at 60°. The vertical acceleration that it leaves out is −0.15 m/s² at 10° and −2.3 m/s² at 40°, nearly a quarter of gravity.
  5. Read it. For a hop whose tilt stays below about 20° the hover model is good to 2% and the missing vertical coupling is below 0.6 m/s². For manoeuvres beyond 30° one linear model is not enough, and the options are several linearizations (gain scheduling, module 5) or a nonlinear controller.
import math
from gnckit import HOPPER, hopper_deriv, jacobian, newton, mat_eigvals

P = HOPPER
g, m, J, l, lam = P['g'], P['m0'], P['J'], P['l'], P['lam']

def f(state, T, delta):
    return hopper_deriv(list(state) + [m], T, delta)[:6]

# trim for a steady lateral acceleration a: no vertical acceleration, no pitch acceleration
def residual(u, a=2.0):
    T, th, delta = u
    d = hopper_deriv([0.0, 10.0, th, 0.0, 0.0, 0.0, m], T, delta)
    return [d[3] - a, d[4], d[5]]
T, th, dl = newton(residual, [m * g, 0.1, -0.01])
print(f'trim at a = 2 m/s^2: thrust {T:.1f} N ({T / (m * g):.4f} x weight), pitch {math.degrees(th):.2f} deg, gimbal {math.degrees(dl):.3f} deg')

lat_idx = (0, 3, 2, 5)
def lateral_AB(T, th, dl):
    x0 = [0.0, 10.0, th, 0.0, 0.0, 0.0]
    A = jacobian(lambda s: f(s, T, dl), x0)
    h = 1e-6
    dfdu = [(a - b) / (2 * h) for a, b in zip(f(x0, T, dl + h), f(x0, T, dl - h))]
    return [[A[i][j] for j in lat_idx] for i in lat_idx], [dfdu[i] for i in lat_idx]
for name, args in (('hover', (m * g, 0.0, 0.0)), ('a = 2 trim', (T, th, dl))):
    A, B = lateral_AB(*args)
    ev = sorted(mat_eigvals(A), key=lambda c: complex(c).real)
    print(f'{name:10s} A[1][2] = {A[1][2]:.3f}  A[3][2] = {A[3][2]:.3f}  B = ({B[1]:.3f}, {B[3]:.3f})  poles {[round(complex(e).real, 3) for e in ev]}')

print('how far the linear model is from the nonlinear one (hover linearization):')
for deg in (10, 20, 30, 40, 60):
    t = math.radians(deg)
    a_nl = g * math.sin(t); a_lin = g * t
    az = g * (math.cos(t) - 1.0)
    print(f'  theta {deg:2d} deg: lateral accel {a_nl:5.2f} vs linear {a_lin:5.2f} m/s^2 ({100 * (a_lin / a_nl - 1):4.1f}% high), vertical accel the linear model leaves out {az:6.2f} m/s^2')
trim at a = 2 m/s^2: thrust 1201.4 N (1.0206 x weight), pitch 11.81 deg, gimbal -0.289 deg
hover      A[1][2] = 9.810  A[3][2] = 0.490  B = (9.810, 19.620)  poles [-0.7, 0.0, 0.0, 0.7]
a = 2 trim A[1][2] = 9.810  A[3][2] = 0.490  B = (9.810, 20.023)  poles [-0.7, 0.0, 0.0, 0.7]
how far the linear model is from the nonlinear one (hover linearization):
  theta 10 deg: lateral accel  1.70 vs linear  1.71 m/s^2 ( 0.5% high), vertical accel the linear model leaves out  -0.15 m/s^2
  theta 20 deg: lateral accel  3.36 vs linear  3.42 m/s^2 ( 2.1% high), vertical accel the linear model leaves out  -0.59 m/s^2
  theta 30 deg: lateral accel  4.90 vs linear  5.14 m/s^2 ( 4.7% high), vertical accel the linear model leaves out  -1.31 m/s^2
  theta 40 deg: lateral accel  6.31 vs linear  6.85 m/s^2 ( 8.6% high), vertical accel the linear model leaves out  -2.30 m/s^2
  theta 60 deg: lateral accel  8.50 vs linear 10.27 m/s^2 (20.9% high), vertical accel the linear model leaves out  -4.90 m/s^2
newton and jacobian are in gnckit; the state vector of hopper_deriv is x, z, theta, vx, vz, q, m.

In robotics

Linearization is the first step of almost every control design, and the choice of trim shapes the result.

  • Aircraft. The trim is a level flight at a chosen airspeed and altitude, found by solving for the angle of attack, elevator and throttle. Linearizing there gives the longitudinal and lateral models whose modes (short period, phugoid, roll, spiral, Dutch roll) module 10 studies. A different airspeed is a different trim and a different model, so an aircraft has a family of them.
  • Multirotors. The hover trim and its linear model are the basis of the attitude and position controllers of UAV M5-T2: Quadrotor dynamic modelling. The lateral channel of Hopper has the same structure as the translational channel of a quadrotor: two integrators fed by the tilt.
  • Tools. Simulation environments linearize a model with a numerical Jacobian exactly as in the worked example: Simulink's linmod, python-control's linearize and the linearization functions of robotics toolboxes. The step size of the numerical derivative matters: too large and it measures curvature, too small and it measures rounding error.
  • Gain scheduling. A family of linearizations over a changing parameter, such as the mass or the dynamic pressure, gives a family of controllers (module 5). Hopper's B\mathbf{B} depends on the thrust, so its pitch authority is 19.6 at liftoff and 11.8 at burnout.
  • Stability of the nonlinear system. If every pole of A\mathbf{A} is in the left half-plane, the nonlinear system is locally stable at the trim, and if one is in the right half-plane, it is unstable. Poles at zero decide nothing. This is Lyapunov's indirect method (module 5). It says nothing about how large the region of stability is.

The Jacobian is the same object that appears in kinematics and in estimation: Linear Algebra M8-T4: Jacobian Matrices derives it for a robot arm, and the extended Kalman filter of module 7 linearizes its measurement model in the same way.

Common misconceptions

“A linearized model is valid everywhere.”

It is exact at the trim and a first-order approximation near it, with an error that grows as the square of the distance. Hopper's lateral model is 5% off at 31° of tilt and 21% off at 60°. A controller designed on it is only guaranteed to work in the region where the model is accurate enough.

“A trim must be a rest state.”

A trim is a steady condition, and the vehicle may be moving. Level flight at 80 m/s, a steady turn and a constant lateral acceleration are all trims. The condition that defines it is that the accelerations that matter are constant, not that the vehicle is still.

“Poles at zero mean the vehicle is unstable.”

A pole at zero is an integrator: the mode neither grows nor decays by itself. Hopper's position and velocity are two such modes, and the vehicle drifts if there is any velocity. Instability is a pole in the right half-plane: Hopper's +0.7.

“The linear model is the same at every trim.”

The poles of Hopper's lateral channel are the same at every steady acceleration, but the input matrix is not: the pitch authority is 19.6 at hover and 20.0 at the 2 m/s² trim, and falls with the mass. The model depends on the operating point through the entries that involve thrust and mass.

“Linearization at hover captures the whole vehicle.”

It decouples the channels. At hover the lateral and vertical motions are independent to first order. Away from hover they interact: at 40° of tilt the thrust loses 23% of its vertical component, an effect that appears in none of the lateral model's equations.

Key takeaways

  1. A trim is a steady operating condition that a vehicle can hold: hover, level flight at an airspeed, a steady acceleration. It is found by solving the steady-state equations, numerically if need be.
  2. Linearizing about a trim gives δx˙=A δx+B δu\delta\dot{\mathbf{x}} = \mathbf{A}\,\delta\mathbf{x} + \mathbf{B}\,\delta\mathbf{u} with the Jacobians of the model as A\mathbf{A} and B\mathbf{B}.
  3. Hopper's lateral channel has poles 0, 0, +0.7 and −0.7 per second at every steady acceleration; only the input matrix changes with thrust and mass.
  4. The error of the linear model is second order in the distance from the trim: for Hopper about θ2/6\theta^2/6 in lateral acceleration.
  5. The linear model also drops couplings: at 40° of tilt, 2.3 m/s² of vertical acceleration is missing.
  6. Compute the range over which the linear model holds before designing on it, and use several linearizations when the vehicle will go farther.

References and further reading

Each source is marked free or paid. Free to read does not mean free to reuse: the course resources page lists every source with its licence.

Knowledge check

Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

At a pitch of 0.3 rad (17°), by what percentage does the linear lateral acceleration gθ differ from the true g sin θ, and does the θ²/6 estimate agree?

Explanation

The true value is sin 0.3 = 0.2955, the linear value is 0.3, so the linear model is 0.3 / 0.2955 − 1 = 1.5% high. The estimate θ²/6 = 0.09/6 = 0.015 = 1.5% agrees to the digit shown. At 17° the hover model is accurate enough for most purposes, and the error would not matter against a navigation budget of tens of centimetres.

Question 2

Between liftoff and burnout, which of the numbers of Hopper's linear lateral model change, and which do not?

Explanation

The matrix A does not change: its entries are g, 1, and λ², and the poles stay at 0, 0, ±0.7 per second. The input matrix changes: the pitch authority b = T l cos δ0 / J falls from 19.6 rad/s² per rad at liftoff to 11.8 at burnout, because the hover thrust follows the mass. The entry g in B does not change. So the open-loop vehicle is the same, and a controller's gain has to be scheduled to keep the closed loop the same.

Question 3

Hopper at liftoff mass must accelerate sideways at 3 m/s². What direction must the thrust have, and what thrust is needed?

Explanation

The thrust vector must balance weight and give the lateral acceleration, so its direction is arctan(a / g) = arctan(3 / 9.81) = 17.0° from vertical and its size is m √(g² + a²) = 120 × √(96.2 + 9) = 120 × 10.26 = 1231 N, which is 1.046 times the weight. The pitch θ is slightly more than 17° because the trim gimbal angle is a small negative number (as in the 2 m/s² case, where θ = 11.81° and δ = −0.29° add to 11.52°); a Newton solve of the three trim equations gives the exact split.

What’s next

Practice this lesson

Trim and Linearize Hopper

Find the gimbal angle and thrust that hold Hopper in hover with an off-centre mass, linearize about that point, and show where the linear model stops matching the simulator.

Next lesson

M2-T5 — Simulation You Can Trust

Choose an integrator and a step size, keep a quaternion normalized, and verify a simulator with conservation checks and a convergence study.

Nothing below is required to finish this lesson.

  • Before
    M2-T3: Forces, Moments and Actuator Models

    Model gravity, thrust and aerodynamic forces with coefficients, and model an actuator by its lag, rate limit and saturation.

  • Lab
    M2-L1: Trim and Linearize Hopper

    Find the gimbal angle and thrust that hold Hopper in hover with an off-centre mass, linearize about that point, and show where the linear model stops matching the simulator.

Other courses on this site treat neighbouring topics from their own angle:

This course leaves the following to the pages that already teach them: