LeakyIntegrator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, CNRS-UM LIRMM
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 #include <Eigen/Dense>
31 
32 namespace utils
33 {
34 
47 {
48  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
49 
57  inline void add(const Eigen::Vector3d & value, double dt)
58  {
59  integral_ = (1. - rate_ * dt) * integral_ + dt * value;
60  if(saturation_ > 0.)
61  {
62  saturate();
63  }
64  }
65 
69  inline const Eigen::Vector3d & eval() const
70  {
71  return integral_;
72  }
73 
77  inline double rate() const
78  {
79  return rate_;
80  }
81 
87  inline void rate(double rate)
88  {
89  rate_ = rate;
90  }
91 
97  inline void saturation(double s)
98  {
99  saturation_ = s;
100  }
101 
105  inline void setZero()
106  {
107  integral_.setZero();
108  }
109 
110 private:
111  inline void saturate()
112  {
113  for(unsigned i = 0; i < 3; i++)
114  {
115  if(integral_(i) < -saturation_)
116  {
117  integral_(i) = -saturation_;
118  }
119  else if(integral_(i) > saturation_)
120  {
121  integral_(i) = saturation_;
122  }
123  }
124  }
125 
126 private:
127  Eigen::Vector3d integral_ = Eigen::Vector3d::Zero();
128  double rate_ = 0.1;
129  double saturation_ = -1.;
130 };
131 
132 } // namespace utils
133 
void setZero()
Reset integral to zero.
double rate() const
Get leak rate.
void saturation(double s)
Set output saturation.
void rate(double rate)
Set the leak rate of the integrator.
const Eigen::Vector3d & eval() const
Evaluate the output of the integrator.
Leaky integrator.
Utility functions and classes.
Definition: clamp.h:35
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void add(const Eigen::Vector3d &value, double dt)
Add constant input for a fixed duration.