0.5.0
Loading...
Searching...
No Matches
WiFiPositioning.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 WiFiPositioning.hpp
10/// @brief WiFi Positioning
11/// @author R. Lintz (r-lintz@gmx.de) (master thesis)
12/// @date 2024-01-08
13
14#pragma once
15
16#include "util/Eigen.hpp"
18#include <vector>
19
24
28
29namespace NAV
30{
31/// @brief Numerically integrates Imu data
32class WiFiPositioning : public Node
33{
34 public:
35 /// @brief Default constructor
37 /// @brief Destructor
38 ~WiFiPositioning() override;
39 /// @brief Copy constructor
41 /// @brief Move constructor
43 /// @brief Copy assignment operator
45 /// @brief Move assignment operator
47
48 /// @brief String representation of the Class Type
49 [[nodiscard]] static std::string typeStatic();
50
51 /// @brief String representation of the Class Type
52 [[nodiscard]] std::string type() const override;
53
54 /// @brief String representation of the Class Category
55 [[nodiscard]] static std::string category();
56
57 /// @brief ImGui config window which is shown on double click
58 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
59 void guiConfig() override;
60
61 /// @brief Saves the node into a json object
62 [[nodiscard]] json save() const override;
63
64 /// @brief Restores the node from a json object
65 /// @param[in] j Json object with the node state
66 void restore(const json& j) override;
67
68 private:
69 constexpr static size_t INPUT_PORT_INDEX_WIFI_OBS = 0; ///< @brief WiFiObs
70 constexpr static size_t OUTPUT_PORT_INDEX_WIFISOL = 0; ///< @brief WiFiPositioningSolution
71
72 /// @brief Number of states
73 uint8_t _numStates = 6;
74
75 /// @brief Number of measurements
76 uint8_t _numMeasurements = 1;
77
78 /// @brief Kalman Filter representation - States: 3xVel, 3xPos, (1xBias) - Measurements: 1xDist
79 KalmanFilter _kalmanFilter{ _numStates, _numMeasurements }; // TODO: Change to KeyedKalmanFilter
80
81 // --------------------------------------------------------------- Gui -----------------------------------------------------------------
82
83 /// @brief Initialize the node
84 bool initialize() override;
85
86 /// @brief Deinitialize the node
87 void deinitialize() override;
88
89 /// @brief Amount of wifi input pins
90 size_t _nWifiInputPins = 1;
91
92 /// @brief Adds/Deletes Input Pins depending on the variable _nNavInfoPins
94
95 // ------------------------------------------------------------ Algorithm --------------------------------------------------------------
96
97 /// @brief Available Frames
98 enum class Frame : uint8_t
99 {
100 ECEF, ///< Earth-Centered Earth-Fixed frame
101 LLA, ///< Latitude-Longitude-Altitude frame
102 };
103 /// Frame to calculate the position in
105
106 /// @brief Available Solution Modes
107 enum class SolutionMode : uint8_t
108 {
109 LSQ, ///< Least Squares
110 KF, ///< Kalman Filter
111 };
112 /// @brief Solution Mode
114
115 /// @brief Selection of whether the bias will be additionally estimated
116 bool _estimateBias = false;
117
118 /// @brief Selection of whether the solution will be weighted
119 bool _weightedSolution = false;
120
121 /// @brief Selection of whether the initial values should always be used or those of the last position
122 bool _useInitialValues = false;
123
124 /// @brief State estimated by the positioning algorithm
125 struct State
126 {
127 /// @brief Estimated position in ECEF frame [m]
128 Eigen::Vector3d e_position = Eigen::Vector3d::Zero();
129 /// @brief Estimated velocity in ECEF frame [m/s]
130 Eigen::Vector3d e_velocity = Eigen::Vector3d::Zero();
131 /// @brief Estimated bias [m]
132 double bias = 0;
133 };
134
135 /// @brief State estimated by the algorithm
137
138 /// @brief Initial state
140
141 /// @brief Input of mac addresses
142 std::vector<std::string> _deviceMacAddresses{ 1 };
143
144 /// @brief Input of positions
145 std::vector<Eigen::Vector3d> _devicePositions{ 1 };
146
147 /// @brief Input of biases
148 std::vector<double> _deviceBias{ 1, 0.0 };
149
150 /// @brief Input of scales
151 std::vector<double> _deviceScale{ 1, 0.0 };
152
153 /// @brief Number of devices
154 size_t _numOfDevices = 0;
155
156 /// @brief Device struct
157 struct Device
158 {
159 Eigen::Vector3d position{ Eigen::Vector3d::Zero() }; ///< Position vector
160 InsTime time; ///< Time
161 double distance{ 0.0 }; ///< Distance
162 double distanceStd{ 0.0 }; ///< Standard deviation of distance measurement
163 };
164 /// @brief Devices which are used for the positioning
165 std::vector<Device> _devices{ 1 };
166
167 /// @brief Time when the last prediction was triggered
169
170 /// @brief Receive Function for the WiFi Observations
171 /// @param[in] queue Queue with all the received data messages
172 /// @param[in] pinIdx Index of the pin the data is received on
173 void recvWiFiObs(InputPin::NodeDataQueue& queue, size_t pinIdx);
174
175 /// @brief Calculate the position using the least squares method
176 /// @return Least Squares solution
178
179 /// @brief Calculate the position
180 void kfSolution();
181
182 // ###########################################################################################################
183
184 /// Possible Units for the measurement noise (standard deviation σ or Variance σ²)
185 enum class MeasurementNoiseUnit : uint8_t
186 {
187 meter2, ///< Variance NED [m^2, m^2, m^2]
188 meter, ///< Standard deviation NED [m, m, m]
189 };
190 /// Gui selection for the Unit of the initial covariance for the position
192
193 /// GUI selection of the process noise (standard deviation σ or Variance σ²)
194 double _measurementNoise = 10;
195
196 // ###########################################################################################################
197
198 /// @brief Possible Units for the process noise (standard deviation σ or Variance σ²)
199 enum class ProcessNoiseUnit : uint8_t
200 {
201 meter2, ///< Variance NED [m^2, m^2, m^2]
202 meter, ///< Standard deviation NED [m, m, m]
203 };
204 /// Gui selection for the Unit of the initial covariance for the position
206
207 /// GUI selection of the process noise (standard deviation σ or Variance σ²)
208 double _processNoise = 10;
209
210 // ###########################################################################################################
211
212 /// @brief Possible Units for the initial covariance for the position (standard deviation σ or Variance σ²)
213 enum class InitCovariancePositionUnit : uint8_t
214 {
215 meter2, ///< Variance NED [m^2, m^2, m^2]
216 meter, ///< Standard deviation NED [m, m, m]
217 };
218 /// Gui selection for the Unit of the initial covariance for the position
220
221 /// GUI selection of the initial covariance diagonal values for position (standard deviation σ or Variance σ²)
222 Eigen::Vector3d _initCovariancePosition{ 100, 100, 100 };
223
224 // ###########################################################################################################
225
226 /// Possible Units for the initial covariance for the velocity (standard deviation σ or Variance σ²)
227 enum class InitCovarianceVelocityUnit : uint8_t
228 {
229 m2_s2, ///< Variance [m^2/s^2]
230 m_s, ///< Standard deviation [m/s]
231 };
232 /// Gui selection for the Unit of the initial covariance for the velocity
234
235 /// GUI selection of the initial covariance diagonal values for velocity (standard deviation σ or Variance σ²)
236 Eigen::Vector3d _initCovarianceVelocity{ 10, 10, 10 };
237
238 // ###########################################################################################################
239
240 /// Possible Units for the initial covariance for the bias (standard deviation σ or Variance σ²)
241 enum class InitCovarianceBiasUnit : uint8_t
242 {
243 meter2, ///< Variance [m^2]
244 meter, ///< Standard deviation [m]
245 };
246 /// Gui selection for the Unit of the initial covariance for the bias
248
249 /// GUI selection of the initial covariance diagonal values for bias (standard deviation σ or Variance σ²)
251};
252} // namespace NAV
Starts a Periodic Timer.
Vector space operations.
nlohmann::json json
json namespace
Kalman Filter with keyed states.
Least Squares Algorithm.
Generalized Kalman Filter class.
Node Class.
Position and Velocity Storage Class.
Position Storage Class.
Espressif Observation Class.
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
Generalized Kalman Filter class.
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::vector< double > _deviceBias
Input of biases.
uint8_t _numStates
Number of states.
SolutionMode
Available Solution Modes.
double _measurementNoise
GUI selection of the process noise (standard deviation σ or Variance σ²)
KalmanFilter _kalmanFilter
Kalman Filter representation - States: 3xVel, 3xPos, (1xBias) - Measurements: 1xDist.
std::vector< Device > _devices
Devices which are used for the positioning.
Frame _frame
Frame to calculate the position in.
size_t _nWifiInputPins
Amount of wifi input pins.
Eigen::Vector3d _initCovarianceVelocity
GUI selection of the initial covariance diagonal values for velocity (standard deviation σ or Varianc...
std::string type() const override
String representation of the Class Type.
void restore(const json &j) override
Restores the node from a json object.
uint8_t _numMeasurements
Number of measurements.
InitCovariancePositionUnit
Possible Units for the initial covariance for the position (standard deviation σ or Variance σ²)
json save() const override
Saves the node into a json object.
Frame
Available Frames.
@ LLA
Latitude-Longitude-Altitude frame.
@ ECEF
Earth-Centered Earth-Fixed frame.
InitCovarianceVelocityUnit
Possible Units for the initial covariance for the velocity (standard deviation σ or Variance σ²)
Eigen::Vector3d _initCovariancePosition
GUI selection of the initial covariance diagonal values for position (standard deviation σ or Varianc...
WiFiPositioning(const WiFiPositioning &)=delete
Copy constructor.
WiFiPositioning()
Default constructor.
void guiConfig() override
ImGui config window which is shown on double click.
MeasurementNoiseUnit
Possible Units for the measurement noise (standard deviation σ or Variance σ²)
@ meter
Standard deviation NED [m, m, m].
std::vector< double > _deviceScale
Input of scales.
LeastSquaresResult< Eigen::VectorXd, Eigen::MatrixXd > lsqSolution()
Calculate the position using the least squares method.
std::vector< std::string > _deviceMacAddresses
Input of mac addresses.
InitCovarianceVelocityUnit _initCovarianceVelocityUnit
Gui selection for the Unit of the initial covariance for the velocity.
bool _estimateBias
Selection of whether the bias will be additionally estimated.
void deinitialize() override
Deinitialize the node.
double _processNoise
GUI selection of the process noise (standard deviation σ or Variance σ²)
static constexpr size_t INPUT_PORT_INDEX_WIFI_OBS
WiFiObs.
void updateNumberOfInputPins()
Adds/Deletes Input Pins depending on the variable _nNavInfoPins.
bool initialize() override
Initialize the node.
SolutionMode _solutionMode
Solution Mode.
InsTime _lastPredictTime
Time when the last prediction was triggered.
InitCovarianceBiasUnit
Possible Units for the initial covariance for the bias (standard deviation σ or Variance σ²)
~WiFiPositioning() override
Destructor.
WiFiPositioning & operator=(WiFiPositioning &&)=delete
Move assignment operator.
WiFiPositioning & operator=(const WiFiPositioning &)=delete
Copy assignment operator.
bool _useInitialValues
Selection of whether the initial values should always be used or those of the last position.
double _initCovarianceBias
GUI selection of the initial covariance diagonal values for bias (standard deviation σ or Variance σ²...
InitCovariancePositionUnit _initCovariancePositionUnit
Gui selection for the Unit of the initial covariance for the position.
static std::string category()
String representation of the Class Category.
State _initialState
Initial state.
static std::string typeStatic()
String representation of the Class Type.
bool _weightedSolution
Selection of whether the solution will be weighted.
WiFiPositioning(WiFiPositioning &&)=delete
Move constructor.
ProcessNoiseUnit
Possible Units for the process noise (standard deviation σ or Variance σ²)
@ meter
Standard deviation NED [m, m, m].
void kfSolution()
Calculate the position.
ProcessNoiseUnit _processNoiseUnit
Gui selection for the Unit of the initial covariance for the position.
InitCovarianceBiasUnit _initCovarianceBiasUnit
Gui selection for the Unit of the initial covariance for the bias.
std::vector< Eigen::Vector3d > _devicePositions
Input of positions.
void recvWiFiObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Function for the WiFi Observations.
State _state
State estimated by the algorithm.
static constexpr size_t OUTPUT_PORT_INDEX_WIFISOL
WiFiPositioningSolution.
MeasurementNoiseUnit _measurementNoiseUnit
Gui selection for the Unit of the initial covariance for the position.
size_t _numOfDevices
Number of devices.
Least Squares Uncertainties return value.
Eigen::Vector3d position
Position vector.
double distanceStd
Standard deviation of distance measurement.
State estimated by the positioning algorithm.
double bias
Estimated bias [m].
Eigen::Vector3d e_velocity
Estimated velocity in ECEF frame [m/s].
Eigen::Vector3d e_position
Estimated position in ECEF frame [m].