Atlas Robotics
Nav2Intermediate

Costmaps: from a raw occupancy grid to a layered cost map

Atlasbot · 17/8/2026 · 11 min read

Costmaps: from a raw occupancy grid to a layered cost map
Multilayer costmap: static, obstacle, inflation

Problem Occupancy Grid has only 3 values per Grid. Nav2 does not use the straight occupancy grid for — planning it transforms into costmap, where each cell carries a cost (cost) continuous, not only binary "with/without obstacles".

Key concepts

Two are both "free" but one is 5 cm from the wall, one is 2 m from the wall — they are not equivalent in terms of safety. The costmap represents this difference by constant cost values (0 - 255): far from low cost obstacle, near increasing high cost obstacle — the planner/controller preferentially passes through the low cost region when there are multiple viable options.

Three common, overlapping costmap layers: Static Layer, Obstacle Layer, Inflation Layer.

How it works

Static Layer     — taken directly from the occupancy grid (the SLAM map)
Obstacle Layer   — updated in real time from sensors (scanning LiDAR)
                   — obstacles NOT present in the static map (people, newly arrived carts)
Inflation Layer  — spreads costs around each obstacle, decreasing with distance

Overlapping layers, the final cost value of each cell is the highest value of the — layers a cell can be "safe" in terms of Static Layer (not on the static map) but "dangerous" in terms of Obstacle Layer (LiDAR has just detected a new obstacle there now).

If only the cell with the obstacle is properly marked as dangerous, the planner can calculate the "no-touch" edge-of-the-impedance grazing path — theoretically but leaves no margin of safety for real-world localization/control errors. The inflation layer resolves by spreading costs out to neighboring plots in configurable radius, decreasing with distance.

In summary: Static Layers respond to "what the static map says" (slow change), Obstacle Layers respond to "what the sensor is seeing right now" (real time), Inflation Layers turn "yes/no obstacles" into "how dangerous by distance". Three complementary classes, not interchangeable.

Technical details

Formulas

inflation_layer:
  inflation_radius: 0.55      # radius spread (m)
  cost_scaling_factor: 3.0    # speed reduces cost by distance

The exponentially decreasing cost from the distance to the nearest obstacle, to the inflation_radius threshold is zero:

cost(d) = 253 × e^(−cost_scaling_factor × (d − robot_radius))
(where d = distance to obstacle, bounded within [robot_radius, inflation_radius])
Larger cost_scaling_factor → cost decreases faster with distance
                          → robot is more willing to approach obstacles at the same inflation_radius

inflation_radius should be set to a minimum of a robotic radius (the Footprint — Nav2 Tuning item) plus a safety amplitude — that is too small, the robot can calculate the obstacle track; too large, the robot dodges too far, failing to cross narrow space although theoretically wide enough to cross.

Parameters

LayerData Sourcesupdate frequency
StaticFilling grid from SLAMInactive, switch only when loading new map
ObstacleReal - time sensors (LiDAR)High, each new scan
InflationRecalculate from 2 layers aboveBy variable source layer frequency

Practical applications

Local Costmap and Global Costmap differ in scope: Global Costmap covers the entire map, used for planner_server total path calculation; Local Costmap covers only a small region around the robot (e.g. 3x3m), high frequency updating, used for controller_server immediate obstacle avoidance. Local costmap is small and fast to update because the controller needs to react immediately to a new obstacle that appears near the robot; global costmap is large but not as fast to update because it is used for general planning, not immediate avoidance.

Practical example

Compare 2 inflation_radius values for a robot of radius 0.3m,
in a corridor 1m wide (0.5m on each side of its centerline):

inflation_radius = 0.55 (robot radius 0.3m + safety margin 0.25m):
  → the high-cost region extends 0.55m from each wall
  → in a 1m-wide corridor, the 2 inflation regions OVERLAP
    in the middle (0.55×2 = 1.1m > corridor width 1m)
  → the planner may consider the entire corridor high-cost and struggle to find a path through

inflation_radius = 0.35 (robot radius 0.3m + smaller safety margin 0.05m):
  → the high-cost regions on the 2 sides do not overlap (0.35×2 = 0.7m < 1m)
  → a low-cost gap remains in the middle
  → the planner finds a path through and the robot travels safely down the center

This example directly illustrates the warning "too big, robot out of range, not able to squeeze through narrow space" stated in the Operating Principles section — that needs to balance safety and the environment's ability to squeeze through narrow real-world space.

Common mistakes

  • Place inflation_radius too large for a narrow— corridor environment as the example above, the robot cannot find its way through the parachute that is theoretically wide enough to pass through.
  • Use inflation_radius smaller than the robot radius— without sufficient margin of safety, the path can graze the obstacle more than acceptable with real-world localization/control errors.
  • Local Costmap and Global Costmap confusion when debug— mischecks costmap when immediate obstacle avoidance problems are suspected (Local should see) or master scheduling (Global should see).
  • Without accounting for the fact that the original data obstacle layer — can "jump" if the dynamic obstacle has moved away but the costmap has not been updated, the robot can dodge a real-world obstacle-free location — which is why recovery behavior ClearEntireCostmap (Nav2, Recovery) exists.

Conclusion

The costmap converts a binary occupancy grid into a continuous cost map through three classes of Static, Obstacle, Inflation — each answering a different question (what the static map says, what the sensor sees right now, how dangerous it is by distance). The right inflation_radius balance between safety and the ability to traverse narrow spaces is the most important fine-tuning decision of this class. The next article in the column goes into Behavior Tree — how Nav2 coordinates the recently learned Planner and Controller into a logical explicit processing flow.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

Costmaps: from a raw occupancy grid to a layered cost map — Atlas Robotics