1#ifndef ROBOTOC_MOVING_WINDOW_FILTER_HPP_
2#define ROBOTOC_MOVING_WINDOW_FILTER_HPP_
19 using Vector = Eigen::Matrix<double, dim, 1>;
28 const double min_sampling_period=0.0)
29 : time_length_(time_length),
30 min_sampling_period_(min_sampling_period),
31 last_sampling_time_(0.0),
35 if (time_length <= 0.0) {
36 throw std::out_of_range(
"[MovingWindowFilter] invalid argument: 'time_length' must be positive!");
38 if (min_sampling_period < 0) {
39 throw std::out_of_range(
"[MovingWindowFilter] invalid argument: 'min_sampling_period' must be non-negative!");
48 min_sampling_period_(0.0),
49 last_sampling_time_(0.0),
87 const
double min_sampling_period=0.0) {
88 if (time_length <= 0.0) {
89 throw std::out_of_range(
"[MovingWindowFilter] invalid argument: 'time_length' must be positive!");
91 if (min_sampling_period < 0) {
92 throw std::out_of_range(
"[MovingWindowFilter] invalid argument: 'min_sampling_period' must be non-negative!");
94 time_length_ = time_length;
95 min_sampling_period_ = min_sampling_period;
102 last_sampling_time_ = 0.0;
116 data_.push_back(data);
118 last_sampling_time_ = t;
121 if (t - last_sampling_time_ >= min_sampling_period_) {
123 data_.push_back(data);
124 while (t - time_.front() > time_length_) {
129 for (
const auto& e : data_) {
130 average_.noalias() += e;
132 average_.array() /= data_.size();
133 last_sampling_time_ = t;
152 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
155 double time_length_, min_sampling_period_, last_sampling_time_;
156 std::deque<double> time_;
Moving window filter for foot step planning.
Definition: moving_window_filter.hpp:17
int size() const
Gets the current data size.
Definition: moving_window_filter.hpp:141
const Vector & average() const
Gets the average.
Definition: moving_window_filter.hpp:148
MovingWindowFilter(const double time_length, const double min_sampling_period=0.0)
Constructs the filter.
Definition: moving_window_filter.hpp:27
void push_back(const double t, const Vector &data)
Push back a data.
Definition: moving_window_filter.hpp:113
MovingWindowFilter(MovingWindowFilter &&) noexcept=default
Default move constructor.
MovingWindowFilter()
Default constructor.
Definition: moving_window_filter.hpp:46
MovingWindowFilter(const MovingWindowFilter &)=default
Default copy constructor.
void clear()
Clear the filter.
Definition: moving_window_filter.hpp:101
Eigen::Matrix< double, dim, 1 > Vector
Definition: moving_window_filter.hpp:19
MovingWindowFilter & operator=(const MovingWindowFilter &)=default
Default copy assign operator.
~MovingWindowFilter()
Destructor.
Definition: moving_window_filter.hpp:58
void setParameters(const double time_length, const double min_sampling_period=0.0)
Set parameters of the filter.
Definition: moving_window_filter.hpp:86
Definition: constraint_component_base.hpp:17
std::deque< T, Eigen::aligned_allocator< T > > aligned_deque
std deque with Eigen::aligned_allocator.
Definition: aligned_deque.hpp:14