Repository navigation
Description
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:
-
Parameter Not Loaded: In src/controller.cpp, inside MPPIController::configure(), the code reads the
visualizeparameter but skips readingpublish_optimal_trajectory. -
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(withvisualize: 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
mini-1235 commentedon Dec 19, 2025
The
publish_optimal_trajectorywas 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
mini-1235 commentedon Dec 19, 2025
Sorry, I think I was reading too fast. I think we have two options here:
Does that solve your problem?
SatArw commentedon Dec 20, 2025
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 thatvisualizenow handles the efficient publishing of both~/trajectoriesand~/optimal_trajectorybased 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.
mini-1235 commentedon Dec 20, 2025
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
SteveMacenski commentedon Dec 25, 2025
@mini-1235 can you restate concisely for the person that is interested in this
help-wantedticket what the objective is to solve the ticket?mini-1235 commentedon Dec 25, 2025
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.~/optimal_trajectoryis introduced in Publishing a full time-series MPPI trajectory if desirable #5057, this can be visualized whenpublish_optimal_trajectoryis set to true.~/optimal_pathis renamed from~/optimal_trajectoryin Publishing a full time-series MPPI trajectory if desirable #5057, this can be visualized whenvisualizeis set to true.~/candidate_trajectoriescan be visualized whenvisualizeis set to true.Both ~/optimal_path and ~/candidate_trajectories are computed when
visualizeis true, but they are only published if there is at least one subscriberOn jazzy, there are two topics related to this issue, namely
optimal_trajectoryand/trajectories.optimal_trajectoryis equivalent to~/optimal_pathin main, this can be visualized whenvisualizeis set to true./trajectoriesis equivalent to~/candidate_trajectoriesin main, this can be visualized whenvisualizeis set to true.Both optimal_trajectory and /trajectories are computed when
visualizeis true, but they are only published if there is at least one subscriberThe 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
visualizein main to avoid ambiguityFor Jazzy: I think we can still go with the second option here #5801 (comment), which is moving the subscription count check before computing:
SatArw commentedon Dec 28, 2025
@mini-1235
Thank you for summarizing the situation on main and jazzy.
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.