Inferensys

Glossary

Costmap

A grid-based data structure used in ROS navigation that aggregates sensor information into occupancy probabilities and inflated obstacle representations for local path planning.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
ROS NAVIGATION STACK

What is Costmap?

A costmap is a 2D or 3D grid-based data structure used in the Robot Operating System (ROS) navigation stack to represent the environment for path planning. Each cell stores a cost value that encodes the probability of an obstacle and the proximity to inflation zones.

A costmap aggregates sensor data from sources like LiDAR, depth cameras, and sonar into a unified occupancy grid. The costmap_2d package maintains layered representations where each cell holds an integer cost from 0 (free) to 254 (lethal obstacle), with a special value of 255 reserved for unknown space. The global costmap represents the entire environment for long-range planning, while the local costmap is a rolling window centered on the robot for reactive obstacle avoidance.

The inflation layer propagates costs outward from detected obstacles using a decay function, typically exponential or linear, creating a safety buffer that penalizes paths near obstacles. This prevents the planner from generating trajectories that graze walls or corners. The costmap updates at a configurable frequency via a costmap update cycle, which clears stale observations, marks new sensor readings, and reinflates obstacles before the local planner queries the cost values for trajectory scoring.

SPATIAL AWARENESS ENGINE

Key Features of Costmaps

A costmap is a grid-based data structure that aggregates sensor information into occupancy probabilities and inflated obstacle representations, serving as the foundational world model for local path planning in ROS-based navigation.

01

Layered Architecture

Costmaps are composed of multiple semantic layers that are combined into a final master grid for planning:

  • Static Map Layer: Loads pre-built SLAM maps representing permanent structures like walls
  • Obstacle Layer: Dynamically marks transient objects detected by LiDAR, depth cameras, or radar
  • Inflation Layer: Expands obstacle boundaries by the robot's inscribed radius plus a safety buffer
  • Voxel Layer: Handles 3D sensor data for platforms operating in non-planar environments Each layer independently updates at configurable rates, enabling efficient sensor fusion without blocking the planning cycle.
4+
Standard Layers
5-30 Hz
Update Frequency
02

Occupancy Grid Representation

Each cell in a costmap stores a probability value between 0 (free) and 255 (occupied), with 128 representing unknown space. This probabilistic framework accommodates sensor noise and transient readings:

  • Log-odds representation: Probabilities are stored in log-odds form for efficient Bayesian updates
  • Thresholding: Cells above a configurable occupancy threshold are treated as lethal obstacles
  • Unknown handling: Planners can be configured to treat unknown cells as free (optimistic) or lethal (conservative) The grid resolution is typically 0.05 meters per cell, balancing computational efficiency with spatial precision.
0-255
Cost Range
0.05 m
Typical Resolution
03

Inflation and Safety Buffers

The inflation layer propagates costs outward from detected obstacles using a decay function, creating a gradient that planners use to maintain safe distances:

  • Inscribed radius: The hard boundary within which the robot would certainly collide
  • Circumscribed radius: The outer limit of the inflation field, defining the maximum cost influence
  • Exponential decay: Cost values decrease exponentially from lethal (254) to neutral (0) with distance This gradient enables planners like the Dynamic Window Approach (DWA) to prefer paths that maximize clearance from obstacles rather than skimming dangerously close to boundaries.
254
Lethal Cost
0.3-0.5 m
Typical Inflation Radius
04

Rolling Window Updates

Local costmaps operate within a sliding window centered on the robot, typically 3-5 meters square, that moves with the platform. This design provides several advantages:

  • Constant memory footprint: Only the local vicinity is maintained, regardless of global map size
  • Sensor horizon alignment: The window size matches the effective range of onboard perception sensors
  • Dynamic obstacle handling: Transient objects enter and exit the window naturally as the robot moves
  • Coordinate frame transformation: Sensor data is continuously transformed from sensor frames into the robot's base frame using TF2 transforms The global costmap, by contrast, maintains a larger fixed frame for high-level route planning.
3-5 m
Window Size
< 50 ms
Update Latency
05

Sensor Data Aggregation

Costmaps implement observation buffers that collect and fuse data from heterogeneous sensors before updating the grid:

  • Clearing observations: Sensor rays that pass through space mark cells as free, removing stale obstacle markings
  • Marking observations: Returns that hit surfaces mark cells as occupied
  • Temporal filtering: Obstacles must persist for a minimum number of observations before being marked, reducing false positives from sensor noise
  • Maximum range filtering: Readings beyond a configurable distance are discarded to prevent inaccurate far-field data from corrupting the map This fusion enables robust operation even when individual sensors produce noisy or intermittent readings.
2-3
Min Observations to Mark
LiDAR + RGB-D
Common Sensor Fusion
06

Cost Function Customization

Beyond binary free/occupied states, costmaps support custom cost functions that encode task-specific preferences into the planning space:

  • Lethal zones: Absolute no-go areas like safety cages or cliff edges
  • Neutral zones: Preferred travel corridors with zero additional cost
  • Penalty zones: Areas with elevated but non-lethal costs, such as high-traffic intersections or fragile flooring
  • Speed restriction zones: Regions where the planner should reduce velocity without altering the path These zones can be injected via polygon-stamped messages from behavior trees or mission planners, enabling dynamic reconfiguration of navigation policies without modifying the map.
0-254
Configurable Cost Range
PolygonStamped
Zone Injection Method
COSTMAP ESSENTIALS

Frequently Asked Questions

Clear, technical answers to the most common questions about the costmap data structure used in ROS-based navigation and autonomous path planning.

A costmap is a 2D or 3D grid-based data structure used in the Robot Operating System (ROS) navigation stack that assigns a numerical cost value to each cell, representing the difficulty or risk of the robot traversing that location. It works by ingesting sensor data—primarily from LiDAR, depth cameras, or sonar—and aggregating it into a probabilistic occupancy grid. Each cell transitions between FREE, OCCUPIED, and UNKNOWN states based on a Markov update model that fuses multiple sensor readings over time. The core mechanism involves two primary layers: a static map layer (typically from SLAM) that represents permanent walls and structures, and a dynamic obstacle layer that updates in real-time from sensor callbacks. A critical post-processing step applies inflation, where a cost gradient is radially propagated outward from detected obstacles using a decay function (commonly exponential or linear), creating a lethal boundary, an inscribed zone, and a gradual cost falloff. This inflation ensures that path planners like the global planner and local planner generate trajectories that maintain safe clearance distances from obstacles, accounting for the robot's physical footprint inscribed within the costmap's dimensions.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.