Skip to the lesson
FixTheRobot Explore Robotics / Guidance, Navigation and Control / M1 The GNC Problem / M1-T2

Guidance, Navigation and Control · Theory · M1

M1-T2 — Nested Loops and Separation of Timescales

A vehicle is a stack of loops. Each assumes the loop beneath it is fast and faithful, and that assumption has a number attached.

  • Lesson 2 of 4
  • Beginner
  • Module 1: The GNC Problem
  • Theory
  • About 17 minutes to read

Hopper's navigation filter runs at 200 Hz, its guidance law re-plans at 5 Hz, and its engine gimbal answers in a fraction of a second. These speeds are not arbitrary. Each loop treats the one beneath it as an instant and faithful servant, and that is true only if the lower loop is clearly faster. This lesson gives the rule, derives the number behind it from one small cascade, and shows what the vehicle does when the rule is broken.

Learning objectives

After this lesson, you should be able to:

  • Order the loops of a vehicle by bandwidth and say which signal links each pair.
  • Distinguish a loop's bandwidth from its update rate.
  • Compute the phase lag an inner loop adds to an outer loop from the ratio of their bandwidths.
  • Predict the overshoot of a two-loop cascade from that ratio, and state the usual minimum ratio.

The intuition

The loop of M1-T1: Three Questions: Where Am I, Where Should I Go, How Do I Get There hides a ladder. Guidance does not talk to the engine. It hands a command to a loop beneath it, which hands a command to the next, and so on down to the actuator. Hopper's chain for holding a position on the range runs like this:

  1. Guidance gives a position command to the lateral-position loop.
  2. That loop turns the position error into a velocity command for the lateral-velocity loop.
  3. That loop turns the velocity error into a pitch command, because tilting the thrust is how a rocket accelerates sideways.
  4. The pitch-angle loop turns the pitch error into a pitch-rate command.
  5. The pitch-rate loop turns the rate error into a gimbal command.
  6. The gimbal actuator moves the engine.

Each loop makes sure the signal it is given is delivered, and each is designed to be quicker than the loop above it. The reason is easiest to see from the point of view of one loop. The loop above sends a command and watches the result. If the loop beneath needs ten seconds to carry out an instruction but the one above checks every two, the upper loop concludes that nothing is happening and piles on more instruction. When the lower loop finally acts, it carries out the whole pile, and the vehicle overshoots. Make the lower loop fast compared with the upper one and the problem disappears: the upper loop sees what it asked for almost at once.

The loops of Hopper on a logarithmic frequency axisSix dots on a logarithmic axis from 0.05 to 100 radians per second, one per loop. From the outermost loop to the innermost: guidance at 0.1, lateral position at 0.4, lateral velocity at 1.2, pitch angle at 4, pitch rate at 12 and gimbal actuator at 40 radians per second. Dashed orange lines join neighbours and are labelled with the ratio of their bandwidths: 4, 3, 3.3, 3 and 3.3.0.1110100closed-loop bandwidth (rad/s), logarithmic scaleGuidance0.1 rad/s×4Lateral position0.4 rad/s×3Lateral velocity1.2 rad/s×3.3Pitch angle4 rad/s×3Pitch rate12 rad/s×3.3Gimbal actuator40 rad/s
The loops of Hopper from guidance (slowest, top) to the gimbal actuator (fastest, bottom). Each step down the ladder is about three times faster.

The rule of thumb

Designers usually make each loop 3 to 10 times faster than the loop it serves, and Hopper's ratios (3 to 4) sit at the low end of that range. The lower end saves hardware and noise, because a faster loop amplifies more sensor noise and asks more of the actuator. The upper end makes the design easy: the outer loop can be tuned as if the inner one were not there. The derivation below shows where the number comes from and why it is a rule of thumb and not a law.

Bandwidth is not update rate

Two different things are called speed here, and mixing them up is a common source of mistakes.

  • The bandwidth of a closed loop is how fast the loop can follow a changing command. A loop with a bandwidth of 4 rad/s follows commands that change over about a second and ignores much faster ones. It is a property of the dynamics and the gains.
  • The update rate is how often the computer recomputes the loop's output. It is a property of the software and the hardware.

The update rate must be much higher than the bandwidth, or the sampling itself becomes a lag inside the loop. A common guide is a sample rate (in rad/s, that is 2π times the rate in hertz) of 10 to 20 times the loop's bandwidth. Hopper's pitch-rate loop has a bandwidth of 12 rad/s (about 2 Hz) and runs at 200 Hz, 100 times faster than it needs.

Hopper's loops, their bandwidths and update rates
LoopTakes in, gives outBandwidthUpdate rate
GuidanceTarget and estimate, gives a position command0.1 rad/s5 Hz
Lateral positionPosition command, gives a velocity command0.4 rad/s20 Hz
Lateral velocityVelocity command, gives a pitch command1.2 rad/s50 Hz
Pitch anglePitch command, gives a pitch-rate command4 rad/s100 Hz
Pitch ratePitch-rate command, gives a gimbal command12 rad/s200 Hz
Gimbal actuatorGimbal command, moves the engine40 rad/sservo hardware
Navigation filterIMU at 200 Hz, beacon ranges at 5 Hz, gives the estimatefaster than every loop it feeds200 Hz

Navigation sits inside every loop

The last row of the table matters. The estimate x^\hat{x} feeds the controllers, so any lag in producing it is a lag inside their loops. The navigation block therefore follows the same rule as the controllers: it must respond faster than any loop that uses its output. A filter that smooths heavily, or one that updates a few times per second, can be the slowest element in a fast loop without anyone noticing. Hopper's filter propagates the estimate with the IMU at 200 Hz and corrects it whenever a beacon fix arrives.

The cost of separation

The ratios multiply. Six loops with a ratio of about 3.3 each span a factor of 400, from 0.1 to 40 rad/s. The outermost loop sets how fast the whole vehicle can change what it is doing, so Hopper's guidance lives on a timescale of about ten seconds. If you want a vehicle that reacts faster, every loop beneath guidance must speed up too, and sensor noise, actuator limits and the update rate put a ceiling on how far that can go. Choosing the bandwidths of a vehicle is a budget of speed.

The UAV track shows the symptoms of a planner that outruns its controller, see UAV M5-T15: Guidance and control integration, and the cascade of PID loops is in UAV M5-T6. This lesson adds the quantity those pages leave out: how much faster the inner loop must be.

Definitions

Closed-loop bandwidth ωb\omega_b
The highest frequency, in rad/s, at which the closed loop still follows a sinusoidal command with at least 70% of its amplitude. A frequency in hertz is f=ω/2πf = \omega / 2\pi. The next module defines it from the frequency response.
Update rate fsf_s and period TT
How often a computed loop produces a new output, in hertz, and its inverse T=1/fsT = 1/f_s in seconds.
Inner and outer loop
The inner loop is the one that carries out the outer loop's command. Their bandwidths are ωi\omega_i and ωo\omega_o.
Separation ratio rr
The ratio of the two: r=ωi/ωor = \omega_i / \omega_o. The rule of thumb asks for rr between 3 and 10.

The simplest model of a loop that is closed and well behaved is a first-order lag. Its response to a command is a smooth rise with time constant 1/ωi1/\omega_i.

Inner loop as a first-order lag
Ti(s)=ωis+ωiT_i(s) = \frac{\omega_i}{s + \omega_i}
ss is the Laplace variable of the next module; for now read TiT_i as "the output of the inner loop divided by its command". At low frequency it equals 1: the inner loop does what it is told.

At a sinusoid of angular frequency ω\omega this lag passes only part of the amplitude and delays it. The part passed and the delay (a phase lag, in degrees or radians) are:

What the inner loop does at frequency ω
∣Ti∣=11+(ω/ωi)2φ=−arctan⁡ ⁣(ωωi)\bigl|T_i\bigr| = \frac{1}{\sqrt{1 + (\omega/\omega_i)^2}} \qquad \varphi = -\arctan\!\left(\frac{\omega}{\omega_i}\right)
At ω=ωi\omega = \omega_i the amplitude is 71% and the phase lag is 45 degrees. At ω≪ωi\omega \ll \omega_i both effects vanish.

Now close an outer position loop around it. The plant of the outer loop is a velocity that is integrated into a position, and the outer loop commands velocity in proportion to the position error:

A two-loop cascade
x˙=vv˙=ωi (vc−v)vc=K (xref−x)\dot{x} = v \qquad \dot{v} = \omega_i\,(v_c - v) \qquad v_c = K\,(x_{\text{ref}} - x)
xx is position, vv velocity, vcv_c the velocity command from the outer loop, KK its gain in 1/s. If the inner loop were instant, v=vcv = v_c and the outer loop would have bandwidth KK. So ωo=K\omega_o = K and r=ωi/Kr = \omega_i/K.

Finally, a computer that holds its output constant between updates delays it on average by half a period. At the frequency ω\omega of a loop that is a further phase lag:

Sampling lag
φsample≈− ω T2\varphi_{\text{sample}} \approx -\,\omega\,\frac{T}{2}
The result is stated here and derived in M3-T7: Digital Control: Sampling, Delay and Anti-Windup. It is why the update rate must be much higher than the loop's bandwidth.

Derivation: why the ratio matters, and the number behind it

The cascade above has two states and one command. Its closed loop is a second-order system, and the question is how its damping depends on the ratio rr. Work with the four lines of the cascade.

  1. L(s)=K ωis (s+ωi)L(s) = \frac{K\,\omega_i}{s\,(s + \omega_i)}

    The open loop is the gain KK, then the inner loop ωi/(s+ωi)\omega_i/(s + \omega_i) from command to velocity, then the integrator 1/s1/s from velocity to position.

  2. 1+L(s)=0  ⇒  s2+ωi s+K ωi=01 + L(s) = 0 \;\Rightarrow\; s^2 + \omega_i\,s + K\,\omega_i = 0

    The closed-loop poles are the roots of 1+L1 + L. Clearing the denominator gives a quadratic.

  3. ωn=K ωi,ζ=ωi2 ωn=12ωiK=12r\omega_n = \sqrt{K\,\omega_i}, \qquad \zeta = \frac{\omega_i}{2\,\omega_n} = \frac12\sqrt{\frac{\omega_i}{K}} = \frac12\sqrt{r}

    Compare with the standard form s2+2ζωns+ωn2s^2 + 2\zeta\omega_n s + \omega_n^2 to read off the natural frequency and the damping ratio. The damping ratio depends on the separation ratio and on nothing else.

  4. ζ≥1  ⟺  r≥4,Mp=e−πζ/1−ζ2  (ζ<1)\zeta \ge 1 \iff r \ge 4, \qquad M_p = e^{-\pi\zeta/\sqrt{1-\zeta^2}}\ \ (\zeta < 1)

    A damping ratio of 1 or more means no overshoot, which needs a ratio of 4. Below that the step response overshoots by the peak MpM_p, a standard result for second-order systems.

  5. ζ=12  ⟺  r=2,Mp=e−π≈4.3%\zeta = \tfrac{1}{\sqrt{2}} \iff r = 2, \qquad M_p = e^{-\pi} \approx 4.3\%

    At a ratio of 2 the overshoot is already down to 4.3%, which most designs accept.

  6. φ ⁣(ωo)=−arctan⁡ ⁣(Kωi)=−arctan⁡ ⁣(1r)\varphi\!\left(\omega_o\right) = -\arctan\!\left(\frac{K}{\omega_i}\right) = -\arctan\!\left(\frac1r\right)

    The phase lag the inner loop adds at the outer loop's bandwidth, from the second definition above. For r=3r = 3 it is 18.4 degrees, for 5 it is 11.3 and for 10 it is 5.7.

Two things follow. First, the idealized floor is about 2: with a first-order inner loop and nothing else, a ratio of 2 gives acceptable overshoot, and a ratio below 1 is a bad design. Second, the real floor is higher. The derivation counted only the inner loop's lag. A real loop also has an actuator lag, a transport delay, sampling (the formula for φsample\varphi_{\text{sample}}) and the lag of the navigation filter, and each takes phase away from the same budget. A ratio of 3 to 10 leaves room for them. That is why the rule of thumb is a range and not a number.

A fast inner loop is not a luxury. It is what lets the outer loop be designed as if the inner one were not there, and the lag it still adds, arctan(1/r), is the price of that simplification.

A worked example

Take the cascade above with an outer gain K=2K = 2 per second, a position step of 1 m, and four different inner loops. Predict the overshoot from the formula, then simulate the cascade and compare.

  1. Fix the outer loop. K=2 s−1K = 2\ \text{s}^{-1} sets the outer bandwidth. It is the same in all four cases.
  2. Choose four inner bandwidths: 20, 8, 2 and 0.5 rad/s. The separation ratios r=ωi/Kr = \omega_i / K are 10, 4, 1 and 0.25.
  3. Predict. From ζ=12r\zeta = \tfrac12\sqrt{r}: 1.58, 1.00, 0.50 and 0.25. The first two do not overshoot. The third overshoots by e−π⋅0.5/0.75=16.3%e^{-\pi \cdot 0.5/\sqrt{0.75}} = 16.3\% and the fourth by 44.4%. The phase lag at KK is arctan⁡(K/ωi)\arctan(K/\omega_i), which is 5.7, 14.0, 45.0 and 76.0 degrees.
  4. Simulate. Step the cascade with a fourth-order Runge-Kutta integrator and a step of 1 ms, and record the peak position above 1 m.
  5. Compare. The simulation agrees with the formula to the digit shown, because for this linear second-order system the formula is exact. A ratio of 10 gives a sluggish, over-damped loop with almost no lag. A ratio of 4 is critically damped. A ratio of 1 is the case of a designer who sets both loops to the same speed: 16% overshoot. At 0.25 the outer loop is four times faster than the loop that carries out its commands, and the vehicle overshoots by almost half the step.

