Franky 0.12.0
A High-Level Motion API for Franka
Loading...
Searching...
No Matches
exponential_filter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <Eigen/Core>
6
7namespace franky {
8
9template <size_t dims>
11 public:
12 explicit ExponentialFilter(double alpha) : alpha_(alpha) {
13 if (alpha < 0 || alpha > 1)
14 throw std::invalid_argument("alpha must be between 0 and 1");
15 }
16
18
19 void add(const Eigen::Vector<double, dims>& value) {
20 if (current_value_.has_value())
21 current_value_ = alpha_ * current_value_.value() + (1 - alpha_) * value;
22 else
23 current_value_ = value;
24 }
25
26 Eigen::Vector<double, dims> current_value() const { return current_value_.value(); }
27
28 Eigen::Vector<double, dims> operator()(const Eigen::Vector<double, dims>& value) {
29 add(value);
30 return current_value();
31 }
32
33 private:
34 std::optional<Eigen::Vector<double, dims>> current_value_;
35 double alpha_;
36};
37
38} // namespace franky
Definition exponential_filter.hpp:10
ExponentialFilter(double alpha)
Definition exponential_filter.hpp:12
Eigen::Vector< double, dims > current_value() const
Definition exponential_filter.hpp:26
ExponentialFilter(const ExponentialFilter &)=default
Eigen::Vector< double, dims > operator()(const Eigen::Vector< double, dims > &value)
Definition exponential_filter.hpp:28
void add(const Eigen::Vector< double, dims > &value)
Definition exponential_filter.hpp:19
Definition dynamics_limit.cpp:8