Skip to content

Add AsymmetricInflationLayer costmap plugin for path-aware lane-keeping - #6118

Merged
SteveMacenski merged 45 commits into
ros-navigation:mainfrom
mbloechli:feat/asymmetric_inflation_layer
Jul 15, 2026
Merged

SteveMacenski merged 45 commits into
ros-navigation:mainfrom
mbloechli:feat/asymmetric_inflation_layer

Conversation

@mbloechli

Copy link
Copy Markdown
Contributor

Basic Info

Info Please fill out this column
Ticket(s) this addresses #6109
Primary OS tested on Ubuntu
Robotic platform tested on gazebo simulation (for the PR in Rolling) & Duatic Alpha (when I was developing in Jazzy)
Does this PR contain AI generated software? Yes, it was proofread and corrected by hand
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

This contribution adds an Asymmetric Inflation Layer, that encourages lane-keeping behaviour without requiring routing. This works by subscribing to the plan topic -> classifying each lethal obstacle as left or right of the global path, then using asymmetric effective distances to bias the BFS priority queue.

Description of documentation updates required from your changes

The layer will need to be documented along the other layers on the nav2 wiki.

Description of how this change was tested

  • I wrote integration and unit test to see if the layer behaves as expected
  • I wrote a performance test to see how its runtime scales with map size
  • Performed linting validation using pre-commit run --all and colcon test

Future work that may be required in bullet points

For Maintainers:

  • Check that any new parameters added are updated in docs.nav2.org
  • Check that any significant change is added to the migration guide
  • Check that any new features OR changes to existing behaviors are reflected in the tuning guide
  • Check that any new functions have Doxygen added
  • Check that any new features have test coverage
  • Check that any new plugins is added to the plugins page
  • If BT Node, Additionally: add to BT's XML index of nodes for groot, BT package's readme table, and BT library lists
  • Should this be backported to current distributions? If so, tag with backport-*.

@mbloechli
mbloechli force-pushed the feat/asymmetric_inflation_layer branch from 669704c to 6265c9c Compare April 29, 2026 19:58

@SteveMacenski SteveMacenski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick initial architectural review:

Out of curiosity, does this share many of the same methods as the legacy layer? If so, can this derive from that layer to make use of the same implementations of those methods?

Does this do incremental updates like the inflation layer? The needs_reinflation_ implies so but I thought you mentioned it does it clean each iteration instead.

@mbloechli

Copy link
Copy Markdown
Contributor Author

Out of curiosity, does this share many of the same methods as the legacy layer? If so, can this derive from that layer to make use of the same implementations of those methods?

Yes, this does indeed share some of the same methods with the legacy layer:

  • distanceLookup() - same
  • cellDistance() - same
  • onFootprintChanged() - nearly the same, a small change in the debug message for both would make them the same
  • updateBounds()- nearly the same, moving the robot_pose update to updateCosts() would make them the same

I'm not sure though if the additional coupling outweighs the inherited methods.

Does this do incremental updates like the inflation layer? The needs_reinflation_ implies so but I thought you mentioned it does it clean each iteration instead.

When I opened the feature request it didn't do incremental updates yet, because when I tried to implement it a month ago, I was having issues with artifacts in the costmap. Yesterday when I was making performance improvements to the updateCosts() and computeObstacleSide() functions, I reimplemented the incremental updates as well and saw now artifacts this time. Maybe I did an error when I tried to implement the iterative updates a month ago.

@mbloechli

Copy link
Copy Markdown
Contributor Author

I've created a PR for docs.nav2.org, adding a basic description of the layer and it's parameters.

@mbloechli
mbloechli force-pushed the feat/asymmetric_inflation_layer branch from 315e30d to 0480c7b Compare May 1, 2026 20:02
Comment thread nav2_costmap_2d/costmap_plugins.xml Resolved
@SteveMacenski

Copy link
Copy Markdown
Member

Rebase/pull in main to get CI to turn over

@SteveMacenski

Copy link
Copy Markdown
Member

@tonynajjar please review since this relates to some of your recent work on this style of new inflation layer

@tonynajjar

Copy link
Copy Markdown
Contributor

@tonynajjar please review since this relates to some of your recent work on this style of new inflation layer

I'm a bit overwhelmed with other tasks currently to thoroughly review such an algorithm-heavy PR that we are not of immediate need for :/

@SteveMacenski

Copy link
Copy Markdown
Member

