Skip to content

Conversation

@danielsanchezaran
Copy link
Contributor

@danielsanchezaran danielsanchezaran commented Dec 9, 2025

refactor(trajectory_optimizer): reorganize plugin utilities into plugin-specific files

Description

This PR refactors the autoware_trajectory_optimizer package by reorganizing plugin utility functions from a central utils.cpp file into plugin-specific utility files. This improves code modularity, maintainability, and makes the codebase easier to navigate.

Changes

Code Organization:

  • Moved trajectory extender utility functions to plugin_utils/trajectory_extender_utils.{hpp,cpp}
  • Moved trajectory point fixer utility functions to plugin_utils/trajectory_point_fixer_utils.{hpp,cpp}
  • Moved spline smoother utility functions to plugin_utils/trajectory_spline_smoother_utils.{hpp,cpp}
  • Moved velocity optimizer utility functions to plugin_utils/trajectory_velocity_optimizer_utils.{hpp,cpp}
  • Retained utils.cpp for shared utilities used across multiple plugins

Testing:

  • Added comprehensive unit tests for each plugin's utility functions:
    • test_trajectory_extender_utils.cpp (344 lines)
    • test_trajectory_point_fixer_utils.cpp (452 lines)
    • test_trajectory_spline_smoother_utils.cpp (143 lines)
    • test_trajectory_velocity_optimizer_utils.cpp (368 lines)
  • Created test_utils.hpp with shared test helper functions (148 lines)
  • Updated existing tests to work with new structure

Optimizations:

  • Fixed unnecessary copy in trajectory processing by using const reference assignment

Benefits

  1. Improved Modularity: Each plugin's utility functions are now isolated in their own files, making it easier to understand and modify individual plugins
  2. Better Testability: Plugin-specific utilities can now be tested independently with focused unit tests
  3. Easier Maintenance: Changes to one plugin's utilities don't require touching a large monolithic utils file
  4. Clearer Dependencies: It's now obvious which utilities belong to which plugin

Related links

Parent Issue:

None - Standalone refactoring work

How was this PR tested?

  • Built the package successfully with colcon build
  • All existing unit tests pass
  • Verified in Psim tests

Notes for reviewers

  • This is primarily a code reorganization with no functional changes
  • The main review focus should be on ensuring all utility functions were moved correctly and no functionality was lost
  • New unit tests provide comprehensive coverage of the moved functions
  • The central utils.cpp still contains shared utilities used by multiple plugins (trajectory resampling, validation, etc.)

Interface changes

ROS Parameter Changes

Additions and removals

Change type Parameter Name Type Default Value Description
Added trajectory_point_fixer.remove_close_points boolean true Enable removal of close proximity points

Modifications

Version Parameter Name Type Default Value Description
Old fix_invalid_points boolean true Remove repeated or invalid points, or points that go against the general trajectory direction
New use_trajectory_point_fixer boolean true Remove repeated or invalid points, or points that go against the general trajectory direction
Old extend_trajectory_backward boolean false Extend trajectory backward using ego pose history
New use_trajectory_extender boolean false Enable trajectory extender to extend trajectory backward using ego pose history
Old optimize_velocity boolean true Enable velocity profile optimization with jerk filtering and constraint enforcement
New use_velocity_optimizer boolean true Enable velocity profile optimization with jerk filtering and constraint enforcement
Old trajectory_point_fixer.min_dist_to_merge_m number 0.05 Minimum distance threshold for merging close proximity points [m]
New trajectory_point_fixer.min_dist_to_resample_m number 0.05 Minimum distance threshold for merging close proximity points [m]

Note: Parameter names were updated to follow consistent naming conventions with use_ prefix for plugin enable flags and clearer semantic naming for distance thresholds.

Effects on system behavior

Minor behavioral improvement:

The trajectory extender now correctly sets both velocity and acceleration fields when prepending ego pose history points, whereas the original implementation only set velocity. This ensures trajectory consistency and prevents discontinuities in the acceleration profile at the junction between historical and planned trajectory segments.

@github-actions github-actions bot added type:documentation Creating or refining documentation. (auto-assigned) component:planning Route planning, decision-making, and navigation. (auto-assigned) labels Dec 9, 2025
@github-actions
Copy link

github-actions bot commented Dec 9, 2025

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@danielsanchezaran danielsanchezaran added run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) run:clang-tidy-pr-review labels Dec 9, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the autoware_trajectory_optimizer package by reorganizing plugin utility functions from a central utils.cpp file into plugin-specific utility files, improving code modularity and maintainability.

