Project

Nonlinear Control of a 2-DoF Gimbal: Robust and Adaptive Designs

· nonlinear control / robust control / adaptive control / Lyapunov / MATLAB

This was my project for Nonlinear Control Theory, a course I took during my Master’s. The system is a two-axis gimbal: a small camera mount with an azimuth joint carrying an elevation joint, the kind of thing you bolt to a drone to keep a lens pointed at something while the aircraft moves underneath it. I built the hardware, derived the dynamics, and then used it as a testbed for the controllers the course covered.

What makes it a good testbed is that it is genuinely nonlinear and genuinely coupled. The inertia the azimuth motor sees depends on where the elevation joint is pointing. Spin one axis and the other feels it. And because the whole thing weighs about seventy grams, the inertias are in the tens of microkilogram-metres-squared, which turns out to matter a great deal — not for the control theory, but for the numerics, as I found out the hard way near the end of this post.

The plan was to design five controllers against the same plant and the same reference, and compare them honestly. The thread running through all of them is a single trick: collapse position and velocity error into one signal, then make a Lyapunov function out of it. Once you have that, every controller on this page is a variation on one theme.

Everything below comes out of a MATLAB simulation that integrates the closed loop directly. The code is in a repository of its own, including the Simulink and Simscape Multibody model I originally built it in.

The system

q2q1gz0boresight
The two joints in series. q₁ rotates the yoke about the vertical axis (azimuth); q₂ tilts the payload about the horizontal axis carried by the yoke (elevation). Gravity acts on the elevation axis only, which is why just one entry of the gravity vector is non-zero.

I derived the kinematics with the modified Denavit–Hartenberg convention and the dynamics from there; the symbolic derivation is in gimbal_dynamics.mlx in the repository. What comes out is the standard rigid-body form:

M(q) q¨+C(q,q˙) q˙+G(q)=τM(q)\,\ddot q + C(q,\dot q)\,\dot q + G(q) = \tau

with q∈R2q \in \mathbb{R}^2 the joint angles, MM the inertia matrix, CC the Coriolis and centripetal matrix, GG the gravity vector and τ\tau the input torques. For this gimbal they work out to

M(q)=[θ1cos⁡2(q2)+θ2θ3sin⁡(q2)θ3sin⁡(q2)θ4]M(q) = \begin{bmatrix} \theta_1 \cos^2(q_2) + \theta_2 & \theta_3 \sin(q_2) \\[4pt] \theta_3 \sin(q_2) & \theta_4 \end{bmatrix} C(q,q˙)=[−12θ1sin⁡(2q2) q˙2−12θ1sin⁡(2q2) q˙1+θ3cos⁡(q2) q˙212θ1sin⁡(2q2) q˙10]C(q,\dot q) = \begin{bmatrix} -\tfrac12 \theta_1 \sin(2q_2)\,\dot q_2 & -\tfrac12 \theta_1 \sin(2q_2)\,\dot q_1 + \theta_3 \cos(q_2)\,\dot q_2 \\[4pt] \tfrac12 \theta_1 \sin(2q_2)\,\dot q_1 & 0 \end{bmatrix} G(q)=[0θ5cos⁡(q2)]G(q) = \begin{bmatrix} 0 \\[4pt] \theta_5 \cos(q_2) \end{bmatrix}

The cos⁡2(q2)\cos^2(q_2) in M11M_{11} is the coupling I mentioned: the effective inertia about the azimuth axis changes as the payload tilts. At q2=0q_2 = 0 the payload’s mass is spread out away from the vertical axis; at q2=π/2q_2 = \pi/2 it is lined up with it.

Lumping the parameters

Notice that the matrices above are written in terms of five numbers θ1…θ5\theta_1 \dots \theta_5 rather than the masses, lengths and inertias themselves. That is deliberate, and it is the single most useful thing about this model. The physical parameters only ever appear in five fixed combinations:

θ1=m2h2x2−Ixx2+Iyy2θ2=m1h1y2+m2h2z2+Izz1+Ixx2θ3=Ixz2−m2h2xh2zθ4=m2h2x2+Izz2θ5=−m2h2xg\begin{aligned} \theta_1 &= m_2 h_{2x}^2 - I_{xx2} + I_{yy2} \\ \theta_2 &= m_1 h_{1y}^2 + m_2 h_{2z}^2 + I_{zz1} + I_{xx2} \\ \theta_3 &= I_{xz2} - m_2 h_{2x} h_{2z} \\ \theta_4 &= m_2 h_{2x}^2 + I_{zz2} \\ \theta_5 &= -m_2 h_{2x} g \end{aligned}

