08 Swarm Behaviors & Formations · #31 of 46

Potential Fields

Let the landscape do the steering

A raindrop has no map of the mountain. It has no plan, no waypoints, no sense of where the sea is. It just falls, and the slope of the rock does the rest. What if a robot could navigate exactly that mindlessly?

That is the whole trick of potential fields. Instead of computing a path, you sculpt a landscape: the goal is a valley, every obstacle is a hill, and the robot simply rolls downhill. No search, no plan, just a force at the robot's current position, recomputed and re-followed dozens of times a second. Here is that landscape, made of magnets.

Roll the marble

30 agents

Drag the attraction and repulsion sliders below and watch the swarm rearrange itself, then read the predictions and check them against what you see.

Try this:

  1. Pure repulsion. Crank attraction to zero. Every robot shoves every other away; they spread until they settle into a maximally-spaced ring. No structure, just personal space.
  2. Pure attraction. Now the reverse. They pull toward each other and collapse into one tight knot, useful right up until they're trying to occupy the same square millimetre.
  3. Find the balance. Mix the two. Somewhere in the middle, push and pull cancel at a preferred spacing and a stable formation crystallizes: close enough to stay a swarm, far enough not to collide.
  4. Strand them. Turn the noise down and watch a robot freeze short of the target, every nearby move feeling worse than standing still. That trap has a name, and it's the entire next lesson.

The point isn't the picture. It's that no robot in there knows the plan. Each one only feels the slope under its own feet.

Two forces, one rule

Give every point in space a number, call it the potential U(p)U(p), an energy. Make the goal low and the obstacles high. Then hand the robot one instruction it can follow forever:

a=Ua = -\nabla U

Accelerate down the steepest slope. The gradient U\nabla U points uphill toward higher energy; the minus sign turns the robot around and sends it toward the valley floor. That's it. The cleverness lives entirely in how you shape UU.

The standard recipe uses two opposite-tempered terms. Obstacles get a repulsive potential that blows up as you approach. Divide by distance, so it spikes near zero and fades to nothing far away:

Urep(d)=krepdpU_{\text{rep}}(d) = \frac{k_{\text{rep}}}{d^{\,p}}

with pp usually 2 or 3. The goal gets an attractive bowl that grows as you stray, like a spring pulling you back:

Uatt(d)=kattd2U_{\text{att}}(d) = k_{\text{att}}\, d^2

Sum them across every obstacle and goal, take the negative gradient, and the robot threads the gaps without ever being told the gaps exist.

Portrait of roboticist Oussama Khatib.
Oussama Khatib · 1951– Introduced the artificial potential field in 1985: the goal pulls, obstacles push, and the robot simply rolls downhill, fast enough to react in real time. read more →

Why swarms love it

For a single robot dodging a wall this is neat. For a swarm it's transformative, because the field is local and anonymous. Each robot treats its neighbours as little repulsive hills and the formation centre as an attractive bowl, then rolls. No leader, no message-passing, no global coordinator deciding who goes where.

That means the same handful of equations scale from three robots to three thousand without a rewrite: every agent is running the identical downhill rule, blind to the others' intentions. Lattices, escort rings, "keep this spacing" flocks: all of them are just different UU recipes with the same negative-gradient engine underneath.

The crack in the floor

Elegant, fast, scalable, and quietly fragile. The same blindness that makes the method beautiful is its undoing: a robot that only feels the slope under its feet can't tell a local valley from the global one. Park it in a dead-end pocket (a U-shaped obstacle, a cul-de-sac of repulsion) and every direction it can sense points uphill. So it stops, perfectly satisfied, perfectly stuck, perfectly wrong.

When exactly does a robot get stuck?

A robot freezes wherever the total force vanishes but it isn't actually home. Mathematically, that's a critical point of the potential: the gradient is zero and the curvature is positive in every direction:

U=0,2U0\nabla U = 0, \qquad \nabla^2 U \succ 0

The first condition says "no force, nowhere to roll." The second (a positive-definite Hessian) says "every nearby move costs energy": you're at the bottom of a bowl. The cruelty is that UU is non-convex: the attractive goal-bowl plus the repulsive obstacle-hills can sum to a surface with many bowls, only one of which is the goal. Gradient descent has no way to know which bowl it landed in; it has no memory and no horizon, only the slope right here.

This is the unavoidable tax on the method's simplicity. The fixes all amount to lending the robot a little foresight it doesn't naturally have: inject noise so it can rattle out of shallow traps, add a random kick when velocity dies but force lingers, or bolt on a wall-following heuristic that traces an obstacle's edge until the path reopens. Each is a patch on the same wound: a purely local rule can't see a global trap coming.

The noise-and-kick fixes are patches. There is also a principled cure, and it has a lovely physical origin.

Is there a potential with no false valleys at all?

Yes. The trick is to be picky about which fields you allow. A harmonic potential field is one that obeys Laplace's equation, the same one that governs steady heat flow, ideal fluids, and electrostatics in empty space:

2U=0\nabla^2 U = 0

Functions that satisfy this have a remarkable property called the maximum principle: they can only reach their extreme values on the boundary, never in the interior. In plain terms, no spurious bowl can form in open space. Set the obstacles and walls to high potential and the goal to low, solve Laplace's equation across the gap, and the only place the robot can come to rest is the goal itself. The local-minimum trap simply has nowhere to hide.

The catch is cost. The local rule "feel the slope, step" gets replaced by solving a partial differential equation over the whole free space, which is exactly the global computation potential fields were invented to avoid. The same idea, an artificial potential with no minima except the target, also goes by the name navigation function in the planning literature. And a third family sidesteps the problem from the other direction: sampling-based planners scatter random configurations and connect the survivors, so they never roll down any slope and never get trapped, at the price of giving up the smooth real-time feel.

Key takeaways

There is something almost philosophical in a potential field: a machine that navigates by feeling, not foresight, trusting the shape of the world to carry it home. Most of the time the slope is kind and the robot arrives looking downright clever.

And then one day it rolls confidently into a dead end, sits down in a valley that isn't the valley, and waits, content, blind, and going nowhere. That gap between a low point and the low point is where the next lesson lives.

full glossary →