0.2.0
Loading...
Searching...
No Matches
Pos.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
13
14#pragma once
15
17#include "Navigation/Transformations/Units.hpp"
18
20#include "NodeData/NodeData.hpp"
22#include "util/Assert.h"
23#include <Eigen/src/Core/MatrixBase.h>
24
25namespace NAV
26{
28class Pos : public NodeData
29{
30 public:
33 [[nodiscard]] static std::string type()
34 {
35 return "Pos";
36 }
37
40 [[nodiscard]] static std::vector<std::string> parentTypes()
41 {
42 return { NodeData::type() };
43 }
44
46 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
47 {
48 return {
49 "Latitude [deg]",
50 "Longitude [deg]",
51 "Altitude [m]",
52 "North/South [m]",
53 "East/West [m]",
54 "X-ECEF [m]",
55 "Y-ECEF [m]",
56 "Z-ECEF [m]",
57 "X-ECEF StDev [m]",
58 "Y-ECEF StDev [m]",
59 "Z-ECEF StDev [m]",
60 "XY-ECEF StDev [m]",
61 "XZ-ECEF StDev [m]",
62 "YZ-ECEF StDev [m]",
63 "North StDev [m]",
64 "East StDev [m]",
65 "Down StDev [m]",
66 "NE StDev [m]",
67 "ND StDev [m]",
68 "ED StDev [m]",
69 };
70 }
71
73 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return 20; }
74
76 [[nodiscard]] std::vector<std::string> staticDataDescriptors() const override { return GetStaticDataDescriptors(); }
77
79 [[nodiscard]] size_t staticDescriptorCount() const override { return GetStaticDescriptorCount(); }
80
84 [[nodiscard]] std::optional<double> getValueAt(size_t idx) const override
85 {
87 switch (idx)
88 {
89 case 0: // Latitude [deg]
90 return rad2deg(latitude());
91 case 1: // Longitude [deg]
92 return rad2deg(longitude());
93 case 2: // Altitude [m]
94 return altitude();
95 case 3: // North/South [m]
97 case 4: // East/West [m]
99 case 5: // X-ECEF [m]
100 return e_position().x();
101 case 6: // Y-ECEF [m]
102 return e_position().y();
103 case 7: // Z-ECEF [m]
104 return e_position().z();
105 case 8: // X-ECEF StDev [m]
106 if (auto stDev = e_positionStdev()) { return stDev->get().x(); }
107 break;
108 case 9: // Y-ECEF StDev [m]
109 if (auto stDev = e_positionStdev()) { return stDev->get().y(); }
110 break;
111 case 10: // Z-ECEF StDev [m]
112 if (auto stDev = e_positionStdev()) { return stDev->get().z(); }
113 break;
114 case 11: // XY-ECEF StDev [m]
115 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosX, States::PosY); }
116 break;
117 case 12: // XZ-ECEF StDev [m]
118 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosX, States::PosZ); }
119 break;
120 case 13: // YZ-ECEF StDev [m]
121 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosY, States::PosZ); }
122 break;
123 case 14: // North StDev [m]
124 if (auto stDev = n_positionStdev()) { return stDev->get().x(); }
125 break;
126 case 15: // East StDev [m]
127 if (auto stDev = n_positionStdev()) { return stDev->get().y(); }
128 break;
129 case 16: // Down StDev [m]
130 if (auto stDev = n_positionStdev()) { return stDev->get().z(); }
131 break;
132 case 17: // NE StDev [m]
133 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosX, States::PosY); }
134 break;
135 case 18: // ND StDev [m]
136 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosX, States::PosZ); }
137 break;
138 case 19: // ED StDev [m]
139 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosY, States::PosZ); }
140 break;
141 default:
142 return std::nullopt;
143 }
144 return std::nullopt;
145 }
146
147 /* -------------------------------------------------------------------------------------------------------- */
148 /* Rotation Quaternions */
149 /* -------------------------------------------------------------------------------------------------------- */
150
153 [[nodiscard]] Eigen::Quaterniond e_Quat_n() const
154 {
155 return trafo::e_Quat_n(latitude(), longitude());
156 }
157
160 [[nodiscard]] Eigen::Quaterniond n_Quat_e() const
161 {
162 return e_Quat_n().conjugate();
163 }
164
165 /* -------------------------------------------------------------------------------------------------------- */
166 /* Position */
167 /* -------------------------------------------------------------------------------------------------------- */
168
170 struct States
171 {
173 States() = delete;
174
184 inline static const std::vector<StateKeys> Pos = { PosX, PosY, PosZ };
185 };
186
188 [[nodiscard]] const Eigen::Vector3d& lla_position() const { return _lla_position; }
189
191 [[nodiscard]] const double& latitude() const { return lla_position()(0); }
192
194 [[nodiscard]] const double& longitude() const { return lla_position()(1); }
195
197 [[nodiscard]] const double& altitude() const { return lla_position()(2); }
198
200 [[nodiscard]] const Eigen::Vector3d& e_position() const { return _e_position; }
201
203 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> e_positionStdev() const { return _e_positionStdev; }
204
206 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> n_positionStdev() const { return _n_positionStdev; }
207
209 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> e_CovarianceMatrix() const { return _e_covarianceMatrix; }
210
212 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> n_CovarianceMatrix() const { return _n_covarianceMatrix; }
213
214 // ###########################################################################################################
215 // Setter
216 // ###########################################################################################################
217
220 void setPosition_e(const Eigen::Vector3d& e_position)
221 {
222 _e_position = e_position;
223 _lla_position = trafo::ecef2lla_WGS84(e_position);
224 }
225
228 void setPosition_lla(const Eigen::Vector3d& lla_position)
229 {
230 _e_position = trafo::lla2ecef_WGS84(lla_position);
231 _lla_position = lla_position;
232 }
233
237 void setPositionAndStdDev_e(const Eigen::Vector3d& e_position, const Eigen::Matrix3d& e_positionCovarianceMatrix)
238 {
240 _e_positionStdev = e_positionCovarianceMatrix.diagonal().cwiseSqrt();
241 _n_positionStdev = (n_Quat_e() * e_positionCovarianceMatrix * e_Quat_n()).diagonal().cwiseSqrt();
242 }
243
247 void setPositionAndStdDev_lla(const Eigen::Vector3d& lla_position, const Eigen::Matrix3d& n_positionCovarianceMatrix)
248 {
250 _n_positionStdev = n_positionCovarianceMatrix.diagonal().cwiseSqrt();
251 _e_positionStdev = (e_Quat_n() * n_positionCovarianceMatrix * n_Quat_e()).diagonal().cwiseSqrt();
252 }
253
257 template<typename Derived>
258 void setPosCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
259 {
260 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
261 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
262
263 _e_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
264 States::StateKeys>(e_covarianceMatrix,
266 _n_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
268 * (*_e_covarianceMatrix)(States::Pos, States::Pos)
269 * e_Quat_n(),
271 }
272
276 template<typename Derived>
277 void setPosCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
278 {
279 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
280 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
281
282 _n_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
283 States::StateKeys>(n_covarianceMatrix,
285 _e_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
287 * (*_n_covarianceMatrix)(States::Pos, States::Pos)
288 * n_Quat_e(),
290 }
291
292 /* -------------------------------------------------------------------------------------------------------- */
293 /* Member variables */
294 /* -------------------------------------------------------------------------------------------------------- */
295
296 private:
298 Eigen::Vector3d _e_position{ std::nan(""), std::nan(""), std::nan("") };
300 Eigen::Vector3d _lla_position{ std::nan(""), std::nan(""), std::nan("") };
301
303 std::optional<Eigen::Vector3d> _e_positionStdev;
305 std::optional<Eigen::Vector3d> _n_positionStdev;
306
308 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _e_covarianceMatrix;
309
311 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _n_covarianceMatrix;
312};
313
314} // namespace NAV
Assertion helpers.
#define INS_ASSERT(_EXPR)
Assert function wrapper.
Definition Assert.h:19
#define INS_ASSERT_USER_ERROR(_EXP, _MSG)
Assert function with message.
Definition Assert.h:21
Common logging variables like time into run and local positions.
Transformation collection.
Abstract NodeData Class.
static LocalPosition calcLocalPosition(const Eigen::Vector3d &lla_position)
Calculate the local position offset from a reference point.
Dynamic sized KeyedMatrix.
Definition KeyedMatrix.hpp:2055
Parent class for all data transmitted over Flow pins.
Definition NodeData.hpp:27
static std::string type()
Returns the type of the data class.
Definition NodeData.hpp:44
Position, Velocity and Attitude Storage Class.
Definition Pos.hpp:29
std::optional< std::reference_wrapper< const Eigen::Vector3d > > e_positionStdev() const
Returns the standard deviation of the position in ECEF frame coordinates in [m].
Definition Pos.hpp:203
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition Pos.hpp:84
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition Pos.hpp:46
void setPositionAndStdDev_e(const Eigen::Vector3d &e_position, const Eigen::Matrix3d &e_positionCovarianceMatrix)
Set the Position in ECEF coordinates and its standard deviation.
Definition Pos.hpp:237
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition Pos.hpp:73
const double & latitude() const
Returns the latitude 𝜙 in [rad].
Definition Pos.hpp:191
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition Pos.hpp:40
std::optional< std::reference_wrapper< const KeyedMatrixXd< States::StateKeys, States::StateKeys > > > n_CovarianceMatrix() const
Returns the Covariance matrix in local navigation frame.
Definition Pos.hpp:212
Eigen::Quaterniond e_Quat_n() const
Returns the Quaternion from navigation to Earth-fixed frame.
Definition Pos.hpp:153
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:33
void setPosCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition Pos.hpp:277
std::optional< std::reference_wrapper< const KeyedMatrixXd< States::StateKeys, States::StateKeys > > > e_CovarianceMatrix() const
Returns the Covariance matrix in ECEF frame.
Definition Pos.hpp:209
void setPositionAndStdDev_lla(const Eigen::Vector3d &lla_position, const Eigen::Matrix3d &n_positionCovarianceMatrix)
Set the Position in LLA coordinates and its standard deviation.
Definition Pos.hpp:247
Eigen::Quaterniond n_Quat_e() const
Returns the Quaternion from Earth-fixed frame to navigation.
Definition Pos.hpp:160
const Eigen::Vector3d & e_position() const
Returns the coordinates in [m].
Definition Pos.hpp:200
const Eigen::Vector3d & lla_position() const
Returns the latitude 𝜙, longitude λ and altitude (height above ground) in [rad, rad,...
Definition Pos.hpp:188
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition Pos.hpp:79
std::optional< std::reference_wrapper< const Eigen::Vector3d > > n_positionStdev() const
Returns the standard deviation of the position in local navigation frame coordinates in [m].
Definition Pos.hpp:206
void setPosition_e(const Eigen::Vector3d &e_position)
Set the Position in coordinates.
Definition Pos.hpp:220
void setPosition_lla(const Eigen::Vector3d &lla_position)
Set the Position lla object.
Definition Pos.hpp:228
const double & altitude() const
Returns the altitude (height above ground) in [m].
Definition Pos.hpp:197
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition Pos.hpp:76
const double & longitude() const
Returns the longitude λ in [rad].
Definition Pos.hpp:194
void setPosCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition Pos.hpp:258
double northSouth
North/South deviation from the reference point [m].
Definition CommonLog.hpp:50
double eastWest
East/West deviation from the reference point [m].
Definition CommonLog.hpp:51
States.
Definition Pos.hpp:171
static const std::vector< StateKeys > Pos
All position keys.
Definition Pos.hpp:184
StateKeys
State Keys.
Definition Pos.hpp:177
@ PosX
Position ECEF_X [m].
Definition Pos.hpp:178
@ States_COUNT
Count.
Definition Pos.hpp:181
@ PosY
Position ECEF_Y [m].
Definition Pos.hpp:179
@ PosZ
Position ECEF_Z [m].
Definition Pos.hpp:180
States()=delete
Constructor.
Matrix which can be accessed by keys.