So there is no point estimating nine physical quantities when only five combinations can ever affect the motion. More importantly, the dynamics are linear in that vector. Any expression built from MM, CC and GG can be factored as a known matrix times the unknown parameters:

Y(q,q˙,⋅) θ=M(q) u+C(q,q˙) v+G(q)Y(q, \dot q, \cdot)\,\theta = M(q)\,u + C(q,\dot q)\,v + G(q)

where YY depends only on measured signals. Hold on to this — it is what makes the adaptive controller at the end of this page possible, and it is the reason the model was written this way in the first place.

ParameterValueParameterValue
m1m_10.051 kgIzz1I_{zz1}2.084×10⁻⁵ kg·m²
m2m_20.0195 kgIxx2I_{xx2}7.4×10⁻⁷ kg·m²
h1yh_{1y}−0.0227 mIyy2I_{yy2}3.86×10⁻⁶ kg·m²
h2xh_{2x}0.0246 mIzz2I_{zz2}3.75×10⁻⁶ kg·m²
h2zh_{2z}0.0014 mIxz2I_{xz2}−5.6×10⁻⁷ kg·m²

Masses came off a scale, centres of mass and inertia tensors out of SolidWorks. Friction is not in the model at all: I never got the hardware instrumented well enough to identify it, so rather than invent a number I left it out and noted the omission. That is a real limitation and I come back to it at the end.

One error signal to rule them all

Here is the idea that the whole course, and this whole page, hangs on.

The tracking error is the obvious thing:

e=qd−qe = q_d - q

But a second-order system needs both position and velocity error controlled, and carrying two signals through a Lyapunov argument is clumsy. So define the filtered tracking error

r=e˙+αe,α=α⊤>0 diagonalr = \dot e + \alpha e, \qquad \alpha = \alpha^\top > 0 \text{ diagonal}

This is just a first-order stable filter applied to ee. The payoff is that driving the single signal rr to zero is enough: if r→0r \to 0, then e˙=−αe\dot e = -\alpha e, which is a stable first-order ODE, so e→0e \to 0 and e˙→0\dot e \to 0 as well. One signal, both guarantees.

Now differentiate and multiply by the inertia matrix — multiplying by MM is the move that makes everything after this work:

Mr˙=M(q¨d+αe˙)−Mq¨M\dot r = M(\ddot q_d + \alpha \dot e) - M\ddot q

Substituting Mq¨=τ−Cq˙−GM\ddot q = \tau - C\dot q - G from the dynamics, and then rewriting q˙=q˙d+αe−r\dot q = \dot q_d + \alpha e - r to pull the rr-dependence out:

Mr˙=M(q¨d+αe˙)+C(q˙d+αe)+G⏟N−Cr−τM\dot r = \underbrace{M(\ddot q_d + \alpha \dot e) + C(\dot q_d + \alpha e) + G}_{N} - C r - \tau

So the error dynamics are

Mr˙=N−Cr−τM\dot r = N - Cr - \tau

with NN collecting everything that does not depend on rr. This is the equation every controller below is designed against. The only thing that changes from one section to the next is how much of NN you think you know.

Why the inertia matrix had to be there

Take the Lyapunov candidate

V=12r⊤MrV = \tfrac12 r^\top M r

This is positive definite because MM is. Differentiating, and remembering that MM is time-varying:

V˙=12r⊤M˙r+r⊤Mr˙=12r⊤(M˙−2C)r+r⊤(N−τ)\dot V = \tfrac12 r^\top \dot M r + r^\top M \dot r = \tfrac12 r^\top \big(\dot M - 2C\big) r + r^\top (N - \tau)

And now the structural property that makes rigid-body manipulators so pleasant to control: M˙−2C\dot M - 2C is skew-symmetric, so for any vector ξ\xi,

ξ⊤(M˙−2C) ξ=0\xi^\top \big(\dot M - 2C\big)\, \xi = 0

This is not a modelling assumption or an approximation, but it does depend on which CC you wrote down, and the usual one-line justification for it is not quite enough. CC is not unique: any matrix satisfying Cq˙=C\dot q = (the Coriolis and centripetal terms) is a legitimate choice, and most of them are not skew-symmetric. The argument people normally reach for — that Coriolis forces do no net work — is really the kinetic-energy identity, and it only pins down the case ξ=q˙\xi = \dot q. Here the identity gets applied to rr, which is a different vector entirely, so that argument does not cover the use it is being put to.

What does cover it is that the CC at the top of this page is the Christoffel construction,

Cij=∑k12(∂Mij∂qk+∂Mik∂qj−∂Mjk∂qi)q˙kC_{ij} = \sum_k \frac{1}{2}\left( \frac{\partial M_{ij}}{\partial q_k} + \frac{\partial M_{ik}}{\partial q_j} - \frac{\partial M_{jk}}{\partial q_i}\right)\dot q_k

which is the choice that makes skew-symmetry hold for every ξ\xi. Substitute the MM and CC from the top of the page and it comes out exactly:

M˙−2C=[0a−a0],a=θ1sin⁡(2q2) q˙1−θ3cos⁡(q2) q˙2\dot M - 2C = \begin{bmatrix} 0 & a \\ -a & 0 \end{bmatrix}, \qquad a = \theta_1 \sin(2q_2)\,\dot q_1 - \theta_3 \cos(q_2)\,\dot q_2

Zero diagonal, antisymmetric off-diagonal, no approximation anywhere. So the entire first term vanishes:

V˙=r⊤(N−τ)\dot V = r^\top (N - \tau)

That is a remarkable simplification. A quadratic form in a time-varying inertia matrix, differentiated, collapses to something with no derivative of MM in it at all. This is why we multiplied by MM back there: so that the awkward M˙\dot M term would have a CC term to cancel against.

Everything from here is choosing τ\tau to make r⊤(N−τ)r^\top(N - \tau) negative.

Exact model knowledge

If you know every parameter, the choice is obvious — cancel NN and add damping:

τ=Krr+M(q¨d+αe˙)+C(q˙d+αe)+G⏟N\tau = K_r r + \underbrace{M(\ddot q_d + \alpha \dot e) + C(\dot q_d + \alpha e) + G}_{N} V˙=r⊤(N−Krr−N)=−r⊤Krr<0\dot V = r^\top (N - K_r r - N) = -r^\top K_r r < 0

Negative definite, so r→0r \to 0 asymptotically, so e→0e \to 0. Done.

With α=diag(1,1)\alpha = \mathrm{diag}(1,1), Kr=diag(2,2)K_r = \mathrm{diag}(2,2), and a sinusoidal reference of amplitude 0.4 rad and period 2 s on both joints:

Two plots of joint angle against time over ten seconds. Measured and reference curves lie exactly on top of each other for both the azimuth and the elevation joint.
The task. Both joints follow a 0.4 rad sinusoid at a 2 s period. With exact model knowledge the measured and reference traces are indistinguishable at this scale, which is the point of the next figure.
Left: tracking error for exact model knowledge, in nanoradians, wandering within forty nanoradians. Right: the same controller against a mismatched plant, with the elevation error climbing to about 2.5 milliradians.
Left: the error with perfect model knowledge, in NANOradians. There is nothing there — what you see is the integrator's own noise floor, not control error. Right: the identical control law against a plant whose parameters have been perturbed. Same axes labels, but the units are now milliradians: five orders of magnitude worse.

The left panel is the theory working exactly as advertised, and it is also slightly dishonest as a plot: with e(0)=0e(0) = 0 and a perfect model, the true solution is e(t)≡0e(t) \equiv 0 for all time, so what is drawn is the numerical integrator talking to itself. The useful number is that it stays below 10⁻⁸ rad.

The right panel is the whole reason the rest of this page exists. I added 14 g to every mass, 5 × 10⁻⁶ kg·m² to every inertia and 7.5 mm to every centre-of-mass offset — perturbations that are small in absolute terms but not at all small relative to a seventy-gram mechanism. The controller, still computing NN from the nominal numbers, now leaves a steady 2.4 mrad of elevation error. Gravity is the main culprit: θ5\theta_5 more than doubles under that perturbation, and nothing in the control law knows.

Two ways to deal with not knowing θ\theta. Assume a bound on how wrong you are and overpower it, which is robust control. Or estimate it online, which is adaptive control.

Robust control

Split NN into what you can compute and what you cannot:

N~=N−N^,∥N~∥≤ρ\tilde N = N - \hat N, \qquad \lVert \tilde N \rVert \le \rho

The controller gets the nominal part plus a damping term plus an extra term whose job is to swamp whatever is left:

τ=Krr+N^+VR\tau = K_r r + \hat N + V_R V˙=r⊤(N~−Krr−VR)\dot V = r^\top \big(\tilde N - K_r r - V_R\big)

The design question is what to put in VRV_R. The course covered three answers, and the interesting thing is that they give three genuinely different stability conclusions.

High frequency

VR=ρ2ρ∥r∥+ε rV_R = \frac{\rho^2}{\rho \lVert r \rVert + \varepsilon}\, r

Substituting and bounding r⊤N~≤ρ∥r∥r^\top \tilde N \le \rho \lVert r \rVert:

V˙≤−λmin⁡{Kr}∥r∥2+ρ∥r∥(1−ρ∥r∥ρ∥r∥+ε)=−λmin⁡{Kr}∥r∥2+ε(ρ∥r∥ρ∥r∥+ε)\dot V \le -\lambda_{\min}\{K_r\} \lVert r \rVert^2 + \rho\lVert r\rVert\left(1 - \frac{\rho\lVert r\rVert}{\rho\lVert r\rVert + \varepsilon}\right) = -\lambda_{\min}\{K_r\}\lVert r \rVert^2 + \varepsilon\left(\frac{\rho\lVert r\rVert}{\rho\lVert r \rVert + \varepsilon}\right)

That bracket is at most 1, so

V˙≤−λmin⁡{Kr}∥r∥2+ε\dot V \le -\lambda_{\min}\{K_r\}\lVert r \rVert^2 + \varepsilon

which gives uniform ultimate boundedness: rr ends up in a ball whose size is set by ε\varepsilon, and no smaller. You buy a smaller residual by picking a smaller ε\varepsilon, which costs you gain.

High gain

VR=ρ2ε rV_R = \frac{\rho^2}{\varepsilon}\, r

which is just a linear term. The bound splits into two cases:

ρ∥r∥>ε  ⟹  V˙≤−λmin⁡{Kr}∥r∥2\rho \lVert r \rVert > \varepsilon \;\Longrightarrow\; \dot V \le -\lambda_{\min}\{K_r\}\lVert r\rVert^2 ε>ρ∥r∥  ⟹  V˙≤−λmin⁡{Kr}∥r∥2+ε\varepsilon > \rho \lVert r \rVert \;\Longrightarrow\; \dot V \le -\lambda_{\min}\{K_r\}\lVert r\rVert^2 + \varepsilon

Exponential while the error is large, ultimately bounded once it is small. Which is the honest description of what a high-gain loop does.

Sliding mode

VR=ρ sgn(r)V_R = \rho\,\mathrm{sgn}(r)

applied elementwise. Since r⊤sgn(r)=∥r∥1≥0r^\top \mathrm{sgn}(r) = \lVert r \rVert_1 \ge 0,

V˙≤−λmin⁡{Kr}∥r∥2\dot V \le -\lambda_{\min}\{K_r\}\lVert r \rVert^2

with no leftover ε\varepsilon at all. On paper this is the strongest of the three: exponential stability, not just boundedness. The discontinuity is doing real work, and it is also where the trouble starts — see below.

What they do

All three with α=diag(1,1)\alpha = \mathrm{diag}(1,1), Kr=diag(10,10)K_r = \mathrm{diag}(10,10), ρ=1\rho = 1, ε=0.01\varepsilon = 0.01 (and ρ=0.1\rho = 0.1 for sliding mode), against the same perturbed plant:

Left: elevation error in microradians for sliding mode and high gain, settling around 470 and 45 microradians. Right: high gain and high frequency plotted together, the two curves lying on top of one another near 45 microradians.
Left: both robust terms against the 2.4 mrad the plain controller left behind — note the axis is now MICROradians, so high gain cuts the error by a factor of fifty. Right: high gain and high frequency, overlaid. They are visually indistinguishable, and their RMS errors differ in the third significant figure.

That right panel surprised me until I looked at the algebra. With ε=0.01\varepsilon = 0.01 and ρ=1\rho = 1, the high-gain term has coefficient ρ2/ε=100\rho^2/\varepsilon = 100. The high-frequency term has coefficient ρ2/(ρ∥r∥+ε)\rho^2/(\rho\lVert r\rVert + \varepsilon), and since ∥r∥\lVert r \rVert here is of order 10⁻⁵, that denominator is 0.01+10−5≈0.010.01 + 10^{-5} \approx 0.01. The two controllers are numerically the same controller. They only diverge when the error is large enough for ρ∥r∥\rho\lVert r\rVert to compete with ε\varepsilon, which on this trajectory happens only in the first few milliseconds.

