Costmap in ROS2 Navigation — Complete Guide | R2BOT
327 words · 2 min read
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.
The navigation localization concept: A costmap is a 2D grid where each
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.
💡 Think of it like…
Think of it like a household object that does the same job — the underlying idea is the same, just adapted for robots.
Why it matters
Without costmap in ros2 navigation — complete guide | r2bot, many navigation localization systems in robotics simply couldn't work.
Costmap in ROS2 Navigation
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.
Ask R2 Co-pilot anything you didn't understand about Costmap in ROS2 Navigation — Complete Guide | R2BOT. It'll explain it plainly.
Keep going
A* (A-Star) Pathfinding in Robotics — Complete Guide
A* finds the shortest path between two points on a grid or graph. It is the most-used pathfinding algorithm in…
ConceptNav2 (ROS2 Navigation Stack) — Complete Guide | R2BOT
Nav2 is the ROS2 navigation stack for mobile robots — planners, controllers, behaviour trees, recovery. Used i…
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
Community discussion
0 questions & insightsLoading discussion…
Spotted something off? Report an error →