Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 38 ยท Path Planning

Potential Fields and Bug Algorithms

Steer a robot with attractive and repulsive potential fields, see the local-minimum trap, and learn simple reactive Bug algorithms, with runnable Python.

Search-based planners need a complete map. Sometimes you do not have one, or you need an answer in microseconds. Reactive planners compute the next move from the current position and nearby readings, with no global search. Two families are worth knowing: artificial potential fields, which treat the robot as a ball rolling downhill, and Bug algorithms, which follow tiny rules to reach a goal with only touch or range sensing.

They are cheap and simple, and they fail in instructive ways. Understanding those failures is half of the lesson.

Potential fields: a ball rolling downhill

Imagine the world as a landscape. The goal sits at the bottom of a valley, and every obstacle is a hill. A ball placed anywhere rolls toward the goal and around the hills. The robot does exactly this: at each step it computes a force and moves along it.

  • Attractive force pulls toward the goal. A common choice is proportional to the distance: F_att = k_att * (goal - position).
  • Repulsive force pushes away from each obstacle, but only when the robot is within a range of influence d0. Close to the obstacle it grows quickly: F_rep = k_rep * (1/d - 1/d0) / d^2 directed away from the obstacle.
  • The total force is the sum. The robot moves a small step in that direction.

The recipe

Attract Pull toward the goal.
Repel Push away from nearby obstacles.
Add and step Move along the sum, repeat.
1 / 2
Python A robot rolling downhill to the goal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The map is flipped so that y grows upward. Each * is one step; the trail bends around the discs instead of crashing into them.

The local minimum problem

The method has a famous flaw. The total force can be zero somewhere that is not the goal. A robot at such a local minimum stops, convinced it has arrived. The classic case is a U-shaped trap or a goal directly behind a wall: the attraction pulls into the wall, the repulsion pushes back, and the two cancel.

Other known issues: oscillation in narrow corridors, and no path through a gap that is narrower than twice d0 (the two repulsions cover it).

Python Stuck behind a wall, then recovering

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Without help the robot halts in front of the wall. The second run adds a crude recovery behavior: when the force vanishes, sidestep along the wall for a while, then let the field take over again. A random-walk escape is another common patch, but neither is a guarantee. Real remedies:

  • Navigation functions are potential fields built with exactly one minimum, at the goal. They need a map of the space.
  • Combine with a global planner. A* gives waypoints; potential fields (or the Dynamic Window Approach) handle local avoidance between them.
  • Wall-following escape, which brings us to the Bug family.

Bug algorithms

Bug algorithms assume the robot knows its own position, the goal's position, and can sense contact (or very short range) with an obstacle. There is no map. They are complete for a 2D point robot: they find the goal or prove it is unreachable.

  • Bug0: head straight to the goal; when you hit an obstacle, follow its boundary (turn left, say) until the straight line to the goal is clear again, then leave. Simple but can loop forever on some shapes.
  • Bug1: circle the whole obstacle once, remembering the point closest to the goal, then go back and leave from there. Always works; the path can be long.
  • Bug2: draw the straight "m-line" from start to goal. Follow the boundary when blocked and leave when you meet the m-line again at a point closer to the goal than where you hit. Usually shorter than Bug1 on friendly maps.
flowchart TD
  A["Move toward the goal along the m-line"] --> B{"Obstacle ahead?"}
  B -- no --> C{"At the goal?"}
  C -- yes --> D["Done"]
  C -- no --> A
  B -- yes --> E["Remember the hit point, follow the boundary"]
  E --> F{"Back on the m-line and closer to the goal?"}
  F -- yes --> A
  F -- no --> G{"Returned to the hit point?"}
  G -- yes --> H["Goal unreachable"]
  G -- no --> E

Bug2 in one picture. Only local sensing and a little memory are needed.

Bug algorithms are rarely used as-is on modern robots, but the idea of "follow the wall, then leave when it is safe" lives on in wall-following behaviors and recovery routines inside navigation stacks.

In practice, a robot combines layers: a global planner for the route, a local planner (such as DWA or potential fields) for reacting to people and clutter, and a recovery behavior (spin, back up, wall-follow) when the local planner is stuck.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a potential field, what does the repulsive force depend on?

    Each obstacle pushes the robot away, strongly when close and not at all beyond the influence distance d0.
  2. 2. What is a local minimum in this context?

    Attraction and repulsion can cancel, so the robot stops somewhere that is not the goal.
  3. 3. Which method needs no map, only position, goal and contact sensing?

    Bug algorithms navigate from local sensing and simple memory, with no global map.
  4. 4. How does Bug2 decide to leave an obstacle boundary?

    Bug2 follows the boundary until it returns to the m-line closer to the goal than the hit point, then continues straight.

Summary

  • Potential fields add an attractive pull to the goal and repulsive pushes from obstacles, then step along the sum.
  • They are fast and local, but can stall in local minima, oscillate in corridors, and miss narrow gaps.
  • Fixes include navigation functions, pairing with a global planner, and random or wall-following escapes.
  • Bug0, Bug1 and Bug2 reach a goal from local sensing alone.
  • Real systems layer a global planner, a local planner, and recovery behaviors.

Next: Sampling-Based Planning: PRM and RRT