So the difference between “ultimately bounded” and “exponentially then ultimately bounded” is, for this plant and these gains, invisible. The distinction is real but it lives in a regime this experiment never enters.

A detour: the sliding-mode result is a numerics result

The sliding-mode row is the one I could not get to agree with my original Simulink results, and chasing down why taught me more than the controller did.

With the ideal sgn(r)\mathrm{sgn}(r) and a fixed-step integrator, I got an RMS velocity error of 7.7 × 10⁻² rad/s — three orders of magnitude worse than anything else on this page. My first guess was chattering. It was not: I checked, and r2r_2 crosses zero exactly once in two seconds. The switch never switches. It just sits at −ρ-\rho and acts as a constant 0.1 N·m bias against a plant whose gravity torque is about 0.01 N·m.

The real cause is the step size. The closed-loop error dynamics are Mr˙≈−KrrM\dot r \approx -K_r r, so their time constant is

M22Kr=4.34×10−510≈4.3 μs\frac{M_{22}}{K_r} = \frac{4.34\times10^{-5}}{10} \approx 4.3\ \mu\text{s}

Four microseconds. That is what a seventy-gram mechanism with a gain of 10 buys you. Refining the step makes the point:

RK4 stepsign changes in r2r_2RMS e˙2\dot e_2
10 µs17.7×10⁻²
3 µs11.7×10⁻³
1 µs27.4×10⁻⁴
0.3 µs196,5201.9×10⁻⁴

Only below the 4.3 µs time constant does the switch start switching, and only then does the answer start converging. Everything above that line is integration error wearing a control result’s clothing.

The fix in practice is the one that was sitting commented out in my own Simulink block the whole time — replace the discontinuity with a saturation:

VR=ρ rr⊤r+ϕV_R = \rho\,\frac{r}{\sqrt{r^\top r + \phi}}

This is smooth, so a stiff solver handles it without heroics, and it is what any real implementation would use anyway, because no motor can switch instantaneously. It costs you the clean exponential bound — you are back to ultimate boundedness, with ϕ\phi playing the role ε\varepsilon played earlier. Every sliding-mode number quoted elsewhere on this page uses this version.

I am fairly sure the same effect explains the sliding-mode row in my original report, whose velocity error sits almost exactly where my 1 µs run does.

Adaptive control

Robust control assumes a bound on the uncertainty and pays for it with gain. Adaptive control does something more ambitious: it estimates the parameters while it runs.

This is where the linear parameterization earns its keep. Write

N=YθN = Y\theta

with Y∈R2×5Y \in \mathbb{R}^{2\times5} built from measured signals. For this gimbal, with u=q¨d+αe˙u = \ddot q_d + \alpha\dot e and v=q˙d+αev = \dot q_d + \alpha e:

Y=[u1cos⁡2q2−12sin⁡(2q2)(v1q˙2+v2q˙1)u1u2sin⁡q2+v2cos⁡q2 q˙20012v1sin⁡(2q2) q˙10u1sin⁡q2u2cos⁡q2]Y = \begin{bmatrix} u_1\cos^2 q_2 - \tfrac12 \sin(2q_2)(v_1 \dot q_2 + v_2 \dot q_1) & u_1 & u_2 \sin q_2 + v_2\cos q_2\,\dot q_2 & 0 & 0 \\[4pt] \tfrac12 v_1 \sin(2q_2)\,\dot q_1 & 0 & u_1 \sin q_2 & u_2 & \cos q_2 \end{bmatrix}

Let θ^\hat\theta be the estimate and θ~=θ−θ^\tilde\theta = \theta - \hat\theta the estimation error. Now augment the Lyapunov function with a term that measures how wrong the estimate is:

V=12r⊤Mr+12θ~⊤Γ−1θ~V = \tfrac12 r^\top M r + \tfrac12 \tilde\theta^\top \Gamma^{-1} \tilde\theta V˙=r⊤(Yθ−τ)−θ~⊤Γ−1θ^˙\dot V = r^\top (Y\theta - \tau) - \tilde\theta^\top \Gamma^{-1} \dot{\hat\theta}

using θ~˙=−θ^˙\dot{\tilde\theta} = -\dot{\hat\theta}, since the true parameters do not change. Choose

τ=Krr+Yθ^,θ^˙=ΓY⊤r\tau = K_r r + Y\hat\theta, \qquad \dot{\hat\theta} = \Gamma Y^\top r

and the cross terms annihilate each other exactly:

V˙=r⊤(Yθ~−Krr)−θ~⊤Γ−1ΓY⊤r=−r⊤Krr\dot V = r^\top\big(Y\tilde\theta - K_r r\big) - \tilde\theta^\top \Gamma^{-1}\Gamma Y^\top r = -r^\top K_r r

This is the most elegant result on the page. The update law is not a gradient descent on anything you specified; it is whatever makes the θ~\tilde\theta terms cancel, and it falls out of the algebra.

But look carefully at what was proved. V˙=−r⊤Krr\dot V = -r^\top K_r r is negative semidefinite in the full state (r,θ~)(r, \tilde\theta) — it is zero whenever r=0r = 0, whatever θ~\tilde\theta happens to be. That is weaker than it looks, and getting from it to r→0r \to 0 takes one more step than the algebra above suggests, because a negative semidefinite V˙\dot V on its own buys only boundedness. The step is Barbalat’s lemma: V˙≤0\dot V \le 0 makes VV non-increasing, so rr and θ~\tilde\theta stay bounded; integrating gives

∫0∞∥r∥2 dτ  ≤  V(0)λmin⁡{Kr}  <  ∞\int_0^\infty \lVert r \rVert^2 \, d\tau \;\le\; \frac{V(0)}{\lambda_{\min}\{K_r\}} \;<\; \infty

so rr is square-integrable; and r˙\dot r is bounded, because everything on the right-hand side of the error dynamics is. A square-integrable signal with a bounded derivative has to go to zero, so r→0r \to 0 and therefore e→0e \to 0.

What no part of that argument gives you is θ^→θ\hat\theta \to \theta.

That is not a technicality:

Left: five parameter estimates divided by their true values, wandering between minus forty and plus one hundred and twenty, with none settling at one except a single trace. Right: elevation error for standard adaptive and desired model compensation, the two curves overlapping and decaying from 0.23 millradians.
Left: each estimate divided by its true value, so convergence would mean settling on 1. Only θ₅, the gravity parameter, gets close — it finishes at 0.93. The others wander, with θ₃ ending at 24 times its true value. Right: the tracking error converges anyway, and the two adaptive variants are indistinguishable.

Only θ5\theta_5 converges. It multiplies cos⁡q2\cos q_2 in the regressor, which is large and persistently varying along this trajectory, so the data forces it. The other four multiply terms that are either small or nearly collinear with one another on a single-frequency sinusoid, so the adaptation has no way to tell them apart. It finds some θ^\hat\theta that cancels the error along this particular trajectory, and stops caring.

This is persistency of excitation, and it is the thing to remember about adaptive control. The estimates are not measurements. Run the same gimbal on a different reference and this θ^\hat\theta would be useless — in fact, parameter error up to 24× sitting inside a controller that tracks to 10⁻⁴ rad is exactly the kind of thing that looks fine until the day the trajectory changes.

Desired model compensation

A variation worth the half page it takes. Evaluate the regressor along the desired trajectory instead of the measured one:

Nd=Mq¨d+Cq˙d+G(qd)=Yd θN_d = M\ddot q_d + C\dot q_d + G(q_d) = Y_d\,\theta τ=Krr+Ydθ^+ρr,θ^˙=ΓYd⊤r\tau = K_r r + Y_d\hat\theta + \rho r, \qquad \dot{\hat\theta} = \Gamma Y_d^\top r

Writing Mr˙=X−Cr−τ+NdM\dot r = \mathcal{X} - Cr - \tau + N_d and assuming ∥X∥≤ρ∥r∥\lVert\mathcal{X}\rVert \le \rho\lVert r\rVert, the same cancellation gives

V˙≤−λmin⁡{Kr}∥r∥2\dot V \le -\lambda_{\min}\{K_r\}\lVert r\rVert^2

It is tempting to read that as exponential stability — the bound is an inequality in ∥r∥2\lVert r \rVert^2 now, which looks stronger than the equality the standard version gave. It is not, and the reason is the θ~\tilde\theta term again. Exponential stability needs V˙≤−cV\dot V \le -cV for some c>0c > 0, and VV still carries 12θ~⊤Γ−1θ~\tfrac12 \tilde\theta^\top \Gamma^{-1}\tilde\theta, which can be as large as you like while r=0r = 0 and V˙=0\dot V = 0. Nothing in the bound pushes the parameter error down. You land exactly where the standard version landed: r∈L2∩L∞r \in \mathcal{L}_2 \cap \mathcal{L}_\infty, then r→0r \to 0 by Barbalat.

The contrast with sliding mode earlier on this page is the whole point. There V=12r⊤MrV = \tfrac12 r^\top M r and nothing else, so V˙≤−λmin⁡{Kr}∥r∥2\dot V \le -\lambda_{\min}\{K_r\}\lVert r \rVert^2 really does imply V˙≤−cV\dot V \le -cV with c=2λmin⁡{Kr}/λmax⁡{M}c = 2\lambda_{\min}\{K_r\}/\lambda_{\max}\{M\}, and exponential stability follows. Add a parameter estimate to the Lyapunov function and that implication is gone. What the ρr\rho r term actually buys is robustness to X\mathcal{X}, the part of the dynamics a desired-trajectory regressor cannot represent — worth having, just not a stronger stability class.

One wrinkle, since the code is linked from the top of this page: the implementation adds ρ∥r∥\rho\lVert r \rVert as a scalar to both channels rather than the vector ρr\rho r the derivation asks for. The proof needs r⊤VR=ρ∥r∥2≥0r^\top V_R = \rho \lVert r \rVert^2 \ge 0; what is implemented gives ρ∥r∥(r1+r2)\rho\lVert r \rVert (r_1 + r_2), which goes negative about a sixth of the time. It changes nothing measurable here — the term peaks at 6.1 × 10⁻⁵ N·m against a peak torque of 1.04 × 10⁻² N·m, so 0.14% — but it is not quite the controller that was proved.

The practical attraction is different though: YdY_d depends only on the reference, which you know ahead of time. You can compute it offline, store it, and skip the regressor evaluation in the control loop entirely. On a microcontroller driving a gimbal at 200 Hz, that is a real saving.

And as the right-hand panel above shows, it costs essentially nothing in tracking performance — 1.24 × 10⁻⁴ against 1.25 × 10⁻⁴ rad.

That agreement deserves a moment, because the obvious explanation for it is wrong. You would guess the two coincide because tracking is good: if q≈qdq \approx q_d then Y≈YdY \approx Y_d, so they are the same controller wearing different clothes. Easy to test — start the gimbal 0.3 rad off the reference and the agreement should fall apart.

It does not. That run has an RMS elevation error five hundred times larger, and the two still agree to four significant figures. What does change is where the estimates end up:

RunRMS e2e_2 [rad]θ^1/θ1\hat\theta_1/\theta_1 at 10 s
Standard, q(0)=0q(0)=01.248×10⁻⁴−2.54
D.m.c., q(0)=0q(0)=01.242×10⁻⁴−2.54
Standard, q(0)=0.3q(0)=0.36.717×10⁻²−1.02
D.m.c., q(0)=0.3q(0)=0.36.717×10⁻²−2.66

The two find genuinely different parameters and get identical tracking out of them. Which is the persistency-of-excitation point again, sharpened: what the adaptation pins down is the product Yθ^Y\hat\theta, the feedforward torque this trajectory demands. Evaluating the regressor at the measured state or at the desired one changes the coordinates that product is written in, not the product itself. Neither version is identifying anything.

Nor is this a case of the model term being too small to matter. Over the nominal run, RMS ∥Yθ^∥\lVert Y\hat\theta \rVert is 8.3 × 10⁻³ N·m against RMS ∥Krr∥\lVert K_r r \rVert of 1.8 × 10⁻³ N·m: the feedforward is doing four and a half times as much work as the feedback. It matters enormously. Both ways of computing it simply do the job equally well.

So: same answer, less arithmetic at run time.

Putting the numbers together

All seven runs, same trajectory, same 10 s horizon, RMS error over the whole run. Every row after the first uses the perturbed plant:

Controllere1e_1 [rad]e2e_2 [rad]e˙1\dot e_1 [rad/s]e˙2\dot e_2 [rad/s]
E.m.k.2.05×10⁻⁸1.98×10⁻⁸1.94×10⁻⁸2.00×10⁻⁸
E.m.k., mismatched9.25×10⁻⁶2.38×10⁻³2.44×10⁻⁵6.43×10⁻⁴
High gain1.67×10⁻⁷4.32×10⁻⁵4.40×10⁻⁷1.17×10⁻⁵
High frequency1.66×10⁻⁷4.34×10⁻⁵4.39×10⁻⁷1.17×10⁻⁵
Sliding mode1.69×10⁻⁶4.32×10⁻⁴4.44×10⁻⁶1.17×10⁻⁴
Adaptive2.79×10⁻⁵1.25×10⁻⁴5.93×10⁻⁵1.16×10⁻⁴
Adaptive, d.m.c.2.76×10⁻⁵1.24×10⁻⁴5.92×10⁻⁵1.15×10⁻⁴
Horizontal bar chart on a logarithmic axis comparing RMS elevation error across seven controllers, spanning from ten to the minus eight up to just above ten to the minus three.
The same column on a log axis. Four orders of magnitude separate the best and worst, and the one bar that matters is the second: that is what happens when you hand a model-based controller the wrong model.

The ordering is clear enough. The robust high-gain and high-frequency designs win, and they win because they are allowed to be stiff: Kr=10K_r = 10 plus a further ρ2/ε=100\rho^2/\varepsilon = 100 of effective gain. Adaptive control lands about three times worse on elevation, which is the price of learning the parameters during the run rather than being handed a bound on them.

But reading that table as a ranking would be a mistake, and here is why:

Two plots of joint torque in millinewton-metres over ten seconds. The high-gain controller's torques are smooth sinusoids within about ten millinewton-metres; the adaptive controller's are similar in magnitude with a slower transient.
What the two designs actually ask of the motors. Both stay within about 10 mN·m, which these Dynamixel servos can deliver — so on this plant the high-gain design's extra stiffness really is free. On a bigger mechanism, or with an actuator closer to saturation, that column of the table would look very different.

The robust controllers win here partly because nothing stopped them. There is no actuator model in this simulation: no torque limit, no bandwidth, no quantization on the encoders. A gain of 110 is fine when the motor is an ideal torque source. Put a real servo in the loop with a 200 Hz update rate and a 4.3 µs closed-loop time constant, and the high-gain design is the first one to fall over, not the last.

What I took away

The Lyapunov machinery is better than I expected it to be. Not because it proves things — I knew that was the point — but because of how much it designs. I never had to guess at the adaptation law θ^˙=ΓY⊤r\dot{\hat\theta} = \Gamma Y^\top r; it is the only choice that makes the cross terms cancel. The skew-symmetry of M˙−2C\dot M - 2C is not a convenient lemma, it is the reason multiplying by MM was the right first move. Three times on this project the algebra told me what to write next, and that is a different experience from tuning a PID.

What the algebra does not tell you is which guarantee is worth having. Sliding mode has the strongest theorem on this page, and it is the one I would be least willing to put on the hardware. Exponential stability bought with a discontinuity assumes an actuator that can switch infinitely fast, and the moment you admit it cannot — via a boundary layer, or just by running at a finite sample rate — you are back to ultimate boundedness with everyone else. The theorem was never wrong. It was answering a question about a system I do not own.

The thing I did not expect to spend two days on is that the numerics have opinions too. A 4.3 µs closed-loop time constant is not something the control design warns you about; it comes from dividing a gain you chose by an inertia the mechanism happens to have, and it quietly invalidates any simulation that steps more slowly. I had a result sitting in a table for weeks that was three orders of magnitude off, and it looked entirely plausible.

As for the gimbal: the controllers are done and the hardware is not. There is no friction in this model, and friction is the dominant unmodelled effect in a small geared servo — likely larger than the parameter uncertainty I spent this whole page defending against. Adding Coulomb and viscous friction terms, then actuator dynamics with real torque limits, is where this goes next. I would expect the ranking in that table to change completely, and I would like to find out how.

References

  1. F. L. Lewis, D. M. Dawson and C. T. Abdallah, Robot Manipulator Control: Theory and Practice, 2nd ed. Marcel Dekker, 2004.
  2. J.-J. E. Slotine and W. Li, Applied Nonlinear Control. Prentice Hall, 1991.
  3. H. K. Khalil, Nonlinear Systems, 3rd ed. Prentice Hall, 2002.
  4. M. W. Spong, S. Hutchinson and M. Vidyasagar, Robot Modeling and Control. Wiley, 2005.
  5. V. I. Utkin, Sliding Modes in Control and Optimization. Springer, 1992.