Algorithmcore
Leader-follower formation control
Also called l-phi formation control.
Each follower keeps a set distance and bearing to its leader by feedback linearization of a point ahead of its axle, so the formation is a tree of such pairs.
- Solves
- Formation control
- Time
- O(k r) totalO(r) per_step
- Space
- O(r) extra
- Counts
- messages O(r) per_step
- Where
- k = the number of integration steps; r = the number of robots
- Model
- Real RAM
- Properties
- deterministiconlinenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jaydev P. Desai, James P. Ostrowski, Vijay Kumar, 2001
Leader-follower formation control builds a formation of wheeled robots from pairs. One robot, the root, drives freely. Each other robot, a follower, picks one leader and keeps a target separation and bearing to it, measured in the frame of the leader. The followers are unicycles, which cannot move sideways, so the law controls a point at a distance ahead of the wheel axle. For that point, the map from the inputs to the rates is invertible, and feedback linearization makes both errors decay exponentially for any motion of the leader. The heading of the follower is left as an internal state, and behind a leader that drives forward it converges to the heading of the leader. The robots form a tree, so the formation is set by pairs of targets.
In plain words
Think of ducklings following their mother. Each duckling does not look at the whole family. It picks one duck ahead of it and tries to stay at a fixed distance and at a fixed angle behind it, for example one step back and a little to the left. The first duck goes where it wants, and the rest of the line follows.
A wheeled robot cannot slide sideways, so it cannot fix both its distance and its angle directly with its own center. Instead it watches a point just in front of its wheels, which it can push in any direction by driving and turning. It steers that point to the right spot next to its leader. The body of the robot then lines up behind, as long as the leader keeps moving forward.
The problem
The model. There are unicycle robots with states in meters and radians, and inputs : , , . The robots form a directed tree: robot 1 is the root, and every other robot has one leader . A follower controls its point , with . It measures the separation and the bearing , defined by
so is measured from the heading of the leader, and means straight behind. It also needs the relative heading , and it receives the inputs and of its leader, one message per follower and per step. Time is continuous. The sign conventions of Desai, Ostrowski and Kumar differ in details; the page uses the conventions above, and the proof derives every formula from them.
Input. The tree, the targets of every follower, the gains , the offset , the initial states, and the inputs of the root as a function of time.
Output. The trajectories, with and for every follower.
How it differs from close pages. In distance-based formation control the graph is rigid and undirected, each robot reacts to several neighbors, and convergence is local. Here the graph is a tree, the root is not influenced by anyone, and the errors decay exponentially from any start with , but an error of a leader passes on to all robots below it. The name "l-phi" in the alias refers to this separation-bearing pair; Desai, Ostrowski and Kumar write it with .
The algorithm
LEADER-FOLLOWER(tree, targets, α1, α2, d, states, root inputs, T, h)- 1
for each step of length h until time T do - 2
for each follower F in tree order, with leader L, do - 3
measure l, ψ and γ = θ_L + ψ - θ_F; receive v_L and ω_L - 4
a ← α1 (l_d - l) + v_L cos ψ ▷ wanted rate of l, plus the motion of the leader - 5
b ← l (α2 (ψ_d - ψ) + ω_L) - v_L sin ψ ▷ the same for ψ, times l - 6
v_F ← a cos γ - b sin γ - 7
ω_F ← (a sin γ + b cos γ) / d - 8
move every robot with its inputs for time h - 9
return the states
Lines L4 to L7 invert the kinematics of the pair. The rates of and depend on through a matrix with determinant , and lines L6 and L7 apply its inverse to the wanted rates. "Tree order" in line L2 means that a leader gets its inputs before its followers, so each follower can use the current and . The angle difference in line L5 is wrapped to . The implementation integrates the closed loop with the classic fourth order Runge-Kutta method and a fixed step.
Example
One evaluation by hand. The leader stands at the origin with and drives straight with m/s. The follower stands at with , and m, so . The target is m and , which is behind the leader and to its left, and per second. Then , and . Line L4 gives , and line L5 gives . So m/s and rad/s. The follower drives fast and turns hard to the left, toward its spot.
The run. With RK4 and s, and follow and :
| (s) | (m) | (rad) | (rad) | follower (m) |
|---|---|---|---|---|
| 0 | 1.9647 | 2.8843 | 0 | |
| 0.5 | 1.5851 | 2.6765 | -0.1830 | |
| 1 | 1.3549 | 2.5505 | -0.0419 | |
| 2 | 1.1306 | 2.4277 | 0.0359 | |
| 4 | 1.0177 | 2.3659 | 0.0123 | |
| 8 | 1.0003 | 2.3564 | 0.0003 |
At s the leader is at , the follower at , and : 1 m away at 135 degrees from the heading of the leader, with the same heading. The heading error first grows, because the follower turns to move its point, and then decays at the rate per second of the zero dynamics.
Zero dynamics. If the follower starts exactly at its target and with a heading error , the errors stay zero, and obeys , so . The tests check this closed form within for , and .
Correctness
The proof derives the rates and of the pair from the unicycle model, and shows that lines L6 and L7 invert them, because the input matrix has determinant . The closed loop is then and , so both errors decay exponentially for any motion of the leader, and stays positive. On a tree, the same holds for every edge. The heading of the follower is the internal state. On the set where the outputs are at their targets, behind a leader that drives straight forward, it obeys and converges to zero from every . The stability of the internal dynamics from other starts and for turning leaders is the analysis of Desai, Ostrowski and Kumar, and the proof does not repeat it.
Proof: The separation-bearing law makes the separation and bearing errors of each follower decay exponentially, and the heading error decays behind a straight leaderfull
Each robot is a unicycle with state and inputs : , , . A follower with leader controls its point with . The separation and the bearing are defined by , and . The follower knows and . Line numbers refer to the pseudocode on the leader-follower formation control page.
Lemma 1 (kinematics of the separation and bearing).
Proof. Let and . Then , so and . Also and . With and , the dot products are , , , and in the normal direction , and . So and . Finally .
Lemma 2 (the inputs invert the kinematics). With and from lines L4 and L5, the inputs of lines L6 and L7 give and .
Proof. Line L6 gives , and line L7 gives . This is the rotation of by , so its inverse rotation gives back : , and . The map from to has the matrix , whose determinant is , so the inversion is possible exactly because and .
Theorem 1 (exponential decay of the output errors). Let , , , and . For any leader inputs, the closed loop gives
Proof. By Lemmas 1 and 2, and , as long as . These are linear equations with the stated solutions. The solution for is a convex combination of and for every , so it stays positive, and the formulas hold for all . The bearing error keeps its sign and shrinks, so it stays in and the wrapping of angles in line L5 never changes it.
Theorem 2 (trees of followers). Let the robots form a directed tree in which each follower has one leader, and let each follower run the law with the actual inputs of its leader. Then the separation and bearing errors of every edge decay as in Theorem 1, whatever the root does.
Proof. Theorem 1 holds for any leader inputs, so it applies to each edge on its own, whether the leader is the root or another follower.
Lemma 3 (zero dynamics behind a straight leader). Let the leader move straight, with constant and , and let the follower start with and . Then the heading error satisfies , and . So for every , and the follower ends with the heading of the leader.
Proof. By Theorem 1, and for all . Then lines L4 and L5 give and , and line L7 gives , since . So . For with , , which gives the formula, and the case is an equilibrium.
What is not proved here. Lemma 3 is the motion on the set where the outputs are already at their targets, the zero dynamics. When the outputs start away from their targets, the heading error is driven also by terms that decay exponentially, and the stability of that cascade for a leader that moves straight, or with bounded turning, is the subject of the analysis of Desai, Ostrowski and Kumar (2001). That analysis, and the case of a leader that moves backward (), where the heading error grows, are not proved here.
Complexity
- Per step. Each follower does work and receives one message with , so a step costs operations in the real RAM model and messages. The tree is fixed, so there is no other communication.
- Rate, proved. The separation and bearing errors decay as and for every follower, independent of the depth of the tree.
- Propagation. Errors in the targets do not decay down the tree: a follower at depth is placed by pairs of targets, so its position error relative to the root is the sum of terms, and a disturbance of the root reaches every robot. This is a structural property, not a bound in the source.
Properties
- Exponential tracking of separation and bearing, for any motion of the leader, as long as and .
- Uses one leader per follower. The graph is a directed tree, so the sensing load is one neighbor per robot.
- Needs the inputs of the leader. The law uses and ; a follower that only sees its leader must estimate them.
- Internal heading dynamics. They are stable behind a leader that moves forward, and unstable when the leader moves backward.
- Deterministic and continuous time. In a sampled implementation the step must be short compared with and .
Variants and improvements
- Separation-separation (l-l) control. A follower keeps two distances to two leaders, which places it by two circles instead of a distance and an angle (Desai, Ostrowski and Kumar 2001).
- Switching formations. The tree and the targets can change, for example to pass a narrow gap in a column and to spread out after it.
- Estimation of the leader motion. Observers or sliding mode terms replace the received and when there is no communication.
- Virtual leaders. The root can be a virtual point that moves along a planned path, so that every real robot is a follower.
- Distance-based and consensus-based laws. These spread the work over an undirected graph and avoid a single point of failure, at the cost of global or local convergence conditions; see formation control.
When to use it
Use leader-follower control for wheeled robots that must drive in a column, a wedge or a line behind one robot that a person or a planner controls, and when each robot can see one other robot and receive its speed and turn rate. It is simple to tune and has an exact exponential rate. Use distance-based formation control when no robot should depend on a single other robot, and consensus-based control when the robots share a compass.
Pitfalls
- Small offset. The input is divided by . A small gives large turn rates, as the 7.58 rad/s in the example shows, and real robots saturate.
- Reverse driving. When the leader drives backward the internal heading dynamics are unstable, and the follower can spin even while and look correct.
- Bearing near the wrap. If is near , the measured bearing jumps between and . Wrap the difference , not alone, as line L5 does.
- Error propagation. A long chain amplifies disturbances of the root, so the robots far down the tree see larger transients.
- Collisions. The law keeps the point at its target, but nothing stops two followers or a follower and its leader from touching during the transient.
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/leader-follower-formation-control/. The authors are listed in prov/P77YSV.jsonl.
"""Separation-bearing (l-psi) leader-follower control of unicycle robots.
A robot has the state (x, y, theta) and the inputs (v, omega), with
x' = v cos(theta), y' = v sin(theta), theta' = omega.
The follower controls its point P_F = (x_F + d cos theta_F, y_F + d sin theta_F),
at the distance d > 0 ahead of its wheel axle. The separation l and the bearing
psi are defined by P_F - p_L = l (cos(theta_L + psi), sin(theta_L + psi)), so psi
is measured from the heading of the leader. With gamma = theta_L + psi - theta_F,
l' = v_F cos(gamma) + d omega_F sin(gamma) - v_L cos(psi)
psi' = (v_L sin(psi) - v_F sin(gamma) + d omega_F cos(gamma)) / l - omega_L.
The control below makes l' = a1 (l_d - l) and psi' = a2 (psi_d - psi).
"""
import math
from typing import Callable, Sequence
State = tuple # (x, y, theta)
def wrap(a: float) -> float:
"""Wrap an angle to [-pi, pi)."""
return (a + math.pi) % (2 * math.pi) - math.pi
def separation_bearing(leader: State, follower: State, d: float) -> tuple[float, float, float]:
"""Return (l, psi, gamma) of the follower with respect to its leader."""
xl, yl, tl = leader
xf, yf, tf = follower
px, py = xf + d * math.cos(tf) - xl, yf + d * math.sin(tf) - yl
l = math.hypot(px, py)
psi = wrap(math.atan2(py, px) - tl)
return l, psi, wrap(tl + psi - tf)
def follower_input(leader: State, vl: float, wl: float, follower: State, ld: float, psid: float,
d: float, a1: float, a2: float) -> tuple[float, float]:
"""The l-psi control law of one follower. Needs d > 0 and l > 0."""
if d <= 0:
raise ValueError("the offset d must be positive")
l, psi, g = separation_bearing(leader, follower, d) # @line L3
a = a1 * (ld - l) + vl * math.cos(psi) # @line L4
b = l * (a2 * wrap(psid - psi) + wl) - vl * math.sin(psi) # @line L5
v = a * math.cos(g) - b * math.sin(g) # @line L6
w = (a * math.sin(g) + b * math.cos(g)) / d # @line L7
return v, w
def unicycle_rate(s: State, v: float, w: float) -> tuple[float, float, float]:
return v * math.cos(s[2]), v * math.sin(s[2]), w
def all_inputs(states: Sequence[State], parent: Sequence[int], targets: Sequence[tuple],
root_input: Callable[[float], tuple[float, float]], t: float, d: float,
a1: float, a2: float) -> list[tuple[float, float]]:
"""Inputs of all robots. Robot 0 is the root; parent[i] < i for every follower i >= 1."""
u = [root_input(t)]
for i in range(1, len(states)): # @line L2
p = parent[i]
ld, psid = targets[i]
u.append(follower_input(states[p], u[p][0], u[p][1], states[i], ld, psid, d, a1, a2))
return u
def simulate(states0: Sequence[State], parent: Sequence[int], targets: Sequence[tuple],
root_input: Callable[[float], tuple[float, float]], t_end: float, h: float,
d: float = 0.1, a1: float = 1.0, a2: float = 1.0) -> list[list[float]]:
"""Integrate the closed loop of a leader-follower tree with RK4 and fixed step h."""
s = [list(map(float, q)) for q in states0]
steps = max(1, round(t_end / h))
h = t_end / steps
t = 0.0
def f(st, tt):
u = all_inputs(st, parent, targets, root_input, tt, d, a1, a2)
return [unicycle_rate(q, *ui) for q, ui in zip(st, u)]
def add(st, k, c):
return [[q[j] + c * kq[j] for j in range(3)] for q, kq in zip(st, k)]
for _ in range(steps): # @line L1
k1 = f(s, t)
k2 = f(add(s, k1, h / 2), t + h / 2)
k3 = f(add(s, k2, h / 2), t + h / 2)
k4 = f(add(s, k3, h), t + h)
s = [[q[j] + h / 6 * (a[j] + 2 * b[j] + 2 * c[j] + e[j]) for j in range(3)] # @line L8
for q, a, b, c, e in zip(s, k1, k2, k3, k4)]
t += h
return s # @line L9
test_leader_follower_formation_control.py 106 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/leader-follower-formation-control/. The authors are listed in prov/P77YSV.jsonl.
import math
import random
import pytest
from leader_follower_formation_control import (
follower_input,
separation_bearing,
simulate,
unicycle_rate,
wrap,
)
def test_kinematics_match_finite_differences() -> None:
# l' and psi' from the formulas against central differences of the geometry
rng = random.Random(1)
d, h = 0.2, 1e-6
for _ in range(50):
sl = (rng.uniform(-2, 2), rng.uniform(-2, 2), rng.uniform(-3, 3))
sf = (sl[0] + rng.uniform(-3, 3), sl[1] + rng.uniform(-3, 3), rng.uniform(-3, 3))
vl, wl, vf, wf = (rng.uniform(-1, 1) for _ in range(4))
l, psi, g = separation_bearing(sl, sf, d)
if l < 0.3 or abs(abs(psi) - math.pi) < 0.1:
continue
def at(c):
a = [p + c * q for p, q in zip(sl, unicycle_rate(sl, vl, wl))]
b = [p + c * q for p, q in zip(sf, unicycle_rate(sf, vf, wf))]
return separation_bearing(a, b, d)
lp, pp, _ = at(h)
lm, pm, _ = at(-h)
dl = (lp - lm) / (2 * h)
dpsi = wrap(pp - pm) / (2 * h)
assert abs(dl - (vf * math.cos(g) + d * wf * math.sin(g) - vl * math.cos(psi))) < 1e-6
want = (vl * math.sin(psi) - vf * math.sin(g) + d * wf * math.cos(g)) / l - wl
assert abs(dpsi - want) < 1e-5
def test_hand_value() -> None:
# leader at the origin heading +x; follower at (-1, 0) heading +x; d = 0.5
# P_F = (-0.5, 0), so l = 0.5, psi = pi wrapped to -pi, gamma = -pi
l, psi, g = separation_bearing((0, 0, 0), (-1, 0, 0), 0.5)
assert abs(l - 0.5) < 1e-15 and abs(psi + math.pi) < 1e-15 and abs(g + math.pi) < 1e-15
v, w = follower_input((0, 0, 0), 1.0, 0.0, (-1, 0, 0), 0.5, -math.pi, 0.5, 2.0, 1.0)
# a = 2 (0.5 - 0.5) + cos(-pi) = -1, b = 0 - sin(-pi) = 0, v = a cos(-pi) = 1, w = 0
assert abs(v - 1.0) < 1e-12 and abs(w) < 1e-12
def test_errors_decay_like_exponentials() -> None:
rng = random.Random(2)
d, a1, a2 = 0.1, 1.5, 0.8
for _ in range(4):
leader = (0.0, 0.0, rng.uniform(-1, 1))
follower = (rng.uniform(-3, -1), rng.uniform(-1, 1), rng.uniform(-0.5, 0.5))
ld, psid = 1.0, 2.5
l0, psi0, _ = separation_bearing(leader, follower, d)
def root(t):
return 0.5, 0.2 * math.sin(t)
for t in (0.5, 2.0):
s = simulate([leader, follower], [-1, 0], [None, (ld, psid)], root, t, 0.002, d, a1, a2)
l, psi, _ = separation_bearing(s[0], s[1], d)
assert abs(l - (ld + (l0 - ld) * math.exp(-a1 * t))) < 1e-6
assert abs(wrap(psi - psid) - wrap(psi0 - psid) * math.exp(-a2 * t)) < 1e-6
def test_internal_dynamics_closed_form() -> None:
# Start at the target l and psi with a heading error e0, leader straight at v_L.
# Then theta_L - theta_F = e obeys e' = -(v_L / d) sin e, so tan(e/2) = tan(e0/2) exp(-v_L t / d).
d, vl, ld, psid = 0.25, 0.4, 1.0, math.pi * 0.8
for e0 in (0.5, 2.0, -2.8):
tf = -e0
px, py = ld * math.cos(psid), ld * math.sin(psid)
follower = (px - d * math.cos(tf), py - d * math.sin(tf), tf)
for t in (1.0, 3.0):
s = simulate([(0.0, 0.0, 0.0), follower], [-1, 0], [None, (ld, psid)],
lambda _t: (vl, 0.0), t, 0.002, d, 1.0, 1.0)
e = wrap(s[0][2] - s[1][2])
want = 2 * math.atan(math.tan(e0 / 2) * math.exp(-vl * t / d))
assert abs(e - want) < 1e-6
def test_chain_of_three_reaches_formation() -> None:
# a column: robot 1 behind robot 0, robot 2 behind robot 1, leader drives straight
d = 0.1
targets = [None, (1.0, math.pi), (1.0, math.pi)]
s0 = [(0.0, 0.0, 0.0), (-2.0, 0.7, 0.4), (-3.5, -0.6, -0.3)]
s = simulate(s0, [-1, 0, 1], targets, lambda _t: (0.5, 0.0), 30.0, 0.01, d, 1.0, 1.0)
for i in (1, 2):
l, psi, _ = separation_bearing(s[i - 1], s[i], d)
assert abs(l - 1.0) < 1e-6 and abs(wrap(psi - math.pi)) < 1e-6
assert abs(wrap(s[i][2] - s[0][2])) < 1e-3
# in a straight column with equal headings the axles are 1 m apart on the line y = 0
assert abs(s[1][1]) < 1e-3 and abs(s[2][1]) < 1e-3
assert abs((s[0][0] - s[1][0]) - (1.0 + d)) < 1e-3
def test_rejects_bad_offset() -> None:
with pytest.raises(ValueError):
follower_input((0, 0, 0), 1.0, 0.0, (-1, 0, 0), 1.0, math.pi, 0.0, 1.0, 1.0)
History
Desai, Ostrowski and Kumar (2001) modeled formations of nonholonomic robots as graphs of leader-follower pairs and gave two laws: one that keeps a separation and a bearing to one leader, and one that keeps two separations to two leaders. They used input-output linearization of an off-axis point and studied the stability of the remaining heading dynamics. Later work, summarized in the survey of Oh, Park and Ahn (2015), added estimation of the leader motion, switching between formations and undirected alternatives.
References
- Jaydev P. Desai, James P. Ostrowski and Vijay Kumar, Modeling and control of formations of nonholonomic mobile robots, IEEE Transactions on Robotics and Automation 17(6), 2001, pages 905 to 908 (the separation-bearing and separation-separation controllers, input-output linearization, and the stability of the internal dynamics)
- Kwang-Kyo Oh, Myoung-Chul Park and Hyo-Sung Ahn, A survey of multi-agent formation control, Automatica 53, 2015, pages 424 to 440 (leader-follower structures among the formation control methods)
- Mehran Mesbahi and Magnus Egerstedt, Graph Theoretic Methods in Multiagent Networks, Princeton University Press, 2010, Chapter 6, Formation Control (formations defined by relative states on a graph)
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 P77YSV Edit this page History Report an error Markdown