Skip to content

[Jazzy] MPPI Controller ignores 'publish_optimal_trajectory' parameter #5801

Closed

Description

@SatArw

Bug report

Required Info:

  • Operating System:
    • Ubuntu 24.04.3 LTS (running in Docker)
  • Computer:
    • Docker Container
  • ROS2 Version:
    • ROS 2 Jazzy Jalisco (Binaries)
  • Version or commit hash:
    • ros-jazzy-nav2-mppi-controller: 1.3.9-1noble.20251009.234418
    • jazzy branch on navigation2
    • (All other nav2 packages are also at version 1.3.9)
  • DDS implementation:
    • FastDDS

Steps to reproduce issue

1. Install `ros-jazzy-navigation2`.
2. Configure `nav2_params.yaml` for the MPPI controller:  
   visualize: false
   publish_optimal_trajectory: true
3. Run the navigation stack.
4. Check for the topic: ros2 topic list | grep optimal_trajectory
Result: The topic is not published.

Expected behavior

Adhering to the documentation, the controller should publish the single best trajectory to ~/optimal_trajectory when publish_optimal_trajectory is true, even if visualize (debug mode) is set to false.

Actual behavior

The optimal_trajectory topic is never published unless visualize is set to true.

While enabling visualize: true does successfully publish the optimal path, it introduces a severe performance penalty because it forces the controller to also generate the full "Candidate Trajectories" marker array.

Crucially, the expensive conversion of these candidate paths from internal tensors to visualization_msgs/MarkerArray occurs unconditionally inside TrajectoryVisualizer::add(), before the publisher checks for subscribers. Consequently, enabling visualize: true spikes CPU usage significantly even if there are zero subscribers to the ~/trajectories topic.

Additional information

Code Analysis & Root Cause:
I looked at the source code in the jazzy branch of nav2_mppi_controller and found two specific instances that prevent this from working:

  1. Parameter Not Loaded: In src/controller.cpp, inside MPPIController::configure(), the code reads the visualize parameter but skips reading publish_optimal_trajectory.

  2. Visualization Logic is Gated: In src/controller.cpp, the visualize() function is blocked by an if statement that only checks visualize_

Because of this, the code that publishes the optimal trajectory never runs unless the full debug mode is on.

Comparison with Main Branch Logic:
In the main (Rolling) branch, this feature is implemented to separate the "heavy" debug visualization from the "light" optimal trajectory publishing. The intended design allows:

  • visualize: true: Publishes ~/trajectories (Candidate paths, CPU heavy) + ~/optimal_trajectory.
  • publish_optimal_trajectory: true (with visualize: false): Publishes ONLY ~/optimal_trajectory (CPU light).

The current Jazzy implementation differs from this by gating all visualization behind the visualize_ boolean, effectively coupling the lightweight optimal path to the heavy candidate generation.

Are there any plans to implement this for the jazzy branch? I have already prototyped a fix for this in my local workspace. If you agree this is a bug, I am happy to open a pull request to patch it for the Jazzy branch.

Activity

  1. mini-1235 commented on Dec 19, 2025

    @mini-1235
    Collaborator

    The publish_optimal_trajectory was introduced 8 months ago in #5057. However, we are unable to backport it because it would break API/ABI compatibility, and Jazzy does not use Eigen.

    As long as the PR does not break the API/ABI compatibility, we are happy to review and merge it

  2. mini-1235 commented on Dec 19, 2025

    @mini-1235
    Collaborator

    Sorry, I think I was reading too fast. I think we have two options here:

    Does that solve your problem?

  3. SatArw commented on Dec 20, 2025

    @SatArw
    ContributorAuthor

    Option 2 seems like the best path forward. It reduces computational load without risking API/ABI compatibility breaks.

    On a side note, once these changes are merged, we should update the documentation for publish_optimal_trajectory. It would be helpful to add a note for Jazzy users indicating that this parameter is not available and that visualize now handles the efficient publishing of both ~/trajectories and ~/optimal_trajectory based on subscription status.

    If you would like me to work on this, I am happy to implement Option 2. However, due to upcoming commitments, I would not be able to submit a PR until late January. If this is urgent, please feel free to handle it internally; otherwise, I can pick it up when I return.

  4. mini-1235 commented on Dec 20, 2025

    @mini-1235
    Collaborator

    Unfortunately, our documentation currently targets only main (rolling). We do plan to support other versions in the future, but our bandwidth is limited at themoment.

    Got it, I will label this as "good first issue" and "help wanted" for now to see if others are interested in contributing. As always, we would be happy to welcome your contribution as well

  5. added
    help wanted
    good first issue
    on Dec 20, 2025
  6. SteveMacenski commented on Dec 25, 2025

    @SteveMacenski
    Member

    @mini-1235 can you restate concisely for the person that is interested in this help-wanted ticket what the objective is to solve the ticket?

  7. mini-1235 commented on Dec 25, 2025

    @mini-1235
    Collaborator

    My bad, it seems that I mixed up optimal_path and optimal_trajectory due to the topic renaming in main. I will try to clearly summarize everything here:

    On main, there are three topics related to this issue, namely ~/optimal_trajectory, ~/optimal_path, and ~/candidate_trajectories.

    Both ~/optimal_path and ~/candidate_trajectories are computed when visualize is true, but they are only published if there is at least one subscriber

    On jazzy, there are two topics related to this issue, namely optimal_trajectory and /trajectories.

    • optimal_trajectory is equivalent to ~/optimal_path in main, this can be visualized when visualize is set to true.
    • /trajectories is equivalent to ~/candidate_trajectories in main, this can be visualized when visualize is set to true.

    Both optimal_trajectory and /trajectories are computed when visualize is true, but they are only published if there is at least one subscriber

    The user wants to subscribe to optimal_trajectory only, and not /trajectories.
    However, when visualize is enabled, both are still being computed, even if only one is subscribed.

    For main: There is already a related PR discussion here: #5643 (comment), we may also want to consider renaming visualize in main to avoid ambiguity
    For Jazzy: I think we can still go with the second option here #5801 (comment), which is moving the subscription count check before computing:

    if (trajectories_publisher_->get_subscription_count() > 0) {
    if (optimal_path_pub_->get_subscription_count() > 0) {
    
  8. SatArw commented on Dec 28, 2025

    @SatArw
    ContributorAuthor

    @mini-1235
    Thank you for summarizing the situation on main and jazzy.

    For Jazzy: I think we can still go with the second option here #5801 (comment), which is moving the subscription count check before computing

    For jazzy, I have made PR #5807 by adding the necessary subscription checks before computing for visualization. Please check it out and let me know if any changes/updates are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions