modm API documentation
ramp.hpp
1 /*
2  * Copyright (c) 2009-2010, Fabian Greif
3  * Copyright (c) 2009-2010, Martin Rosekeit
4  * Copyright (c) 2010, Georgi Grinshpun
5  * Copyright (c) 2012, Niklas Hauser
6  * Copyright (c) 2012, Sascha Schade
7  *
8  * This file is part of the modm project.
9  *
10  * This Source Code Form is subject to the terms of the Mozilla Public
11  * License, v. 2.0. If a copy of the MPL was not distributed with this
12  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13  */
14 // ----------------------------------------------------------------------------
15 
16 #ifndef MODM_FILTER_RAMP_HPP
17 #define MODM_FILTER_RAMP_HPP
18 
19 namespace modm
20 {
21  namespace filter
22  {
23  /**
24  * \brief Ramp
25  *
26  * The output value is incremented or decremented at every call to update
27  * until target has been reached by increment or decrement.
28  *
29  * The final value is always set to target after several calls to update.
30  *
31  * Example:
32  * \todo example
33  *
34  * \todo documentation
35  * \ingroup modm_math_filter
36  */
37  template<typename T>
38  class Ramp
39  {
40  public:
41  /**
42  * \brief Create a ramp generator
43  *
44  * \param increment Step size for positive direction
45  * \param decrement Step size for the negative direction.
46  * <b>Needs to be positive!</b>
47  * \param initialValue Starting value
48  *
49  * \warning Both values for increment and decrement needs to
50  * be positive!
51  */
52  Ramp(const T& increment,
53  const T& decrement,
54  const T& initialValue = T());
55 
56  inline void
57  setTarget(const T& target);
58 
59  /// Calculate the next step
60  void
61  update();
62 
63  inline void
64  reset(const T& value = T());
65 
66  inline const T&
67  getValue() const;
68 
69  inline bool
70  isTargetReached() const;
71 
72  private:
73  T target;
74  T value;
75  bool targetReached;
76 
77  T increment;
78  T decrement;
79  };
80  }
81 }
82 
83 #include "ramp_impl.hpp"
84 
85 #endif // MODM_FILTER_RAMP_HPP
void update()
Calculate the next step.
Ramp(const T &increment, const T &decrement, const T &initialValue=T ())
Create a ramp generator.
Ramp.
Definition: ramp.hpp:38