0.3.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
LowPassFilter.hpp
Go to the documentation of this file.
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
18
21
22#include "util/Eigen.hpp"
23#include <map>
24
25namespace NAV
26{
27/// Filters incoming data
28class LowPassFilter : public Node
29{
30 public:
31 /// @brief Default constructor
33 /// @brief Destructor
34 ~LowPassFilter() override;
35 /// @brief Copy constructor
36 LowPassFilter(const LowPassFilter&) = delete;
37 /// @brief Move constructor
39 /// @brief Copy assignment operator
41 /// @brief Move assignment operator
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
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)
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
96 /// Cutoff frequency [Hz], inverse of this parameter equals to fitting period
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
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
148void 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
152void from_json(const json& j, NAV::LowPassFilter::FilterItem& data);
153
154} // namespace NAV
Vector space operations.
nlohmann::json json
json namespace
Data storage class for one VectorNavImu observation.
Parent Class for all IMU Observations.
Node Class.
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
void afterCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link was established.
void restore(const json &j) override
Restores the node from a json object.
std::vector< FilterItem > _filterItems
Items to filter.
static std::string category()
String representation of the Class Category.
LowPassFilter & operator=(LowPassFilter &&)=delete
Move assignment operator.
LowPassFilter()
Default constructor.
friend void from_json(const json &j, FilterItem &data)
Converts the provided json object into a link object.
LowPassFilter(LowPassFilter &&)=delete
Move constructor.
size_t _gui_availableItemsSelection
Selected item in the combo.
LowPassFilter & operator=(const LowPassFilter &)=delete
Copy assignment operator.
bool resetNode() override
Resets the node. It is guaranteed that the node is initialized when this is called.
static std::optional< double > filterData(FilterItem &item, const InsTime &insTime, double value)
Filter the provided data.
void afterDeleteLink(OutputPin &startPin, InputPin &endPin) override
Called when a link was deleted.
~LowPassFilter() override
Destructor.
LowPassFilter(const LowPassFilter &)=delete
Copy constructor.
static constexpr size_t INPUT_PORT_INDEX_FLOW
Flow.
FilterType
Types of available filters (to be extended)
@ COUNT
Amount of items in the enum.
static std::string typeStatic()
String representation of the Class Type.
json save() const override
Saves the node into a json object.
void guiConfig() override
ImGui config window which is shown on double click.
std::string type() const override
String representation of the Class Type.
friend void to_json(json &j, const FilterItem &data)
Converts the provided link into a json object.
static const char * to_string(FilterType value)
Converts the enum to a string.
std::vector< std::string > _availableItems
Available items.
static constexpr size_t OUTPUT_PORT_INDEX_FLOW
Flow.
void receiveObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Callback when receiving data on a port.
Node(std::string name)
Constructor.
Definition Node.cpp:30
Output pins of nodes.
Definition Pin.hpp:338
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:27
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
FilterItem()=default
Default Constructor.
std::string dataDescription
Description of the data.
size_t dataIndex
Index of the data.
FilterType filterType
Selected filter type in the GUI.
double linear_filter_cutoff_frequency
Cutoff frequency [Hz], inverse of this parameter equals to fitting period.
FilterItem(std::string dataDescription, size_t dataIndex)
Constructor.
bool modified
Flag to show indicator that it was modified.
std::map< InsTime, double > dataToFilter
Map which stores all last data points which were used in the previous fit.