Configuring ROS 2 Nav2 Costmaps: Inflation, Footprints, and Clearing for Constrained Corridors

ContentsIntroduction
- Introduction
- Nav2 2D Costmap Layer Architecture
- Mathematical Foundations of Inflation Cost Decay
- Tuning Rule for Constrained Corridors:
- Modeling the Chassis: Circular Radius vs. Polygonal Vector Footprint
- Sensor Clearing Policies & Preventing Ghost Obstacles
- Illustrative Nav2 Local Costmap YAML Configuration
- Costmap Debugging and Field Verification Checklist
- Validate the complete navigation stack
- Further reading and technical reference
Introduction
Autonomous Mobile Robots (AMRs) deployed in fulfillment centers, hospitals, and manufacturing floors frequently struggle when navigating through narrow doorways or constrained aisles. A common manifestation of poor navigation configuration is an AMR stalling, oscillating wildly, or aborting paths near doorway frames that are physically wide enough for the chassis to pass.
This issue rarely stems from path planner failures (such as Smac Planner or NavFn). Instead, it is often related to misconfigured Nav2 2D Costmaps. When costmap inflation parameters are set too conservatively, or when the robot's footprint is modeled as a simple bounding circle, the costmap marks valid free space around doorway frames with high inflation costs—tricking the global and local planners into believing the corridor is blocked.
This guide details the mathematical foundations of Nav2 costmap calculation, explains how to define precise polygonal footprints, and provides a illustrative YAML configuration tailored for constrained space navigation.
Nav2 2D Costmap Layer Architecture
The Navigation 2 stack maintains two separate grid costmaps:
- Global Costmap: Used by the global planner to compute long-distance topological paths across the entire facility map.
- Local Costmap: Used by the local planner (e.g., DWB or MPPI) to avoid dynamic obstacles in real time within a rolling window around the robot (typically 3m×3m).
COSTMAP LAYER STACK+-------------------------------------------------------------------+| Footprint used for collision checking (not a standard plugin layer) |+-------------------------------------------------------------------+| 3. Inflation Layer (Exponential Decay Cost Grid) |+-------------------------------------------------------------------+| 2. Obstacle / Voxel Layer (3D Point Cloud & 2D LiDAR Marking) |+-------------------------------------------------------------------+| 1. Static Layer (Occupancy Grid Map loaded from Map Server) |+-------------------------------------------------------------------+Cost values in Nav2 range from 0 (completely free space) to 255 (unknown/unmapped space):
- 254 (LETHAL_OBSTACLE): A physical obstacle detected by sensors or mapped in the static environment.
- 253 (INSCRIBED_INFLATION): The zone where the robot's center point cannot enter without its outer boundary physically contacting a lethal obstacle.
- 1−252 (INFLATION_DECAY): A gradient of decreasing cost extending outward from obstacles to keep the robot centered in corridors.
- 0 (FREE_SPACE): A costmap classification, not permission to drive at full speed.
Mathematical Foundations of Inflation Cost Decay
The inflation layer assigns costs to grid cells adjacent to lethal obstacles based on an exponential decay equation:
cost(d)=(INSCRIBED_INFLATED_OBSTACLE−1)⋅exp(−γ⋅(d−rinscribed))
Where:
- d is the distance from the cell center to the nearest lethal obstacle cell.
- rinscribed is the inscribed radius of the robot chassis (the radius of the largest circle that fits inside the robot footprint).
- γ is the cost_scaling_factor specified in the costmap configuration.
Cost Value 254 | [LETHAL] | | 253 |--+-----+ <--- Inscribed Radius (r_inscribed) | | | | | \ | | \ Exponential Decay via cost_scaling_factor (gamma) 1 | | \_________________ 0 |__|_______|_________________|______ Distance (d) 0 r_inscribed Inflation RadiusTuning Rule for Constrained Corridors:
- Increasing cost_scaling_factor (γ): Causes the exponential curve to drop off more steeply. The cost decays rapidly, allowing the planner to push paths closer to walls and doorway frames.
- Decreasing cost_scaling_factor (γ): Creates a smooth, wide cost slope. This keeps the robot centered in wide hallways, but causes the robot to freeze near tight doorways because the cost inside the opening remains artificially high.
Modeling the Chassis: Circular Radius vs. Polygonal Vector Footprint
Using a simple scalar robot_radius parameter is mathematically efficient, but it forces rectangular or non-symmetrical chassis to be enclosed in an overly conservative bounding circle.
Circular Footprint (Wasteful Area): Polygonal Vector Footprint (Tight Fit): +------------------------+ +------------------------+ | /------------------\ | | +------------------+ | | / \ | | | | | || ROBOT CHASSIS || | | ROBOT CHASSIS | | | \ / | | | | | | \------------------/ | | +------------------+ | +------------------------+ +------------------------+ (Redundant clearance blocked) (Accurate clearance in tight doors)For rectangular mobile platforms, replace robot_radius with an explicit 2D coordinate array defined in meters relative to the robot's base frame (base_link or base_footprint):
# Precise footprint coordinates for a 0.6m long by 0.4m wide rectangular AMRfootprint: "[ [0.3, 0.2], [0.3, -0.2], [-0.3, -0.2], [-0.3, 0.2] ]"Sensor Clearing Policies & Preventing Ghost Obstacles
Dynamic objects (such as pedestrians or forklifts) leave behind cost entries in the obstacle_layer. If sensor noise or reflections create temporary point drops, these entries can persist as "ghost obstacles" that block valid paths.
To eliminate ghost obstacles, configure continuous raytracing in your observation sources:
- marking: true: Inserts obstacles into the costmap when point cloud or 2D LiDAR rays intersect a physical surface within max_obstacle_height and obstacle_max_range.
- clearing: true: Traces continuous rays from the sensor location to the detected point. All grid cells along the ray path before the point are explicitly cleared back to FREE_SPACE (cost = 0).
Illustrative Nav2 Local Costmap YAML Configuration
Below is an example nav2_costmap_2d configuration for a hypothetical 0.6 m long by 0.44 m wide chassis. It is not a measured or certified doorway configuration:
local_costmap: local_costmap: ros__parameters: update_frequency: 10.0 publish_frequency: 5.0 global_frame: odom robot_base_frame: base_link use_sim_time: false rolling_window: true width: 4 height: 4 resolution: 0.05 # 5cm grid resolution for high spatial accuracy # Polygonal footprint definition for rectangular chassis footprint: "[ [0.3, 0.22], [0.3, -0.22], [-0.3, -0.22], [-0.3, 0.22] ]" plugins: ["obstacle_layer", "inflation_layer"] obstacle_layer: plugin: "nav2_costmap_2d::ObstacleLayer" enabled: true observation_sources: scan scan: topic: /scan max_obstacle_height: 2.0 clearing: true marking: true data_type: "LaserScan" raytrace_max_range: 3.0 raytrace_min_range: 0.0 obstacle_max_range: 2.5 obstacle_min_range: 0.0 inflation_layer: plugin: "nav2_costmap_2d::InflationLayer" enabled: true # Inflation radius extends just beyond inscribed radius to allow tight fits inflation_radius: 0.55 # High cost_scaling_factor creates a steep cost drop-off near doorway frames cost_scaling_factor: 8.0 inflate_unknown: falseCostmap Debugging and Field Verification Checklist
- Visualize Costmaps in RViz2: Add a Map display plugin in RViz2 and set the topic to /local_costmap/costmap. Change the Color Scheme to Costmap (Red/Purple/Blue gradient) to inspect inflation gradients directly over map geometry.
- Verify clearance using the complete oriented footprint and controller collision checks. Inflated costs need not all be zero for a valid path; include localization error, padding, sensor uncertainty, turning geometry, and stopping distance.
- Raytrace Sanity Check: Stand in front of the robot's 2D LiDAR and walk away. Verify that dynamic cost cells behind you clear instantly within 1−2 costmap update cycles (100ms−200ms).
Validate the complete navigation stack
Higher cost_scaling_factor makes the gradient fall more steeply, but increasing it is not a universal doorway fix. Planner, controller, resolution, TF, footprint padding, and sensor range all interact. Simulate constrained passages first, then use low-speed supervised tests with emergency stopping available. A local-only YAML snippet does not replace the global costmap, controller, behavior server, lifecycle, or transform configuration.
Further reading and technical reference
For the prerequisites, read our ROS 2 obstacle avoidance and Nav2 architecture. For implementation details and version-specific behavior, consult the official Nav2 costmap configuration reference.