Please pull in main / rebase to have CI turn over. I need to see the coverage metrics for the unit tests

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new AsymmetricInflationLayer costmap plugin that biases inflation relative to the global path to encourage lane-keeping behavior, along with unit, integration, and benchmark coverage.

Changes:

  • Adds the asymmetric inflation plugin implementation, header, build registration, and pluginlib metadata.
  • Adds unit and integration tests for LUT generation, side classification, and basic layer behavior.
  • Adds benchmark coverage comparing asymmetric inflation against existing inflation implementations.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
nav2_costmap_2d/CMakeLists.txt Builds the new asymmetric inflation plugin source into the layers library.
nav2_costmap_2d/costmap_plugins.xml Registers AsymmetricInflationLayer as a costmap plugin.
nav2_costmap_2d/include/nav2_costmap_2d/asymmetric_inflation_layer.hpp Declares the new path-aware asymmetric inflation layer API and state.
nav2_costmap_2d/plugins/asymmetric_inflation_layer.cpp Implements path subscription, side classification, asymmetric distance transform, and dynamic parameters.
nav2_costmap_2d/test/unit/CMakeLists.txt Adds the asymmetric inflation unit test target.
nav2_costmap_2d/test/unit/asymmetric_inflation_layer_test.cpp Tests disfavored LUT construction and obstacle side classification.
nav2_costmap_2d/test/integration/CMakeLists.txt Adds the asymmetric inflation integration test target and launch registration.
nav2_costmap_2d/test/integration/asymmetric_inflation_tests.cpp Tests standalone layer behavior with and without paths and interface conformance.
nav2_costmap_2d/test/benchmark/CMakeLists.txt Adds the asymmetric inflation benchmark target.
nav2_costmap_2d/test/benchmark/asymmetric_layer_updatecosts_benchmark.cpp Adds full-map and incremental benchmarks for asymmetric, current, and legacy inflation layers.
Comments suppressed due to low confidence (3)

nav2_costmap_2d/test/benchmark/asymmetric_layer_updatecosts_benchmark.cpp:864

  • These registered benchmark cases allocate extremely large costmaps (up to 25,600 × 25,600 cells) and the update path also creates float distance maps, which can require multiple gigabytes of RAM per case and make the benchmark OOM on typical developer or CI machines. Please gate the extreme cases behind an opt-in flag or reduce the default registered sizes so the benchmark target remains runnable by default.
->Args({25600, 25600, 100, 0})  // 1280×1280 m map, ~5 m patch, full diagonal path
->Args({25600, 25600, 200, 0})  // 1280×1280 m map, ~10 m patch, full diagonal path
->Args({800, 800, 100, 20})  // 40×40 m map, ~5 m patch, fixed 20 m path
->Args({1600, 1600, 100, 20})  // 80×80 m map, ~5 m patch, fixed 20 m path
->Args({3200, 3200, 100, 20})  // 160×160 m map, ~5 m patch, fixed 20 m path
->Args({6400, 6400, 100, 20})  // 320×320 m map, ~5 m patch, fixed 20 m path
->Args({12800, 12800, 100, 20})  // 640×640 m map, ~5 m patch, fixed 20 m path
->Args({25600, 25600, 100, 20})  // 1280×1280 m map, ~5 m patch, fixed 20 m path
->Iterations(50)

nav2_costmap_2d/test/benchmark/asymmetric_layer_updatecosts_benchmark.cpp:480

  • The asymmetric full-map benchmark registers the same 12,800 × 12,800 default case, but this fixture runs both the inherited inflation pass and the asymmetric overlay, multiplying the memory pressure from full-size distance maps. Please keep such extreme sizes behind an explicit opt-in instead of registering them by default.
->Args({3200, 3200})  // 160x160 m
->Args({6400, 6400})  // 320x320 m
->Args({12800, 12800})  // 640x640 m
->Iterations(50)

nav2_costmap_2d/test/benchmark/asymmetric_layer_updatecosts_benchmark.cpp:586

  • The incremental baseline registrations include 25,600 × 25,600 maps by default. Even with a small update window, fixture setup allocates and pre-warms the full costmap, which can consume gigabytes and make the benchmark unusable without a very large machine; please make these stress cases opt-in.
->Args({12800, 12800, 100})  // 640×640 m map, ~5 m patch
->Args({12800, 12800, 200})  // 640×640 m map, ~10 m patch
->Args({25600, 25600, 100})  // 1280×1280 m map, ~5 m patch
->Args({25600, 25600, 200})  // 1280×1280 m map, ~10 m patch
->Iterations(50)

