Skip to content

Commit b385e27

Browse files
committed
utilizing filters.hpp
Signed-off-by: silanus23 <berkantali23@outlook.com>
1 parent 79f4b3f commit b385e27

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

control_toolbox/include/control_filters/exponential_filter.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "control_toolbox/exponential_filter.hpp"
2626
#include "control_toolbox/exponential_filter_parameters.hpp"
27-
#include "control_toolbox/filters.hpp"
2827

2928
namespace control_filters
3029
{

control_toolbox/include/control_toolbox/exponential_filter.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <vector>
2525

2626
#include "control_toolbox/filter_traits.hpp"
27+
#include "control_toolbox/filters.hpp"
2728

2829
namespace control_toolbox
2930
{
@@ -101,8 +102,8 @@ bool ExponentialFilter<T>::update(const T & data_in, T & data_out)
101102
StorageType storage_in;
102103
Traits::assign(storage_in, data_in);
103104

104-
// Exponential filter update: y[n] = α * x[n] + (1-α) * y[n-1]
105-
old_value_ = storage_in * alpha_ + old_value_ * (1.0 - alpha_);
105+
// Exponential filter update using the templated exponentialSmoothing function
106+
old_value_ = filters::exponentialSmoothing(storage_in, old_value_, alpha_);
106107

107108
Traits::assign(data_out, old_value_);
108109
Traits::add_metadata(data_out, data_in);

control_toolbox/include/control_toolbox/filters.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ namespace filters
4040
/** Exponential smoothing filter. Alpha is between 0 and 1.
4141
* Values closer to 0 weight the last smoothed value more heavily */
4242

43-
static inline double exponentialSmoothing(
44-
double current_raw_value, double last_smoothed_value, double alpha)
43+
template <typename T>
44+
static inline T exponentialSmoothing(const T & current_raw_value, const T & last_smoothed_value, double alpha)
4545
{
4646
return alpha * current_raw_value + (1 - alpha) * last_smoothed_value;
4747
}
4848
} // namespace filters
4949

50-
#endif // CONTROL_TOOLBOX__FILTERS_HPP_"
50+
#endif // CONTROL_TOOLBOX__FILTERS_HPP_

0 commit comments

Comments
 (0)