30% off your first 3 months

Get the deal

Obstacle avoidance with a potential field

by DuckyHelperNov 12, 20265 min read
Robotics

TL;DR:

  • A potential field makes the goal pull the robot and obstacles push it away. The robot moves in the direction of the sum of these forces.

  • It is simple and reacts quickly, but the robot can get stuck at a local minimum where the forces cancel before it reaches the goal.

  • Treat it as a local, reactive method, and combine it with a global planner for real tasks.

Imagine the floor is a hillside. The goal sits at the bottom of a valley, and each obstacle is a hill. Drop a ball, and it rolls toward the goal and around the hills. A potential field makes a robot behave like that ball. It needs no map search, just a little arithmetic at each step.

What it does on a robot

Instead of planning a whole path, the robot computes one force vector at its current position and moves a small step in that direction, then repeats. The force is the sum of two parts: an attractive force toward the goal and a repulsive force away from each nearby obstacle. It is fast, easy to code and reacts immediately when something moves.

The math

Let the robot be at position q and the goal at q_goal.

Attractive force (a spring toward the goal): F_att = k_a × (q_goal − q). The farther away, the stronger it pulls.

Repulsive force (zero beyond a range ρ₀, rising steeply near the obstacle): for an obstacle at distance ρ ≤ ρ₀,

|F_rep| = k_r × (1/ρ − 1/ρ₀) × (1/ρ²)

pointing directly away from the obstacle. Outside ρ₀, there is no force. The total is the sum: F = F_att + ΣF_rep. The robot drives in the direction of F.

Worked example: a robot pulled to a goal and pushed from walls

Let k_a = 1, k_r = 20 and ρ₀ = 2.0 m. The robot is at (1, 1) and the goal at (5, 4). An obstacle is at (2, 2).

  1. Attractive force: 1 × (5 − 1, 4 − 1) = (4, 3), with magnitude 5.

  2. Distance to the obstacle: ρ = √((1−2)² + (1−2)²) = √2 = 1.414 m. This is inside ρ₀, so it repels.

  3. Repulsive magnitude: 20 × (1/1.414 − 1/2.0) × (1/1.414²) = 20 × (0.7071 − 0.5) × 0.5 = 20 × 0.2071 × 0.5 = 2.071.

  4. Direction away from the obstacle: (q − obstacle) / ρ = (−1, −1) / 1.414 = (−0.7071, −0.7071). So F_rep = 2.071 × (−0.7071, −0.7071) = (−1.464, −1.464).

  5. Total: F = (4 − 1.464, 3 − 1.464) = (2.536, 1.536).

The robot still moves toward the goal, but it is deflected: the direction angle is atan2(1.536, 2.536) = 31.2°, compared with atan2(3, 4) = 36.9° straight at the goal. The obstacle bends the path away from it, to the lower right.

Check the numbers: 2.071 × 0.7071 = 1.464, and 4 − 1.464 = 2.536, 3 − 1.464 = 1.536. ✓

Local minima: where the forces cancel

Now put the robot, the obstacle and the goal on one line: robot at (0, 0), obstacle at (2, 0), goal at (5, 0). The robot moves along the x-axis. At position x:

  • Attractive: 5 − x (forward).

  • Repulsive: with ρ = 2 − x, the magnitude is 20 × (1/ρ − 0.5) / ρ² (backward).

Compute a few points:

x (m)

ρ (m)

Attractive

Repulsive

Net

0.5

1.5

4.50

1.48

+3.02 (forward)

0.77

1.23

4.23

4.14

+0.09

0.78

1.22

4.22

4.30

−0.08

1.0

1.0

4.00

10.0

−6.0 (backward)

The net force changes sign between x = 0.77 and x = 0.78. At about x ≈ 0.77 m the forces cancel: the robot stops 1.2 m short of the obstacle and 4.2 m short of the goal. It is stuck at a local minimum of the field: any small motion forward is pushed back, and any motion backward is pulled forward again.

In this exact line-up the force has no sideways part, so the robot has no reason to turn. A tiny sideways nudge (noise, an uneven floor) usually lets it slide off, but U-shaped walls make deep traps with no easy way out.

Where it goes wrong

  • Local minima. The best-known problem, as above. Common fixes: add random motion when stuck, follow the wall, or use a navigation function that has no local minima (harder to build).

  • Oscillation. In narrow corridors the repulsive forces from both walls push the robot back and forth.

  • Goals near obstacles. The repulsion can prevent the robot from reaching a goal that is close to an obstacle.

  • Gain tuning. Too strong a repulsion makes the robot timid. Too weak and it hits the obstacle.

  • Speed. The force should set a direction, with a speed limit that falls near obstacles. A robot cannot stop instantly.

  • Noisy sensing. Obstacle positions from a distance sensor jitter, so the force vector jitters. Smooth the readings (see sensor noise and how to smooth it).

Safety: A reactive avoider is a convenience, not a safety system. Do not rely on it to stop a robot near people. Keep a hardware emergency stop, limit the maximum speed, and test in an open space with soft obstacles first. A robot that gets stuck at a local minimum can also start moving unpredictably when it is nudged free.

How real robots use it

Potential fields are used as the local layer in navigation: a global planner on a map (occupancy grid maps provide the obstacle data) sets the route, and a field-based method adjusts the motion around unexpected things like a person walking by. The same idea is used for robot arms, with the field in joint space or around the tool. For planning in many dimensions without local minima, see sampling-based planning.

Try it yourself

Write a small simulation on a 2D grid. Place a goal, an obstacle and a robot, then step the robot a small distance along F each iteration. Draw the path. Try the obstacle directly between robot and goal, then shift the obstacle sideways by 0.1 m and see how the robot slips round. Then make a U-shaped wall and watch it get stuck.

Frequently asked questions

Why does the robot stop before the goal?

It has reached a point where the pull toward the goal and the push from an obstacle cancel, a local minimum. A sideways nudge, a wall-following mode or a global plan gets it out.

Can I use a potential field without a map?

Yes. It only needs the positions of nearby obstacles from sensors, so it works as a reactive layer, but without a map it cannot plan around dead ends.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.