Key changes:

  • Moved utility functions to plugin-specific files (trajectory_extender_utils, trajectory_point_fixer_utils, trajectory_spline_smoother_utils, trajectory_velocity_optimizer_utils)
  • Added comprehensive unit tests for each plugin's utilities (1,307 lines total)
  • Renamed ROS parameters for consistency (fix_invalid_pointsuse_trajectory_point_fixer, optimize_velocityuse_velocity_optimizer, extend_trajectory_backwarduse_trajectory_extender, min_dist_to_merge_mmin_dist_to_resample_m)

Reviewed changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_utils.hpp Shared test helper functions for trajectory creation
tests/test_trajectory_velocity_optimizer_utils.cpp Unit tests for velocity optimizer utilities
tests/test_trajectory_spline_smoother_utils.cpp Unit tests for spline smoother utilities
tests/test_trajectory_point_fixer_utils.cpp Unit tests for point fixer utilities
tests/test_trajectory_extender_utils.cpp Unit tests for trajectory extender utilities
tests/test_trajectory_optimizer.cpp Removed tests moved to plugin-specific test files
tests/test_trajectory_mpt_optimizer_utils.cpp Updated to use shared test utilities
src/utils.cpp Removed plugin-specific utilities, retained shared functions
src/trajectory_optimizer_plugins/*.cpp Updated to use plugin-specific utility namespaces
src/trajectory_optimizer_plugins/plugin_utils/*.cpp New plugin-specific utility implementations
include/autoware/trajectory_optimizer/utils.hpp Removed declarations of moved functions
include/autoware/trajectory_optimizer/trajectory_optimizer_structs.hpp Updated parameter names
include/autoware/trajectory_optimizer/trajectory_optimizer_plugins/*.hpp Updated parameter names and added new utility headers
schema/trajectory_optimizer.schema.json Updated parameter names and descriptions
config/*.yaml Updated parameter names in configuration files
README.md Updated parameter reference in documentation
CMakeLists.txt Added new utility source files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danielsanchezaran danielsanchezaran marked this pull request as ready for review December 9, 2025 09:53
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 70.26684% with 234 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.79%. Comparing base (2a1e270) to head (4b700ba).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...imizer/tests/test_trajectory_point_fixer_utils.cpp 70.28% 0 Missing and 63 partials ⚠️
...tests/test_trajectory_velocity_optimizer_utils.cpp 72.10% 0 Missing and 41 partials ⚠️
...ugin_utils/trajectory_velocity_optimizer_utils.cpp 56.17% 39 Missing ⚠️
...optimizer/tests/test_trajectory_extender_utils.cpp 78.10% 0 Missing and 30 partials ⚠️
.../plugin_utils/trajectory_spline_smoother_utils.cpp 57.57% 8 Missing and 6 partials ⚠️
...er/tests/test_trajectory_spline_smoother_utils.cpp 64.86% 0 Missing and 13 partials ⚠️
...ctory_optimizer_plugins/trajectory_point_fixer.cpp 0.00% 12 Missing ⚠️
..._trajectory_optimizer/src/trajectory_optimizer.cpp 0.00% 8 Missing ⚠️
...ptimizer_plugins/trajectory_velocity_optimizer.cpp 0.00% 6 Missing ⚠️
...ajectory_optimizer_plugins/trajectory_extender.cpp 0.00% 4 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11760      +/-   ##
==========================================
+ Coverage   17.46%   17.79%   +0.32%     
==========================================
  Files        1827     1836       +9     
  Lines      125897   126531     +634     
  Branches    43190    43457     +267     
==========================================
+ Hits        21988    22516     +528     
- Misses      85522    85649     +127     
+ Partials    18387    18366      -21     
Flag Coverage Δ *Carryforward flag
daily 19.96% <ø> (-0.09%) ⬇️ Carriedforward from 2a1e270
daily-cuda 17.60% <ø> (-0.09%) ⬇️ Carriedforward from 2a1e270
differential 16.54% <70.26%> (?)
total-cuda 17.60% <ø> (-0.09%) ⬇️ Carriedforward from 2a1e270

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@danielsanchezaran danielsanchezaran force-pushed the refactor/trajectory_optimizer branch from c61225d to 4b700ba Compare December 10, 2025 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:planning Route planning, decision-making, and navigation. (auto-assigned) run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) run:clang-tidy-pr-review type:documentation Creating or refining documentation. (auto-assigned)

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

2 participants