Skip to content

Conversation

silanus23
Copy link

@silanus23 silanus23 commented Sep 29, 2025

I have tried to solve the issue on #365. Tried to go with the way of low_pass_filter:

  • Added support both std::vector<double> and geometry_msgs::msg::WrenchStamped.
  • Created a header in control_toolbox and making it use control_filters header.
  • Expanded tests in a way that it tests all data types and their results in the new style.

@Copilot Copilot AI review requested due to automatic review settings September 29, 2025 08:44
@silanus23 silanus23 marked this pull request as draft September 29, 2025 08:45
Copy link

@Copilot 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 exponential filter implementation to use a common backend filter from control_toolbox instead of maintaining separate logic. The refactoring introduces support for additional data types including std::vector<double> and geometry_msgs::msg::WrenchStamped.

  • Adds a new ExponentialFilter class in control_toolbox with template support for multiple data types
  • Updates control_filters::ExponentialFilter to delegate filtering operations to the control_toolbox implementation
  • Expands test coverage with comprehensive tests for the new data types and edge cases

Reviewed Changes

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

File Description
control_toolbox/include/control_toolbox/exponential_filter.hpp New template-based exponential filter implementation with support for multiple data types
control_toolbox/include/control_filters/exponential_filter.hpp Refactored to use control_toolbox backend with specialized templates for WrenchStamped and vector
control_toolbox/src/control_filters/exponential_filter.cpp Added plugin exports for new supported data types
control_toolbox/test/control_filters/test_exponential_filter.cpp Comprehensive test suite covering all supported data types and edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@silanus23 silanus23 marked this pull request as ready for review September 30, 2025 06:33
@silanus23 silanus23 mentioned this pull request Oct 1, 2025
8 tasks
@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 92.46575% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.68%. Comparing base (11a6b04) to head (e685aed).
⚠️ Report is 1 commits behind head on ros2-master.

Files with missing lines Patch % Lines
...box/include/control_filters/exponential_filter.hpp 43.75% 6 Missing and 3 partials ⚠️
...box/include/control_toolbox/exponential_filter.hpp 81.81% 2 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           ros2-master     #493      +/-   ##
===============================================
+ Coverage        80.77%   81.68%   +0.90%     
===============================================
  Files               29       30       +1     
  Lines             2023     2178     +155     
  Branches           124      125       +1     
===============================================
+ Hits              1634     1779     +145     
- Misses             320      326       +6     
- Partials            69       73       +4     
Flag Coverage Δ
unittests 81.68% <92.46%> (+0.90%) ⬆️

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

Files with missing lines Coverage Δ
...x/test/control_filters/test_exponential_filter.cpp 100.00% <100.00%> (ø)
...box/include/control_toolbox/exponential_filter.hpp 81.81% <81.81%> (ø)
...box/include/control_filters/exponential_filter.hpp 52.94% <43.75%> (-13.73%) ⬇️

... and 1 file with indirect coverage changes

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

Copy link
Contributor

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. I think this can be simplified a bit, but maybe I've overseen something.

using Traits = FilterTraits<T>;
using StorageType = typename Traits::StorageType;

StorageType input_value, output_value, old_value;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have to store the last input and output?
Plus, in ros-controls we use code style with trailing _ for class member variables.

Suggested change
StorageType input_value, output_value, old_value;
StorageType old_value_;

Comment on lines +75 to +77
Traits::initialize(output_value);
Traits::initialize(input_value);
Traits::initialize(old_value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Traits::initialize(output_value);
Traits::initialize(input_value);
Traits::initialize(old_value);
Traits::initialize(old_value_);

Comment on lines +91 to +102
if (Traits::is_nan(output_value) || Traits::is_empty(output_value))
{
if (!Traits::is_finite(data_in))
{
return false;
}
Traits::assign(old_value, data_in);
}
else
{
Traits::validate_input(data_in, output_value, data_out);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (Traits::is_nan(output_value) || Traits::is_empty(output_value))
{
if (!Traits::is_finite(data_in))
{
return false;
}
Traits::assign(old_value, data_in);
}
else
{
Traits::validate_input(data_in, output_value, data_out);
}
if (Traits::is_nan(old_value_) || Traits::is_empty(old_value_))
{
if (!Traits::is_finite(data_in))
{
return false;
}
Traits::assign(old_value_, data_in);
}
else
{
Traits::validate_input(data_in, old_value_, data_out);
}

Comment on lines +104 to +109
Traits::assign(input_value, data_in);
// Exponential filter update: y[n] = α * x[n] + (1-α) * y[n-1]
output_value = alpha_ * input_value + (1.0 - alpha_) * old_value;
old_value = output_value;

Traits::assign(data_out, output_value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Traits::assign(input_value, data_in);
// Exponential filter update: y[n] = α * x[n] + (1-α) * y[n-1]
output_value = alpha_ * input_value + (1.0 - alpha_) * old_value;
old_value = output_value;
Traits::assign(data_out, output_value);
// Exponential filter update: y[n] = α * x[n] + (1-α) * y[n-1]
old_value_ = alpha_ * data_in + (1.0 - alpha_) * old_value_;
Traits::assign(data_out, old_value_);

Comment on lines +27 to +28

#include "geometry_msgs/msg/wrench_stamped.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include "geometry_msgs/msg/wrench_stamped.hpp"

do we need this here?

template <typename T>
bool ExponentialFilter<T>::update(const T & data_in, T & data_out)
{
if (!this->configured_)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!this->configured_)
if (!this->configured_ || !expo_ || !expo_->is_configured())

}

template <>
inline bool ExponentialFilter<std::vector<double>>::update(
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this overload at all?


template <typename T>
bool ExponentialFilter<T>::update(const T & data_in, T & data_out)
template <>
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this overload at all?

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.

3 participants