-
Notifications
You must be signed in to change notification settings - Fork 113
Exponantial filter refactoring #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ros2-master
Are you sure you want to change the base?
Conversation
Signed-off-by: silanus23 <[email protected]>
Signed-off-by: silanus23 <[email protected]>
Signed-off-by: silanus23 <[email protected]>
There was a problem hiding this 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 incontrol_toolbox
with template support for multiple data types - Updates
control_filters::ExponentialFilter
to delegate filtering operations to thecontrol_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.
control_toolbox/test/control_filters/test_exponential_filter.cpp
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Signed-off-by: silanus23 <[email protected]>
Signed-off-by: silanus23 <[email protected]>
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
StorageType input_value, output_value, old_value; | |
StorageType old_value_; |
Traits::initialize(output_value); | ||
Traits::initialize(input_value); | ||
Traits::initialize(old_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Traits::initialize(output_value); | |
Traits::initialize(input_value); | |
Traits::initialize(old_value); | |
Traits::initialize(old_value_); |
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} |
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_); |
|
||
#include "geometry_msgs/msg/wrench_stamped.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!this->configured_) | |
if (!this->configured_ || !expo_ || !expo_->is_configured()) |
} | ||
|
||
template <> | ||
inline bool ExponentialFilter<std::vector<double>>::update( |
There was a problem hiding this comment.
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 <> |
There was a problem hiding this comment.
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?
I have tried to solve the issue on #365. Tried to go with the way of
low_pass_filter
:std::vector<double>
andgeometry_msgs::msg::WrenchStamped
.control_toolbox
and making it usecontrol_filters
header.