0.4.1
Loading...
Searching...
No Matches
AllanDeviation.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 AllanDeviation.hpp
10/// @brief Computes Allan Deviation
11/// @author M. Seyfried (Master thesis student)
12/// @author T. Topp (topp@ins.uni-stuttgart.de)
13/// @date 2023-03-29
14
15#pragma once
16
18
19#include "util/Eigen.hpp"
20#include <array>
21#include <cstdint>
22#include <mutex>
23#include <vector>
24
25namespace NAV
26{
27/// @brief Computes Allan Deviation of IMU Observations
28class AllanDeviation : public Node
29{
30 public:
31 /// @brief Default constructor
33 /// @brief Destructor
34 ~AllanDeviation() override;
35 /// @brief Copy constructor
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 INPUT_PORT_INDEX_IMU_OBS = 0; ///< @brief Flow (ImuObs)
66
67 /// @brief Initialize the node
68 bool initialize() override;
69
70 /// @brief Deinitialize the node
71 void deinitialize() override;
72
73 /// @brief Receive Sensor Data
74 /// @param[in] queue Queue with all the received data messages
75 /// @param[in] pinIdx Index of the pin the data is received on
76 void receiveImuObs(InputPin::NodeDataQueue& queue, size_t pinIdx);
77
78 // ------------------------------------------------------------ Algorithm --------------------------------------------------------------
79
80 /// Sensor types
81 enum SensorType : uint8_t
82 {
83 Accel, ///< Accelerometer
84 Gyro, ///< Gyroscope
85 SensorType_COUNT, ///< Amount of sensors to use
86 };
87
88 /// Data for each sensor
89 struct Sensor
90 {
91 /// Cumulative Sums
92 std::vector<Eigen::Vector3d> cumSum{ Eigen::Vector3d::Zero() };
93
94 /// Allan Variance precursor
95 std::array<std::vector<double>, 3> allanSum{};
96
97 /// Allan Variance
98 std::array<std::vector<double>, 3> allanVariance{};
99
100 /// Allan Deviation
101 std::array<std::vector<double>, 3> allanDeviation{};
102
103 /// Slope of Allan Variance
104 std::array<std::vector<double>, 3> slope{};
105
106 /// Confidence of Allan Deviation
107 std::array<std::array<std::vector<double>, 2>, 3> allanDeviationConfidenceIntervals{};
108
109 /// Mutex to lock plotting
110 std::mutex mutex;
111 };
112
113 /// Sensor data
114 std::array<Sensor, SensorType_COUNT> _sensors;
115
116 /// sampling interval
117 double _samplingInterval = 0.0;
118
119 /// Time of first epoch received
121
122 /// averaging factors (n) used for Allan Variance computation
123 std::vector<double> _averagingFactors;
124
125 /// averaging times (τ)
126 std::vector<double> _averagingTimes;
127
128 /// number of observations for each τ
129 std::vector<double> _observationCount;
130
131 /// number of IMU observations / length of cumulative sums
132 unsigned int _imuObsCount{ 0 };
133
134 /// number of averaging factors per decade
136
137 /// next averaging factor to be appended to _averagingFactors
138 unsigned int _nextAveragingFactor{ 1 };
139
140 /// exponent of next averaging factor
142
143 /// multiplication factor for simple confidence
145
146 /// Flag wether to display confidence intervals
147 bool _displayConfidence{ false };
148 /// The alpha value for the shaded plot of the confidence intervals
149 float _confidenceFillAlpha{ 0.4F };
150 /// Flag wether to update the plot for each message or once at the end
151 bool _updateLast{ false };
152
153 /// @brief Returns a string representation of the type
154 /// @param[in] sensorType Sensor Type
155 static const char* to_string(SensorType sensorType);
156
157 /// @brief Returns a string for the unit of the type
158 /// @param[in] sensorType Sensor Type
159 static const char* unitString(SensorType sensorType);
160};
161
162} // namespace NAV
Vector space operations.
nlohmann::json json
json namespace
Node Class.
std::vector< double > _averagingFactors
averaging factors (n) used for Allan Variance computation
unsigned int _imuObsCount
number of IMU observations / length of cumulative sums
AllanDeviation & operator=(AllanDeviation &&)=delete
Move assignment operator.
~AllanDeviation() override
Destructor.
AllanDeviation & operator=(const AllanDeviation &)=delete
Copy assignment operator.
static const char * unitString(SensorType sensorType)
Returns a string for the unit of the type.
static std::string category()
String representation of the Class Category.
std::vector< double > _averagingTimes
averaging times (τ)
static constexpr size_t INPUT_PORT_INDEX_IMU_OBS
Flow (ImuObs)
static std::string typeStatic()
String representation of the Class Type.
InsTime _startingInsTime
Time of first epoch received.
AllanDeviation(const AllanDeviation &)=delete
Copy constructor.
AllanDeviation(AllanDeviation &&)=delete
Move constructor.
json save() const override
Saves the node into a json object.
std::array< Sensor, SensorType_COUNT > _sensors
Sensor data.
float _confidenceFillAlpha
The alpha value for the shaded plot of the confidence intervals.
double _samplingInterval
sampling interval
void deinitialize() override
Deinitialize the node.
unsigned int _nextAveragingFactor
next averaging factor to be appended to _averagingFactors
AllanDeviation()
Default constructor.
std::vector< double > _confidenceMultiplicationFactor
multiplication factor for simple confidence
bool _updateLast
Flag wether to update the plot for each message or once at the end.
bool _displayConfidence
Flag wether to display confidence intervals.
@ Accel
Accelerometer.
@ SensorType_COUNT
Amount of sensors to use.
static const char * to_string(SensorType sensorType)
Returns a string representation of the type.
double _averagingFactorsPerDecade
number of averaging factors per decade
void restore(const json &j) override
Restores the node from a json object.
unsigned int _nextAveragingFactorExponent
exponent of next averaging factor
void receiveImuObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Sensor Data.
bool initialize() override
Initialize the node.
std::string type() const override
String representation of the Class Type.
void guiConfig() override
ImGui config window which is shown on double click.
std::vector< double > _observationCount
number of observations for each τ
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
Node(std::string name)
Constructor.
Definition Node.cpp:30
Data for each sensor.
std::array< std::vector< double >, 3 > allanVariance
Allan Variance.
std::mutex mutex
Mutex to lock plotting.
std::array< std::vector< double >, 3 > allanSum
Allan Variance precursor.
std::array< std::vector< double >, 3 > slope
Slope of Allan Variance.
std::vector< Eigen::Vector3d > cumSum
Cumulative Sums.
std::array< std::array< std::vector< double >, 2 >, 3 > allanDeviationConfidenceIntervals
Confidence of Allan Deviation.
std::array< std::vector< double >, 3 > allanDeviation
Allan Deviation.