GCC Code Coverage Report


Directory: ./
File: include/sot/core/filter-differentiator.hh
Date: 2024-08-13 12:13:25
Exec Total Coverage
Lines: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*
2 * Copyright 2017-, Rohan Budhirja, LAAS-CNRS
3 *
4 * This file is part of sot-torque-control.
5 * sot-torque-control is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 * sot-torque-control is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details. You should
13 * have received a copy of the GNU Lesser General Public License along
14 * with sot-torque-control. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #ifndef __sot_torque_control_FilterDifferentiator_H__
18 #define __sot_torque_control_FilterDifferentiator_H__
19 /* --------------------------------------------------------------------- */
20 /* --- API ------------------------------------------------------------- */
21 /* --------------------------------------------------------------------- */
22
23 #if defined(WIN32)
24 #if defined(low_pass_filter_EXPORTS)
25 #define SOTFILTERDIFFERENTIATOR_EXPORT __declspec(dllexport)
26 #else
27 #define SOTFILTERDIFFERENTIATOR_EXPORT __declspec(dllimport)
28 #endif
29 #else
30 #define SOTFILTERDIFFERENTIATOR_EXPORT
31 #endif
32
33 //#define VP_DEBUG 1 /// enable debug output
34 //#define VP_DEBUG_MODE 20
35
36 /* --------------------------------------------------------------------- */
37 /* --- INCLUDE --------------------------------------------------------- */
38 /* --------------------------------------------------------------------- */
39
40 /* HELPER */
41 #include <dynamic-graph/signal-helper.h>
42
43 #include <sot/core/causal-filter.hh>
44 #include <sot/core/stop-watch.hh>
45
46 namespace dynamicgraph {
47 namespace sot {
48 /** \addtogroup Filters
49 \section subsec_filterdiff FilterDifferentiator
50 This Entity takes as inputs a signal and applies a low pass filter
51 (implemented through CasualFilter) and computes finite difference derivative.
52
53 The input signal is provided through m_xSIN (an entity signal).
54 The filtered signal is given through m_x_filteredSOUT.
55 The first derivative of the filtered signal is provided with m_dxSOUT.
56 The second derivative of the filtered signal is provided with m_ddxSOUT.
57 */
58 class SOTFILTERDIFFERENTIATOR_EXPORT FilterDifferentiator
59 : public ::dynamicgraph::Entity {
60 5 DYNAMIC_GRAPH_ENTITY_DECL();
61
62 public: /* --- SIGNALS --- */
63 /// Input signals
64 DECLARE_SIGNAL_IN(x, dynamicgraph::Vector);
65 /// Output signal x_filtered
66 DECLARE_SIGNAL_OUT(x_filtered, dynamicgraph::Vector);
67 DECLARE_SIGNAL_OUT(dx, dynamicgraph::Vector);
68 DECLARE_SIGNAL_OUT(ddx, dynamicgraph::Vector);
69
70 /// The following inner signals are used because this entity has
71 /// some output signals
72 /// whose related quantities are computed at the same time by the
73 /// same algorithm
74 /// To avoid the risk of recomputing the same things twice,
75 /// we create an inner signal that groups together
76 /// all the quantities that are computed together.
77 /// Then the single output signals will depend
78 /// on this inner signal, which is the one triggering the computations.
79 /// Inner signals are not exposed, so that nobody can access them.
80
81 /// This signal contains the estimated positions, velocities and
82 /// accelerations.
83 DECLARE_SIGNAL_INNER(x_dx_ddx, dynamicgraph::Vector);
84
85 protected:
86 double m_dt; /// sampling timestep of the input signal
87 int m_x_size;
88
89 /// polynomial-fitting filters
90 CausalFilter *m_filter;
91
92 public:
93 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
94
95 /** --- CONSTRUCTOR ---- */
96 FilterDifferentiator(const std::string &name);
97
98 /** Initialize the FilterDifferentiator.
99 * @param timestep Period (in seconds) after which
100 * the sensors' data are updated.
101 * @param sigSize Size of the input signal.
102 * @param delay Delay (in seconds) introduced by the estimation.
103 * This should be a multiple of timestep.
104 * @note The estimationDelay is half of the length of the
105 * window used for the
106 * polynomial fitting. The larger the delay,
107 * the smoother the estimations.
108 */
109 void init(const double &timestep, const int &xSize,
110 const Eigen::VectorXd &filter_numerator,
111 const Eigen::VectorXd &filter_denominator);
112
113 void switch_filter(const Eigen::VectorXd &filter_numerator,
114 const Eigen::VectorXd &filter_denominator);
115
116 protected:
117 public: /* --- ENTITY INHERITANCE --- */
118 virtual void display(std::ostream &os) const;
119
120 }; // class FilterDifferentiator
121
122 } // namespace sot
123 } // namespace dynamicgraph
124
125 #endif // #ifndef __sot_torque_control_FilterDifferentiator_H__
126