Skip to content

feat: optimize trajectory integration and fix Apple Clang template ambiguity - #6017

Merged
SteveMacenski merged 5 commits into
ros-navigation:humblefrom
idesign0:mppi-apple-fix
Mar 11, 2026
Merged

SteveMacenski merged 5 commits into
ros-navigation:humblefrom
idesign0:mppi-apple-fix

Conversation

@idesign0

@idesign0 idesign0 commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR resolves build-blocking template ambiguity on macOS (Apple Clang) and introduces a performance optimization for trajectory integration in the MPPI controller.

Key Changes

  • Isolated Workarounds: Created apple_utils.hpp to house manual cumsum implementations, bypassing xtensor template issues specific to the Clang compiler.
  • Abstraction Layer: Implemented Cumsum1DOp and Cumsum2DOp aliases in optimizer.hpp. This centralizes the platform-specific logic, allowing the core controller code to remain clean and free of #ifdef blocks.
  • Performance Optimization: Updated the smoothing filter and internal utilities to use fixed-rank xt::xtensor<float, 1> instead of xarray. This assists with type deduction and improves execution speed across all platforms.

Performance Benchmarks (macOS ARM64)

Benchmarks were conducted in Release mode (-O3) over 1,000,000 iterations with a 100-step horizon.

Operation Original xtensor Manual (This PR) Improvement
1D Cumsum 0.367784 µs 0.13083 µs ~35% faster
2D Cumsum 0.509195 µs 0.218972 µs ~43% faster

Testing & Verification

The full project currently fails to compile on macOS with the existing xt::cumsum calls. Verification was performed using an isolated benchmark script to compare the standard library against the manual implementation.

Compilation command used for verification:

clang++ -O3 -std=c++17 benchmark.cpp \
  -I ~/humble-ros2/install/include \
  -I ./include \
  -o bench

The following script was used to generate the results:

#include <chrono>
#include <iostream>
#include <xtensor/xtensor.hpp>
#include <xtensor/xmath.hpp> 
#include "nav2_mppi_controller/tools/apple_utils.hpp"

void benchmark_1d_manual(const size_t size, const int iterations) {
   xt::xtensor<float, 1> data = xt::ones<float>({size}) * 0.1f;
   auto start = std::chrono::high_resolution_clock::now();
   float sink = 0.0f;
   for (int i = 0; i < iterations; ++i) {
       auto res = mppi::utils::manual_cumsum_1d(data);
       sink += res(size - 1);
   }
   auto end = std::chrono::high_resolution_clock::now();
   std::cout << "1D Manual:   " << (std::chrono::duration<double>(end-start).count() / iterations) * 1e6 << " us" << std::endl;
}

void benchmark_1d_original(const size_t size, const int iterations) {
   xt::xtensor<float, 1> data = xt::ones<float>({size}) * 0.1f;
   auto start = std::chrono::high_resolution_clock::now();
   float sink = 0.0f;
   for (int i = 0; i < iterations; ++i) {
       auto res = xt::cumsum(data, 0); 
       sink += res(size - 1);
   }
   auto end = std::chrono::high_resolution_clock::now();
   std::cout << "1D Original: " << (std::chrono::duration<double>(end-start).count() / iterations) * 1e6 << " us" << std::endl;
}

void benchmark_2d_manual(const size_t rows, const size_t cols, const int iterations) {
   xt::xtensor<float, 2> data = xt::ones<float>({rows, cols}) * 0.1f;
   auto start = std::chrono::high_resolution_clock::now();
   float sink = 0.0f;
   for (int i = 0; i < iterations; ++i) {
       auto res = mppi::utils::manual_cumsum_2d(data, 0);
       sink += res(rows - 1, cols - 1);
   }
   auto end = std::chrono::high_resolution_clock::now();
   std::cout << "2D Manual:   " << (std::chrono::duration<double>(end-start).count() / iterations) * 1e6 << " us" << std::endl;
}

