Skip to content

Conversation

@tonynajjar
Copy link
Contributor

@tonynajjar tonynajjar commented Aug 28, 2025


Basic Info

Info Please fill out this column
Ticket(s) this addresses #5484
Primary OS tested on Ubuntu
Robotic platform tested on private sim
Does this PR contain AI generated software? here and there, not marked (does it matter at this point?)
Was this PR description generated by AI software? Out of respect for maintainers, AI for human-to-human communications are banned

Description of contribution in a few bullet points

  • Add plan_length and plan_length_up_to_inversion and have them computed in the path_handler and passed to the critics data
  • Use one of these paths (according enforce_path_inversion) in the critics

Description of documentation updates required from your changes

Description of how this change was tested


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-*.

@tonynajjar
Copy link
Contributor Author

@claude review the PR

@claude
Copy link
Contributor

claude bot commented Aug 28, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@tonynajjar
Copy link
Contributor Author

Tests probably still need fixing but let's start with functionality review first

@SteveMacenski
Copy link
Member

I'll review, but you got some test failures which makes me suspicious that there are functional problems with this approach if you're getting 0s where you have have non-zeros.

@SteveMacenski SteveMacenski requested a review from Copilot August 28, 2025 22:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces integral path distance calculations for MPPI critics instead of relying on Euclidean distance calculations. The change aims to improve path following accuracy by using actual path length measurements from the robot's current position to the goal.

  • Add plan_length and plan_length_up_to_inversion fields to the Path model and calculate them in the path handler
  • Update all critics to use path distance instead of Euclidean distance for goal proximity checks
  • Modify the optimizer interface to accept and pass through the calculated path lengths

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
nav2_mppi_controller/include/nav2_mppi_controller/models/path.hpp Add plan length fields to Path struct
nav2_mppi_controller/include/nav2_mppi_controller/tools/path_handler.hpp Add methods for path length calculation and retrieval
nav2_mppi_controller/include/nav2_mppi_controller/optimizer.hpp Update optimizer interface to accept plan lengths
nav2_mppi_controller/include/nav2_mppi_controller/tools/utils.hpp Add utility function for getting critic goal path distance
nav2_mppi_controller/src/path_handler.cpp Implement path length calculation logic
nav2_mppi_controller/src/optimizer.cpp Update optimizer to use new plan length parameters
nav2_mppi_controller/src/controller.cpp Pass calculated plan lengths to optimizer
nav2_mppi_controller/src/critics/*.cpp Update critics to use path distance instead of Euclidean distance
nav2_mppi_controller/test/*.cpp Update tests to work with new optimizer interface
nav2_mppi_controller/benchmark/optimizer_benchmark.cpp Update benchmark to use new optimizer interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

You have

I honestly have no idea what I started typing here

@codecov
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...v2_mppi_controller/src/critics/twirling_critic.cpp 75.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
...clude/nav2_mppi_controller/critics/cost_critic.hpp 81.25% <ø> (ø)
...nav2_mppi_controller/critics/goal_angle_critic.hpp 100.00% <ø> (ø)
...clude/nav2_mppi_controller/critics/goal_critic.hpp 100.00% <ø> (ø)
.../nav2_mppi_controller/critics/obstacles_critic.hpp 100.00% <ø> (ø)
...nav2_mppi_controller/critics/path_align_critic.hpp 100.00% <ø> (ø)
...nav2_mppi_controller/critics/path_angle_critic.hpp 100.00% <ø> (ø)
...av2_mppi_controller/critics/path_follow_critic.hpp 100.00% <ø> (ø)
..._mppi_controller/critics/prefer_forward_critic.hpp 100.00% <ø> (ø)
...e/nav2_mppi_controller/critics/twirling_critic.hpp 100.00% <ø> (ø)
...ller/include/nav2_mppi_controller/models/state.hpp 100.00% <ø> (ø)
... and 12 more

... and 3 files with indirect coverage changes

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

Copy link
Member

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

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

DCO sign off 😉 Otherwise LGTM if you don't have any concerns from your testing

}

geometry_msgs::msg::Pose goal = utils::getCriticGoal(data, enforce_path_inversion_);
if (data.goal_checker != nullptr) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this one special to use the goal checker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, question right back at you; seems like it's been like this forever

Copy link
Member

Choose a reason for hiding this comment

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

Oh this was just wrapped into the util function, got it. I thought you introduced this, not refactoring it

@SteveMacenski SteveMacenski linked an issue Sep 3, 2025 that may be closed by this pull request
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
.
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
@tonynajjar tonynajjar force-pushed the critics-integral-distance-main branch from 3f5786c to 614a26c Compare September 4, 2025 08:46
@tonynajjar
Copy link
Contributor Author

tonynajjar commented Sep 4, 2025

LGTM if you don't have any concerns from your testing

We haven't migrated to MPPI yet in production so the testing was limited to simulation. Would be great if OP @bektaskemal could also give it a test
But I think we can merge in the meantime

@SteveMacenski SteveMacenski merged commit c0da22a into ros-navigation:main Sep 4, 2025
17 checks passed
@SteveMacenski
Copy link
Member

SteveMacenski commented Sep 4, 2025

@bektaskemal please test and let us know how it goes! :-)

tonynajjar added a commit to angsa-robotics/navigation2 that referenced this pull request Sep 5, 2025
* Implement integral distance for critics

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* .

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* more linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reset path length

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix sign

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix return value

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* Revert "fix return value"

This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* remove extra variable

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* add doxygen

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* rename getCriticGoalPathDistance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* delete withinPositionGoalTolerance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* use only one path distance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* cleanup

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reorder

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* format

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

---------

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
@sebatztian
Copy link

@tonynajjar for my clarity, this implementation only works as intended, as long as the threshold to consider is smaller than the pruning distance and local costmap bounds, right?

@tonynajjar
Copy link
Contributor Author

this implementation only works as intended

Not sure what you mean by that, because what is intended is that the critic is activated based on which one of threshold_to_consider and the local_path_length is greater. if threshold_to_consider is huge then some critics will always be activated and some others not.

@sebatztian
Copy link

Okay, thanks for the clarification.
I tried to implement the same functionality as a Critic Plugin, where I could only use the pruned path, since the global path is not handed to the critics.
So I was interested in your solution, and wanted to compare.
I guess in theory we would like to check the actual remaining path length, but I am on the same page, that greater threshold distances make little sense.

armgits pushed a commit to armgits/navigation2 that referenced this pull request Sep 5, 2025
* Implement integral distance for critics

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* .

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* more linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reset path length

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix sign

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix return value

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* Revert "fix return value"

This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* remove extra variable

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* add doxygen

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* rename getCriticGoalPathDistance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* delete withinPositionGoalTolerance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* use only one path distance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* cleanup

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reorder

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* format

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

---------

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
armgits pushed a commit to armgits/navigation2 that referenced this pull request Sep 5, 2025
* Implement integral distance for critics

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* .

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* more linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reset path length

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix sign

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix return value

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* Revert "fix return value"

This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* remove extra variable

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* add doxygen

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* rename getCriticGoalPathDistance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* delete withinPositionGoalTolerance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* use only one path distance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* cleanup

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reorder

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* format

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

---------

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
Signed-off-by: Abhishekh Reddy <helloarm@pm.me>
silanus23 pushed a commit to silanus23/navigation2 that referenced this pull request Sep 18, 2025
* Implement integral distance for critics

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* .

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* more linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reset path length

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix sign

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix return value

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* Revert "fix return value"

This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* remove extra variable

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* add doxygen

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* rename getCriticGoalPathDistance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* delete withinPositionGoalTolerance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* use only one path distance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* cleanup

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reorder

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* format

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

---------

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
BCKSELFDRIVEWORLD pushed a commit to BCKSELFDRIVEWORLD/navigation2 that referenced this pull request Sep 23, 2025
* Implement integral distance for critics

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* .

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* more linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reset path length

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix sign

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix return value

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* Revert "fix return value"

This reverts commit 8b21e89.

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* remove extra variable

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* add doxygen

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* rename getCriticGoalPathDistance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* delete withinPositionGoalTolerance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* use only one path distance

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* cleanup

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* linting

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* reorder

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* format

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

* fix tests

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>

---------

Signed-off-by: Tony Najjar <tony.najjar.1997@gmail.com>
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.

MPPI threshold_to_consider computation

3 participants