# Module 3.4: Local Reactive Obstacle Avoidance

- Course: [Course 3: Motion Planning & Navigation](https://roboticsconcepts.dev/courses/motion-planning-navigation.md)
- HTML Page: https://roboticsconcepts.dev/courses/motion-planning-navigation/local-reactive-obstacle-avoidance/
- Key Concepts: Attractive & repulsive potential fields, Local minima traps, Dynamic Window Approach (DWA)

Global planners like A* and RRT are great when you know the whole map ahead of time. Out in the real world, someone steps into the aisle with a pallet jack, and your robot has 50 milliseconds to decide how not to hit them.

## Goals that pull, obstacles that push

One of the cleanest mental models for reactive avoidance is the Artificial Potential Field. Picture your robot as a marble rolling on a stretchy rubber sheet.

You poke the sheet down at the goal so everything slopes smoothly toward it (an attractive potential), and you push sharp tents upward under every detected obstacle (repulsive potentials). Compute the downhill slope at your robot's current position, and you immediately get a steering velocity — no full graph search needed.

## Where rubber-sheet physics gets trapped

Potential fields are fast and intuitive, which is why people fall in love with them — until their robot parks itself right in front of a couch and shivers in place. When the forward pull of the goal exactly cancels the backward push of an obstacle directly ahead, the net slope hits zero. That dead spot is a local minimum.

To avoid getting stuck while still respecting wheel speed and turning limits, mobile robots commonly use the Dynamic Window Approach (DWA) instead:

- Look only at velocities (linear v, angular ω) the motors can actually reach in the next fraction of a second — that's the 'dynamic window'.
- Simulate short forward arcs (say 1.5 seconds ahead) for dozens of candidate (v, ω) pairs.
- Discard any arc that clips an obstacle, then score the surviving arcs by heading toward the goal, speed, and clearance.

## Hands-On Lab

Open the companion marimo notebook (04_local_reactive_obstacle_avoidance.py) to place obstacles directly between start and goal, watch a pure potential-field robot stall in a local minimum, and compare how DWA samples short collision-free velocity arcs around the corner.

## Pairing a global map with a fast local reflex

Notice the natural division of labor here. DWA only looks a couple of seconds ahead, so on its own it can still get fooled by a long dead-end corridor. Meanwhile, A* knows the whole building layout, but takes too long to re-run from scratch every 20 milliseconds when a person walks by.

Almost every practical navigation stack puts them together: a global planner lays down a coarse breadcrumb trail every second or two, and a local reactive controller like DWA or MPPI follows the next local breadcrumb while dodging surprise obstacles at high frequency.

## Potential field force balance

```text
F_total(x) = −∇U_att(x) − ∇U_rep(x)
```

The attractive gradient pulls toward the goal while the repulsive gradient pushes away inside an obstacle's influence radius. Whenever those two vectors cancel to zero away from the goal, the robot stalls in a local minimum.

## Check Your Intuition

**Question:** Why does the Dynamic Window Approach (DWA) restrict its candidate (v, ω) arcs to a small 'window' around the robot's current speed instead of testing any speed up to top speed?

- [ ] Because sensors stop working at high speeds
- [✓] Because real motors have acceleration limits — the robot can only reach velocities within ±a_max·Δt during the next control tick
- [ ] Because spinning in place is mathematically illegal in DWA

**Explanation:** A robot moving at 1.2 m/s cannot instantly jump to -1.0 m/s in 50 ms. Filtering to dynamically reachable (v, ω) pairs guarantees the winning arc is actually physically drivable.

## Where You'll See This in Modern Robotics

In modern robotics, DWA's sample-rollout idea evolved directly into Model Predictive Path Integral (MPPI) control and learned local planners, which roll out thousands of short trajectories in parallel on a GPU against live depth or LiDAR costmaps.

## Companion Python Notebook: 04 · Potential Fields & Dynamic Window Approach

Simulate artificial potential fields getting caught in a U-shaped trap, then escape using Dynamic Window velocity rollouts.

- Open in molab (WASM): https://molab.marimo.io/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/course-3/04_local_reactive_obstacle_avoidance.py/wasm
- Open in Google Colab: https://colab.research.google.com/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/colab/course-3/04_local_reactive_obstacle_avoidance.ipynb
- Download .py: https://roboticsconcepts.dev/downloads/notebooks/course-3/04_local_reactive_obstacle_avoidance.py
- Download .ipynb: https://roboticsconcepts.dev/downloads/notebooks/colab/course-3/04_local_reactive_obstacle_avoidance.ipynb
- Run locally: `uvx marimo edit --sandbox notebooks/course-3/04_local_reactive_obstacle_avoidance.py`