void benchmark_2d_original(const size_t rows, const size_t cols, const int iterations) {
   xt::xtensor<float, 2> data = xt::ones<float>({rows, cols}) * 0.1f;
   auto start = std::chrono::high_resolution_clock::now();
   float sink = 0.0f;
   for (int i = 0; i < iterations; ++i) {
       auto res = xt::cumsum(data, 0);
       sink += res(rows - 1, cols - 1);
   }
   auto end = std::chrono::high_resolution_clock::now();
   std::cout << "2D Original: " << (std::chrono::duration<double>(end-start).count() / iterations) * 1e6 << " us" << std::endl;
}

int main() {
   const int iterations = 1000000;
   const size_t size = 100;
   benchmark_1d_manual(size, iterations);
   benchmark_1d_original(size, iterations);
   benchmark_2d_manual(size, 3, iterations);
   benchmark_2d_original(size, 3, iterations);
   return 0;
}

Related Issues

Fixes #6003

@mergify

mergify Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

@idesign0, all pull requests must be targeted towards the main development branch.
Once merged into main, it is possible to backport to @humble, but it must be in main
to have these changes reflected into new distributions.

@idesign0
idesign0 changed the base branch from humble to humble_main March 7, 2026 11:43
@mergify

mergify Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

This pull request is in conflict. Could you fix it @idesign0?

@idesign0
idesign0 changed the base branch from humble_main to humble March 7, 2026 11:44

@mini-1235 mini-1235 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@idesign0
idesign0 requested a review from mini-1235 March 8, 2026 14:03

@SteveMacenski SteveMacenski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Otherwise, approved!

Comment thread nav2_mppi_controller/src/bench Resolved
Comment thread nav2_mppi_controller/src/benchmark.cpp Resolved
@idesign0
idesign0 requested a review from SteveMacenski March 9, 2026 10:00

@SteveMacenski SteveMacenski left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your linter changes are making CI fail; please remove them. Otherwise other than below the rest are approved.

view = xt::sign(wz) * xt::fabs(vx) / min_turning_r_;
auto condition = (xt::fabs(vx) / xt::fabs(wz)) < min_turning_r_;
auto constrained_wz = xt::eval(xt::sign(wz) * xt::fabs(vx) / min_turning_r_);
wz = xt::where(condition, constrained_wz, wz);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are there performance changes from this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that has slipped my mind. will come back to you with the stats.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@SteveMacenski I benchmarked three approaches for the wz minimum turning radius:

Method Avg time (ns)
masked_view 29,361
xt::where 33,292
manual loop 9,973

Summary: The manual loop eliminates temporaries, performs in-place updates, and is ~3× faster than masked_view and ~3.3× faster than xt::where, making it the most efficient choice for high-frequency MPPI updates.

The following script was used to generate these metrics:

#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xmath.hpp>
#include <xtensor/xmasked_view.hpp>
#include <chrono>

using namespace std::chrono;

// ---------------- Functions ----------------
double benchmark_masked_view(const xt::xarray<double>& vx, const xt::xarray<double>& wz, double min_turning_r_, size_t iterations)
{
    double total_time = 0.0;
    for (size_t iter = 0; iter < iterations; ++iter)
    {
        auto wz_copy = wz;
        auto start = high_resolution_clock::now();

        // --- masked view logic ---
        auto view = xt::masked_view(wz_copy, (xt::fabs(vx) / xt::fabs(wz_copy)) < min_turning_r_);
        view = xt::sign(wz_copy) * xt::fabs(vx) / min_turning_r_;

        auto end = high_resolution_clock::now();
        total_time += duration<double, std::nano>(end - start).count();
    }
    return total_time / iterations; // average per iteration
}

double benchmark_where(const xt::xarray<double>& vx, const xt::xarray<double>& wz, double min_turning_r_, size_t iterations)
{
    double total_time = 0.0;
    for (size_t iter = 0; iter < iterations; ++iter)
    {
        auto wz_copy = wz;
        auto start = high_resolution_clock::now();

        // --- xt::where logic ---
        auto abs_vx = xt::fabs(vx);
        auto abs_wz = xt::fabs(wz_copy);
        auto condition = (abs_vx / abs_wz) < min_turning_r_;
        wz_copy = xt::where(condition, xt::sign(wz_copy) * abs_vx / min_turning_r_, wz_copy);

        auto end = high_resolution_clock::now();
        total_time += duration<double, std::nano>(end - start).count();
    }
    return total_time / iterations;
}

double benchmark_manual_loop(const xt::xarray<double>& vx, const xt::xarray<double>& wz, double min_turning_r_, size_t iterations)
{
    double total_time = 0.0;
    for (size_t iter = 0; iter < iterations; ++iter)
    {
        auto wz_copy = wz;
        auto start = high_resolution_clock::now();

        // --- manual loop logic ---
        auto abs_vx = xt::fabs(vx);
        auto abs_wz = xt::fabs(wz_copy);
        for (size_t i = 0; i < wz_copy.size(); ++i)
        {
            if ((abs_vx[i] / abs_wz[i]) < min_turning_r_)
                wz_copy[i] = std::copysign(abs_vx[i] / min_turning_r_, wz_copy[i]);
        }

        auto end = high_resolution_clock::now();
        total_time += duration<double, std::nano>(end - start).count();
    }
    return total_time / iterations;
}

// ---------------- Main ----------------
int main()
{
    const size_t N = 100;       // array size
    const size_t iterations = 1000000;  // repeat for averaging
    const double min_turning_r_ = 1.0;

    xt::xarray<double> vx = xt::ones<double>({N});
    xt::xarray<double> wz = 5.0 * xt::ones<double>({N});

    double avg_masked = benchmark_masked_view(vx, wz, min_turning_r_, iterations);
    double avg_where = benchmark_where(vx, wz, min_turning_r_, iterations);
    double avg_loop = benchmark_manual_loop(vx, wz, min_turning_r_, iterations);

    std::cout << "Average time (ns) per iteration:\n";
    std::cout << "masked_view : " << avg_masked << " ns\n";
    std::cout << "xt::where    : " << avg_where << " ns\n";
    std::cout << "manual loop  : " << avg_loop << " ns\n";

    return 0;
}

@SteveMacenski

Copy link
Copy Markdown
Member

Can you fix the linting bits? This makes it hard to review given all the other changes (and CI fails as a result)

@idesign0

Copy link
Copy Markdown
Contributor Author

Your linter changes are making CI fail; please remove them. Otherwise other than below the rest are approved.

got laptop access just now. : D

@idesign0
idesign0 force-pushed the mppi-apple-fix branch 4 times, most recently from be2c641 to f870206 Compare March 10, 2026 21:53
Signed-off-by: Dhruv Patel <[email protected]>
@idesign0

Copy link
Copy Markdown
Contributor Author

@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
...ler/include/nav2_mppi_controller/motion_models.hpp 100.00% <100.00%> (ø)
...troller/include/nav2_mppi_controller/optimizer.hpp 100.00% <ø> (ø)
...oller/include/nav2_mppi_controller/tools/utils.hpp 97.08% <100.00%> (ø)
nav2_mppi_controller/src/optimizer.cpp 99.53% <100.00%> (ø)

