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.
Glossary
Costmap

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the foundational algorithms and data structures that interact with the costmap to enable robust autonomous navigation.
Signed Distance Field (SDF)
A volumetric representation where each voxel stores the shortest distance to the nearest obstacle surface, with negative values indicating interior points. SDFs enable efficient collision checking by simply evaluating the signed distance at a query point. In costmap contexts, SDFs provide a mathematically smooth alternative to binary occupancy grids for gradient-based trajectory optimization.
Inflation Layer
A costmap plugin that artificially expands obstacle boundaries by propagating cost values outward from detected obstacles. This creates a safety buffer that accounts for the robot's physical footprint and localization uncertainty. The inflation radius is typically set to at least half the robot's inscribed radius, with cost decay functions—linear, exponential, or Gaussian—determining how quickly costs drop with distance.
Model Predictive Control (MPC)
A real-time control strategy that solves a finite-horizon optimization problem at each timestep using the costmap as its cost function landscape. MPC evaluates candidate trajectories against the costmap's occupancy probabilities, selecting the path that minimizes cumulative cost while respecting dynamic constraints. This enables smooth, anticipatory obstacle avoidance rather than reactive stopping.
Dynamic Window Approach (DWA)
A velocity-space local planner that samples achievable linear and angular velocities within the robot's dynamic window, then scores each trajectory against the costmap. DWA evaluates clearance, heading alignment, and velocity maximization to select the optimal command. It is the default local planner in ROS navigation and relies directly on the costmap for real-time obstacle scoring.
Voxel Layer
A 3D-aware costmap plugin that maintains a volumetric occupancy grid to handle obstacles that overhang or are sensed at different heights. Unlike the flat obstacle layer, the voxel layer can mark space above the robot as free while marking columns at ground level as occupied. This is critical for robots operating under tables, shelves, or in environments with non-floor-level obstructions.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us