Algorithmadvanced
Slotine-Li adaptive controller
Also called adaptive computed torque.
Tracks a joint trajectory while it adapts the dynamic parameters along the regressor. Its stability proof uses the skew symmetry of the arm dynamics.
- Time
- O(n^2) per_step
- Space
- O(n^2) extra
- Where
- n = the number of joints; the arm has 10 n inertial parameters, and the bounds are for one control step with the regressor formed explicitly
- Model
- Real RAM
- Properties
- deterministicnot exactonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jean Jacques E. Slotine, Weiping Li, 1987
The Slotine-Li adaptive controller makes a robot arm follow a joint trajectory when the masses, centers of mass and inertias of its links are not known. It uses the fact that the arm dynamics are linear in these parameters, , and updates an estimate online from the tracking error. Unlike adaptive versions of computed-torque control, it needs neither the measured joint accelerations nor the inverse of the estimated inertia matrix. Its Lyapunov proof uses the skew symmetry of , which places it among the passivity-based controllers. The tracking error goes to zero; the parameter estimate goes to the true value only if the trajectory is rich enough.
In plain words
A controller with a model of the arm can follow a path closely, but only if the model is right. A new payload in the gripper changes the model. This controller starts with a guess of the masses and inertias and keeps correcting the guess while it moves.
It combines the position error and the speed error into one number per joint, called . When is zero, the position error dies out by itself at a fixed rate. The controller pushes toward zero with a model-based torque and a damping term. Each time is not zero, it shifts the guessed parameters in the direction that would have reduced . A sum of a kinetic energy in and the squared parameter error never grows, and this gives the proof.
The problem
The arm has joints and obeys the manipulator equation with no contact. The matrix is built from the Christoffel symbols, so is skew-symmetric. By linearity in the dynamic parameters, there is a known regressor matrix with
for all , , , , where is a constant but unknown parameter vector. A desired trajectory is given, with , and bounded. The task is to choose from , and the trajectory, without , so that .
The algorithm
The gains are symmetric positive definite matrices and of size and of size . In practice they are diagonal. The state of the controller is the estimate .
SLOTINE-LI(q, q', q_d, q_d', q_d'', π̂, Λ, K_D, Γ)- 1
q̃ ← q - q_d - 2
q_r' ← q_d' - Λ q̃ ▷ reference velocity - 3
q_r'' ← q_d'' - Λ (q' - q_d') ▷ its derivative, without q'' - 4
s ← q' - q_r' ▷ s = q̃' + Λ q̃ - 5
τ ← Y(q, q', q_r', q_r'') π̂ - K_D s - 6
π̂' ← -Γ Y(q, q', q_r', q_r'')ᵀ s ▷ adaptation law - 7
return τ, π̂'
The program integrates with the rate of line L6 between control steps. Line L3 uses , so the law needs no acceleration measurement. The velocity slot of gets , not : the model torque in line L5 is . The name "adaptive computed torque" is also used for the earlier scheme of Craig, Hsu and Sastry, which needs the acceleration and the inverse of .
Example
Take the planar 2R arm with m and point masses of 1 kg at the link ends, in a vertical plane, with m/s. Its dynamics are linear in , where , , , and . The true value is , and the controller starts with half of it, . The desired trajectory is rad. The gains are , and .
At the arm is at rest at , and , , .
| line | value |
|---|---|
| L1 | |
| L2 | |
| L3 | |
| L4 | |
| L5 | N m |
| L6 |
A simulation of the closed loop with RK4 and a step of 4 ms gives these values, where is the Lyapunov function of the next section.
| time (s) | largest joint error (rad) | ||
|---|---|---|---|
| 0 | 0.200 | 4.509 | |
| 1 | 0.046 | 1.543 | |
| 2 | 0.012 | 1.372 | |
| 5 | 0.011 | 1.048 | |
| 10 | 0.003 | 0.883 |
The error falls, and never grows. The estimate moves toward the truth, but after 10 s it is still far from it in and : the tracking does not need the true parameters.
Correctness
Write . Putting line L5 into the arm equation and subtracting gives the closed loop
The function has the derivative , because the adaptation law of line L6 cancels the cross term and is skew-symmetric. So never grows, and and stay bounded. The integral of is at most , and Barbalat's lemma then gives . Since , also and . The full proof is in the proof file.
The skew symmetry is used with the vector , not with . This needs the matrix from the Christoffel symbols; another factorization with the same product does not work.
Proof: The Slotine-Li controller drives the tracking error to zerofull
The arm obeys with . We assume:
- is symmetric, and there are constants with for all , .
- is the Christoffel matrix, so is skew-symmetric: for every vector , where .
- , , and are continuous, and for all arguments, with a constant . On bounded sets of arguments they are bounded.
- , and are bounded, and , , are symmetric positive definite.
We write , , and for .
Lemma 1 (closed loop). Under SLOTINE-LI, and .
Proof. Line L4 gives , which is the first equation. The derivative of is , which is the value of line L3. So . By assumption 3, , and line L5 gives . The arm equation becomes . We subtract and use and to get .
Lemma 2. The function satisfies .
Proof. is constant, so by line L6. and are symmetric, so
The terms and are the same number and cancel. What is left is , and the last term is zero by assumption 2.
Theorem. Under assumptions 1 to 4, every solution of the closed loop is bounded, is bounded, and and as .
Proof. Step 1 (boundedness). By Lemma 2, . By assumption 1, , so is bounded, and is bounded because is positive definite. The equation is a linear system with the Hurwitz matrix and a bounded input, so is bounded, and then is bounded. With assumption 4, , , and are bounded. So , and are bounded by assumption 3. By Lemma 1 and assumption 1, is bounded, since .
Step 2 (). Integrating Lemma 2 gives . So the function has a finite integral over . Its derivative is bounded by step 1, so is uniformly continuous. By Barbalat's lemma, , and since is positive definite, .
Step 3 (). Let be the smallest eigenvalue of . Then because is symmetric. For ,
Given , choose with for . Then , which is less than for large. So , and .
Remark on the parameters. The proof shows that is bounded, not that it converges to . When and , Lemma 1 gives along the trajectory. If along the desired trajectory is persistently exciting, this forces ; otherwise can stay away from zero.
Complexity
In the real-RAM model, a serial arm with joints has inertial parameters (fewer after reduction to the base inertial parameters). The regressor is an matrix, but the torque of joint depends only on the parameters of links to , so it has nonzero entries. Forming , the product and the product take operations per control step with recursive kinematics, and the memory is . The 2R example has and constant cost.
Properties
- Tracking without parameters. The tracking error goes to zero for any constant parameter error, from any initial state, with no bound on the gains other than positive definiteness.
- No acceleration, no inverse. The law uses only , and the trajectory, and it never inverts the estimated inertia matrix, which could become singular during adaptation.
- Asymptotic, not exponential. Without more conditions, the proof gives only . With persistent excitation of along the desired trajectory, the estimate converges to and the convergence becomes exponential.
- Bounded parameter estimate. The estimate stays bounded but need not converge. For a set point, it usually stops at a wrong value that matches the gravity torque at the goal.
Variants and improvements
- Passivity-based form. With fixed to a known model, the law is the passivity-based tracking controller (Spong, Hutchinson and Vidyasagar call the adaptive case passivity-based adaptive control).
- Robust modifications. With noise or unmodeled dynamics, the estimate can drift. A dead zone on , projection of onto a known box, or sigma modification keeps the estimate bounded.
- Composite adaptation. Slotine and Li also combined the tracking error with a prediction error of the torque in the update, which uses the data better.
- Physically consistent estimates. Projection onto parameters with positive masses and valid inertia tensors keeps positive definite, which some variants need.
- Other adaptive schemes. Craig, Hsu and Sastry adapt computed-torque control; their proof needs the joint acceleration and a bounded . For general systems, see adaptive control and model-reference adaptive control.
When to use it
Use it when the arm follows trajectories with an unknown or changing payload, and the structure of the dynamics is known exactly. Typical cases are direct drive and low-friction arms where the rigid body model dominates. If the parameters are known well from dynamic parameter identification, a fixed-model law is simpler. If the model structure is wrong, for example with large friction, add friction terms to or use a robust law such as sliding mode control.
Pitfalls
- Wrong . Using a factorization of the Coriolis terms that is not the Christoffel one breaks the proof, because the proof needs for .
- Drift of the estimate. Bounded noise or a small model error can make drift slowly without bound in the pure law. Use one of the robust modifications on a real arm.
- Large adaptation gains. A large makes the estimate react to noise and can excite unmodeled dynamics. Choose by scale: parameters in kg m and in N m need different gains.
- Expecting identification. A converged tracking error does not mean a converged parameter estimate. Do not use as an identified model unless the trajectory was persistently exciting.
- Discrete time. The proof is for continuous time. A slow control rate or a crude integration of line L6 adds errors that the proof does not cover.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/slotine-li-adaptive-control/. The authors are listed in prov/RN7MPK.jsonl.
"""The Slotine-Li adaptive controller, with a planar 2R arm to test it.
The arm obeys M(q) q'' + C(q, q') q' + g(q) = tau, and the dynamics are
linear in a parameter vector: M(q) a + C(q, q') v + g(q) = Y(q, q', v, a) pi.
The law uses the reference velocity qr' = qd' - Lambda (q - qd) and the
sliding variable s = q' - qr':
tau = Y(q, q', qr', qr'') pi_hat - Kd s, pi_hat' = -Gamma Y^T s.
C must be the Christoffel matrix, so that M' - 2 C is skew-symmetric.
Matrices are lists of rows and vectors are lists. Only the standard library.
"""
import math
GRAVITY = 9.81
class TwoLinkArm:
"""Planar 2R arm in a vertical plane, with point masses at the link ends.
The parameter vector is pi = (a1, a2, a3, b1, b2) with
a1 = (m1 + m2) l1^2 + m2 l2^2, a2 = m2 l1 l2, a3 = m2 l2^2,
b1 = (m1 + m2) l1 g and b2 = m2 l2 g.
"""
def __init__(self, m1=1.0, m2=1.0, l1=1.0, l2=1.0, grav=GRAVITY):
self.m1, self.m2, self.l1, self.l2, self.grav = m1, m2, l1, l2, grav
def params(self):
m1, m2, l1, l2, gr = self.m1, self.m2, self.l1, self.l2, self.grav
return [
(m1 + m2) * l1 * l1 + m2 * l2 * l2,
m2 * l1 * l2,
m2 * l2 * l2,
(m1 + m2) * l1 * gr,
m2 * l2 * gr,
]
def mass(self, q):
a1, a2, a3, _, _ = self.params()
c2 = math.cos(q[1])
return [[a1 + 2 * a2 * c2, a3 + a2 * c2], [a3 + a2 * c2, a3]]
def coriolis(self, q, qd):
h = self.params()[1] * math.sin(q[1])
return [[-h * qd[1], -h * (qd[0] + qd[1])], [h * qd[0], 0.0]]
def gravity(self, q):
_, _, _, b1, b2 = self.params()
c1, c12 = math.cos(q[0]), math.cos(q[0] + q[1])
return [b1 * c1 + b2 * c12, b2 * c12]
def accel(self, q, qd, tau):
"""Solve M q'' = tau - C q' - g for q''."""
m = self.mass(q)
c = self.coriolis(q, qd)
g = self.gravity(q)
r = [tau[i] - c[i][0] * qd[0] - c[i][1] * qd[1] - g[i] for i in range(2)]
return solve2(m, r)
def regressor(q, qd, v, a):
"""Y(q, q', v, a) with Y pi = M(q) a + C(q, q') v + g(q) for the 2R arm."""
c1, c2 = math.cos(q[0]), math.cos(q[1])
s2 = math.sin(q[1])
c12 = math.cos(q[0] + q[1])
row1 = [
a[0],
2 * c2 * a[0] + c2 * a[1] - s2 * qd[1] * v[0] - s2 * (qd[0] + qd[1]) * v[1],
a[1],
c1,
c12,
]
row2 = [0.0, c2 * a[0] + s2 * qd[0] * v[0], a[0] + a[1], 0.0, c12]
return [row1, row2]
def solve2(a, b):
"""Solve the 2 by 2 system a x = b by Cramer's rule."""
det = a[0][0] * a[1][1] - a[0][1] * a[1][0]
if det == 0.0:
raise ValueError("singular 2 by 2 matrix")
return [(b[0] * a[1][1] - a[0][1] * b[1]) / det, (a[0][0] * b[1] - b[0] * a[1][0]) / det]
def slotine_li(q, qd, q_des, qd_des, qdd_des, pi_hat, lam, kd, gamma):
"""Return (tau, pi_hat_dot) of the Slotine-Li law.
lam, kd and gamma are lists of diagonal gains. pi_hat is the current
estimate of the parameter vector.
"""
n = len(q)
qt = [q[i] - q_des[i] for i in range(n)] # @line L1
qr_d = [qd_des[i] - lam[i] * qt[i] for i in range(n)] # @line L2
qr_dd = [qdd_des[i] - lam[i] * (qd[i] - qd_des[i]) for i in range(n)] # @line L3
s = [qd[i] - qr_d[i] for i in range(n)] # @line L4
y = regressor(q, qd, qr_d, qr_dd) # @line L5
p = len(pi_hat)
tau = [sum(y[i][k] * pi_hat[k] for k in range(p)) - kd[i] * s[i] for i in range(n)]
pi_dot = [-gamma[k] * sum(y[i][k] * s[i] for i in range(n)) for k in range(p)] # @line L6
return tau, pi_dot # @line L7
def lyapunov(arm, q, qd, q_des, qd_des, pi_hat, lam, gamma):
"""V = 1/2 s^T M s + 1/2 (pi_hat - pi)^T Gamma^(-1) (pi_hat - pi)."""
s = [qd[i] - qd_des[i] + lam[i] * (q[i] - q_des[i]) for i in range(2)]
m = arm.mass(q)
pi = arm.params()
kin = 0.5 * sum(s[i] * m[i][j] * s[j] for i in range(2) for j in range(2))
est = 0.5 * sum((pi_hat[k] - pi[k]) ** 2 / gamma[k] for k in range(len(pi)))
return kin + est
def rk4_step(f, t, x, dt):
"""One classical Runge-Kutta step for x' = f(t, x)."""
k1 = f(t, x)
k2 = f(t + dt / 2, [x[i] + dt / 2 * k1[i] for i in range(len(x))])
k3 = f(t + dt / 2, [x[i] + dt / 2 * k2[i] for i in range(len(x))])
k4 = f(t + dt, [x[i] + dt * k3[i] for i in range(len(x))])
return [x[i] + dt / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]) for i in range(len(x))]
def closed_loop(arm, traj, lam, kd, gamma):
"""Right side of the closed loop on the state (q, q', pi_hat)."""
def f(t, x):
q, qd, pi_hat = x[:2], x[2:4], x[4:]
qs, qds, qdds = traj(t)
tau, pi_dot = slotine_li(q, qd, qs, qds, qdds, pi_hat, lam, kd, gamma)
return qd + arm.accel(q, qd, tau) + pi_dot
return f
def simulate(arm, traj, q0, qd0, pi0, lam, kd, gamma, dt, steps):
"""Simulate with RK4. Return the list of (t, q, qd, pi_hat)."""
f = closed_loop(arm, traj, lam, kd, gamma)
x = list(q0) + list(qd0) + list(pi0)
out = [(0.0, x[:2], x[2:4], x[4:])]
for k in range(steps):
x = rk4_step(f, k * dt, x, dt)
out.append(((k + 1) * dt, x[:2], x[2:4], x[4:]))
return out
test_slotine_li_adaptive_control.py 116 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/slotine-li-adaptive-control/. The authors are listed in prov/RN7MPK.jsonl.
import math
import random
from slotine_li_adaptive_control import (
TwoLinkArm,
closed_loop,
lyapunov,
regressor,
rk4_step,
simulate,
slotine_li,
)
LAM = [5.0, 5.0]
KD = [20.0, 20.0]
GAMMA = [1.0, 1.0, 1.0, 20.0, 20.0]
def traj(t):
q = [0.5 * math.sin(t), 0.3 * math.cos(2 * t)]
qd = [0.5 * math.cos(t), -0.6 * math.sin(2 * t)]
qdd = [-0.5 * math.sin(t), -1.2 * math.cos(2 * t)]
return q, qd, qdd
def test_regressor_matches_model():
rng = random.Random(3)
for _ in range(20):
arm = TwoLinkArm(*[rng.uniform(0.5, 2.0) for _ in range(4)])
q, qd, v, a = ([rng.uniform(-3, 3) for _ in range(2)] for _ in range(4))
y = regressor(q, qd, v, a)
pi = arm.params()
m, c, g = arm.mass(q), arm.coriolis(q, qd), arm.gravity(q)
for i in range(2):
want = sum(m[i][j] * a[j] + c[i][j] * v[j] for j in range(2)) + g[i]
assert abs(sum(y[i][k] * pi[k] for k in range(5)) - want) < 1e-12
def test_tracking_with_wrong_parameters_and_energy_balance():
arm = TwoLinkArm()
pi0 = [0.5 * p for p in arm.params()]
dt = 4e-3
out = simulate(arm, traj, [0.2, 0.1], [0.0, 0.0], pi0, LAM, KD, GAMMA, dt, 2500)
vs, ws = [], []
for t, q, qd, ph in out:
qs, qds, _ = traj(t)
vs.append(lyapunov(arm, q, qd, qs, qds, ph, LAM, GAMMA))
s = [qd[i] - qds[i] + LAM[i] * (q[i] - qs[i]) for i in range(2)]
ws.append(sum(KD[i] * s[i] ** 2 for i in range(2)))
for k in range(len(vs) - 1):
assert vs[k + 1] <= vs[k] + 1e-9
# V(0) - V(T) equals the integral of s^T Kd s (Simpson's rule).
inner = sum((4 if k % 2 else 2) * ws[k] for k in range(1, len(ws) - 1))
dissipated = dt / 3 * (ws[0] + inner + ws[-1])
assert abs((vs[0] - vs[-1]) - dissipated) < 1e-3
t, q, _, _ = out[-1]
qs = traj(t)[0]
assert max(abs(q[i] - qs[i]) for i in range(2)) < 0.02
def test_lyapunov_derivative_formula():
arm = TwoLinkArm(m1=0.8, m2=1.3, l1=1.1, l2=0.7)
f = closed_loop(arm, traj, LAM, KD, GAMMA)
rng = random.Random(9)
for _ in range(10):
t = rng.uniform(0, 5)
x = [rng.uniform(-2, 2) for _ in range(4)] + [p * rng.uniform(0.3, 1.7) for p in arm.params()]
h = 1e-5
xp, xm = rk4_step(f, t, x, h), rk4_step(f, t, x, -h)
def v(y, tt):
qs, qds, _ = traj(tt)
return lyapunov(arm, y[:2], y[2:4], qs, qds, y[4:], LAM, GAMMA)
dv = (v(xp, t + h) - v(xm, t - h)) / (2 * h)
qs, qds, _ = traj(t)
s = [x[2 + i] - qds[i] + LAM[i] * (x[i] - qs[i]) for i in range(2)]
want = -sum(KD[i] * s[i] ** 2 for i in range(2))
assert abs(dv - want) < 1e-4 * (1 + abs(want))
def test_exact_parameters_on_the_sliding_surface():
# With pi_hat = pi, Gamma = 0 and s(0) = 0, s stays 0 and q~ = q~(0) e^(-lambda t).
arm = TwoLinkArm()
qs, qds, _ = traj(0.0)
qt0 = [0.1, -0.2]
q0 = [qs[i] + qt0[i] for i in range(2)]
qd0 = [qds[i] - LAM[i] * qt0[i] for i in range(2)]
out = simulate(arm, traj, q0, qd0, arm.params(), LAM, KD, [0.0] * 5, 2e-3, 1000)
for t, q, _, _ in out[::100]:
qs = traj(t)[0]
for i in range(2):
assert abs((q[i] - qs[i]) - qt0[i] * math.exp(-LAM[i] * t)) < 1e-9
def test_set_point_does_not_identify_the_parameters():
arm = TwoLinkArm()
goal = [0.4, 0.6]
def hold(t):
return goal, [0.0, 0.0], [0.0, 0.0]
pi0 = [0.5 * p for p in arm.params()]
out = simulate(arm, hold, [0.0, 0.0], [0.0, 0.0], pi0, LAM, KD, GAMMA, 6e-3, 2500)
_, q, qd, ph = out[-1]
assert max(abs(goal[i] - q[i]) for i in range(2)) < 1e-3
# The inertial parameters a1, a2, a3 stop changing far from the truth.
pi = arm.params()
assert abs(ph[1] - pi[1]) > 1.0
_, _, _, ph_mid = out[1250]
assert max(abs(ph[k] - ph_mid[k]) for k in range(3)) < 1e-2
tau, _ = slotine_li(q, qd, goal, [0.0, 0.0], [0.0, 0.0], ph, LAM, KD, GAMMA)
assert all(math.isfinite(v) for v in tau)
History
Adaptive control of manipulators was an active topic in the mid-1980s. Craig, Hsu and Sastry published an adaptive computed-torque law in the International Journal of Robotics Research in 1987, after a conference version in 1986. In the same year and journal, Slotine and Li published their law, which uses the reference velocity and the skew symmetry of the dynamics, and needs no acceleration and no inverse of . Textbooks now present it as the main example of adaptive robot control and of passivity-based design.
References
- Jean-Jacques E. Slotine and Weiping Li, On the adaptive control of robot manipulators, The International Journal of Robotics Research 6(3), 1987, pages 49 to 59
- John J. Craig, Ping Hsu and S. Shankar Sastry, Adaptive control of mechanical manipulators, The International Journal of Robotics Research 6(2), 1987, pages 16 to 28
- Mark W. Spong, Seth Hutchinson and M. Vidyasagar, Robot Modeling and Control, second edition, Wiley, 2020, Chapter 9, Section 9.4 (passivity-based control) and Section 9.4.2 (passivity-based adaptive control)
- Bruno Siciliano, Lorenzo Sciavicco, Luigi Villani and Giuseppe Oriolo, Robotics, Modelling, Planning and Control, Springer, 2009, Chapter 8 (motion control, adaptive control)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag RN7MPK Edit this page History Report an error Markdown