Comment thread nav2_costmap_2d/costmap_plugins.xml Resolved
@SteveMacenski

SteveMacenski commented May 14, 2026 •

Copy link
Copy Markdown
Member

Something to double check: we do things like this for optimized collision checking: https://github.com/ros-navigation/navigation2/blob/855ba78e14c69839cb7a798ce2634293d5150dc0/nav2_mppi_controller/src/critics/cost_critic.cpp#L114C31-L114C42 does this return the most conservative cost at all times for the L/R scale factor parameters?

@jwallace42 jwallace42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any visuals of the inflation in a narrow aisle (i.e when the asymmetric inflation would overlap the symmetric inflation)? I might be missing something but I think you could get end up with discrete jumps in cost in these scenarios.

Nice job btw :) Wicked cool.

@mbloechli

Copy link
Copy Markdown
Contributor Author

Thank you very much for the reviews! Sorry for not addressing your reviews earlier. I'm currently overworked, but have time this weekend to address it.

@mbloechli
mbloechli force-pushed the feat/asymmetric_inflation_layer branch 3 times, most recently from 12153f7 to e9465c5 Compare May 25, 2026 11:59
@codecov

codecov Bot commented May 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.35897% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
..._costmap_2d/plugins/asymmetric_inflation_layer.cpp 99.35% 2 Missing ⚠️
Files with missing lines Coverage Δ
...ude/nav2_costmap_2d/asymmetric_inflation_layer.hpp 100.00% <100.00%> (ø)
..._costmap_2d/plugins/asymmetric_inflation_layer.cpp 99.35% <99.35%> (ø)

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbloechli

Copy link
Copy Markdown
Contributor Author

Do you have any visuals of the inflation in a narrow aisle (i.e when the asymmetric inflation would overlap the symmetric inflation)? I might be missing something but I think you could get end up with discrete jumps in cost in these scenarios.

I uploaded a video of the robot driving through our office a few weeks ago in issue 6109

Inflation jumps happen the same way as in the standard inflation_layer. -> Wherever two inflation waves meet, they'll have the same cost at the boundary, though the derivative at that point will be not continious.

@mbloechli

Copy link
Copy Markdown
Contributor Author

Something to double check: we do things like this for optimized collision checking: https://github.com/ros-navigation/navigation2/blob/855ba78e14c69839cb7a798ce2634293d5150dc0/nav2_mppi_controller/src/critics/cost_critic.cpp#L114C31-L114C42 does this return the most conservative cost at all times for the L/R scale factor parameters?

It should, yes.
The asymmetric inflation layer inherits from the inflation layer and calls it with the higher cost_scaling_factors of L or R. computeCost() should therefore always yield the more conservative cost

@mbloechli
mbloechli force-pushed the feat/asymmetric_inflation_layer branch 2 times, most recently from 073d11f to 606fd46 Compare June 10, 2026 12:37
@mbloechli

Copy link
Copy Markdown
Contributor Author

@SteveMacenski @jwallace42
The test coverage should now be up to nav2 standard as well. Before rebasing this branch onto main, the code coverage workflow passed with 100%.

After rebasing the circleci release_test now fails for the nav2_system_test package. I do think this is unrelated to my changes though, because the nav2_system_test package isn't using the proposed asymmetric_inflation_layer

Is there anything else I should change?

@jwallace42 jwallace42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated a few comments. Feel free to request a review in the future if you need me to take another look. Otherwise I assume you are still working :).

mbloechli and others added 20 commits July 15, 2026 19:47
Signed-off-by: mbloechli <[email protected]>
Signed-off-by: Marc Blöchlinger <[email protected]>
@mbloechli
mbloechli force-pushed the feat/asymmetric_inflation_layer branch from 74e14ad to 328da2e Compare July 15, 2026 17:47
@SteveMacenski
SteveMacenski merged commit 6a8161e into ros-navigation:main Jul 15, 2026
15 checks passed
mbloechli added a commit to Duatic/navigation2 that referenced this pull request Oct 23, 2026
Backport of ros-navigation#6118. Upstream builds the layer on the distance transform
InflationLayer from ros-navigation#5933, which Jazzy does not have, so the layer is
ported onto Jazzy's InflationLayer instead:

* Pass 1 uses Jazzy's InflationLayer::updateCosts for the symmetric
  baseline. Pass 2 matches upstream and uses distance_transform.hpp, taken
  unchanged from ros-navigation#5933. Nothing else from ros-navigation#5933 is backported, so
  Jazzy's InflationLayer keeps its implementation and class layout.
* Parameters are declared with Layer::declareParameter, and a single
  on-set callback validates and applies them, as in Jazzy's other layers.
* num_threads and the OpenMP loop are dropped, since Jazzy builds the
  layers without OpenMP.
* plan_topic is resolved in the costmap's parent namespace inside the
  layer, because Jazzy's Layer has no joinWithParentNamespace.
* Includes the null check on the first path message from ros-navigation#6281.
* The benchmark is dropped, as Jazzy has no costmap benchmark suite.

The tests follow the same changes: nav2_util::LifecycleNode, no
activate, deactivate or num_threads cases, and a new case for rejecting
negative parameters.

(cherry picked from commit 6a8161e)
Signed-off-by: mbloechli <[email protected]>
mbloechli added a commit to Duatic/navigation2 that referenced this pull request Oct 23, 2026
Backport of ros-navigation#6118. Upstream builds the layer on the distance transform
InflationLayer from ros-navigation#5933, which Kilted does not have, so the layer is
ported onto Kilted's InflationLayer instead, as in the Jazzy backport:

* Pass 1 uses Kilted's InflationLayer::updateCosts for the symmetric
  baseline. Pass 2 matches upstream and uses distance_transform.hpp, taken
  unchanged from ros-navigation#5933. Nothing else from ros-navigation#5933 is backported, so
  Kilted's InflationLayer keeps its implementation and class layout.
* distance_transform.hpp needs Eigen, so Eigen3 is added as a dependency
  of the layers library and exported, as ros-navigation#5933 does upstream.
* Parameters are declared with Layer::declareParameter, and a single
  on-set callback validates and applies them, as in Kilted's other layers.
* num_threads and the OpenMP loop are dropped, since Kilted builds the
  layers without OpenMP.
* Includes the null check on the first path message from ros-navigation#6281.
* The benchmark is dropped, as Kilted has no costmap benchmark suite.

The tests follow the same changes: nav2_util::LifecycleNode, no
activate, deactivate or num_threads cases, a new case for rejecting
negative parameters and one for resolving plan_topic.

(cherry picked from commit 6a8161e)
Signed-off-by: mbloechli <[email protected]>
SteveMacenski pushed a commit that referenced this pull request Oct 27, 2026
…-aware lane-keeping (backport #6118 & #6487) (#6688)

* feat(nav2_costmap_2d): backport AsymmetricInflationLayer to Jazzy

Backport of #6118. Upstream builds the layer on the distance transform
InflationLayer from #5933, which Jazzy does not have, so the layer is
ported onto Jazzy's InflationLayer instead:

* Pass 1 uses Jazzy's InflationLayer::updateCosts for the symmetric
  baseline. Pass 2 matches upstream and uses distance_transform.hpp, taken
  unchanged from #5933. Nothing else from #5933 is backported, so
  Jazzy's InflationLayer keeps its implementation and class layout.
* Parameters are declared with Layer::declareParameter, and a single
  on-set callback validates and applies them, as in Jazzy's other layers.
* num_threads and the OpenMP loop are dropped, since Jazzy builds the
  layers without OpenMP.
* plan_topic is resolved in the costmap's parent namespace inside the
  layer, because Jazzy's Layer has no joinWithParentNamespace.
* Includes the null check on the first path message from #6281.
* The benchmark is dropped, as Jazzy has no costmap benchmark suite.

The tests follow the same changes: nav2_util::LifecycleNode, no
activate, deactivate or num_threads cases, and a new case for rejecting
negative parameters.

(cherry picked from commit 6a8161e)
Signed-off-by: mbloechli <[email protected]>

* test(nav2_costmap_2d): clean up rclcpp in asymmetric inflation tests

Backport of #6487. The integration tests initialised and shut down rclcpp
from a global fixture, which ran at process exit and hung under Zenoh.
main() now owns rclcpp::init and rclcpp::shutdown, and the fixture's
TearDown releases the layer, costmap, TF buffer and node first.

Resolved against Jazzy's nav2_util::LifecycleNode and tf2_ros::Buffer
members.

(cherry picked from commit f31c7f4)
Signed-off-by: mbloechli <[email protected]>

---------

Signed-off-by: mbloechli <[email protected]>
Co-authored-by: Tony Najjar <[email protected]>
SteveMacenski pushed a commit that referenced this pull request Oct 27, 2026
…-aware lane-keeping (backport #6118 & #6487) (#6689)

* feat(nav2_costmap_2d): backport AsymmetricInflationLayer to Kilted

Backport of #6118. Upstream builds the layer on the distance transform
InflationLayer from #5933, which Kilted does not have, so the layer is
ported onto Kilted's InflationLayer instead, as in the Jazzy backport:

* Pass 1 uses Kilted's InflationLayer::updateCosts for the symmetric
  baseline. Pass 2 matches upstream and uses distance_transform.hpp, taken
  unchanged from #5933. Nothing else from #5933 is backported, so
  Kilted's InflationLayer keeps its implementation and class layout.
* distance_transform.hpp needs Eigen, so Eigen3 is added as a dependency
  of the layers library and exported, as #5933 does upstream.
* Parameters are declared with Layer::declareParameter, and a single
  on-set callback validates and applies them, as in Kilted's other layers.
* num_threads and the OpenMP loop are dropped, since Kilted builds the
  layers without OpenMP.
* Includes the null check on the first path message from #6281.
* The benchmark is dropped, as Kilted has no costmap benchmark suite.

The tests follow the same changes: nav2_util::LifecycleNode, no
activate, deactivate or num_threads cases, a new case for rejecting
negative parameters and one for resolving plan_topic.

(cherry picked from commit 6a8161e)
Signed-off-by: mbloechli <[email protected]>

* test(nav2_costmap_2d): clean up rclcpp in asymmetric inflation tests

Backport of #6487. The integration tests initialised and shut down rclcpp
from a global fixture, which ran at process exit and hung under Zenoh.
main() now owns rclcpp::init and rclcpp::shutdown, and the fixture's
TearDown releases the layer, costmap, TF buffer and node first.

Resolved against Kilted's nav2_util::LifecycleNode and tf2_ros::Buffer
members.

(cherry picked from commit f31c7f4)
Signed-off-by: mbloechli <[email protected]>

---------

Signed-off-by: mbloechli <[email protected]>
Co-authored-by: Tony Najjar <[email protected]>
Rooteq pushed a commit to Rooteq/navigation2 that referenced this pull request Nov 9, 2026
…-aware lane-keeping (backport ros-navigation#6118 & ros-navigation#6487) (ros-navigation#6688)

* feat(nav2_costmap_2d): backport AsymmetricInflationLayer to Jazzy

Backport of ros-navigation#6118. Upstream builds the layer on the distance transform
InflationLayer from ros-navigation#5933, which Jazzy does not have, so the layer is
ported onto Jazzy's InflationLayer instead:

* Pass 1 uses Jazzy's InflationLayer::updateCosts for the symmetric
  baseline. Pass 2 matches upstream and uses distance_transform.hpp, taken
  unchanged from ros-navigation#5933. Nothing else from ros-navigation#5933 is backported, so
  Jazzy's InflationLayer keeps its implementation and class layout.
* Parameters are declared with Layer::declareParameter, and a single
  on-set callback validates and applies them, as in Jazzy's other layers.
* num_threads and the OpenMP loop are dropped, since Jazzy builds the
  layers without OpenMP.
* plan_topic is resolved in the costmap's parent namespace inside the
  layer, because Jazzy's Layer has no joinWithParentNamespace.
* Includes the null check on the first path message from ros-navigation#6281.
* The benchmark is dropped, as Jazzy has no costmap benchmark suite.

The tests follow the same changes: nav2_util::LifecycleNode, no
activate, deactivate or num_threads cases, and a new case for rejecting
negative parameters.

(cherry picked from commit 6a8161e)
Signed-off-by: mbloechli <[email protected]>

* test(nav2_costmap_2d): clean up rclcpp in asymmetric inflation tests

Backport of ros-navigation#6487. The integration tests initialised and shut down rclcpp
from a global fixture, which ran at process exit and hung under Zenoh.
main() now owns rclcpp::init and rclcpp::shutdown, and the fixture's
TearDown releases the layer, costmap, TF buffer and node first.

Resolved against Jazzy's nav2_util::LifecycleNode and tf2_ros::Buffer
members.

(cherry picked from commit f31c7f4)
Signed-off-by: mbloechli <[email protected]>

---------

Signed-off-by: mbloechli <[email protected]>
Co-authored-by: Tony Najjar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants