Skip to content

Initialize the wrench filter state with NaN explicitly - #693

Merged
christophfroehlich merged 1 commit into
ros-controls:masterfrom
christophfroehlich:fix-wrench-filter-nan-init
Nov 11, 2026
Merged

christophfroehlich merged 1 commit into
ros-controls:masterfrom
christophfroehlich:fix-wrench-filter-nan-init

Conversation

@christophfroehlich

Copy link
Copy Markdown
Member

The `WrenchStamped` filter traits relied on `EIGEN_INITIALIZE_MATRICES_BY_NAN`, defined in `filter_traits.hpp`, to mark the filter state as uninitialized. The macro has no effect if Eigen was included before this header, and inline Eigen constructors can also be bound to the definition from another shared library loaded in the same process. In that case, the state is uninitialized memory instead of NaN, so `LowPassFilter` (and `ExponentialFilter`) do not initialize from the first sample but start from garbage/zero.

Observed in the admittance_controller (ros-controls/ros2_controllers#560): after activation, the filtered wrench ramps up from zero, i.e., the gravity compensation outputs a fake force (~20 N in the test) for the first updates.

Changes:

  • Fill the storage explicitly with NaN in `FilterTraits::initialize`.
  • Remove the `#define EIGEN_INITIALIZE_MATRICES_BY_NAN` from the public header, it is no longer needed and changes the Eigen behavior of every includer that happens to include it first.
  • Test: the low-pass filter tests include Eigen first, and a new test checks that an unseeded wrench filter returns its first input (fails without the fix).

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.77%. Comparing base (3657779) to head (7cd81ac).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #693      +/-   ##
==========================================
+ Coverage   83.72%   83.77%   +0.05%     
==========================================
  Files          32       32              
  Lines        2224     2231       +7     
  Branches      130      130              
==========================================
+ Hits         1862     1869       +7     
  Misses        277      277              
  Partials       85       85              
Flag Coverage Δ
unittests 83.77% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
..._toolbox/include/control_toolbox/filter_traits.hpp 71.25% <100.00%> (ø)
control_toolbox/test/low_pass_filter_tests.cpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the change making wrench filter initialization independent of Eigen include order.

No open issues 🎉

What changed in this PR

Makes wrench filter initialization independent of Eigen include order and constructor behavior, so unseeded filters initialize from the first sample rather than garbage or zero.

Changes:

  • Explicitly fills WrenchStamped filter storage with NaN.
  • Removes the public header’s EIGEN_INITIALIZE_MATRICES_BY_NAN definition.
  • Adds a first-sample regression test with Eigen included before the filter headers.
File Description
control_toolbox/​test/​low_pass_filter_tests.cpp Includes Eigen first and tests that an unseeded wrench filter returns its first input.
control_toolbox/​include/​control_toolbox/​filter_traits.hpp Replaces macro-dependent initialization with explicit NaN values.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to Ready for review in Review triage Nov 11, 2026
@christophfroehlich christophfroehlich moved this from Ready for review to Needs 2nd review in Review triage Nov 11, 2026

@saikishor saikishor 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.

That's a very good one

@saikishor saikishor added backport-jazzy Triggers PR backport to ROS 2 jazzy. backport-kilted Triggers PR backport to ROS 2 kilted. labels Nov 11, 2026
@christophfroehlich
christophfroehlich merged commit 91fa469 into ros-controls:master Nov 11, 2026
32 checks passed
@github-project-automation github-project-automation Bot moved this from Needs 2nd review to Done in Review triage Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-jazzy Triggers PR backport to ROS 2 jazzy. backport-kilted Triggers PR backport to ROS 2 kilted.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants