Costmap in ROS2 Navigation
327 words · 2 min read · 1 source
A costmap is a 2D grid where each cell holds a cost reflecting how desirable it is to traverse. Backbone of Nav2 local and global planners.
A costmap is a 2D grid representation of the world where each cell holds a numeric cost indicating how undesirable it is for the robot to be there. Obstacles get high cost, free space gets zero, and areas near obstacles get inflated cost. Planners like A* and Dijkstra navigate by minimising total path cost.
What is Costmap in ROS2 Navigation?
A costmap is a 2D grid representation of the world where each cell holds a numeric cost indicating how undesirable it is for the robot to be there. Obstacles get high cost, free space gets zero, and areas near obstacles get inflated cost. Planners like A* and Dijkstra navigate by minimising total path cost.
How It Works
Nav2 builds costmaps in layers. The static layer reads a known map. The obstacle layer adds dynamic obstacles from LIDAR/depth sensors. The inflation layer adds a halo of decreasing cost around every obstacle to keep the robot at a safe distance. The voxel layer extends to 3D. Each layer can be enabled or disabled per planner. The global costmap covers the entire environment for long-range planning; the local costmap is a small, fast-updating window around the robot for reactive avoidance.
Real-World Example
Every Nav2-based warehouse robot uses costmaps with inflation tuned to its physical width. Hospital delivery robots inflate human-sized buffers around detected legs. Outdoor mowing robots add custom layers for grass-height and slope.
Why It Matters for Robotics
Costmap tuning is the single most impactful factor in whether a Nav2 robot behaves well or terribly. Inflation radius too low → robot scrapes walls. Too high → robot refuses to enter narrow doorways. Every Nav2 engineer must master costmap layers and parameters.
Try It Yourself
Launch the Nav2 TurtleBot3 demo in Gazebo + RViz2. Visualise the global and local costmaps in RViz. Change the inflation radius parameter live with ros2 param set and watch the robot's path change in real time.
Quick Quiz
Quick Quiz
3 questions
1.A costmap cell encodes:
2.The inflation layer in Nav2 adds:
3.Local vs global costmaps differ in:
Further Reading
Ask R2 About This
Open the R2 Co-pilot (press ⌘K anywhere on R2BOT) and ask: "Explain Costmap in ROS2 Navigation for a Class 9 student in India, with one real-world Indian example." You'll get a tailored, sourced answer in seconds.
🐍 Python Playground · runs in your browser
Editor · 15 lines
Output
Press ▶ Run to execute. First run downloads Python (~6MB) — only happens once per page.
Powered by Pyodide · Python in WebAssembly · no server required.
Next: the course path
Five free courses, from zero to your own robot design
Short videos with a quiz after each one, a final activity and a certificate per course.
See the course path →Plain English. Free. Unsubscribe in one click.
Keep going
Nav2 (ROS2 Navigation Stack)
Nav2 is the ROS2 navigation stack for mobile robots — planners, controllers, behaviour trees, recovery. Used i…
ConceptPath planning
Path planning is the process of finding a route through space from a starting point to a goal, avoiding obstac…
ConceptOccupancy grid
An occupancy grid is a map of the environment divided into a regular grid of cells, where each cell stores a p…
Last updated · 2026-05-21
Spotted something off? Report an error →