The same experiment as a program that uses only the standard library:

import math

K = 2.0   # outer (position) loop gain in 1/s: its bandwidth if the inner loop were instant

def overshoot(w_inner, K, t_end=15.0, dt=0.001):
    """Unit step. Plant: x' = v. Inner velocity loop: v' = w_inner * (v_cmd - v). Outer loop: v_cmd = K * (1 - x)."""
    def f(x, v):
        return v, w_inner * (K * (1.0 - x) - v)
    x = v = peak = 0.0
    for _ in range(int(t_end / dt)):
        k1 = f(x, v)
        k2 = f(x + 0.5 * dt * k1[0], v + 0.5 * dt * k1[1])
        k3 = f(x + 0.5 * dt * k2[0], v + 0.5 * dt * k2[1])
        k4 = f(x + dt * k3[0], v + dt * k3[1])
        x += dt / 6 * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0])
        v += dt / 6 * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1])
        peak = max(peak, x)
    return max(0.0, peak - 1.0)

print(' ratio  zeta  lag at K  overshoot (formula)  overshoot (simulated)')
for w_inner in (20.0, 8.0, 2.0, 0.5):
    r = w_inner / K
    zeta = 0.5 * math.sqrt(r)
    formula = math.exp(-math.pi * zeta / math.sqrt(1 - zeta ** 2)) if zeta < 1 else 0.0
    lag = math.degrees(math.atan(K / w_inner))
    print(f'{r:6.2f} {zeta:6.2f} {lag:6.1f} deg {100 * formula:14.1f} % {100 * overshoot(w_inner, K):18.1f} %')
 ratio  zeta  lag at K  overshoot (formula)  overshoot (simulated)
 10.00   1.58    5.7 deg            0.0 %                0.0 %
  4.00   1.00   14.0 deg            0.0 %                0.0 %
  1.00   0.50   45.0 deg           16.3 %               16.3 %
  0.25   0.25   76.0 deg           44.4 %               44.4 %
The overshoot depends only on the ratio of the two bandwidths, not on their individual values.

In robotics

Every flight controller you will meet is built as a cascade, and its documentation names the loops in the order of the ladder.

  • Multicopters. PX4 and ArduPilot run an angular-rate loop inside an attitude loop inside a velocity and position loop, with mission logic on top. The controller diagrams in the PX4 documentation show the chain, and UAV M5-T6: PID controllers tunes it loop by loop. Tuning guides always say the same thing: tune the innermost loop first, and only then the one above it.
  • Aircraft. An autopilot is closed by successive loop closure: a pitch-rate or yaw-damper loop first, then the attitude loops, then airspeed, altitude and path on top. Each outer loop is designed treating the inner one as a unity gain, which is the assumption of this lesson (module 10).
  • Spacecraft. The separation can be extreme. A satellite's attitude loop settles in seconds while its orbit changes over minutes to hours, so guidance and attitude control are effectively decoupled (module 11).
  • Estimators. A navigation filter has a timescale too. If an estimator smooths a measurement for a second, then any control loop with a bandwidth near 1 rad/s that uses its output has the smoothing lag inside the loop. That is why the filter's rate, and the latency from sensor to estimate, appear on every timing budget (see UAV M7-T6: End-to-end latency).

The practical use of the rule is in the other direction too. When a vehicle oscillates, a quick check is to list the loop bandwidths and look for a neighbouring pair with a ratio below about 3. Oscillation at a frequency near the crossover of an outer loop usually means that the loop beneath it is too slow, or that something (a filter, a delay, a saturated actuator) has made it so.

Common misconceptions

“Faster loops are always better.”

A faster loop amplifies sensor noise, asks more of the actuator, and needs a higher update rate. Past some point more bandwidth makes the vehicle worse: the noise reaches the actuator and the actuator saturates. The right bandwidth is the lowest one that meets the requirement with the margin the derivation shows is needed.

“Bandwidth and update rate are the same thing.”

The update rate is how often a computer runs the loop, the bandwidth is how fast the closed loop can respond. A loop running at 200 Hz can have a bandwidth of 2 rad/s. The rate must be far above the bandwidth, or sampling adds a lag of about ωT/2\omega T/2 to the loop.

