Line |
Branch |
Exec |
Source |
1 |
|
|
// This file is part of INSTINCT, the INS Toolkit for Integrated |
2 |
|
|
// Navigation Concepts and Training by the Institute of Navigation of |
3 |
|
|
// the University of Stuttgart, Germany. |
4 |
|
|
// |
5 |
|
|
// This Source Code Form is subject to the terms of the Mozilla Public |
6 |
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this |
7 |
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
8 |
|
|
|
9 |
|
|
/// @file LowPassFilter.hpp |
10 |
|
|
/// @brief Filters incoming data |
11 |
|
|
/// @author T. Hobiger (thomas.hobiger@ins.uni-stuttgart.de) |
12 |
|
|
/// @author T. Topp (topp@ins.uni-stuttgart.de) |
13 |
|
|
/// @date 2024-12-20 |
14 |
|
|
|
15 |
|
|
#pragma once |
16 |
|
|
|
17 |
|
|
#include "internal/Node/Node.hpp" |
18 |
|
|
|
19 |
|
|
#include "NodeData/IMU/ImuObs.hpp" |
20 |
|
|
#include "NodeData/IMU/ImuObsWDelta.hpp" |
21 |
|
|
|
22 |
|
|
#include "util/Eigen.hpp" |
23 |
|
|
#include <map> |
24 |
|
|
|
25 |
|
|
namespace NAV |
26 |
|
|
{ |
27 |
|
|
/// Filters incoming data |
28 |
|
|
class LowPassFilter : public Node |
29 |
|
|
{ |
30 |
|
|
public: |
31 |
|
|
/// @brief Default constructor |
32 |
|
|
LowPassFilter(); |
33 |
|
|
/// @brief Destructor |
34 |
|
|
~LowPassFilter() override; |
35 |
|
|
/// @brief Copy constructor |
36 |
|
|
LowPassFilter(const LowPassFilter&) = delete; |
37 |
|
|
/// @brief Move constructor |
38 |
|
|
LowPassFilter(LowPassFilter&&) = delete; |
39 |
|
|
/// @brief Copy assignment operator |
40 |
|
|
LowPassFilter& operator=(const LowPassFilter&) = delete; |
41 |
|
|
/// @brief Move assignment operator |
42 |
|
|
LowPassFilter& operator=(LowPassFilter&&) = delete; |
43 |
|
|
|
44 |
|
|
/// @brief String representation of the Class Type |
45 |
|
|
[[nodiscard]] static std::string typeStatic(); |
46 |
|
|
|
47 |
|
|
/// @brief String representation of the Class Type |
48 |
|
|
[[nodiscard]] std::string type() const override; |
49 |
|
|
|
50 |
|
|
/// @brief String representation of the Class Category |
51 |
|
|
[[nodiscard]] static std::string category(); |
52 |
|
|
|
53 |
|
|
/// @brief ImGui config window which is shown on double click |
54 |
|
|
/// @attention Don't forget to set _hasConfig to true in the constructor of the node |
55 |
|
|
void guiConfig() override; |
56 |
|
|
|
57 |
|
|
/// @brief Saves the node into a json object |
58 |
|
|
[[nodiscard]] json save() const override; |
59 |
|
|
|
60 |
|
|
/// @brief Restores the node from a json object |
61 |
|
|
/// @param[in] j Json object with the node state |
62 |
|
|
void restore(const json& j) override; |
63 |
|
|
|
64 |
|
|
private: |
65 |
|
|
constexpr static size_t OUTPUT_PORT_INDEX_FLOW = 0; ///< @brief Flow |
66 |
|
|
constexpr static size_t INPUT_PORT_INDEX_FLOW = 0; ///< @brief Flow |
67 |
|
|
|
68 |
|
|
// ########################################################################################################### |
69 |
|
|
|
70 |
|
|
/// Types of available filters (to be extended) |
71 |
|
|
enum class FilterType : uint8_t |
72 |
|
|
{ |
73 |
|
|
Linear, ///< Linear fit filter |
74 |
|
|
// Experimental, |
75 |
|
|
COUNT, ///< Amount of items in the enum |
76 |
|
|
}; |
77 |
|
|
|
78 |
|
|
/// Filter description |
79 |
|
|
struct FilterItem |
80 |
|
|
{ |
81 |
|
|
/// @brief Default Constructor |
82 |
|
✗ |
FilterItem() = default; |
83 |
|
|
|
84 |
|
|
/// @brief Constructor |
85 |
|
|
/// @param[in] dataDescription Description of the data (dynamic data identifier) |
86 |
|
|
/// @param[in] dataIndex Index of the data (relevant for static data mostly) |
87 |
|
✗ |
FilterItem(std::string dataDescription, size_t dataIndex) |
88 |
|
✗ |
: dataDescription(std::move(dataDescription)), dataIndex(dataIndex) {} |
89 |
|
|
|
90 |
|
|
/// Description of the data |
91 |
|
|
std::string dataDescription; |
92 |
|
|
/// Index of the data |
93 |
|
|
size_t dataIndex = 0; |
94 |
|
|
/// Selected filter type in the GUI |
95 |
|
|
FilterType filterType = FilterType::Linear; |
96 |
|
|
/// Cutoff frequency [Hz], inverse of this parameter equals to fitting period |
97 |
|
|
double linear_filter_cutoff_frequency = 10.0; |
98 |
|
|
/// Map which stores all last data points which were used in the previous fit |
99 |
|
|
std::map<InsTime, double> dataToFilter; |
100 |
|
|
/// Flag to show indicator that it was modified |
101 |
|
|
bool modified = true; |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
/// @brief Selected item in the combo |
105 |
|
|
size_t _gui_availableItemsSelection = 0; |
106 |
|
|
|
107 |
|
|
/// Available items |
108 |
|
|
std::vector<std::string> _availableItems; |
109 |
|
|
/// Items to filter |
110 |
|
|
std::vector<FilterItem> _filterItems; |
111 |
|
|
|
112 |
|
|
/// @brief Converts the enum to a string |
113 |
|
|
/// @param[in] value Enum value to convert into text |
114 |
|
|
/// @return String representation of the enum |
115 |
|
|
static const char* to_string(FilterType value); |
116 |
|
|
|
117 |
|
|
/// @brief Resets the node. It is guaranteed that the node is initialized when this is called. |
118 |
|
|
bool resetNode() override; |
119 |
|
|
|
120 |
|
|
/// @brief Called when a new link was established |
121 |
|
|
/// @param[in] startPin Pin where the link starts |
122 |
|
|
/// @param[in] endPin Pin where the link ends |
123 |
|
|
void afterCreateLink(OutputPin& startPin, InputPin& endPin) override; |
124 |
|
|
|
125 |
|
|
/// @brief Called when a link was deleted |
126 |
|
|
/// @param[in] startPin Pin where the link starts |
127 |
|
|
/// @param[in] endPin Pin where the link ends |
128 |
|
|
void afterDeleteLink(OutputPin& startPin, InputPin& endPin) override; |
129 |
|
|
|
130 |
|
|
/// @brief Callback when receiving data on a port |
131 |
|
|
/// @param[in] queue Queue with all the received data messages |
132 |
|
|
/// @param[in] pinIdx Index of the pin the data is received on |
133 |
|
|
void receiveObs(InputPin::NodeDataQueue& queue, size_t pinIdx); |
134 |
|
|
|
135 |
|
|
/// @brief Filter the provided data |
136 |
|
|
/// @param[in] item Filter item to fit |
137 |
|
|
/// @param[in] insTime Current Time |
138 |
|
|
/// @param[in] value Current value to filter |
139 |
|
|
[[nodiscard]] static std::optional<double> filterData(FilterItem& item, const InsTime& insTime, double value); |
140 |
|
|
|
141 |
|
|
friend void to_json(json& j, const FilterItem& data); |
142 |
|
|
friend void from_json(const json& j, FilterItem& data); |
143 |
|
|
}; |
144 |
|
|
|
145 |
|
|
/// @brief Converts the provided link into a json object |
146 |
|
|
/// @param[out] j Json object which gets filled with the info |
147 |
|
|
/// @param[in] data Data to convert into json |
148 |
|
|
void to_json(json& j, const NAV::LowPassFilter::FilterItem& data); |
149 |
|
|
/// @brief Converts the provided json object into a link object |
150 |
|
|
/// @param[in] j Json object with the needed values |
151 |
|
|
/// @param[out] data Object to fill from the json |
152 |
|
|
void from_json(const json& j, NAV::LowPassFilter::FilterItem& data); |
153 |
|
|
|
154 |
|
|
} // namespace NAV |
155 |
|
|
|