Skip to content

[Main] Optimize MPPI visualization to skip processing when no subscribers#5851

Merged
SteveMacenski merged 2 commits intoros-navigation:mainfrom
SatArw:feature/reduce_mppi_vis_load_main
Jan 7, 2026
Merged

[Main] Optimize MPPI visualization to skip processing when no subscribers#5851
SteveMacenski merged 2 commits intoros-navigation:mainfrom
SatArw:feature/reduce_mppi_vis_load_main

Conversation

@SatArw
Copy link
Copy Markdown
Contributor

@SatArw SatArw commented Jan 7, 2026


Basic Info

Info Please fill out this column
Ticket(s) this addresses Issue #5801
Primary OS tested on Ubuntu 24.04.3 LTS (via nav2_dev Docker container)
Robotic platform tested on Gazebo Simulation (TurtleBot3 Waffle)
Does this PR contain AI generated software? No
Was this PR description generated by AI software? No

Description of contribution in a few bullet points

This PR is an adaptation of #5807 for the main (rolling) branch.

  • Updated both overloaded instances of TrajectoryVisualizer::add to check subscription counts before executing the marker generation loops.
    • Topics involved: Checks get_subscription_count() on the /candidate_trajectories (MarkerArray) and /optimal_path (Path) publishers.
  • When visualize is set to true:
    • 0 Subscribers (Both topics): The method returns immediately. No markers or paths are calculated.
    • Subscriber for /optimal_path only: Generates and publishes the visualization data for only the optimal trajectory.
    • Subscriber for /candidate_trajectories: Generates the visualization data for all the trajectories (including the optimal trajectory).
  • Reduces controller_server CPU usage when visualization is enabled but not being actively viewed.
  • This is the same optimization previously applied to the Jazzy branch, now ported to main (rolling).

Description of documentation updates required from your changes

  • No documentation updates required. This is an internal optimization that does not change the user-facing API or behavior of the visualize parameter.

Description of how this change was tested

  • Unit Testing:

    • Ran the nav2_mppi_controller GTest suite locally. All tests pass (100%).
    • Verified that the logic changes did not break existing functionality or style guidelines (passed ament_uncrustify and cpplint).
  • Performance Testing:

    • This optimization was previously tested and validated on the Jazzy branch (see related PR [Jazzy] Optimize MPPI visualization to skip processing when no subscribers #5807 for detailed performance metrics).
    • Results demonstrated significant CPU reduction when visualize=true but no subscribers are present.
    • The same logic applies to the main branch with identical expected benefits.
    • Main branch has the additional publish_optimal_trajectory parameter, but this PR's optimization is independent and complementary to that feature.

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

- Added subscription count check in TrajectoryVisualizer::add

Signed-off-by: SatArw <satwik090202@gmail.com>
@SteveMacenski
Copy link
Copy Markdown
Member

Ill leave for Maurice to review / approve before I merge

Remove redundant brackets in if statement

Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
nav2_mppi_controller/src/trajectory_visualizer.cpp 100.00% <100.00%> (ø)

... and 134 files with indirect coverage changes

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

@SteveMacenski
Copy link
Copy Markdown
Member

Eh actually I think this is good, no reason to bother Maurice, he's a busy guy

@SteveMacenski SteveMacenski merged commit 5452855 into ros-navigation:main Jan 7, 2026
16 checks passed
masf7g pushed a commit to quasi-robotics/navigation2 that referenced this pull request Jan 8, 2026
…bers (ros-navigation#5851)

* Optimize MPPI visualization to skip processing when no subscribers

- Added subscription count check in TrajectoryVisualizer::add

Signed-off-by: SatArw <satwik090202@gmail.com>

* Update nav2_mppi_controller/src/trajectory_visualizer.cpp

Remove redundant brackets in if statement

Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>

---------

Signed-off-by: SatArw <satwik090202@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>
Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Lotusymt pushed a commit to Lotusymt/navigation2 that referenced this pull request Jan 16, 2026
…bers (ros-navigation#5851)

* Optimize MPPI visualization to skip processing when no subscribers

- Added subscription count check in TrajectoryVisualizer::add

Signed-off-by: SatArw <satwik090202@gmail.com>

* Update nav2_mppi_controller/src/trajectory_visualizer.cpp

Remove redundant brackets in if statement

Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>

---------

Signed-off-by: SatArw <satwik090202@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>
Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Lotusymt pushed a commit to Lotusymt/navigation2 that referenced this pull request Jan 16, 2026
…bers (ros-navigation#5851)

* Optimize MPPI visualization to skip processing when no subscribers

- Added subscription count check in TrajectoryVisualizer::add

Signed-off-by: SatArw <satwik090202@gmail.com>

* Update nav2_mppi_controller/src/trajectory_visualizer.cpp

Remove redundant brackets in if statement

Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>

---------

Signed-off-by: SatArw <satwik090202@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>
Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: lotusymt <mengtiy5@uci.edu>
Pana1v pushed a commit to Arnav-panjla/navigation2 that referenced this pull request Feb 21, 2026
…bers (ros-navigation#5851)

* Optimize MPPI visualization to skip processing when no subscribers

- Added subscription count check in TrajectoryVisualizer::add

Signed-off-by: SatArw <satwik090202@gmail.com>

* Update nav2_mppi_controller/src/trajectory_visualizer.cpp

Remove redundant brackets in if statement

Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>

---------

Signed-off-by: SatArw <satwik090202@gmail.com>
Signed-off-by: Satwik Arawalli <96329337+SatArw@users.noreply.github.com>
Co-authored-by: Steve Macenski <stevenmacenski@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.

2 participants