“With enough separation the loops do not interact.”

They never fully decouple. The inner loop always adds a phase lag of arctan⁡(1/r)\arctan(1/r) at the outer loop's bandwidth, 18 degrees at a ratio of 3. Separation makes the interaction small enough to ignore in the first design, not zero, and the final design is checked with the inner loop included.

“Once the inner loop is tuned, it stays tuned.”

The inner bandwidth depends on the vehicle. When Hopper burns fuel and loses 40% of its mass, its control authority per unit of gimbal changes, and so does the inner bandwidth. The outer loops then see a ratio different from the one they were designed with. Module 5 addresses this with gain scheduling.

“Guidance is not a loop, so it has no speed.”

Guidance re-plans at some rate and its commands change over some timescale, and the loop beneath it must be faster than that. A guidance law that commands a position change every 100 ms to a position loop with a 2.5 s time constant makes exactly the mistake the manager analogy describes.

Key takeaways

  1. A vehicle is a cascade of loops: each loop's output is the command of the loop beneath it, down to the actuator.
  2. Each loop is designed 3 to 10 times faster than the loop it serves, so that the outer loop sees the inner one as an almost instant servant.
  3. For a first-order inner loop under an integrating outer loop the damping ratio is ζ=12r\zeta = \tfrac12\sqrt{r}: a ratio of 4 gives no overshoot, a ratio of 2 about 4%, a ratio of 1 about 16%.
  4. At the outer loop's bandwidth the inner loop adds a phase lag of arctan⁡(1/r)\arctan(1/r), which is 18 degrees at a ratio of 3.
  5. Bandwidth (how fast the closed loop responds) is not update rate (how often the computer runs it). The rate must be much higher.
  6. The navigation filter is inside every loop that uses its estimate, so it must be faster than all of them.

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

Hopper's lateral-velocity loop has a bandwidth of 1.2 rad/s. Under the 3 to 10 rule, what bandwidth range should the pitch-angle loop beneath it have, and how much phase lag does a first-order pitch loop add to the velocity loop at 1.2 rad/s if the ratio is exactly 3?

Explanation

The pitch-angle loop should have a bandwidth between 3 × 1.2 = 3.6 and 10 × 1.2 = 12 rad/s. At a ratio of 3 a first-order inner loop adds a phase lag of arctan(1/3) = 18.4 degrees at the outer loop's bandwidth. Hopper uses 4 rad/s, a ratio of 3.3, which adds arctan(1.2/4) = 16.7 degrees. That lag comes out of the velocity loop's phase margin, which module 3 will quantify.

Question 2

A team raises the lateral-position gain from 0.4 to 1.0 per second to make hops faster, without touching the 1.2 rad/s velocity loop beneath it. Predict what happens to a position step.

Explanation

The separation ratio drops from 1.2/0.4 = 3 to 1.2/1.0 = 1.2. The damping ratio is ζ = ½√1.2 = 0.55, and the overshoot is exp(−π·0.55/√(1−0.30)) = 12.8% of the step, about 13 m on a 100 m hop. The change that was meant to speed the vehicle up produced an overshoot because the loop beneath could not keep pace. The fix is to speed up the velocity loop first (and, beneath it, the pitch loop), or to accept the slower position loop.

Question 3

Hopper's navigation filter is moved to a slower computer and now outputs the estimate at 5 Hz. The 4 rad/s pitch-angle loop uses that estimate. What is wrong, using the sampling-lag formula?

Explanation

A 5 Hz output has a period T = 0.2 s, so holding it between updates adds a phase lag of about ωT/2 = 4 × 0.2 / 2 = 0.4 rad = 22.9 degrees to a loop with a bandwidth of 4 rad/s. The sample rate is 2π·5 = 31 rad/s, only 7.9 times the loop bandwidth, below the guide of 10 to 20. The lag eats the phase margin the inner loop was designed with. The fix is to propagate the estimate at the IMU rate between fixes, as Hopper normally does at 200 Hz, so that the loop sees fresh data at a much higher rate.

What’s next

Practice this lesson

Who Missed the Pad?

Hopper lands 4 m from its pad in three different flights. From the logged truth, estimate and command signals, decide in each flight whether navigation, guidance or control is responsible.

Next lesson

M1-T3 — One Block Diagram, Four Vehicles

Map the same GNC diagram onto a rover, a multirotor, an aircraft and a spacecraft, and say which blocks change and why.

Nothing below is required to finish this lesson.

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

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