... and 5 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
SteveMacenski merged commit e9caa42 into ros-navigation:humble Mar 11, 2026
3 checks passed
sandeepdutta pushed a commit to sandeepdutta/navigation2 that referenced this pull request Apr 21, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Apr 28, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request May 23, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request May 28, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Jun 25, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Oct 10, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Oct 20, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Oct 25, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Nov 1, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Nov 15, 2026
…biguity (ros-navigation#6017)

* feat: optimize trajectory integration and fix Apple Clang template ambiguity

Signed-off-by: Dhruv Patel <[email protected]>

* added apple_utils and removed xt::masked_view

Signed-off-by: Dhruv Patel <[email protected]>

* used inline cumsum instead of Typedefs and added Copyright

Signed-off-by: Dhruv Patel <[email protected]>

* removed uncrusify changes and added manual loop in applyContraint

Signed-off-by: Dhruv Patel <[email protected]>

* code style divergence fixes

Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
@idesign0

Copy link
Copy Markdown
Contributor Author

Could this also go to jazzy? Jazzy's MPPI still uses xtensor and needs the same Apple Clang fix.

@jwallace42

Copy link
Copy Markdown
Contributor

Could this also go to jazzy? Jazzy's MPPI still uses xtensor and needs the same Apple Clang fix.

Yes! Feel free to open a pr.

jwallace42 pushed a commit that referenced this pull request Nov 18, 2026
…ly fixes (#6815)

* Use Mach thread policy for soft real-time priority on macOS (backport #5679)

Partial backport of #5679 to jazzy: only the nav2_util node_utils change.
sched_setscheduler() and SCHED_FIFO do not exist on macOS, so nav2_util
fails to compile there. On __APPLE__, setSoftRealTimePriority() now uses
the Mach thread precedence policy; other platforms are unchanged. The
std::chrono cast part of #5679 targets main and is not needed on jazzy.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install: nav2_util builds with nav2_package()'s -Werror.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>

* Add template keyword for dependent calls on macOS (backport #5729)

Backport of #5729 to jazzy. Apple clang rejects calls to member templates
of a dependent type without the `template` keyword, so nav2_behavior_tree
(bt_action_server_impl.hpp, subtree blackboard setters) and nav2_route
(route_operation_client.hpp, create_client) fail to compile there.
jazzy already has the route_server.hpp part via #6016. jazzy also sets
cancel_timeout on the subtree blackboard (#5903); it is kept, with the
same keyword.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install: nav2_behavior_tree and nav2_bt_navigator build with
nav2_package()'s -Werror.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>

* Fix Apple Clang template ambiguity in MPPI (backport #6017)

Backport of #6017 (merged into humble) to jazzy, whose MPPI still uses
xtensor. On Apple clang the xt::cumsum(..., {1}) calls in optimizer.cpp
resolve through a braced scalar (-Wbraced-scalar-init, an error under
nav2_package()'s -Werror). As in #6017, these use the cumsum helpers in
tools/apple_utils.hpp on __APPLE__; the non-Apple path is unchanged in
result. The humble commit does not apply cleanly to jazzy, so this is
the same change adapted to jazzy's files.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install, both sides with the same local CMakeLists workaround
for the separate AppleClang flag issue: upstream jazzy reports
optimizer.cpp:380/396/398 "braces around scalar initializer"; with this
change those are gone and the remaining errors (-Wpessimizing-move in
four critics, a separate issue) are identical on both sides.

Signed-off-by: Dhruv Patel <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Fix clang -Werror errors in nav2_system_tests and nav2_rviz_plugins (#6803)

Backport of #6803 to jazzy.

* nav2_system_tests: mark the UnknownErrorController overrides (cleanup,
  activate, deactivate, setPlan, computeVelocityCommands, setSpeedLimit)
  with override (-Winconsistent-missing-override).
* nav2_rviz_plugins: discard the stoi() result explicitly
  (-Wunused-result; libc++ marks std::stoi [[nodiscard]]).

Adapted to jazzy: setPlan instead of newPathReceived, and
computeVelocityCommands takes the GoalChecker.

Compile-tested on macOS 27 (arm64, Apple clang 21) as an overlay on a
ROS 2 Jazzy install, with nav2_package()'s -Werror:
nav2_system_tests fails on upstream jazzy with 6 missing-override errors
and builds with this change; nav2_rviz_plugins' nav2_panel.cpp
-Wunused-result error is gone.

(cherry picked from commit 6272fad)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>

* nav2_rviz_plugins: Remove slots without implementation (#4974)

Without this change, when compiled for Jazzy with Nix using gcc14 and
qt-5.15, loading the plugins to rviz fails with the following error:

    [rviz2]: PluginlibFactory: The plugin for class
    'nav2_rviz_plugins/Navigation 2' failed to load. Error: Failed to
    load library /nix/store/...-ros-env/lib/libnav2_rviz_plugins.so.
    Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in
    the library code, and that names are consistent between this macro
    and your XML. Error string: Could not load library dlopen error:
    /nix/store/...-ros-env/lib/libnav2_rviz_plugins.so: undefined
    symbol: _ZN17nav2_rviz_plugins12DockingPanel9onStartupEv, at
    /build/rcutils-release-release-jazzy-rcutils-6.7.2-1/src/shared_library.c:99

The dynamic linker complains about undefined symbol, which corresponds
to a Qt slot, which is declared, but has no implementation. I'm not
sure what is the root cause of this behavior, but removing the slot
definitions fixes the problem and the plugins can be loaded.

Signed-off-by: Michal Sojka <[email protected]>
(cherry picked from commit e6f500e)
Signed-off-by: Dhruv Patel <[email protected]>

* nav2_rviz_plugins: Don't use non-existent slot (#5016)

The definition of the slot was removed in commit
e6f500e ("nav2_rviz_plugins: Remove slots without
implementation (#4974)", 2025-03-10), because it had no
implementation. But we forgot to remove the reference to this slot,
because the compiler cannot detect it.

We remove the reference now. Without this, rviz shows warnings like:

    QObject::connect: No such slot nav2_rviz_plugins::CostmapCostTool::updateAutoDeactivate()
    QObject::connect:  (sender name:   'Single click')

Signed-off-by: Michal Sojka <[email protected]>
(cherry picked from commit 46dbd07)
Signed-off-by: Dhruv Patel <[email protected]>

* Mark virtual overrides with override (backport of #5782)

Clang reports -Winconsistent-missing-override (an error under
nav2_package()'s -Werror) in costmap_filter.hpp, keepout_filter.hpp,
plugin_container_layer.hpp and route_tool.hpp, where some overrides are
marked and others are not. Same headers as #5782 on main; jazzy keeps
`override` instead of `final` on CostmapFilter::isClearable() so
out-of-tree filters that override it still build, and keepout_filter
uses jazzy's Pose2D signature. The map_server and planner_server parts of
#5782 are not needed on jazzy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>

* Circle: keep Polygon::updatePolygon overloads visible (-Woverloaded-virtual)

  circle.hpp:102:8: error: 'nav2_collision_monitor::Circle::updatePolygon' hides
  overloaded virtual function [-Werror,-Woverloaded-virtual]

Circle::updatePolygon(double) hid Polygon::updatePolygon(const Velocity &) (public,
virtual) and Polygon::updatePolygon(PolygonStamped::ConstSharedPtr) (protected).
A using-declaration in Circle's protected section brings them back into Circle's
scope. Circle overrides neither, so virtual dispatch is unchanged; the one call inside
Circle, updatePolygon(msg->data) with a float, still selects updatePolygon(double)
(Velocity is an aggregate and a shared_ptr is not constructible from a float), and
calls through Polygon pointers are unaffected.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* mppi: only probe x86 SIMD flags on x86 (-Wunused-command-line-argument)

  clang++: error: argument unused during compilation: '-msse4.2'
  [-Werror,-Wunused-command-line-argument]

On arm64, check_cxx_compiler_flag("-msse4.2") passes (clang only warns that the flag
is unused) while -mno-avx512f, -mavx2 and -mfma are rejected, so -msse4.2 alone was
added -- with no effect on arm64 code, and fatal under -Werror. The checks and
add_compile_options now run only when CMAKE_SYSTEM_PROCESSOR is x86; on x86 they are
exactly as before.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* mppi: guard GCC-only diagnostic pragmas from clang (-Wunknown-warning-option)

  tools/utils.hpp: error: unknown warning group '-Wstringop-overflow', ignored
  [-Werror,-Wunknown-warning-option]
  (and '-Wmaybe-uninitialized'; same in critic_data.hpp, critic_manager.hpp,
  models/*.hpp, motion_models.hpp, optimizer.hpp, tools/noise_generator.hpp,
  tools/trajectory_visualizer.hpp)

-Wstringop-overflow and -Wmaybe-uninitialized exist only in GCC; clang ignores the
pragma and warns. Each such pragma line is wrapped in
#if defined(__GNUC__) && !defined(__clang__). GCC sees the same pragmas as before;
clang never acted on them. -Warray-bounds (known to both) is left as is.
(test/utils_test.cpp carries the same pragma and gets the same guard; tests were not
built here.)

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* mppi: drop std::move on xtensor expression temporaries (-Wpessimizing-move)

  constraint_critic.cpp: error: moving a temporary object prevents copy elision
  [-Werror,-Wpessimizing-move]   (6x; velocity_deadband_critic.cpp 4x,
  prefer_forward_critic.cpp 2x, path_follow_critic.cpp 2x)

std::move(expr) on a prvalue only adds a move. Each std::move(X) becomes (X) --
parentheses kept, so grouping is unchanged: e.g. std::move(a + b + c) * dt stays
(a + b + c) * dt, not a + b + c * dt -- and where the call was already wrapped,
(std::move(X)) becomes (X). Machine code of all four critics is byte-identical to before
(see below).

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* route, smac_planner: use the nlohmann_json / nanoflann targets for their headers

  nav2_route/include/nav2_route/graph_loader.hpp:22:10: fatal error:
  'nlohmann/json.hpp' file not found
  nav2_route/include/nav2_route/node_spatial_tree.hpp:21:10: fatal error:
  'nanoflann.hpp' file not found
  nav2_smac_planner/include/nav2_smac_planner/node_lattice.hpp:30:10: fatal error:
  'nlohmann/json.hpp' file not found

nav2_route names nlohmann_json in ament_target_dependencies(), which only forwards
<pkg>_INCLUDE_DIRS/<pkg>_TARGETS -- nlohmann_json's config defines neither -- and it
find_package()s nanoflann without using it; nav2_smac_planner includes json.hpp
without finding the package. Both only build where the headers sit in a default
include dir (/usr/include on Ubuntu). Link nlohmann_json::nlohmann_json (and
nanoflann::nanoflann for nav2_route), header-only INTERFACE targets that add their
include dir, and export the dependencies their installed headers need so consumers
(nav2_rviz_plugins) can resolve those targets. Both are already <depend>s in
package.xml. No generated code changes (nav2_route and nav2_smac_planner objects are
byte-identical, below).

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* smac_planner: drop unused #include <omp.h>

  nav2_smac_planner/src/a_star.cpp:16:10: fatal error: 'omp.h' file not found

a_star.cpp uses no OpenMP (no #pragma omp, no omp_* call) and the package neither
finds nor links OpenMP, so the include is unused; it only compiles where omp.h is a
default header (GCC). Removed; a_star.cpp's object code is byte-identical.

Tested on macOS 27 (arm64), Apple clang 21, CMake 4.4.2: all 45 packages of this
branch build as an overlay on ros2-jazzy 26.11.16.7 with nav2_package()'s -Werror active
and no extra compiler flags. Every translation unit of nav2_costmap_2d,
nav2_collision_monitor, nav2_mppi_controller, nav2_route, nav2_rviz_plugins,
nav2_smac_planner and the nav2_system_tests controller plugins (138) was compiled from
the previous commit and from this series with identical flags (the originals with
-Wno-error, both with the source root mapped to one path): `otool -tV` output is
byte-identical for all 138. planner/controller/behavior/bt_navigator/smoother/
waypoint_follower/velocity_smoother/collision_monitor/route_server configure through
lifecycle with nav2_bringup's nav2_params.yaml.
Co-Authored-By: Claude Opus 5.5 <[email protected]>

Signed-off-by: Dhruv Patel <[email protected]>

* nav2_mppi_controller: GCC-only flags only for GCC, match AppleClang

Two compiler checks in the CMakeLists break Apple clang:
* -finline-limit is passed to every compiler; clang rejects it
  (-Wignored-optimization-argument, an error under -Werror). It is now
  added only for GCC; the other optimization flags are unchanged for all.
* The C++20 branch checks CMAKE_CXX_COMPILER_ID STREQUAL "Clang", but
  Apple's compiler reports "AppleClang", so it gets -fconcepts
  (clang++: error: unknown argument: '-fconcepts'). Use MATCHES "Clang",
  as in #6816 on main.

GCC gets exactly the same flags as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Dhruv Patel <[email protected]>

---------

Signed-off-by: Dhruv Patel <[email protected]>
Signed-off-by: Michal Sojka <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Michal Sojka <[email protected]>
idesign0 added a commit to idesign0/id_navigation2 that referenced this pull request Nov 30, 2026
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.

[Humble][macOS] Build Failure in nav2_mppi_controller on macOS (Apple Clang xtensor template ambiguity)

4 participants