mc_rtc  2.16.0
StationaryOffset.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  *
4  * This file is inspired by Stephane's Caron original implementation as part of
5  * lipm_walking_controller <https://github.com/stephane-caron/lipm_walking_controller>
6  */
7 
8 #pragma once
9 
11 
12 namespace mc_filter
13 {
21 template<typename VectorT>
23 {
34  StationaryOffset(double dt, double timeConstant, const VectorT & initValue = VectorT::Zero())
35  : average_(dt, timeConstant, initValue)
36  { this->reset(initValue); }
37 
43  void update(const VectorT & value)
44  {
45  average_.append(value);
46  filteredValue_ = value - average_.eval();
47  if(saturation_ > 0.) { utils::clampInPlace(filteredValue_, -saturation_, saturation_); }
48  }
49 
53  const VectorT & eval() const { return filteredValue_; }
54 
59  void reset(const VectorT & initValue)
60  {
61  average_.reset(initValue);
62  filteredValue_ = initValue;
63  }
64 
68  double timeConstant() const { return average_.timeConstant(); }
69 
75  void timeConstant(double T) { average_.timeConstant(T); }
76 
81  void saturation(double limit) { saturation_ = limit; }
82 
83 private:
84  VectorT filteredValue_ = VectorT::Zero();
86  double saturation_ = -1;
87 };
88 } // namespace mc_filter
std::optional< Eigen::VectorXd > value
void clampInPlace(double &value, double lower, double upper)
Definition: clamp.h:36
Definition: ExponentialMovingAverage.h:15
Definition: ExponentialMovingAverage.h:40
Definition: StationaryOffset.h:23
void timeConstant(double T)
Definition: StationaryOffset.h:75
const VectorT & eval() const
Definition: StationaryOffset.h:53
StationaryOffset(double dt, double timeConstant, const VectorT &initValue=VectorT::Zero())
Definition: StationaryOffset.h:34
void reset(const VectorT &initValue)
Definition: StationaryOffset.h:59
double timeConstant() const
Definition: StationaryOffset.h:68
void update(const VectorT &value)
Definition: StationaryOffset.h:43
void saturation(double limit)
Definition: StationaryOffset.h:81