Mppi trajectory visualization

From wimblerobotics/ros2-copilot-skills · View interactive version

Mppi trajectory visualization is an AI agent skill from the GitHub repository wimblerobotics/ros2-copilot-skills. Visualize MPPI trajectory rollouts. Use when debugging MPPI controller behavior, viewing sampled trajectories, or analyzing critic scoring.

How to use this skill

Skill file

<!--

SPDX-FileCopyrightText: 2026 Michael Wimble

SPDX-License-Identifier: Apache-2.0

-->


name: mppi-trajectory-visualization

description: 'Visualize MPPI trajectory rollouts. Use when debugging MPPI controller behavior, viewing sampled trajectories, or analyzing critic scoring.'


MPPI Trajectory Visualization

Enabling Visualization

Set visualize: true in the MPPI controller configuration:

controller_server:
  ros__parameters:
    FollowPath:
      plugin: "nav2_mppi_controller::MPPIController"
      visualize: true
      # ... other params

Published Topics

When visualization is enabled, MPPI publishes:

| Topic | Type | Description |

|-------|------|-------------|

| /mppi_controller/trajectories | visualization_msgs/msg/MarkerArray | All sampled trajectory rollouts |

| /mppi_controller/transformed_global_plan | nav_msgs/msg/Path | The portion of the global plan used by MPPI |

| /mppi_controller/optimal_trajectory | visualization_msgs/msg/MarkerArray | The selected optimal trajectory |

RViz2 Setup

  1. Open RViz2 and click Add → By topic.
  2. Expand /mppi_controller/trajectories and select MarkerArray.
  3. Expand /mppi_controller/optimal_trajectory and select MarkerArray.
  4. Optionally add /mppi_controller/transformed_global_plan as a Path display.

Recommended RViz2 display settings:

MarkerArray (trajectories):
  Topic: /mppi_controller/trajectories
  Marker Alpha: 0.3  (reduce opacity to avoid visual clutter)
  
MarkerArray (optimal):
  Topic: /mppi_controller/optimal_trajectory
  Marker Alpha: 1.0

Color Coding

Trajectories are colored by cost using a gradient:

The optimal trajectory (the weighted average of good trajectories) is displayed separately and is typically a distinct color (blue or bright green).

Interpreting Healthy Visualization

Healthy Patterns

Problematic Patterns

All Trajectories Red
Trajectories Cluster Very Tightly
Trajectories Oscillate Frame-to-Frame
Trajectories Extend Too Far or Too Short
Trajectories Curve Away from the Path
Optimal Trajectory Passes Through Obstacles

CPU Impact

Visualization adds overhead:

Always disable for production (visualize: false). The overhead can push the controller computation over the frequency budget.

Diagnostic Workflow

  1. Set visualize: true and open RViz2 with the trajectory MarkerArray.
  2. Command a navigation goal through a challenging area (doorway, corner, narrow hall).
  3. Observe:
  1. If problems are visible, adjust critic weights and re-test.
  2. Compare with the global plan (Path display) to verify alignment.
  3. Once satisfied, disable visualization.

Recording for Off-line Analysis

ros2 bag record /mppi_controller/trajectories /mppi_controller/optimal_trajectory \
  /local_costmap/costmap /plan -o mppi_debug_bag

Replay with:

ros2 bag play mppi_debug_bag

Then open RViz2 and add the topics for frame-by-frame analysis.

Combining with Costmap Visualization

For full diagnostic visibility, also display:

Overlay all four with the MPPI trajectory markers for a complete picture of the controller's decision-making.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.