Skip to content

[mppi] Add pluginized motion models#6076

Merged
SteveMacenski merged 12 commits intoros-navigation:mainfrom
Alessio-Parmeggiani:pluginized-motion-models
Apr 21, 2026
Merged

[mppi] Add pluginized motion models#6076
SteveMacenski merged 12 commits intoros-navigation:mainfrom
Alessio-Parmeggiani:pluginized-motion-models

Conversation

@Alessio-Parmeggiani
Copy link
Copy Markdown
Contributor

@Alessio-Parmeggiani Alessio-Parmeggiani commented Apr 10, 2026


Basic Info

Info Please fill out this column
Ticket(s) this addresses #6032
Primary OS tested on Ubuntu 24 (ROS2 Kilted)
Robotic platform tested on Custom setup with simulated movements and maps
Does this PR contain AI generated software? AI suggestions used and manually checked
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

As discussed in #6032 I added motion models for the mppi controller as plugins instead of hardcoded modes.
In this way it is possible for an user to add its own motion model and constraints.

Custom plugins can be added in another package and used with:

      motion_model: "my_motion_model" 
      my_motion_model:
        plugin: "my_pkg::MyMotionModel"
        random_parameter: 0.1 # a parameter to do something

Description of documentation updates required from your changes

plugin needs to be specified with parameters. For example, instead of:

motion_model: "Ackermann"
AckermannConstraints:
    min_turning_r: 0.2

Now is:

      motion_model: "ackermann" 
      ackermann:
        plugin: "mppi::AckermannMotionModel"
        min_turning_r: 0.4  # Minimum turning radius in metres

Implementation notes

I tried to keep the modifications at minimum, some notable changes are:

  • Check for motion model type is no more done using a static cast but uses hasConstrainedTurningRadius and isHolonomic().
  • motionModel.initialize() has been renamed setConstraints(). A new initialize() method is used to retrieve the plugin specific parameter since constructors must be without arguments now that the motion model is a plugin.

Description of how this change was tested

First I ensured that the package nav2_mppi_controller compiles correctly and I run the tests of the nav2_mppi_controller package (colcon test ...) to see if they passed.

I created some node to test the correct behavior with a dummy empty global costmap, a local costmap containing some obstacles and a node that emualtes actuation by converting velocity commands into TF publishing.
I verified that the existing motion models works correctly:

  • with mppi::DiffDriveMotionModel motion model only vx and wz is used
  • with mppi::OmniMotionModel motion model also vy is used
  • with mppi::AckermannMotionModel motion model the velocity uses the minimum turning radius

I also created a new motion model StraightOnlyMotionModel that can only go straight and it works.


Future work that may be required in bullet points

  • I created a new file (motion_models.cpp) and had to put a copyright notice on it to pass the checks, i used "// Copyright (c) 2026 Open Navigation LLC", don't know if it is ok
  • Don't know if using the mppi:: namespace for the motion models is ok

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

Signed-off-by: Alessio Parmeggiani <[email protected]>
Signed-off-by: Alessio Parmeggiani <[email protected]>
Signed-off-by: Alessio Parmeggiani <[email protected]>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
...ler/include/nav2_mppi_controller/motion_models.hpp 100.00% <100.00%> (ø)
...troller/include/nav2_mppi_controller/optimizer.hpp 100.00% <ø> (ø)
..._mppi_controller/src/critics/constraint_critic.cpp 100.00% <ø> (ø)
nav2_mppi_controller/src/motion_models.cpp 100.00% <100.00%> (ø)
nav2_mppi_controller/src/optimizer.cpp 96.82% <100.00%> (ø)

... and 19 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
Copy Markdown
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.

At some point I had to stop reviewing this, this looks too AI generated and not reviewed by a human. Revert all unnecessary changes and TMI commentary. Please try again after you give this a deeper look and change only what is necessay

Comment thread nav2_bringup/params/nav2_params.yaml Outdated
Comment thread nav2_mppi_controller/README.md Outdated
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp Outdated
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp Outdated
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp
@Alessio-Parmeggiani
Copy link
Copy Markdown
Contributor Author

Sorry for that, will fix asap

@Alessio-Parmeggiani Alessio-Parmeggiani marked this pull request as draft April 11, 2026 08:41
Comment thread nav2_mppi_controller/src/optimizer.cpp Outdated
Comment thread nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp Outdated
Copy link
Copy Markdown
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.

Pedantic; I consider this to be done with these changes and our conversation on the pluginlib stuff -- thanks!

The docs definitely need updates on docs.nav2.org for MPPI new parameter / plugins & the migration guide to tell people what to change to make this work for them

Comment thread nav2_bringup/params/nav2_params.yaml Outdated
Comment thread nav2_mppi_controller/test/optimizer_unit_tests.cpp Outdated
Comment thread nav2_mppi_controller/README.md Outdated
Signed-off-by: Alessio Parmeggiani <[email protected]>
Signed-off-by: Alessio Parmeggiani <[email protected]>
Comment thread nav2_mppi_controller/src/optimizer.cpp Outdated
Comment thread nav2_mppi_controller/src/optimizer.cpp Outdated
Comment on lines +604 to +605
motion_model_->initialize(parameters_handler_, plugin_ns);
motion_model_->setConstraints(settings_.constraints, settings_.model_dt);
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.

Put these in the try/catch as well as a protection in case the initialization can cause an exception to be thrown

@SteveMacenski
Copy link
Copy Markdown
Member

Please fix the small conflict + add a test for the catch case here so that we can have full test coverage (i.e. pass in a bogus motion model type that should not be loaded correctly as it does not exist)

+   try {
+     plugin_type = nav2::get_plugin_type_param(node, plugin_ns);
+   } catch (const std::exception & ex) {
+     throw std::runtime_error(
+       "Failed to get plugin type for mppi controller " + plugin_ns + ". Exception: " +
+       ex.what());
+   }
+ 

Otherwise LGTM. The docs updat is the last thing before merge.

The docs definitely need updates on docs.nav2.org for MPPI new parameter / plugins & the migration guide to tell people what to change to make this work for them

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 20, 2026

This pull request is in conflict. Could you fix it @Alessio-Parmeggiani?

Signed-off-by: Alessio Parmeggiani <[email protected]>
@Alessio-Parmeggiani
Copy link
Copy Markdown
Contributor Author

Alessio-Parmeggiani commented Apr 21, 2026

Please fix the small conflict

How should I manage conflicts? Is it ok to merge the main branch into my fork and fix the conflicts like this?

The docs definitely need updates on docs.nav2.org for MPPI new parameter / plugins & the migration guide to tell people what to change to make this work for them

Sure, working on it!

EDIT: made a PR on docs repository

@SteveMacenski
Copy link
Copy Markdown
Member

Fix however you like - we squash merge anyway so feel free to add commits or get messy.

Signed-off-by: Alessio Parmeggiani <[email protected]>
@SteveMacenski
Copy link
Copy Markdown
Member

CI failed + a small adjustment to your docs PR, then we can merge the pair once this CI passes!

@SteveMacenski
Copy link
Copy Markdown
Member

Should this be removed from draft if you're done?

Comment thread nav2_mppi_controller/src/optimizer.cpp Outdated
Signed-off-by: Alessio Parmeggiani <[email protected]>
@Alessio-Parmeggiani Alessio-Parmeggiani marked this pull request as ready for review April 21, 2026 21:08
@SteveMacenski SteveMacenski merged commit 8b40796 into ros-navigation:main Apr 21, 2026
19 checks passed
tonynajjar pushed a commit to botsandus/navigation2 that referenced this pull request Apr 24, 2026
* first draft, compiles correctly

Signed-off-by: Alessio Parmeggiani <[email protected]>

* minor fixes, unit tests ok

Signed-off-by: Alessio Parmeggiani <[email protected]>

* minor doc update

Signed-off-by: Alessio Parmeggiani <[email protected]>

* addressing review comments, removing unnecessary changes

Signed-off-by: Alessio Parmeggiani <[email protected]>

* minor changes to pass tests, removed some descriptions

Signed-off-by: Alessio Parmeggiani <[email protected]>

* using casting to determine motion model type and using existing utils

Signed-off-by: Alessio Parmeggiani <[email protected]>

* minor changes

Signed-off-by: Alessio Parmeggiani <[email protected]>

* removed default diffDrive plugin

Signed-off-by: Alessio Parmeggiani <[email protected]>

* Update nav2_mppi_controller/src/optimizer.cpp

Signed-off-by: Steve Macenski <[email protected]>

* small change and add test for coverage

Signed-off-by: Alessio Parmeggiani <[email protected]>

* minor refactor

Signed-off-by: Alessio Parmeggiani <[email protected]>

---------

Signed-off-by: Alessio Parmeggiani <[email protected]>
Signed-off-by: Steve Macenski <[email protected]>
Co-authored-by: Steve Macenski <[email protected]>
Signed-off-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.

2 participants