Algorithm Search⌘K

Algorithmresearch

L1 adaptive control

Also called L1 adaptive controller.

A fast adaptation law with a low-pass filter on the control signal that separates adaptation from robustness and bounds the transient.

Time
O(N n^2) worst
Space
O(n^2) extra
Where
N = the number of integration steps; n = the order of the plant
Properties
deterministicnot exactonlineiterative
Origin
Chengyu Cao, Naira Hovakimyan, 2006

L1 adaptive control is a predictor based form of model reference adaptive control in which the control signal passes through a strictly proper low-pass filter C(s)C(s), so that the adaptation gain Γ\Gamma can be made very large without high frequency content in the input. Its theory gives bounds on the transient in the norm of the supremum over time (the L∞L_\infty norm): the distance between the adaptive closed loop and a non-adaptive reference system is of order 1/Γ1/\sqrt\Gamma, under a small gain condition on the L1L_1 norm of the impulse response of H(s)(1−C(s))H(s)(1 - C(s)). The bandwidth of CC, not Γ\Gamma, then sets the robustness margins. The method has been disputed: Ioannou and co-authors and Ortega and Panteley (2014) argue that with a measured state it is an MRAC with a filtered input, and that in the limit of a large Γ\Gamma it becomes a fixed linear controller.

In plain words

An adaptive controller learns an unknown part of the plant while it controls it. Fast learning gives good tracking, but it also makes the control signal jump and shake, and that can excite parts of the plant that the model leaves out. L1 adaptive control lets the learning run very fast inside a software copy of the plant, the predictor, and then smooths the control signal with a filter before it reaches the real plant. The filter decides how aggressive the control can be; the learning speed only decides how closely the result matches an ideal controller that knows the unknown part. The price is that the filter must leave out some of the correction, so the loop cannot cancel the uncertainty at high frequencies.

The problem

The plant is x˙=Amx+b(ωu+θTx+σ)\dot x = A_m x + b(\omega u + \theta^T x + \sigma) with the state measured, a known Hurwitz matrix AmA_m, a known bb, and unknown parameters in known sets: here the scalar case with ω=1\omega = 1 and σ=0\sigma = 0 is treated, so

x˙=amx+b(u+θx),am<0, ∣θ∣≤θb.\dot x = a_m x + b(u + \theta x), \qquad a_m < 0,\ |\theta| \le \theta_b .

The aim is that xx tracks the response of xm=b kgs−amrx_m = \frac{b\,k_g}{s - a_m} r with kg=−am/bk_g = -a_m/b, with a transient that is bounded uniformly in time and a control signal without high frequency components, for every θ\theta in the set.

The algorithm

Let p=−1/(2am)p = -1/(2a_m) solve 2amp=−12 a_m p = -1, choose Γ>0\Gamma > 0, a projection set given by θb\theta_b and ϵ>0\epsilon > 0, and the filter C(s)=ωc/(s+ωc)C(s) = \omega_c/(s + \omega_c). With x~=x^−x\tilde x = \hat x - x, the controller is

  • the state predictor x^˙=amx^+b(u+θ^x)\dot{\hat x} = a_m \hat x + b(u + \hat\theta x),
  • the adaptive law θ^˙=Γ Proj(θ^,−x~ p b x)\dot{\hat\theta} = \Gamma\,\mathrm{Proj}(\hat\theta, -\tilde x\, p\, b\, x), with the smooth projection operator of parameter projection,
  • the control law u=C(s) [kgr−θ^x]u = C(s)\,[k_g r - \hat\theta x].
  1. L1-ADAPTIVE(Γ, θ_b, ε, ω_c, k_g, dt, N)
  2. 1θ̂ ← θ̂₀; x̂ ← x(0); u ← 0
  3. 2for i ← 0 to N - 1 do
  4. 3r ← r(t); measure x ▷ t = i dt
  5. 4x̃ ← x̂ - x ▷ prediction error
  6. 5x̂' ← a_m x̂ + b (u + θ̂ x) ▷ state predictor
  7. 6θ̂' ← Γ Proj(θ̂, -x̃ p b x) ▷ adaptation with projection
  8. 7u' ← ω_c (k_g r - θ̂ x - u) ▷ low-pass filter C(s)
  9. 8advance x, x̂, θ̂ and u by one RK4 step of length dt
  10. 9return θ̂

The projection uses f(θ)=(θ2−θb2)/(ϵθb2)f(\theta) = (\theta^2 - \theta_b^2)/(\epsilon\theta_b^2). It returns yy unchanged when f≤0f \le 0 or yy points inward, and otherwise y(1−f)y(1 - f), so ∣θ^∣≤θb1+ϵ|\hat\theta| \le \theta_b\sqrt{1 + \epsilon} for all time. The difference from MRAC is in line L7: the law u=kgr−θ^xu = k_g r - \hat\theta x of MRAC passes through C(s)C(s).

Example

Take am=−1a_m = -1, b=1b = 1, the unknown θ=1.5\theta = 1.5 (so the open loop pole is at +0.5+0.5), θb=2\theta_b = 2, ϵ=0.1\epsilon = 0.1, ωc=10\omega_c = 10 rad/s, kg=1k_g = 1, p=1/2p = 1/2 and the step r=1r = 1. Everything starts at zero, and θ^(0)=0\hat\theta(0) = 0.

The condition. G(s)=H(s)(1−C(s))=s(s+1)(s+ωc)G(s) = H(s)(1 - C(s)) = \frac{s}{(s + 1)(s + \omega_c)} has the impulse response g(t)=(ωce−ωct−e−t)/(ωc−1)g(t) = (\omega_c e^{-\omega_c t} - e^{-t})/(\omega_c - 1). It changes sign once, at t0=ln⁡ωc/(ωc−1)t_0 = \ln\omega_c/(\omega_c - 1), and integrates to G(0)=0G(0) = 0, so ∥G∥L1=2(e−t0−e−ωct0)/(ωc−1)\|G\|_{L_1} = 2(e^{-t_0} - e^{-\omega_c t_0})/(\omega_c - 1). With L=θb=2L = \theta_b = 2:

ωc\omega_c ∥G∥L1\|G\|_{L_1} ∥G∥L1L\|G\|_{L_1} L
1 0.7358 1.472
2 0.5000 1.000
5 0.2675 0.535
10 0.1549 0.310
20 0.0854 0.171
50 0.0369 0.074

The condition ∥G∥L1L<1\|G\|_{L_1} L < 1 holds for ωc=5\omega_c = 5 and above, and fails for ωc≤2\omega_c \le 2.

The reference system. With θ^=θ\hat\theta = \theta the loop is linear, with the characteristic polynomial (s−0.5)(s+10)+15=s2+9.5s+10(s - 0.5)(s + 10) + 15 = s^2 + 9.5s + 10 and the poles −1.21-1.21 and −8.29-8.29. Its step response is x(1)=0.650x(1) = 0.650, x(2)=0.895x(2) = 0.895 and x(10)=1.0000x(10) = 1.0000.

The adaptive loop. RK4 with dt=0.002dt = 0.002 s over 10 s. The bound on x~\tilde x is θ~(0)2/(Γp)\sqrt{\tilde\theta(0)^2/(\Gamma p)} (see Correctness). These are measurements, except the bound.

Γ\Gamma max⁡∣x~∣\max \lvert\tilde x\rvert bound max⁡∣x−xref∣\max\lvert x - x_{\mathrm{ref}}\rvert max⁡∣u−uref∣\max\lvert u - u_{\mathrm{ref}}\rvert θ^(10)\hat\theta(10)
10 0.4955 0.6708 0.5316 1.162 1.4939
100 0.1759 0.2121 0.1817 0.595 1.4955
1000 0.0598 0.0671 0.0558 0.303 1.4962

The distance to the reference system falls by about 10=3.2\sqrt{10} = 3.2 per factor 10 of Γ\Gamma in xx, and by about 2 in uu. In every run x(10)x(10) is within 0.005 of 1, and θ^\hat\theta reaches 2.0976, just inside the projection limit 21.1=2.09762\sqrt{1.1} = 2.0976, during the first transient.

Correctness

The proof in proofs/correctness.md gives the prediction error bound in full. With V=px~2+θ~2/ΓV = p\tilde x^2 + \tilde\theta^2/\Gamma and θ~=θ^−θ\tilde\theta = \hat\theta - \theta, the error equation is x~˙=amx~+bθ~x\dot{\tilde x} = a_m\tilde x + b\tilde\theta x, and the projection gives V˙≤−x~2\dot V \le -\tilde x^2 whenever ∣θ∣≤θb|\theta| \le \theta_b. So px~2≤V(0)=θ~(0)2/Γp\tilde x^2 \le V(0) = \tilde\theta(0)^2/\Gamma when x~(0)=0\tilde x(0) = 0, which gives ∥x~∥L∞≤θ~(0)2/(Γp)\|\tilde x\|_{L_\infty} \le \sqrt{\tilde\theta(0)^2/(\Gamma p)}, a theorem; the general form uses the largest possible θ~\tilde\theta, 4θb2(1+ϵ)4\theta_b^2(1 + \epsilon) in place of θ~(0)2\tilde\theta(0)^2. The second step is the main theorem of Cao and Hovakimyan, stated here and not reproved: if ∥G∥L1L<1\|G\|_{L_1} L < 1, the reference system is bounded in the L∞L_\infty norm, and ∥x−xref∥L∞≤γ1/Γ\|x - x_{\mathrm{ref}}\|_{L_\infty} \le \gamma_1/\sqrt\Gamma and ∥u−uref∥L∞≤γ2/Γ\|u - u_{\mathrm{ref}}\|_{L_\infty} \le \gamma_2/\sqrt\Gamma with constants that do not depend on Γ\Gamma. The proof combines the prediction error bound with the small gain theorem for the filtered loop.

Proof: The L1 adaptive law with projection bounds the prediction error by a term of order one over the square root of the adaptation gainfull

Notation is that of the page. The plant is x˙=amx+b(u+θx)\dot x = a_m x + b(u + \theta x) with am<0a_m < 0, b≠0b \ne 0 and ∣θ∣≤θb|\theta| \le \theta_b. The predictor is x^˙=amx^+b(u+θ^x)\dot{\hat x} = a_m\hat x + b(u + \hat\theta x), the law is θ^˙=Γ Proj(θ^,y)\dot{\hat\theta} = \Gamma\,\mathrm{Proj}(\hat\theta, y) with y=−x~ p b xy = -\tilde x\,p\,b\,x, x~=x^−x\tilde x = \hat x - x, θ~=θ^−θ\tilde\theta = \hat\theta - \theta and p=−1/(2am)>0p = -1/(2a_m) > 0. The projection is Proj(θ^,y)=y(1−f(θ^))\mathrm{Proj}(\hat\theta, y) = y(1 - f(\hat\theta)) if f(θ^)>0f(\hat\theta) > 0 and yf′(θ^)>0y f'(\hat\theta) > 0, and yy otherwise, with f(θ)=(θ2−θb2)/(ϵθb2)f(\theta) = (\theta^2 - \theta_b^2)/(\epsilon\theta_b^2).

Claim 1 (the estimate stays in the band). If ∣θ^(0)∣≤θb1+ϵ|\hat\theta(0)| \le \theta_b\sqrt{1 + \epsilon}, then ∣θ^(t)∣≤θb1+ϵ|\hat\theta(t)| \le \theta_b\sqrt{1 + \epsilon} for all tt.

Proof. The bound is the set f(θ^)≤1f(\hat\theta) \le 1. Along solutions, ddtf(θ^)=f′(θ^) Γ Proj(θ^,y)\frac{d}{dt}f(\hat\theta) = f'(\hat\theta)\,\Gamma\,\mathrm{Proj}(\hat\theta, y). When f(θ^)>0f(\hat\theta) > 0 and yf′>0y f' > 0, this is Γf′y(1−f)\Gamma f' y (1 - f), which is at most 00 when f≥1f \ge 1. In the other case, either f≤0<1f \le 0 < 1, or yf′≤0y f' \le 0 and the derivative is Γf′y≤0\Gamma f' y \le 0. So ff cannot increase while f≥1f \ge 1, and it cannot cross the level 11 from below. □\square

Claim 2 (projection does not increase the parameter error). If ∣θ∣≤θb|\theta| \le \theta_b, then θ~ (Proj(θ^,y)−y)≤0\tilde\theta\,(\mathrm{Proj}(\hat\theta, y) - y) \le 0.

Proof. The difference is nonzero only when f(θ^)>0f(\hat\theta) > 0 and yf′(θ^)>0y f'(\hat\theta) > 0, and then it equals −f(θ^) y-f(\hat\theta)\,y. Here f(θ^)>0f(\hat\theta) > 0 means ∣θ^∣>θb≥∣θ∣|\hat\theta| > \theta_b \ge |\theta|, and f′=2θ^/(ϵθb2)f' = 2\hat\theta/(\epsilon\theta_b^2) has the sign of θ^\hat\theta, so yy has the sign of θ^\hat\theta. Also θ~=θ^−θ\tilde\theta = \hat\theta - \theta has the sign of θ^\hat\theta, because ∣θ^∣>∣θ∣|\hat\theta| > |\theta|. So θ~y>0\tilde\theta y > 0 and θ~(Proj−y)=−f θ~y<0\tilde\theta(\mathrm{Proj} - y) = -f\,\tilde\theta y < 0. □\square

Claim 3 (Lyapunov function). Let V=px~2+θ~2/ΓV = p\tilde x^2 + \tilde\theta^2/\Gamma. Then V˙≤−x~2\dot V \le -\tilde x^2.

Proof. Subtract the plant from the predictor: x~˙=amx~+bθ~x\dot{\tilde x} = a_m\tilde x + b\tilde\theta x. Since θ\theta is constant, θ~˙=θ^˙\dot{\tilde\theta} = \dot{\hat\theta}. Then

V˙=2px~(amx~+bθ~x)+2θ~ Proj(θ^,y)=2pamx~2+2θ~ pbxx~+2θ~y+2θ~(Proj−y).\dot V = 2p\tilde x(a_m\tilde x + b\tilde\theta x) + 2\tilde\theta\,\mathrm{Proj}(\hat\theta, y) = 2pa_m\tilde x^2 + 2\tilde\theta\,p b x\tilde x + 2\tilde\theta y + 2\tilde\theta(\mathrm{Proj} - y).

With y=−x~pbxy = -\tilde x p b x the second and third terms cancel, 2pam=−12pa_m = -1, and the last term is at most 00 by Claim 2. □\square

Claim 4 (the bound). If x^(0)=x(0)\hat x(0) = x(0), then for all t≥0t \ge 0,

∣x~(t)∣≤θ~(0)2Γp≤2θb1+ϵΓp.|\tilde x(t)| \le \sqrt{\frac{\tilde\theta(0)^2}{\Gamma p}} \le \frac{2\theta_b\sqrt{1+\epsilon}}{\sqrt{\Gamma p}}.

Proof. The solution exists for all t≥0t \ge 0: by Claim 1, θ^\hat\theta is bounded, and for a given θ^(t)\hat\theta(t) the equations of xx, x^\hat x and uu are linear with bounded coefficients, so they have no finite escape time. By Claim 3, px~(t)2≤V(t)≤V(0)=θ~(0)2/Γp\tilde x(t)^2 \le V(t) \le V(0) = \tilde\theta(0)^2/\Gamma. For the second form, ∣θ~(0)∣≤∣θ^(0)∣+∣θ∣≤θb1+ϵ+θb≤2θb1+ϵ|\tilde\theta(0)| \le |\hat\theta(0)| + |\theta| \le \theta_b\sqrt{1 + \epsilon} + \theta_b \le 2\theta_b\sqrt{1+\epsilon}. □\square

Claim 4 holds whatever the input uu is, so it needs no assumption on the filter. It is the first step of the analysis of Cao and Hovakimyan. Their main theorem, which is not reproved here, adds the condition ∥G∥L1L<1\|G\|_{L_1} L < 1 for G=H(1−C)G = H(1 - C) and L=θbL = \theta_b, uses the small gain theorem to show that the reference system with the true θ\theta in the control law is bounded in the L∞L_\infty norm, and then shows ∥x−xref∥L∞≤γ1/Γ\|x - x_{\mathrm{ref}}\|_{L_\infty} \le \gamma_1/\sqrt\Gamma and ∥u−uref∥L∞≤γ2/Γ\|u - u_{\mathrm{ref}}\|_{L_\infty} \le \gamma_2/\sqrt\Gamma.

The L1 norm in the example. For G(s)=s/((s+1)(s+ωc))G(s) = s/((s + 1)(s + \omega_c)) with ωc≠1\omega_c \ne 1, partial fractions give g(t)=(ωce−ωct−e−t)/(ωc−1)g(t) = (\omega_c e^{-\omega_c t} - e^{-t})/(\omega_c - 1). The function gg is positive for t<t0t < t_0 and negative for t>t0t > t_0, where ωce−ωct0=e−t0\omega_c e^{-\omega_c t_0} = e^{-t_0}, that is t0=ln⁡ωc/(ωc−1)t_0 = \ln\omega_c/(\omega_c - 1). Since ∫0∞g dt=G(0)=0\int_0^\infty g\,dt = G(0) = 0, ∫0∞∣g∣ dt=2∫0t0g dt=2 (1−e−ωct0)−(1−e−t0)ωc−1\int_0^\infty |g|\,dt = 2\int_0^{t_0} g\,dt = 2\,\frac{(1 - e^{-\omega_c t_0}) - (1 - e^{-t_0})}{\omega_c - 1}, which is the formula of the page. For ωc=2\omega_c = 2, t0=ln⁡2t_0 = \ln 2 and the norm is 2(1/2−1/4)=1/22(1/2 - 1/4) = 1/2. The tests check the formula against a numerical integral and the bound of Claim 4 against the simulation.

Complexity

For an nn-dimensional state, each evaluation of the right-hand side costs O(n2)O(n^2) for the plant, the predictor and the matrix PP, and O(n)O(n) for the adaptive law and the filter, in the real-RAM model. NN RK4 steps cost O(Nn2)O(N n^2), and the memory is O(n2)O(n^2) for AmA_m and PP. The large Γ\Gamma makes the adaptive law stiff, so dtdt must shrink as Γ\Gamma grows: with RK4 the product of dtdt and the adaptation rate Γpb2x2\Gamma p b^2 x^2 must stay below about 2.8 (a rule of thumb from the stability region of RK4). In an implementation on a computer, the sampling period hh of the adaptive law limits the useful Γ\Gamma.

Properties

  • Uniform transient bounds. Theorem (Cao and Hovakimyan): under the L1L_1 norm condition the state and the input stay within O(1/Γ)O(1/\sqrt\Gamma) of a linear reference system, uniformly in time, not only as t→∞t \to \infty.
  • Robustness set by the filter. The time delay margin of the loop is bounded below by a quantity that depends on C(s)C(s) and not on Γ\Gamma, as Γ→∞\Gamma \to \infty (theorem in Hovakimyan and Cao, Chapter 2).
  • Trade-off in the filter. A wider filter bandwidth makes ∥G∥L1\|G\|_{L_1} smaller and the reference system closer to the ideal model, but it lowers the robustness margins. The table shows how ∥G∥L1\|G\|_{L_1} falls with ωc\omega_c.
  • No parameter convergence claim. As in MRAC, θ^\hat\theta need not converge to θ\theta; the example gives 1.4941.494 to 1.4961.496 after 10 s.
  • Disputed interpretation. Ioannou and co-authors (2014) argue that with a measured state the scheme is an MRAC with an input filter, and that its claimed advantages can be obtained by standard robust adaptive designs. Ortega and Panteley (2014) show that as Γ→∞\Gamma \to \infty the controller tends to a linear time-invariant controller, so the adaptation is not needed for the limit. Hovakimyan and co-authors disputed these readings. This page states the theorems and the critique; it does not decide between them.

Variants and improvements

  • Unknown input gain and disturbances. The general architecture estimates ω\omega, θ\theta and σ\sigma with three projection laws and uses a filter D(s)D(s) with a feedback gain kk in u=−kD(s)(η^−kgr)u = -k D(s)(\hat\eta - k_g r).
  • Piecewise constant adaptation. The adaptive law is replaced by a law that updates σ^\hat\sigma once per sampling period hh from the prediction error, which makes the speed of adaptation a matter of hh (Hovakimyan and Cao treat this law in the later chapters of the book).
  • Output feedback. For a plant with only the output measured, the predictor is an output predictor, and the same filter structure applies.
  • Nonlinear and time-varying uncertainty. The theory extends to matched nonlinear uncertainty that is Lipschitz in xx and to unmatched uncertainty.

When to use it

Use L1 adaptive control when the state is measured, the uncertainty is matched and bounded in a known set, and a guaranteed transient bound in the L∞L_\infty norm matters more than parameter learning, for example in flight control research. The computer that runs it must have a fast sampling rate to support a large Γ\Gamma. If the analysis of a fixed robust controller with the same filter gives the same margins, as the critique says it often does, prefer the fixed controller.

Pitfalls

  • The condition fails. For a narrow filter, ∥G∥L1L≥1\|G\|_{L_1} L \ge 1, and the bounds do not hold. The example shows the border at ωc=2\omega_c = 2.
  • Stiff integration. A large Γ\Gamma needs a small step dtdt or sampling period hh; otherwise the discrete adaptive law is not a good approximation of the continuous law, and the bounds of the continuous theory do not apply.
  • Projection set too small. The proof needs the true θ\theta inside the set ∣θ∣≤θb|\theta| \le \theta_b. A wrong set gives a biased estimate and no bound.
  • Filter too wide. A filter with a large bandwidth gives a small ∥G∥L1\|G\|_{L_1} but passes the high frequency content of θ^x\hat\theta x to the plant, which the filter was meant to remove.
  • Reading 1/Γ1/\sqrt\Gamma as zero. The bounds compare with the reference system, not with the ideal model xmx_m; the reference system itself differs from xmx_m by an amount set by C(s)C(s).

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

ctlsim.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the control pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Fixed step simulation for the control pages.

Conventions:
- A continuous-time system is a function f(t, x, u) that returns x' as a
  flat list. x is a flat list. u is whatever the control returns (a flat
  list, a scalar, or None when there is no control).
- A discrete-time system is a function F(k, x, u) that returns x_(k+1).
- The integrator is the classical 4th order Runge-Kutta method with a fixed
  step dt. The input is held constant over each step.
- Time t_k = t0 + k dt is computed by multiplication, not by summation.
- The number of steps round((t1 - t0) / dt) and the hold ratio
  round(hold / dt) must match the real ratios within 1e-9 (relative), or
  ValueError is raised.

This file holds no controller or observer of a control page.
"""

__all__ = ["rk4_step", "simulate", "simulate_discrete", "lti"]


def _axpy(a, x, y):
    return [yi + a * xi for xi, yi in zip(x, y)]


def rk4_step(f, t, x, u, dt):
    """Return x(t + dt) after one RK4 step of x' = f(t, x, u), u held constant."""
    k1 = f(t, x, u)
    k2 = f(t + dt / 2, _axpy(dt / 2, k1, x), u)
    k3 = f(t + dt / 2, _axpy(dt / 2, k2, x), u)
    k4 = f(t + dt, _axpy(dt, k3, x), u)
    return [xi + dt / 6 * (a + 2 * b + 2 * c + d) for xi, a, b, c, d in zip(x, k1, k2, k3, k4)]


def _ratio(num, den, what):
    r = round(num / den)
    if abs(r * den - num) > 1e-9 * max(abs(num), abs(den)):
        raise ValueError(what + " is not an integer multiple of dt")
    return r


def simulate(f, x0, t0, t1, dt, control=None, hold=None):
    """Simulate x' = f(t, x, u) from x(t0) = x0 to t1 with RK4 and step dt.

    control(t, x) gives the input. It is called at each sampling instant
    t0 + j hold, and its value is held (zero-order hold) until the next
    instant. hold must be an integer multiple of dt; hold = None means
    hold = dt. With control = None the input is None.

    Returns (ts, xs, us): ts has N + 1 times, xs the N + 1 states, and us the
    N inputs, where us[k] acts on [ts[k], ts[k + 1]].
    """
    if dt <= 0:
        raise ValueError("dt must be positive")
    n_steps = _ratio(t1 - t0, dt, "t1 - t0")
    if n_steps < 0:
        raise ValueError("t1 is before t0")
    r = 1 if hold is None else _ratio(hold, dt, "hold")
    if r < 1:
        raise ValueError("hold must be at least dt")
    x = list(x0)
    ts = [t0]
    xs = [list(x)]
    us = []
    u = None
    for k in range(n_steps):
        t = t0 + k * dt
        if control is not None and k % r == 0:
            u = control(t, list(x))
        x = rk4_step(f, t, x, u, dt)
        ts.append(t0 + (k + 1) * dt)
        xs.append(x)
        us.append(u)
    return ts, xs, us


def simulate_discrete(F, x0, N, control=None):
    """Run x_(k+1) = F(k, x_k, u_k) for k = 0, ..., N - 1.

    u_k = control(k, x_k), or None if control is None. Returns (xs, us) with
    N + 1 states and N inputs. Exact if F and control are exact.
    """
    x = list(x0)
    xs = [list(x)]
    us = []
    for k in range(N):
        u = control(k, list(x)) if control is not None else None
        x = list(F(k, x, u))
        xs.append(x)
        us.append(u)
    return xs, us


def lti(A, B=None):
    """Return f(t, x, u) = A x + B u for the system x' = A x + B u.

    u may be a flat list, a scalar (one input) or None (zero input). B may
    be None for a system with no input.
    """
    def f(t, x, u):
        dx = [sum(a * xi for a, xi in zip(row, x)) for row in A]
        if B is None or u is None:
            return dx
        uu = u if isinstance(u, (list, tuple)) else [u]
        return [d + sum(b * ui for b, ui in zip(row, uu)) for d, row in zip(dx, B)]
    return f


def _self_test():
    import math
    f = lti([[-1.0]])
    _, xs, _ = simulate(f, [1.0], 0.0, 1.0, 0.01)
    assert abs(xs[-1][0] - math.exp(-1.0)) < 1e-9
    return True


if __name__ == "__main__":
    _self_test()
l1_adaptive_control.py 94 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/l1-adaptive-control/. The authors are listed in prov/S1SMGT.jsonl.

"""L1 adaptive control of a scalar plant with an unknown state feedback gain.

Plant:      x' = a_m x + b (u + theta x),   a_m < 0, b > 0 known, theta unknown
            with |theta| <= theta_b.
Predictor:  xh' = a_m xh + b (u + thetah x)
Adaptation: thetah' = Gamma Proj(thetah, -xt p b x),  xt = xh - x,
            p = -1 / (2 a_m) solves 2 a_m p = -1.
Control:    u = C(s) (k_g r - thetah x),  C(s) = omega_c / (s + omega_c),
            k_g = -a_m / b, as the state u' = omega_c (k_g r - thetah x - u).

Proj is the smooth projection operator with
f(theta) = (theta^2 - theta_b^2) / (eps theta_b^2): it leaves y unchanged
inside the ball |theta| <= theta_b, and on the outer band it removes the
outward part of y in proportion to f, so |thetah| <= theta_b sqrt(1 + eps)
for all time.

The simulation uses the classical RK4 method with a fixed step dt from
ctlsim. The time t1 must be an integer multiple of dt.
"""

import math

from ctlsim import rk4_step

__all__ = ["proj", "l1_simulate", "l1_norm_g", "prediction_bound"]


def _steps(t1, dt):
    n = round(t1 / dt)
    assert abs(n * dt - t1) <= 1e-9 * max(1.0, abs(t1)), "dt must divide t1"
    return n


def proj(theta, y, theta_b, eps):
    """Smooth projection operator for a scalar parameter."""
    f = (theta * theta - theta_b * theta_b) / (eps * theta_b * theta_b)
    df = 2.0 * theta / (eps * theta_b * theta_b)
    if f > 0 and y * df > 0:
        return y - f * y  # the scalar form of y - f grad f grad f^T y / |grad f|^2
    return y


def l1_simulate(theta, theta_b, eps, gamma, omega_c, r, t1, dt, a_m=-1.0, b=1.0,
                thetah0=0.0, x0=0.0, every=1):
    """Simulate the L1 adaptive controller. r(t) is the reference.

    Returns (ts, xs, xhs, thetahs, us) sampled every `every` steps.
    """
    p = -1.0 / (2.0 * a_m)
    k_g = -a_m / b
    s = [float(x0), float(x0), float(thetah0), 0.0]  # @line L1

    def f(t, z, _u):
        x, xh, th, u = z
        rt = r(t)  # @line L3
        xt = xh - x  # @line L4
        dx = a_m * x + b * (u + theta * x)
        dxh = a_m * xh + b * (u + th * x)  # @line L5
        dth = gamma * proj(th, -xt * p * b * x, theta_b, eps)  # @line L6
        du = omega_c * (k_g * rt - th * x - u)  # @line L7
        return [dx, dxh, dth, du]

    N = _steps(t1, dt)
    out = ([0.0], [s[0]], [s[1]], [s[2]], [s[3]])
    for i in range(N):  # @line L2
        s = rk4_step(f, i * dt, s, None, dt)  # @line L8
        if (i + 1) % every == 0:
            out[0].append((i + 1) * dt)
            for j in range(4):
                out[j + 1].append(s[j])
    return out  # @line L9


def l1_norm_g(omega_c):
    """L1 norm of the impulse response of G(s) = s / ((s + 1)(s + omega_c)).

    G = H (1 - C) with H = 1 / (s + 1) and C = omega_c / (s + omega_c). The
    impulse response (omega_c e^(-omega_c t) - e^(-t)) / (omega_c - 1)
    changes sign once, at t0 = ln(omega_c) / (omega_c - 1), and integrates
    to G(0) = 0, so the norm is twice its integral over [0, t0].
    """
    if omega_c == 1.0:
        return 2.0 / math.e
    t0 = math.log(omega_c) / (omega_c - 1.0)
    return 2.0 * (math.exp(-t0) - math.exp(-omega_c * t0)) / (omega_c - 1.0)


def prediction_bound(thetah0, theta, gamma, a_m=-1.0):
    """Bound on |xh - x| from V = p xt^2 + (thetah - theta)^2 / Gamma, xt(0) = 0."""
    p = -1.0 / (2.0 * a_m)
    return math.sqrt((thetah0 - theta) ** 2 / (gamma * p))
test_l1_adaptive_control.py 74 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/l1-adaptive-control/. The authors are listed in prov/S1SMGT.jsonl.

"""Tests for the L1 adaptive controller. RK4 with a fixed step; tolerances are stated."""

import math
import unittest

from l1_adaptive_control import l1_norm_g, l1_simulate, prediction_bound, proj

THETA, THETA_B, EPS, OMEGA_C = 1.5, 2.0, 0.1, 10.0


def step(t):
    return 1.0


def run(gamma, thetah0=0.0):
    # 10 s with dt = 0.002: 5000 steps
    return l1_simulate(THETA, THETA_B, EPS, gamma, OMEGA_C, step, 10.0, 0.002, thetah0=thetah0)


