Algorithmadvanced
Elastic bands
Also called Quinlan-Khatib elastic band.
Deforms a path in real time under internal contraction forces and external repulsion from obstacles, keeping it short and safe.
- Solves
- Motion planning
- Time
- O(S m C) worst
- Space
- O(m) extra
- Where
- C = the time of one distance query; S = the number of sweeps; m = the largest number of bubbles during the run
- Model
- Real RAM
- Properties
- deterministicnot exactonlinenot randomized
- Evidence
- Proof sketchCode in 1 languages
An elastic band takes a free path from a global planner and keeps improving it while the robot moves. The path is a chain of bubbles: each bubble is a disc around a point of the path whose radius is the distance to the nearest obstacle, so it is free space. While neighbor bubbles overlap, the path through their centers is free of collision. In each sweep, every inner bubble feels a contraction force that pulls the band tight and a repulsion force that pushes it away from close obstacles, and moves only if it still overlaps its neighbors. New bubbles fill gaps, and bubbles that are not needed are removed. The band stays safe in a fixed scene, but it is a local method with no general convergence guarantee, and it can only bend the path, not find a new route.
In plain words
Think of a rubber band laid along a path between two pins, with soft balls threaded on it. Each ball is as large as the free space around it allows, and the band is safe while the balls touch each other. The band pulls itself tight, and obstacles push the balls away when they come close. A ball moves only if it still touches its neighbors afterwards. Where two balls are about to lose contact, a new ball goes between them; where a ball is not needed, it is taken out. When an obstacle moves a little, the band bends around it at once, with no new plan. When an obstacle moves fast or blocks the way, the band can break, and a planner must find a new path.
The problem
Input: a start and a goal in the plane, a distance function that gives the distance from to the nearest obstacle, and a band from the start to the goal that is valid: for every , and neighbors overlap,
Output: a valid band with the same ends that is shorter and keeps some distance from the obstacles. The obstacles can change between sweeps; the band must then be valid for the new scene before the next sweep. This page uses a point robot and disc obstacles, with . For a robot with a body, is the distance from the body to the obstacles, as returned by a distance query or read from a distance transform.
The algorithm
ELASTIC-BAND(b_0, …, b_m, ρ, S)- 1
for s ← 1 to S do - 2
for i ← 1 to m - 1 do ▷ inner bubbles only - 3
r ← ρ(b_i) - 4
f ← k_c (u(b_{i-1}) + u(b_{i+1})) + k_r max(0, ρ_0 - r) ∇ρ(b_i), minus its part along the band - 5
c ← b_i + h f with h = α min(r, 1), halving h at most `tries` times - 6
if ρ(c) ≥ ρ_min and c overlaps b_{i-1} and b_{i+1} then b_i ← c - 7
for each pair of neighbors a, b with ‖b - a‖ > 0.9 (ρ(a) + ρ(b)) do insert (a + b)/2 between them - 8
for each inner b_i with ‖b_{i+1} - b_{i-1}‖ < 0.5 (ρ(b_{i-1}) + ρ(b_{i+1})) do delete b_i - 9
return b
Here is the unit vector from toward the neighbor . The code uses , , , , and four tries.
Line L4 computes the force. The contraction part is the sum of the unit vectors toward the two neighbors; it is zero when the three points are on a line and points inward at a bend, so it straightens the band. The repulsion part pushes away from the nearest obstacle when it is closer than . The part of the force along the band is removed, because it would only slide bubbles along the band and bunch them up. This is a simple form of the forces; the original paper uses forces of the same kind, and other versions scale the contraction by the distance to the neighbors.
Line L5 scales the step by the radius of the bubble, so a bubble in open space moves far and a bubble near an obstacle moves a little. Line L6 is the safety test: the new bubble must be free and overlap both current neighbors. If the test fails, the step is halved, and after the last try the bubble stays where it was.
Line L7 inserts a bubble where two neighbors are close to losing contact. The midpoint of two overlapping bubbles always overlaps both, so this step needs no test (proof, Lemma 5). Line L8 removes a bubble whose two neighbors overlap well by themselves; this keeps the band short and the number of bubbles small.
Example
A point moves from to around one disc of radius at the origin. A global planner returned the polyline through and , which is resampled to 19 points at most apart. The table gives the band after each number of sweeps. The clearance of the path is sampled at 21 points on each segment; it is smaller than the smallest bubble, because a segment passes closer to the disc than its ends.
| sweeps | bubbles | length | smallest bubble | clearance of the path | highest point |
|---|---|---|---|---|---|
| 0 | 19 | 3.4439 | 0.400 | 0.400 | 0.900 |
| 1 | 10 | 2.9376 | 0.311 | 0.310 | 0.867 |
| 2 | 10 | 2.7305 | 0.292 | 0.288 | 0.811 |
| 3 | 10 | 2.6376 | 0.269 | 0.253 | 0.769 |
| 5 | 10 | 2.5780 | 0.235 | 0.217 | 0.737 |
| 10 | 10 | 2.5591 | 0.225 | 0.207 | 0.727 |
| 20 | 10 | 2.5579 | 0.225 | 0.207 | 0.727 |
In the first sweep the band drops from 19 to 10 bubbles, because the bubbles far from the disc are large and overlap well without their neighbors. After about twenty sweeps the band does not change at four decimals, and the band is valid after every sweep. The shortest path around the disc, made of two tangents and an arc on the disc, has length ; the band stays longer, because the repulsion holds it about away from the disc, where it balances the contraction. With the disc moved far away, the band becomes the straight segment of length with only its two ends.
Then a second disc of radius comes down at from height to height , with one sweep after each step. At a speed of per step the band bends away and stays valid at every step, with a smallest clearance of ; at per step the smallest clearance is . At per step, the band is already cut by the new disc when it reaches height , before the sweep can react. The guarantee holds only when the band is valid for the scene it is updated in.
Correctness
The proof shows that a valid band stays valid. A bubble contains no obstacle point, and two overlapping bubbles cover the segment between their centers, so the polyline of a valid band is free of collision. A move of line L6 is tested against the current neighbors. A midpoint inserted by line L7 always overlaps both neighbors, because the distance function changes by at most the distance moved. A deletion of line L8 happens only when the two new neighbors overlap. The ends never move. So in a fixed scene every sweep returns a valid band. Nothing is proved about convergence, about the length going down, or about reaching the shortest path; with moving obstacles, the band is safe only if it is valid for the new scene before the sweep.
Proof: Every sweep of the elastic band keeps a valid band valid, so the path through the bubble centers stays free of collisionfull
We use the notation of the page and of the code. The obstacles are closed discs with centers and radii , and
A band is a list of points . It is valid if for every and every two neighbors overlap, . The bubble of is the open disc with center and radius . The method gives no convergence guarantee, and this proof does not claim one. It proves that the band stays safe in a fixed scene.
Lemma 1: a bubble contains no obstacle point
Claim. If and , then lies outside every disc .
Proof. For every , , because .
Lemma 2: a valid band gives a free path
Claim. If and overlap, the segment from to lies in . So the polyline through the points of a valid band is free of collision.
Proof. Let and with . Then and . If , then . Otherwise and , so . With Lemma 1, no point of the polyline is in an obstacle.
Lemma 3: the distance function is 1-Lipschitz
Claim. for all .
Proof. Each function is 1-Lipschitz by the triangle inequality, and the minimum of 1-Lipschitz functions is 1-Lipschitz: if the minimum at is attained by , then , and the same holds with and exchanged.
Lemma 4: a move keeps the band valid
Claim. If the band is valid before line L5 handles point , it is valid afterwards.
Proof. Line L6 accepts a candidate only if and overlaps the current points and ; the test uses the current band, so a neighbor that moved earlier in the same sweep is tested at its new place. Only the two pairs that contain point change, and both are tested. If no candidate is accepted after the given number of halvings, point does not move.
Lemma 5: a midpoint insertion keeps the band valid
Claim. If and overlap and , then , overlaps , and overlaps .
Proof. Let ; then . By Lemma 3, and , so
Also , so and overlap; the same argument with and exchanged shows that and overlap.
Line L7 inserts at most one midpoint into each pair of neighbors, and each such pair overlaps after the moves (Lemma 4). So no test is needed for the insertion; the condition of line L7 only decides whether a new bubble is useful.
Lemma 6: a deletion keeps the band valid
Claim. If the band is valid and line L8 deletes point , the band is valid afterwards.
Proof. Line L8 deletes point only if with in the code. The radii are positive and , so and overlap. The deletion removes the two pairs that contain point and adds this one; the other pairs do not change. The loop then tests the new neighbors of the next point, so each deletion is tested on the current band.
Theorem
Claim. If the input band is valid for , then every call of update with the same returns a valid band with the same first and last point, and its polyline is free of collision. So elastic_band returns a valid band after any number of sweeps in a fixed scene.
Proof. Lines L2 to L6 move only the interior points, one at a time, and keep the band valid by Lemma 4. Line L7 keeps the first point and every old point and adds midpoints of overlapping pairs, so the band stays valid by Lemma 5. Line L8 deletes only interior points and keeps the band valid by Lemma 6. So the ends never change, and the result is valid. Lemma 2 gives a free polyline. Induction over the sweeps of line L1 gives the second sentence. Each sweep ends: the move loop runs at most tries tests per point, line L7 at most doubles the number of points, and every step of line L8 either deletes a point or advances .
Moving obstacles
The theorem needs a band that is valid for the scene used in the update. When the obstacles move between two updates, the old band may already cut a bubble of the new scene, and nothing in the update repairs that, because the tests of lines L6 and L8 assume overlap before the change. In practice the band stays valid when the obstacles move slowly compared with the radii of the bubbles: if every obstacle moves by at most , then drops by at most at every point, and the band stays valid as long as every pair of neighbors has an overlap margin larger than and every radius is larger than .
What is not proved
Nothing here says that the band converges, that its length goes down at every sweep, or that it reaches the shortest path of its homotopy class. The forces are rules of thumb: the contraction and the repulsion balance at a point that depends on the gains and on , and a different choice gives a different band. The moves are small compared with the bubbles, so in practice the band stays on the same side of each obstacle, and a band that goes around the wrong side stays there; this is a local method, and the proof above does not need or show more.
Complexity
One sweep with bubbles makes distance queries: a bounded number of tries per bubble in lines L5 and L6, and a constant number of queries per pair in lines L7 and L8. So one sweep costs , and sweeps cost with the largest number of bubbles during the run. Line L7 can at most double the number of bubbles in one sweep. The memory is .
There is no bound on the number of sweeps to reach a resting band. The twenty sweeps of the example are a measurement, not a bound. In practice the band runs a fixed number of sweeps per control cycle and never "finishes".
Properties
- Safe in a fixed scene. Every sweep keeps the band valid, so the path is always free of collision.
- Local. The band can only deform the path it has; it does not find a route on the other side of an obstacle.
- Reactive. A sweep is cheap, so it can run in every control cycle and follow slowly moving obstacles.
- Adaptive resolution. Bubbles are small and many near obstacles and big and few in open space.
- Deterministic. The same band and scene give the same result.
- No convergence guarantee. The resting band depends on the gains and on , and the band need not settle at all.
Variants and improvements
- Elastic strips. For mobile manipulators, the bubbles become protective volumes around the whole body of the robot along the path.
- Timed elastic band. Each point gets a time step as well, and the band is deformed by an optimizer with costs for time, velocity and acceleration; this is widely used as a local planner for mobile robots.
- Other forces. The contraction can depend on the distance to the neighbors, like a spring, and the repulsion can use a smooth function of , in the spirit of potential fields.
- Optimization view. Seen as gradient steps on length plus an obstacle cost, the band is close to CHOMP and other methods of trajectory optimization; the difference is the safety test of line L6 instead of a soft cost.
When to use it
Use an elastic band between a global planner and the controller, when the path must stay smooth and safe while obstacles move slowly and the robot cannot wait for a new plan. It is simple, cheap per cycle, and easy to reason about in a fixed scene. It does not replace a planner: when an obstacle blocks the band or moves fast, call a planner such as an RRT again. To smooth a path once, offline, random shortcutting or trajectory optimization is simpler. For velocity commands near moving obstacles, see the dynamic window approach.
Pitfalls
- Fast obstacles. The tests of lines L6 and L8 assume that the band is valid before the sweep. If an obstacle jumps onto the band between two sweeps, nothing repairs it; check the band against the new scene first and replan if it is cut.
- Step size. If the step of line L5 is too big, most candidates fail the test of line L6 and the band stalls; if it is too small, the band follows obstacles too slowly.
- Insertion and deletion thresholds. If the factor of line L8 is close to the factor of line L7, a bubble can be inserted and deleted again in every sweep. Keep them well apart, as and here.
- Gains are tuning. The gains , and the influence distance of line L4 are rules of thumb; they set how far from the obstacles the band rests, and other robots need other values.
- Distance quality. The safety argument needs a true lower bound on the distance in line L3. A distance that is too large, for example from a coarse grid, can let the band pass through an obstacle.
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/elastic-bands/. The authors are listed in prov/32ZJAX.jsonl.
"""Elastic bands with bubbles (Quinlan and Khatib) for a point robot in the plane.
The band is a list of bubble centers b_0, ..., b_m from the start to the
goal. The bubble at b is the open disc of radius rho(b), the distance from b
to the nearest obstacle, so every bubble is free of obstacles. The band is
valid when consecutive bubbles overlap:
|b_(i+1) - b_i| < rho(b_i) + rho(b_(i+1)) for every i.
Then the polyline through the centers lies inside the union of the bubbles
and is free of collision. Every operation below keeps a valid band valid:
a bubble moves only if the new bubble still overlaps both neighbors, a new
bubble is inserted at the midpoint of two overlapping bubbles (which always
works), and a bubble is deleted only if its two neighbors overlap.
Each interior bubble feels a contraction force, the sum of the unit vectors
toward its two neighbors, and a repulsion force k_r (rho_0 - rho) grad rho
when rho < rho_0. The component along the band is removed, and the bubble
moves by alpha * rho * f, so big bubbles in open space move far and small
bubbles near obstacles move little.
"""
import math
def disc_world(discs):
"""rho(p) = distance to the nearest disc, and its gradient."""
def rho(p):
best, grad = math.inf, (0.0, 0.0)
for ox, oy, r in discs:
dx, dy = p[0] - ox, p[1] - oy
dist = math.hypot(dx, dy)
d = dist - r
if d < best:
best = d
grad = (dx / dist, dy / dist) if dist > 0.0 else (0.0, 0.0)
return best, grad
return rho
def overlap(a, b, ra, rb):
return math.hypot(b[0] - a[0], b[1] - a[1]) < ra + rb
def is_valid(band, rho):
rs = [rho(b)[0] for b in band]
if min(rs) <= 0.0:
return False
return all(overlap(band[i], band[i + 1], rs[i], rs[i + 1]) for i in range(len(band) - 1))
def segment_clearance(band, rho, per=20):
"""Smallest distance to the obstacles along the polyline, sampled."""
best = math.inf
for i in range(len(band) - 1):
for j in range(per + 1):
a = j / per
p = (band[i][0] * (1 - a) + band[i + 1][0] * a, band[i][1] * (1 - a) + band[i + 1][1] * a)
best = min(best, rho(p)[0])
return best
def length(band):
return sum(math.hypot(band[i + 1][0] - band[i][0], band[i + 1][1] - band[i][1]) for i in range(len(band) - 1))
def force(band, i, rho, k_c, k_r, rho0):
b, prev, nxt = band[i], band[i - 1], band[i + 1]
f = [0.0, 0.0]
for q in (prev, nxt):
dx, dy = q[0] - b[0], q[1] - b[1]
d = math.hypot(dx, dy)
if d > 0.0:
f[0] += k_c * dx / d
f[1] += k_c * dy / d
r, g = rho(b)
if r < rho0:
f[0] += k_r * (rho0 - r) * g[0]
f[1] += k_r * (rho0 - r) * g[1]
tx, ty = nxt[0] - prev[0], nxt[1] - prev[1]
tn = math.hypot(tx, ty)
if tn > 0.0:
tx, ty = tx / tn, ty / tn
dot = f[0] * tx + f[1] * ty
f[0] -= dot * tx
f[1] -= dot * ty
return f
def update(band, rho, k_c=1.0, k_r=4.0, rho0=0.3, alpha=0.3, rho_min=1e-3, ins=0.9, dele=0.5, tries=4):
"""One sweep over the band: moves, then insertions, then deletions. Returns a new band."""
band = [tuple(b) for b in band]
for i in range(1, len(band) - 1): # @line L2
r = rho(band[i])[0] # @line L3
f = force(band, i, rho, k_c, k_r, rho0) # @line L4
step = alpha * min(r, 1.0)
for _ in range(tries):
cand = (band[i][0] + step * f[0], band[i][1] + step * f[1]) # @line L5
rc = rho(cand)[0]
if (rc >= rho_min and overlap(cand, band[i - 1], rc, rho(band[i - 1])[0])
and overlap(cand, band[i + 1], rc, rho(band[i + 1])[0])): # @line L6
band[i] = cand
break
step *= 0.5
out = [band[0]]
for i in range(1, len(band)): # @line L7
a, b = out[-1], band[i]
ra, rb = rho(a)[0], rho(b)[0]
if math.hypot(b[0] - a[0], b[1] - a[1]) > ins * (ra + rb):
out.append(((a[0] + b[0]) / 2.0, (a[1] + b[1]) / 2.0))
out.append(b)
band = out
i = 1
while i < len(band) - 1: # @line L8
a, c = band[i - 1], band[i + 1]
if math.hypot(c[0] - a[0], c[1] - a[1]) < dele * (rho(a)[0] + rho(c)[0]):
del band[i]
else:
i += 1
return band
def elastic_band(band, rho, sweeps=100, **kw):
"""Run several sweeps against a fixed scene. Returns the band and the lengths."""
lengths = [length(band)]
for _ in range(sweeps): # @line L1
band = update(band, rho, **kw)
lengths.append(length(band))
return band, lengths # @line L9
def polyline(points, step):
"""Resample a polyline so that consecutive points are at most step apart."""
out = [tuple(points[0])]
for a, b in zip(points, points[1:]):
n = max(1, math.ceil(math.hypot(b[0] - a[0], b[1] - a[1]) / step))
for j in range(1, n + 1):
out.append((a[0] + (b[0] - a[0]) * j / n, a[1] + (b[1] - a[1]) * j / n))
return out
test_elastic_bands.py 109 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/elastic-bands/. The authors are listed in prov/32ZJAX.jsonl.
import random
import unittest
from elastic_bands import (
disc_world,
elastic_band,
is_valid,
length,
overlap,
polyline,
segment_clearance,
update,
)
START = polyline([(-1.0, 0.0), (-0.8, 0.9), (0.8, 0.9), (1.0, 0.0)], 0.2)
class TestWorkedExample(unittest.TestCase):
def test_band_around_a_disc(self):
rho = disc_world([(0.0, 0.0, 0.5)])
self.assertTrue(is_valid(START, rho))
self.assertAlmostEqual(length(START), 3.4439, places=4)
band = START
for _ in range(20):
band = update(band, rho)
self.assertTrue(is_valid(band, rho))
self.assertAlmostEqual(length(band), 2.5579, places=3)
self.assertEqual(len(band), 10)
self.assertAlmostEqual(segment_clearance(band, rho), 0.2069, places=3)
self.assertAlmostEqual(max(p[1] for p in band), 0.7268, places=3)
self.assertEqual((band[0], band[-1]), (START[0], START[-1]))
def test_slow_obstacle_keeps_the_band_valid(self):
rho = disc_world([(0.0, 0.0, 0.5)])
band, _ = elastic_band(START, rho, sweeps=20)
y = 1.5
for _ in range(25):
y -= 0.03
world = disc_world([(0.0, 0.0, 0.5), (-0.4, y, 0.15)])
self.assertTrue(is_valid(band, world))
band = update(band, world)
self.assertTrue(is_valid(band, world))
self.assertGreater(segment_clearance(band, world), 0.05)
class TestEdgeCases(unittest.TestCase):
def test_free_space_gives_the_segment(self):
rho = disc_world([(0.0, 5.0, 0.1)])
band, lengths = elastic_band(START, rho, sweeps=10)
self.assertAlmostEqual(lengths[-1], 2.0, places=9)
self.assertEqual(band, [(-1.0, 0.0), (1.0, 0.0)])
def test_fast_obstacle_can_break_the_band(self):
# The guarantee is for a fixed scene: an obstacle that jumps can cut the band.
rho = disc_world([(0.0, 0.0, 0.5)])
band, _ = elastic_band(START, rho, sweeps=20)
broken = False
y = 1.5
while y > 0.75 and not broken:
y -= 0.1
world = disc_world([(0.0, 0.0, 0.5), (-0.4, y, 0.15)])
if not is_valid(band, world):
broken = True
else:
band = update(band, world)
self.assertTrue(broken)
def test_midpoint_of_overlapping_bubbles_overlaps_both(self):
rng = random.Random(1993)
checked = 0
while checked < 300:
discs = [(rng.uniform(-1, 1), rng.uniform(-1, 1), rng.uniform(0.05, 0.3)) for _ in range(3)]
rho = disc_world(discs)
a = (rng.uniform(-1.5, 1.5), rng.uniform(-1.5, 1.5))
b = (a[0] + rng.uniform(-0.5, 0.5), a[1] + rng.uniform(-0.5, 0.5))
ra, rb = rho(a)[0], rho(b)[0]
if ra <= 0 or rb <= 0 or not overlap(a, b, ra, rb):
continue
m = ((a[0] + b[0]) / 2, (a[1] + b[1]) / 2)
rm = rho(m)[0]
self.assertGreater(rm, 0.0)
self.assertTrue(overlap(a, m, ra, rm))
self.assertTrue(overlap(m, b, rm, rb))
checked += 1
class TestRandomized(unittest.TestCase):
def test_invariant_on_random_scenes(self):
rng = random.Random(7)
done = 0
while done < 4:
discs = [(rng.uniform(-0.7, 0.7), rng.uniform(-0.6, 0.4), rng.uniform(0.1, 0.3)) for _ in range(4)]
rho = disc_world(discs)
start = polyline([(-1.5, 0.0), (-1.5, 1.2), (1.5, 1.2), (1.5, 0.0)], 0.1)
if not is_valid(start, rho):
continue
band = start
for _ in range(30):
band = update(band, rho)
self.assertTrue(is_valid(band, rho))
self.assertGreater(segment_clearance(band, rho), 0.0)
self.assertLess(length(band), length(start))
done += 1
if __name__ == "__main__":
unittest.main()
History
Sean Quinlan and Oussama Khatib at Stanford introduced elastic bands at ICRA 1993, as a link between a global planner, which finds a path once, and a controller, which must react to obstacles in real time. Their bubbles are regions of free space found from distance information, and the band is deformed by internal contraction and external repulsion forces while new bubbles are added and old ones removed. Khatib and his students later extended the idea to whole-body motion of mobile manipulators as elastic strips, and the timed elastic band, which adds time to each point, became a common local planner in robot navigation software.
References
- Sean Quinlan and Oussama Khatib, Elastic bands: Connecting path planning and control, IEEE International Conference on Robotics and Automation (ICRA), 1993, vol. 2, 802-807, the whole paper (bubbles, the contraction and repulsion forces, and the insertion and deletion of bubbles)
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 32ZJAX Edit this page History Report an error Markdown