Blog

Tuning a Nav2 Costmap for Terrain, Not for a Warehouse Floor

Tom Cosgrove,

Reading Room: The Fictionlab Blog

TL;DR: Common Nav2 example costmap parameters are often configured for flat floors, static obstacles, and clean LiDAR returns. Outdoors, grass reflects noisy points, tall weeds get marked as walls, and uncorrected robot pitch on slopes can trigger false positives. This guide shows Nav2 costmap tuning for outdoor scenarios step by step: adjust obstacle_max_range, raytrace_max_range, inflation_radius, and cost_scaling_factor, add a voxel layer with sensible mark_threshold, and filter ground points before they enter the costmap. Working YAML snippets and diff examples included, tested on the Leo Rover platform.

Why default Nav2 costmap parameters fail on terrain

Nav2 does not provide one universal set of parameters tuned for every robot; its example and tutorial configurations are commonly aimed at indoor differential-drive robots moving through corridors and rooms. Values such as an inflation_radius of 0.55 m, an obstacle_max_range of 2.5 m, and a 2D obstacle layer can work well when the floor is planar and returns come only from walls and static furniture. Field robotics breaks many of those assumptions.

On grass, mud, or gravel, a horizontal LiDAR scan drops points onto uneven ground, and small pitch changes can push those returns into the costmap as phantom obstacles. Tall grass reflects intermittently, so the same tuft appears and disappears between scans. On a slope, level ground can look like a rising wall when the cloud is not transformed using an attitude-correct, gravity-aligned frame. In each case, Nav2 costmap tuning for outdoor terrain means telling the planner what to ignore, not just what to avoid.

This article focuses on the nav2_costmap_2d plugin layers you will actually edit: the obstacle layer, the voxel layer, and the inflation layer. It assumes you run ROS 2 Humble or newer with Nav2 on a UGV such as the Leo Rover, equipped with a 3D LiDAR or depth camera.

What the costmap layers actually do outdoors

A Nav2 costmap is a stack of plugins that each write into a shared occupancy grid. Understanding which layer produces which artifact is the shortest path to a stable outdoor configuration.

  • Static layer: reads a map, typically from /map. Outdoors this is often empty or a coarse aerial mask. You can disable it for pure local navigation.
  • Obstacle layer (2D): processes 2D laser scans or projected observations. Cheap, but blind to overhangs and unable to distinguish grass from rock.
  • Voxel layer (3D): accumulates points into 3D voxels and projects occupied columns to 2D. Requires mark_threshold tuning to reject sparse noise.
  • Inflation layer: assigns a decaying cost around obstacles. The inflation_radius and cost_scaling_factor determine how aggressively the planner avoids clutter.

For terrain, the voxel layer plus a tuned inflation layer can be more robust than a 2D obstacle layer. A voxel column can require multiple occupied voxels before marking a cell occupied, so an isolated point in a single voxel need not create a phantom rock.

How to configure the obstacle and voxel layers for grass and gravel

Below is a typical example configuration that can fail outdoors, followed by a terrain-tuned version. The robot is a skid-steer platform with a tilted 3D LiDAR at approximately 0.4 m height.

Before: indoor defaults on grass

This snippet is close to common Nav2 tutorial configurations. On a lawn, it can produce a costmap covered in gray blobs that shift every scan, and the planner may oscillate or refuse to move.

  • obstacle_layer.plugin: "nav2_costmap_2d::ObstacleLayer"
  • observation_sources: scan
  • scan.topic: /scan
  • scan.max_obstacle_height: 2.0
  • scan.obstacle_max_range: 2.5
  • scan.raytrace_max_range: 3.0
  • inflation_layer.inflation_radius: 0.55
  • inflation_layer.cost_scaling_factor: 3.0

After: voxel layer with ground filtering

The tuned configuration replaces the 2D obstacle layer with a voxel layer, raises the minimum obstacle height above expected grass, and widens ranges to match sensor reach. It also reduces the inflation radius where the robot footprint and safety margin allow it.

Here is the YAML block for local_costmap:

  • plugins: ["voxel_layer", "inflation_layer"]
  • voxel_layer.plugin: "nav2_costmap_2d::VoxelLayer"
  • voxel_layer.enabled: true
  • voxel_layer.publish_voxel_map: true
  • voxel_layer.origin_z: 0.0
  • voxel_layer.z_resolution: 0.1
  • voxel_layer.z_voxels: 16
  • voxel_layer.min_obstacle_height: 0.15
  • voxel_layer.max_obstacle_height: 1.5
  • voxel_layer.mark_threshold: 2
  • voxel_layer.unknown_threshold: 12
  • voxel_layer.observation_sources: pointcloud
  • voxel_layer.pointcloud.topic: /velodyne_points_filtered
  • voxel_layer.pointcloud.data_type: "PointCloud2"
  • voxel_layer.pointcloud.obstacle_max_range: 5.0
  • voxel_layer.pointcloud.raytrace_max_range: 6.0
  • voxel_layer.pointcloud.marking: true
  • voxel_layer.pointcloud.clearing: true
  • inflation_layer.inflation_radius: 0.35
  • inflation_layer.cost_scaling_factor: 2.0

The important choices: min_obstacle_height: 0.15 ignores returns below 15 cm in the costmap’s transformed frame, which can discard typical mown grass and small pebbles when the transform correctly represents robot attitude. mark_threshold: 2 requires at least two occupied voxels in a column before marking the cell; it is a vertical-voxel threshold, not a requirement for two observations over time. obstacle_max_range: 5.0 should match the useful range of the actual sensor and terrain, beyond which beam spacing, vegetation, and pitch can make marking unreliable.

How to filter ground points before Nav2 sees them

The min_obstacle_height parameter helps, but it is not a substitute for ground segmentation. If the cloud is transformed without reliable pitch and roll compensation, level ground can rise above that threshold and get marked. The reliable fix is to remove ground points upstream with a dedicated node.

A pragmatic pipeline uses PCL-based filtering and a passthrough plus a plane-fit filter. This is normally implemented in a dedicated ROS 2 node or composable component rather than as a generic ros2 run command chain:

  1. Transform the raw cloud into a gravity-aligned frame using calibrated TF and IMU attitude information.
  2. Apply a VoxelGrid filter at 0.05 m to reduce density.
  3. Run a SACSegmentation plane fit with a distance threshold of 0.08 m to identify the ground.
  4. Publish the non-ground points on /velodyne_points_filtered.

For production use on rough terrain, the patchwork_pp package, an open-source ground-segmentation implementation, can handle changing slopes better than a single plane fit when properly configured. Feed its non-ground output to the voxel layer topic and validate the result on the vegetation and terrain found at the deployment site.

How to tune inflation radius and cost scaling for tight vegetation

Indoor defaults can inflate obstacles by 0.55 m with a steep cost falloff. Outdoors, this can make a robot refuse to enter narrow tracks between crops or trees. The inflation_radius should reflect the robot’s footprint plus a safety margin. The cost_scaling_factor controls how quickly costs decay outside the robot’s inscribed radius: lower values retain cost farther from obstacles, while higher values make the cost decay more quickly.

A working starting point in agricultural rows is to set inflation_radius only after measuring the configured footprint and the required clearance:

  • inflation_radius: 0.30 to 0.35 can be appropriate only for robots whose footprint and safety margin fit within that distance.
  • cost_scaling_factor: 2.0 produces a gentle cost gradient that can help keep the robot centered in a traversable corridor.

A 0.6 m corridor is not necessarily safe or traversable: it must accommodate the robot’s full width, localization error, tracking error, and the required clearance. If the planner refuses valid gaps, first verify the footprint and reduce inflation_radius only to a safe value. If inflated costs, rather than lethal or footprint collision costs, are causing the rejection, increasing cost_scaling_factor can make costs decay more quickly. If the robot clips obstacles, raise inflation_radius before changing the scaling factor. These trade-offs matter directly in agricultural applications where row spacing is fixed by the crop.

How to validate the tuned costmap on a real trajectory

Parameter changes need empirical checks. A short reproducible test loop:

  1. Record a rosbag of /tf, /tf_static, the raw point cloud, and /odom while teleoperating a 30 m path through the target terrain.
  2. Replay with ros2 bag play and run Nav2 with the candidate YAML, using simulation time where appropriate.
  3. Enable publish_voxel_map: true and visualize /local_costmap/voxel_grid in RViz2.
  4. Count phantom obstacles per meter traveled, and inspect planner and behavior-tree diagnostics, including /behavior_tree_log when behavior-tree logging is enabled.

In field tests, switching from a 2D obstacle layer to a tuned voxel layer with upstream ground filtering can substantially reduce phantom marks and planner oscillation. Exact results depend on sensor, cloud density, transforms, and terrain, so treat this as a starting reference rather than a benchmark.

Iterate one parameter at a time. Change mark_threshold, replay the bag, inspect the voxel grid. This discipline turns Nav2 costmap tuning for outdoor work from guesswork into a measurable process, whether the deployment is a research platform or a production inspection robot.

FAQ

What is a safe default for min_obstacle_height on mown grass?

Between 0.10 m and 0.20 m is a reasonable starting range for many lawn conditions. Below 0.10 m you can catch too many grass returns; above 0.20 m you may miss curbs and small rocks. Verify the setting against the transformed cloud, robot attitude compensation, LiDAR mounting height, and the obstacles that must be detected.

Should you disable the static layer for outdoor navigation?

If you have no prior map, yes. If you have a coarse satellite-derived keepout mask or field boundary, keep the static layer but ensure it publishes at a compatible resolution. Mixed setups often use a KeepoutFilter instead.

How do you prevent tall grass from being marked as an obstacle?

Combine three techniques: raise min_obstacle_height where safe, increase mark_threshold in the voxel layer, and filter ground and low vegetation upstream with a segmentation node. No single parameter is sufficient.

What frame rate should the voxel layer run at?

update_frequency: 5.0 and publish_frequency: 2.0 Hz are reasonable starting values for outdoor UGVs at 1 to 2 m/s, but the required rate depends on speed, stopping distance, sensor rate, and available CPU. Higher frequencies can improve responsiveness when the robot moves quickly or obstacles appear at close range.

Does the inflation layer need to differ between local and global costmaps?

Often yes. The global costmap can use a slightly larger inflation_radius to bias long-horizon plans away from clutter, while the local costmap stays tight to allow reactive maneuvers. Keep the resulting clearance behavior consistent so the global and local planners do not prefer incompatible routes.

Can you use a depth camera instead of a 3D LiDAR?

Yes, with caveats. Depth cameras give dense clouds at close range but may degrade in direct sunlight, reflective surfaces, or adverse weather. Reduce obstacle_max_range to the camera’s reliable measured range, and expect more ground-filtering work.

How do you debug a planner that keeps replanning?

Enable publish_voxel_map, watch for flickering cells in RViz2, and check whether mark_threshold is too low, transforms are stable, or observation_persistence is retaining stale observations. Frequent replans can be caused by noisy marking, but may also result from localization, controller, progress-checker, or planner settings.

For full parameter references, tested configurations, and platform-specific tutorials, see the Fictionlab documentation at docs.fictionlab.pl.


Read more