{"id":4031,"date":"2025-10-01T12:41:28","date_gmt":"2025-10-01T12:41:28","guid":{"rendered":"https:\/\/learnbydoing.dev\/?p=4031"},"modified":"2026-01-10T21:55:05","modified_gmt":"2026-01-10T21:55:05","slug":"mastering-nav2-costmaps-in-ros-2","status":"publish","type":"post","link":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/","title":{"rendered":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4031\" class=\"elementor elementor-4031\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e28ab35 e-flex e-con-boxed e-con e-parent\" data-id=\"e28ab35\" data-element_type=\"container\" data-e-type=\"container\" id=\"content\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-62ab6e3 e-con-full e-flex e-con e-child\" data-id=\"62ab6e3\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-62ab203 elementor-align-center elementor-widget elementor-widget-post-info\" data-id=\"62ab203\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"post-info.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<ul class=\"elementor-inline-items elementor-icon-list-items elementor-post-info\">\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item elementor-repeater-item-2c98363 elementor-inline-item\" itemprop=\"about\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-terms\">\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-post-info__terms-list\">\n\t\t\t\t<span class=\"elementor-post-info__terms-list-item\">ROS 2<\/span>, <span class=\"elementor-post-info__terms-list-item\">Tutorials<\/span>\t\t\t\t<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t<\/ul>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-0650e10 e-con-full e-flex e-con e-child\" data-id=\"0650e10\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-ac19582 elementor-view-default elementor-widget elementor-widget-icon\" data-id=\"ac19582\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<div class=\"elementor-icon\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"75\" height=\"75\" viewBox=\"0 0 75 75\" fill=\"none\"><path d=\"M74.9999 75H13.1889V73.0002H71.5859L0.460938 1.87521L1.87515 0.460999L73.0001 71.586V13.1889H74.9999V75Z\" fill=\"white\"><\/path><\/svg>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-47aa245d e-flex e-con-boxed e-con e-parent\" data-id=\"47aa245d\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-206a001 elementor-widget elementor-widget-image\" data-id=\"206a001\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1920\" height=\"1080\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\" class=\"attachment-full size-full wp-image-4048\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp 1920w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5-18x10.webp 18w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4bc31ca3 elementor-widget elementor-widget-text-editor\" data-id=\"4bc31ca3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"365\" data-end=\"694\">When we move from simple robot experiments to real-world navigation, the environment is no longer an abstract concept. A robot needs to understand where it can move, where it cannot, and how to plan paths that are not only valid but also safe and efficient. This is where <strong data-start=\"637\" data-end=\"649\">costmaps<\/strong> come into play in ROS 2 Navigation (Nav2).<br \/><br \/><\/p><p data-start=\"696\" data-end=\"1133\">A costmap is essentially a grid-based representation of the environment, where each cell carries a \u201ccost\u201d that indicates how desirable or undesirable it is for the robot to step into it. Free space has low cost, obstacles have high cost, and unsafe zones around obstacles are inflated to discourage risky paths. By combining different layers of information, costmaps provide a comprehensive, real-time view of the robot\u2019s surroundings.<br \/><br \/><\/p><p>\u00a0<\/p><p data-start=\"1135\" data-end=\"1485\">In this article, we will dive into the theory behind costmaps and then build a full <strong data-start=\"1219\" data-end=\"1249\">Nav2 costmap configuration<\/strong> using three essential layers: the static layer, the obstacle layer, and the inflation layer. At the end, you will have a working configuration file, fully explained line by line, that you can plug into your robot\u2019s navigation system.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-12a4ca0 elementor-widget elementor-widget-text-editor\" data-id=\"12a4ca0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\">\ud83e\udd14 <strong>Understanding Costmaps in ROS 2<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\">At its core, a costmap is a <strong data-start=\"1558\" data-end=\"1569\">2D grid<\/strong> laid over the robot\u2019s environment. Each cell in this grid contains an integer value:<\/p><ul data-start=\"1658\" data-end=\"1780\"><li data-start=\"1658\" data-end=\"1687\"><p data-start=\"1660\" data-end=\"1687\"><code data-start=\"1660\" data-end=\"1663\">0<\/code> represents free space<\/p><\/li><li data-start=\"1688\" data-end=\"1720\"><p data-start=\"1690\" data-end=\"1720\"><code data-start=\"1690\" data-end=\"1695\">100<\/code> represents an obstacle<\/p><\/li><li data-start=\"1721\" data-end=\"1780\"><p data-start=\"1723\" data-end=\"1780\">values in between represent inflated or uncertain zones<\/p><\/li><\/ul><p data-start=\"1782\" data-end=\"2028\">This grid allows Nav2 to perform <strong data-start=\"1815\" data-end=\"1837\">collision checking<\/strong> and <strong data-start=\"1842\" data-end=\"1859\">path planning<\/strong> efficiently. Rather than reasoning about the entire geometry of the robot and the environment, the system just checks the costs of cells and looks for low-cost paths.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1641777 elementor-widget elementor-widget-image\" data-id=\"1641777\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1024x576.webp\" class=\"attachment-large size-large wp-image-4037\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-18x10.webp 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap.webp 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4229593 elementor-widget elementor-widget-text-editor\" data-id=\"4229593\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\"><strong>\ud83d\uddfa\ufe0f\u00a0Global and Local Costmaps<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"2067\" data-end=\"2458\">In Nav2, we typically define two separate costmaps. The <strong data-start=\"2123\" data-end=\"2141\">global costmap<\/strong> provides a large-scale, static view of the environment, usually aligned with the map, and is used for long-term path planning. The <strong data-start=\"2273\" data-end=\"2290\">local costmap<\/strong> instead provides a smaller, robot-centered view, updated at a higher frequency, and accounts for dynamic obstacles, enabling local replanning and obstacle avoidance.<br \/><br \/>By combining the two, the robot can plan safe long-distance routes while also reacting in real-time to sudden changes in the environment.<\/p><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3faa2ce elementor-widget elementor-widget-image\" data-id=\"3faa2ce\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-1024x576.webp\" class=\"attachment-large size-large wp-image-4038\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1-18x10.webp 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-1.webp 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fcee8d1 elementor-widget elementor-widget-text-editor\" data-id=\"fcee8d1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\">\u26a1 <strong>Static Layer: Integrating the Map<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"2067\" data-end=\"2458\">The static layer imports information from a pre-built occupancy grid map, usually the one generated by SLAM or mapping. By subscribing to <code data-start=\"2784\" data-end=\"2790\">\/map<\/code>, it guarantees that the costmap reflects static structures like walls and corridors.<\/p><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b839d73 elementor-widget elementor-widget-image\" data-id=\"b839d73\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-1024x576.webp\" class=\"attachment-large size-large wp-image-4039\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2-18x10.webp 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-2.webp 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6e47554 elementor-widget elementor-widget-text-editor\" data-id=\"6e47554\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\">\ud83d\udea7 <strong>Obstacle Layer: Detecting What\u2019s Around<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"2930\" data-end=\"3146\">The obstacle layer integrates sensor data from LiDAR or depth cameras to detect obstacles in real-time. It listens to topics like <code data-start=\"3060\" data-end=\"3067\">\/scan<\/code> and constantly updates the costmap, ensuring dynamic objects are considered.<\/p><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2aeee33 elementor-widget elementor-widget-image\" data-id=\"2aeee33\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-1024x576.webp\" class=\"attachment-large size-large wp-image-4040\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3-18x10.webp 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-3.webp 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-afb6841 elementor-widget elementor-widget-text-editor\" data-id=\"afb6841\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\">\ud83d\udea6 <strong>Inflation Layer: Creating Safe Navigation Zones<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"2930\" data-end=\"3146\">The inflation layer expands the occupied areas detected in the costmap, effectively creating a buffer zone around obstacles. This prevents the robot from planning paths that pass dangerously close to walls or objects. Parameters like <code data-start=\"3441\" data-end=\"3459\">inflation_radius<\/code> and <code data-start=\"3464\" data-end=\"3485\">cost_scaling_factor<\/code> determine how wide and steep this buffer is.<\/p><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c84395b elementor-widget elementor-widget-image\" data-id=\"c84395b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-1024x576.webp\" class=\"attachment-large size-large wp-image-4041\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4-18x10.webp 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-4.webp 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-961c2f7 elementor-widget elementor-widget-text-editor\" data-id=\"961c2f7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"2586\" data-end=\"2639\"><strong> &lt;\/&gt; Practical Implementation: Configuring Nav2 Costmaps<\/strong><\/h3><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p><p data-start=\"3597\" data-end=\"3815\">We are now ready to implement a working costmap in ROS 2. Costmaps are configured using <strong data-start=\"3685\" data-end=\"3709\">YAML parameter files<\/strong>. Let\u2019s create a file called <code data-start=\"3738\" data-end=\"3759\">costmap_params.yaml<\/code> inside the <code data-start=\"3771\" data-end=\"3779\">config<\/code> folder of our navigation package.<br \/><br \/><\/p><h5 data-start=\"3817\" data-end=\"3859\"><strong>Here is the complete configuration file:<\/strong><\/h5><p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-936bc8d elementor-widget elementor-widget-code-highlight\" data-id=\"936bc8d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp># costmap_params.yaml\r\nnav2_costmap_2d:\r\n  global_costmap:\r\n    ros__parameters:\r\n      global_frame: map\r\n      robot_base_frame: base_link\r\n      update_frequency: 10.0\r\n      publish_frequency: 10.0\r\n      resolution: 0.05\r\n      width: 10\r\n      height: 10\r\n      origin_x: 0.0\r\n      origin_y: 0.0\r\n      plugins: [\"static_layer\", \"obstacle_layer\", \"inflation_layer\"]\r\n\r\n      static_layer:\r\n        plugin: \"nav2_costmap_2d::StaticLayer\"\r\n        map_subscribe_transient_local: true\r\n\r\n      obstacle_layer:\r\n        plugin: \"nav2_costmap_2d::ObstacleLayer\"\r\n        observation_sources: laser_scan_sensor\r\n        laser_scan_sensor:\r\n          topic: \/scan\r\n          clearing: true\r\n          marking: true\r\n          data_type: \"LaserScan\"\r\n          inf_is_valid: true\r\n\r\n      inflation_layer:\r\n        plugin: \"nav2_costmap_2d::InflationLayer\"\r\n        inflation_radius: 0.55\r\n        cost_scaling_factor: 10.0\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-424d237 elementor-widget elementor-widget-text-editor\" data-id=\"424d237\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"4770\" data-end=\"4797\">\ud83e\udde0 <strong>Breaking Down the Code<\/strong><\/h3><p data-start=\"4799\" data-end=\"4886\">We now break down the file, section by section, and explain what each parameter does.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-91b3bd0 elementor-widget elementor-widget-text-editor\" data-id=\"91b3bd0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Declaring the costmap section<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-34e2893 elementor-widget elementor-widget-code-highlight\" data-id=\"34e2893\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>nav2_costmap_2d:\r\n  global_costmap:\r\n    ros__parameters:\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0ed0bb9 elementor-widget elementor-widget-text-editor\" data-id=\"0ed0bb9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This opens the costmap configuration inside the <code data-start=\"515\" data-end=\"528\">nav2_params<\/code> file. The section <code data-start=\"547\" data-end=\"564\">ros__parameters<\/code> will contain all the parameters that define how the costmap works.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a08c7cf elementor-widget elementor-widget-text-editor\" data-id=\"a08c7cf\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Time and reference frames<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fbbfe30 elementor-widget elementor-widget-code-highlight\" data-id=\"fbbfe30\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>      use_sim_time: true\r\n      global_frame: map\r\n      robot_base_frame: base_link\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-dc28add elementor-widget elementor-widget-text-editor\" data-id=\"dc28add\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Here we enable simulation time (<code data-start=\"795\" data-end=\"815\">use_sim_time: true<\/code>) so the costmap synchronizes with Gazebo or another simulator. The <code data-start=\"883\" data-end=\"897\">global_frame<\/code> is set to <code data-start=\"908\" data-end=\"913\">map<\/code> so all obstacle positions are relative to the global map. The <code data-start=\"976\" data-end=\"994\">robot_base_frame<\/code> indicates the robot\u2019s main reference frame, usually <code data-start=\"1047\" data-end=\"1058\">base_link<\/code>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5ca0e43 elementor-widget elementor-widget-text-editor\" data-id=\"5ca0e43\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Frequencies and resolution<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7da3562 elementor-widget elementor-widget-code-highlight\" data-id=\"7da3562\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>      update_frequency: 5.0\r\n      publish_frequency: 2.0\r\n      resolution: 0.05<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a73b77a elementor-widget elementor-widget-text-editor\" data-id=\"a73b77a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The update frequency determines how often the costmap integrates new sensor data (in Hz), while the publish frequency sets how often the costmap is broadcast to other nodes. The <code data-start=\"1367\" data-end=\"1379\">resolution<\/code> defines the grid cell size in meters \u2014 in this case, each cell is 5 cm.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7deb9a4 elementor-widget elementor-widget-text-editor\" data-id=\"7deb9a4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Size and origin<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9790003 elementor-widget elementor-widget-code-highlight\" data-id=\"9790003\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>      width: 10.0\r\n      height: 10.0\r\n      origin_x: -5.0\r\n      origin_y: -5.0\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-09ad431 elementor-widget elementor-widget-text-editor\" data-id=\"09ad431\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"1569\" data-end=\"1754\">These parameters configure the costmap\u2019s size in meters and where it is centered. A width and height of 10 meters with origin at -5,-5 places the costmap symmetrically around the robot.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-de053c3 elementor-widget elementor-widget-text-editor\" data-id=\"de053c3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Adding the static layer<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-41dc26a elementor-widget elementor-widget-code-highlight\" data-id=\"41dc26a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>      plugins:\r\n        - {name: static_layer, type: \"nav2_costmap_2d::StaticLayer\"}\r\n      static_layer:\r\n        map_subscribe_transient_local: true\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a962652 elementor-widget elementor-widget-text-editor\" data-id=\"a962652\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"1949\" data-end=\"2139\">The static layer plugin loads the environment map. The option <code data-start=\"2011\" data-end=\"2042\">map_subscribe_transient_local<\/code> ensures the costmap always receives the map even if it was published before the costmap started.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-531ef90 elementor-widget elementor-widget-text-editor\" data-id=\"531ef90\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Adding the obstacle layer<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c2c1ba4 elementor-widget elementor-widget-code-highlight\" data-id=\"c2c1ba4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>        - {name: obstacle_layer, type: \"nav2_costmap_2d::ObstacleLayer\"}\r\n      obstacle_layer:\r\n        observation_sources: scan\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b70a0c1 elementor-widget elementor-widget-text-editor\" data-id=\"b70a0c1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This section enables the obstacle layer. It subscribes to one or more sensor topics, in this case just <code data-start=\"2420\" data-end=\"2426\">scan<\/code>, which is usually the LiDAR data.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6b53ddc elementor-widget elementor-widget-code-highlight\" data-id=\"6b53ddc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>        scan:\r\n          topic: \/scan\r\n          max_obstacle_height: 2.0\r\n          clearing: true\r\n          marking: true\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f590093 elementor-widget elementor-widget-text-editor\" data-id=\"f590093\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"2595\" data-end=\"2796\">The obstacle data comes from <code data-start=\"2624\" data-end=\"2631\">\/scan<\/code>. Any obstacle taller than 2 meters is ignored. Marking adds detected obstacles into the costmap, while clearing removes them when the sensor no longer detects them.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-52ed877 elementor-widget elementor-widget-text-editor\" data-id=\"52ed877\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h5><strong>Adding the inflation layer<\/strong><\/h5>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3cb5649 elementor-widget elementor-widget-code-highlight\" data-id=\"3cb5649\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash \">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>        - {name: inflation_layer, type: \"nav2_costmap_2d::InflationLayer\"}\r\n      inflation_layer:\r\n        inflation_radius: 0.55\r\n        cost_scaling_factor: 10.0\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-640f341 elementor-widget elementor-widget-text-editor\" data-id=\"640f341\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The inflation layer creates a safety buffer around obstacles. The <code data-start=\"3075\" data-end=\"3093\">inflation_radius<\/code> determines how far costs spread, and the <code data-start=\"3135\" data-end=\"3156\">cost_scaling_factor<\/code> adjusts how quickly the costs decay with distance from obstacles.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-acb53bd elementor-widget elementor-widget-text-editor\" data-id=\"acb53bd\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"7371\" data-end=\"7395\">\ud83d\ude80 <strong>Running the Costmap<\/strong><\/h3><p data-start=\"7397\" data-end=\"7474\">With the configuration in place, we can build and run the navigation stack.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ee2f91b elementor-widget elementor-widget-code-highlight\" data-id=\"ee2f91b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>cd ~\/arduinobot_ws\r\ncolcon build\r\nsource install\/setup.bash\r\nros2 launch nav2_bringup bringup_launch.py params_file:=\/path\/to\/costmap_params.yaml\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-80bbf0d elementor-widget elementor-widget-text-editor\" data-id=\"80bbf0d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"7632\" data-end=\"7836\">Opening RViz will show the costmap overlayed on the map. Obstacles will appear as blocked areas, and inflated zones will surround them as gray gradients, making it clear where the robot can move safely.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3c61bba elementor-widget elementor-widget-text-editor\" data-id=\"3c61bba\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"7843\" data-end=\"7858\">\ud83c\udfaf <strong>Conclusion<\/strong><\/h3><p data-start=\"7860\" data-end=\"8292\">Costmaps are a fundamental part of robot navigation in ROS 2. They combine static knowledge from maps, dynamic perception from sensors, and safety margins from inflation, resulting in a layered representation of the environment. In this article, we explored the theory behind costmaps, then implemented a complete configuration with static, obstacle, and inflation layers, and finally explained each section of the code in detail.<br \/><br \/><\/p><p data-start=\"8294\" data-end=\"8432\">With this setup, your robot can plan paths that are not only feasible but also safe, handling both static maps and dynamic environments.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-c5d20e7 e-con-full e-flex e-con e-parent\" data-id=\"c5d20e7\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e8bdddd elementor-bg-transform elementor-bg-transform-move-left elementor-cta--layout-image-left elementor-cta--mobile-layout-image-above elementor-cta--skin-classic elementor-animated-content elementor-widget elementor-widget-call-to-action\" data-id=\"e8bdddd\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"call-to-action.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-cta\">\n\t\t\t\t\t<div class=\"elementor-cta__bg-wrapper\">\n\t\t\t\t<div class=\"elementor-cta__bg elementor-bg\" style=\"background-image: url(https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/plan_navigation.webp);\" role=\"img\" aria-label=\"plan_navigation\"><\/div>\n\t\t\t\t<div class=\"elementor-cta__bg-overlay\"><\/div>\n\t\t\t<\/div>\n\t\t\t\t\t\t\t<div class=\"elementor-cta__content\">\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<h2 class=\"elementor-cta__title elementor-cta__content-item elementor-content-item\">\n\t\t\t\t\t\tWant to learn more?\t\t\t\t\t<\/h2>\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-cta__description elementor-cta__content-item elementor-content-item\">\n\t\t\t\t\t\tDiscover how to design, build, and use costmaps in real robotic systems in the \"Self Driving and ROS 2 - Learn by doing! Plan &amp; Navigation\" course\t\t\t\t\t<\/div>\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-cta__button-wrapper elementor-cta__content-item elementor-content-item \">\n\t\t\t\t\t<a class=\"elementor-cta__button elementor-button elementor-size-\" href=\"\" target=\"_blank\">\n\t\t\t\t\t\tEnroll Now\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<div class=\"elementor-ribbon elementor-ribbon-right\">\n\t\t\t\t<div class=\"elementor-ribbon-inner\">\n\t\t\t\t\tDISCOUNT\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>When we move from simple robot experiments to real-world navigation, the environment is no longer an abstract concept. A robot needs to understand where it can move, where it cannot, and how to plan paths that are not only valid but also safe and efficient. This is where costmaps come into play in ROS 2 [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4048,"comment_status":"closed","ping_status":"open","sticky":false,"template":"elementor_header_footer","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[45,43],"tags":[328,347,349,179,66,74,106,319,96,110,343,348,296,71,107,72,342,76,73],"class_list":["post-4031","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ros-2","category-tutorials","tag-antonio-brandi","tag-brandi","tag-costmaps","tag-lbd","tag-learn-by-doing","tag-linux","tag-mapping","tag-maps","tag-nav2","tag-navigation","tag-obstacle","tag-pc","tag-raspberry","tag-ros","tag-ros-2","tag-ros2","tag-static","tag-step-by-step","tag-ubuntu"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained - Learn by Doing!<\/title>\n<meta name=\"description\" content=\"Learn how to configure and use the ROS 2 Nav2 Costmap, including static, obstacle, and inflation layers. A complete step-by-step guide with YAML examples, code breakdown, and practical explanations to optimize your robot navigation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnbydoing.dev\/es\/mastering-nav2-costmaps-in-ros-2\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained\" \/>\n<meta property=\"og:description\" content=\"Learn by Doing!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnbydoing.dev\/es\/mastering-nav2-costmaps-in-ros-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn by Doing!\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-01T12:41:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-10T21:55:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained\",\"datePublished\":\"2025-10-01T12:41:28+00:00\",\"dateModified\":\"2026-01-10T21:55:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/\"},\"wordCount\":980,\"publisher\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\",\"keywords\":[\"antonio brandi\",\"brandi\",\"costmaps\",\"lbd\",\"learn by doing\",\"Linux\",\"mapping\",\"Maps\",\"nav2\",\"navigation\",\"obstacle\",\"pc\",\"Raspberry\",\"ROS\",\"ROS 2\",\"ROS2\",\"static\",\"step by step\",\"Ubuntu\"],\"articleSection\":[\"ROS 2\",\"Tutorials\"],\"inLanguage\":\"es\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/\",\"url\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/\",\"name\":\"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained - Learn by Doing!\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\",\"datePublished\":\"2025-10-01T12:41:28+00:00\",\"dateModified\":\"2026-01-10T21:55:05+00:00\",\"description\":\"Learn how to configure and use the ROS 2 Nav2 Costmap, including static, obstacle, and inflation layers. A complete step-by-step guide with YAML examples, code breakdown, and practical explanations to optimize your robot navigation.\",\"breadcrumb\":{\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage\",\"url\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\",\"contentUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#website\",\"url\":\"https:\/\/learnbydoing.dev\/es\/\",\"name\":\"Learn by Doing!\",\"description\":\"Learn Robotics the fun way\",\"publisher\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnbydoing.dev\/es\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\",\"name\":\"Learn by Doing!\",\"url\":\"https:\/\/learnbydoing.dev\/es\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png\",\"contentUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png\",\"width\":512,\"height\":512,\"caption\":\"Learn by Doing!\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/antonio-brandi-512166bb\/\"]},{\"@type\":\"Person\",\"@id\":\"\",\"url\":\"https:\/\/learnbydoing.dev\/es\/author\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained - Learn by Doing!","description":"Learn how to configure and use the ROS 2 Nav2 Costmap, including static, obstacle, and inflation layers. A complete step-by-step guide with YAML examples, code breakdown, and practical explanations to optimize your robot navigation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnbydoing.dev\/es\/mastering-nav2-costmaps-in-ros-2\/","og_locale":"es_ES","og_type":"article","og_title":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained","og_description":"Learn by Doing!","og_url":"https:\/\/learnbydoing.dev\/es\/mastering-nav2-costmaps-in-ros-2\/","og_site_name":"Learn by Doing!","article_published_time":"2025-10-01T12:41:28+00:00","article_modified_time":"2026-01-10T21:55:05+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"","Tiempo de lectura":"8 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#article","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/"},"author":{"name":"","@id":""},"headline":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained","datePublished":"2025-10-01T12:41:28+00:00","dateModified":"2026-01-10T21:55:05+00:00","mainEntityOfPage":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/"},"wordCount":980,"publisher":{"@id":"https:\/\/learnbydoing.dev\/es\/#organization"},"image":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp","keywords":["antonio brandi","brandi","costmaps","lbd","learn by doing","Linux","mapping","Maps","nav2","navigation","obstacle","pc","Raspberry","ROS","ROS 2","ROS2","static","step by step","Ubuntu"],"articleSection":["ROS 2","Tutorials"],"inLanguage":"es"},{"@type":"WebPage","@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/","url":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/","name":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained - Learn by Doing!","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage"},"image":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp","datePublished":"2025-10-01T12:41:28+00:00","dateModified":"2026-01-10T21:55:05+00:00","description":"Learn how to configure and use the ROS 2 Nav2 Costmap, including static, obstacle, and inflation layers. A complete step-by-step guide with YAML examples, code breakdown, and practical explanations to optimize your robot navigation.","breadcrumb":{"@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#primaryimage","url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp","contentUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/CostMap-5.webp","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/learnbydoing.dev\/mastering-nav2-costmaps-in-ros-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/"},{"@type":"ListItem","position":2,"name":"Mastering Nav2 Costmaps in ROS 2: Static, Obstacle, and Inflation Layers Explained"}]},{"@type":"WebSite","@id":"https:\/\/learnbydoing.dev\/es\/#website","url":"https:\/\/learnbydoing.dev\/es\/","name":"Learn by Doing!","description":"Learn Robotics the fun way","publisher":{"@id":"https:\/\/learnbydoing.dev\/es\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnbydoing.dev\/es\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/learnbydoing.dev\/es\/#organization","name":"Learn by Doing!","url":"https:\/\/learnbydoing.dev\/es\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/","url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png","contentUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png","width":512,"height":512,"caption":"Learn by Doing!"},"image":{"@id":"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/antonio-brandi-512166bb\/"]},{"@type":"Person","@id":"","url":"https:\/\/learnbydoing.dev\/es\/author\/"}]}},"_links":{"self":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/4031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/comments?post=4031"}],"version-history":[{"count":16,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/4031\/revisions"}],"predecessor-version":[{"id":5493,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/4031\/revisions\/5493"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media\/4048"}],"wp:attachment":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media?parent=4031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/categories?post=4031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/tags?post=4031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}