class TestL1Norm(unittest.TestCase):
    def test_formula_against_quadrature(self):
        # reference: trapezoid rule for the integral of |g| on [0, 40]
        for w in (2.0, 5.0, 10.0, 20.0):
            n, T = 20000, 40.0
            h = T / n
            g = [abs((w * math.exp(-w * k * h) - math.exp(-k * h)) / (w - 1.0)) for k in range(n + 1)]
            quad = h * (sum(g) - (g[0] + g[-1]) / 2)
            self.assertLess(abs(quad - l1_norm_g(w)), 1e-4)

    def test_small_gain_condition(self):
        # L = theta_b = 2; the condition ||G||_L1 L < 1 holds for omega_c = 5, 10, 20
        self.assertAlmostEqual(l1_norm_g(2.0), 0.5, places=12)
        self.assertFalse(l1_norm_g(2.0) * THETA_B < 1.0)
        for w in (5.0, 10.0, 20.0):
            self.assertLess(l1_norm_g(w) * THETA_B, 1.0)


class TestProjection(unittest.TestCase):
    def test_operator(self):
        self.assertEqual(proj(1.0, 3.0, 2.0, 0.1), 3.0)    # inside the ball
        self.assertEqual(proj(2.09, -1.0, 2.0, 0.1), -1.0)  # pointing inward
        f = (2.09 ** 2 - 4.0) / 0.4
        self.assertAlmostEqual(proj(2.09, 1.0, 2.0, 0.1), 1.0 - f, places=12)
        # on the outer boundary f = 1 and the outward part is removed
        self.assertAlmostEqual(proj(2.0 * math.sqrt(1.1), 1.0, 2.0, 0.1), 0.0, places=12)


class TestClosedLoop(unittest.TestCase):
    def test_prediction_error_bound_low_gains(self):
        for gamma in (10.0, 100.0):
            _, xs, xhs, ths, _ = run(gamma)
            err = max(abs(a - b) for a, b in zip(xs, xhs))
            self.assertLess(err, prediction_bound(0.0, THETA, gamma))
            self.assertLessEqual(max(abs(v) for v in ths), THETA_B * math.sqrt(1 + EPS) + 1e-9)
            self.assertLess(abs(xs[-1] - 1.0), 0.01)

    def test_high_gain_approaches_reference_system(self):
        # reference: the same loop with the true theta and no adaptation
        _, x_ref, _, _, _ = run(0.0, thetah0=THETA)
        self.assertLess(abs(x_ref[-1] - 1.0), 1e-4)
        _, xs, xhs, _, _ = run(1000.0)
        self.assertLess(max(abs(a - b) for a, b in zip(xs, xhs)), prediction_bound(0.0, THETA, 1000.0))
        self.assertLess(max(abs(a - b) for a, b in zip(xs, x_ref)), 0.07)

    def test_dt_must_divide_t1(self):
        with self.assertRaises(AssertionError):
            l1_simulate(THETA, THETA_B, EPS, 10.0, OMEGA_C, step, 1.0, 0.3)


if __name__ == "__main__":
    unittest.main()

History

Cao and Hovakimyan introduced the architecture in 2006 and published the analysis with the uniform transient bounds in 2008. The book of Hovakimyan and Cao (2010) collects the state feedback, output feedback and nonlinear versions. In 2014 Ioannou, Annaswamy, Narendra, Jafari, Rudd, Ortega and Boskovic published a critique of the stability and robustness claims, and Ortega and Panteley showed that the controller tends to a fixed linear controller for large Γ\Gamma. The debate is about the interpretation of the results and their advantage over earlier robust adaptive designs.

References

  1. Naira Hovakimyan and Chengyu Cao, L1 Adaptive Control Theory: Guaranteed Robustness with Fast Adaptation, SIAM 2010, Chapter 2, State feedback in the presence of matched uncertainties (the architecture, the condition on the L1 norm and the transient bounds)
  2. C. Cao and N. Hovakimyan, Design and analysis of a novel L1 adaptive control architecture with guaranteed transient performance, IEEE Transactions on Automatic Control 53(2), 2008, pages 586 to 591
  3. P. A. Ioannou, A. M. Annaswamy, K. S. Narendra, S. Jafari, L. Rudd, R. Ortega and J. Boskovic, L1-adaptive control: stability, robustness, and interpretations, IEEE Transactions on Automatic Control 59(11), 2014, pages 3075 to 3080 (the critique)
  4. R. Ortega and E. Panteley, Adaptation is unnecessary in L1-adaptive control, International Journal of Control 87(3), 2014, pages 581 to 588 (the limit of a high adaptation gain)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example