0.3.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
16#include <cstdint>
18#include "Navigation/Transformations/Units.hpp"
19
21#include "NodeData/NodeData.hpp"
23#include "util/Assert.h"
24#include <Eigen/src/Core/MatrixBase.h>
25
26namespace NAV
27{
29class Pos : public NodeData
30{
31 public:
34 [[nodiscard]] static std::string type()
35 {
36 return "Pos";
37 }
38
41 [[nodiscard]] std::string getType() const override { return type(); }
42
45 [[nodiscard]] static std::vector<std::string> parentTypes()
46 {
47 return { NodeData::type() };
48 }
49
51 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
52 {
53 return {
54 "Latitude [deg]",
55 "Longitude [deg]",
56 "Altitude [m]",
57 "North/South [m]",
58 "East/West [m]",
59 "X-ECEF [m]",
60 "Y-ECEF [m]",
61 "Z-ECEF [m]",
62 "X-ECEF StDev [m]",
63 "Y-ECEF StDev [m]",
64 "Z-ECEF StDev [m]",
65 "XY-ECEF StDev [m]",
66 "XZ-ECEF StDev [m]",
67 "YZ-ECEF StDev [m]",
68 "North StDev [m]",
69 "East StDev [m]",
70 "Down StDev [m]",
71 "NE StDev [m]",
72 "ND StDev [m]",
73 "ED StDev [m]",
74 };
75 }
76
78 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return 20; }
79
81 [[nodiscard]] std::vector<std::string> staticDataDescriptors() const override { return GetStaticDataDescriptors(); }
82
84 [[nodiscard]] size_t staticDescriptorCount() const override { return GetStaticDescriptorCount(); }
85
89 [[nodiscard]] std::optional<double> getValueAt(size_t idx) const override
90 {
92 switch (idx)
93 {
94 case 0: // Latitude [deg]
95 return rad2deg(latitude());
96 case 1: // Longitude [deg]
97 return rad2deg(longitude());
98 case 2: // Altitude [m]
99 return altitude();
100 case 3: // North/South [m]
102 case 4: // East/West [m]
104 case 5: // X-ECEF [m]
105 return e_position().x();
106 case 6: // Y-ECEF [m]
107 return e_position().y();
108 case 7: // Z-ECEF [m]
109 return e_position().z();
110 case 8: // X-ECEF StDev [m]
111 if (auto stDev = e_positionStdev()) { return stDev->get().x(); }
112 break;
113 case 9: // Y-ECEF StDev [m]
114 if (auto stDev = e_positionStdev()) { return stDev->get().y(); }
115 break;
116 case 10: // Z-ECEF StDev [m]
117 if (auto stDev = e_positionStdev()) { return stDev->get().z(); }
118 break;
119 case 11: // XY-ECEF StDev [m]
120 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosX, States::PosY); }
121 break;
122 case 12: // XZ-ECEF StDev [m]
123 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosX, States::PosZ); }
124 break;
125 case 13: // YZ-ECEF StDev [m]
126 if (e_CovarianceMatrix().has_value()) { return (*e_CovarianceMatrix())(States::PosY, States::PosZ); }
127 break;
128 case 14: // North StDev [m]
129 if (auto stDev = n_positionStdev()) { return stDev->get().x(); }
130 break;
131 case 15: // East StDev [m]
132 if (auto stDev = n_positionStdev()) { return stDev->get().y(); }
133 break;
134 case 16: // Down StDev [m]
135 if (auto stDev = n_positionStdev()) { return stDev->get().z(); }
136 break;
137 case 17: // NE StDev [m]
138 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosX, States::PosY); }
139 break;
140 case 18: // ND StDev [m]
141 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosX, States::PosZ); }
142 break;
143 case 19: // ED StDev [m]
144 if (n_CovarianceMatrix().has_value()) { return (*n_CovarianceMatrix())(States::PosY, States::PosZ); }
145 break;
146 default:
147 return std::nullopt;
148 }
149 return std::nullopt;
150 }
151
156 [[nodiscard]] bool setValueAt(size_t idx, double value) override
157 {
159 switch (idx)
160 {
161 case 0: // Latitude [deg]
162 _lla_position(0) = deg2rad(value);
163 _e_position = trafo::lla2ecef_WGS84(_lla_position);
164 break;
165 case 1: // Longitude [deg]
166 _lla_position(1) = deg2rad(value);
167 _e_position = trafo::lla2ecef_WGS84(_lla_position);
168 break;
169 case 2: // Altitude [m]
170 _lla_position(2) = value;
171 _e_position = trafo::lla2ecef_WGS84(_lla_position);
172 break;
173 case 3: // North/South [m]
174 _e_position += e_Quat_n() * Eigen::Vector3d(value, 0.0, 0.0);
175 _e_position = trafo::lla2ecef_WGS84(_lla_position);
176 break;
177 case 4: // East/West [m]
178 _e_position += e_Quat_n() * Eigen::Vector3d(0.0, value, 0.0);
179 _e_position = trafo::lla2ecef_WGS84(_lla_position);
180 break;
181 case 5: // X-ECEF [m]
182 _e_position(0) = value;
183 _lla_position = trafo::ecef2lla_WGS84(_e_position);
184 break;
185 case 6: // Y-ECEF [m]
186 _e_position(1) = value;
187 _lla_position = trafo::ecef2lla_WGS84(_e_position);
188 break;
189 case 7: // Z-ECEF [m]
190 _e_position(2) = value;
191 _lla_position = trafo::ecef2lla_WGS84(_e_position);
192 break;
193 case 8: // X-ECEF StDev [m]
194 case 9: // Y-ECEF StDev [m]
195 case 10: // Z-ECEF StDev [m]
196 case 11: // XY-ECEF StDev [m]
197 case 12: // XZ-ECEF StDev [m]
198 case 13: // YZ-ECEF StDev [m]
199 case 14: // North StDev [m]
200 case 15: // East StDev [m]
201 case 16: // Down StDev [m]
202 case 17: // NE StDev [m]
203 case 18: // ND StDev [m]
204 case 19: // ED StDev [m]
205 default:
206 return false;
207 }
208
209 return true;
210 }
211
212 /* -------------------------------------------------------------------------------------------------------- */
213 /* Rotation Quaternions */
214 /* -------------------------------------------------------------------------------------------------------- */
215
218 [[nodiscard]] Eigen::Quaterniond e_Quat_n() const
219 {
220 return trafo::e_Quat_n(latitude(), longitude());
221 }
222
225 [[nodiscard]] Eigen::Quaterniond n_Quat_e() const
226 {
227 return e_Quat_n().conjugate();
228 }
229
230 /* -------------------------------------------------------------------------------------------------------- */
231 /* Position */
232 /* -------------------------------------------------------------------------------------------------------- */
233
235 struct States
236 {
238 States() = delete;
239
241 enum StateKeys : uint8_t
242 {
247 };
249 inline static const std::vector<StateKeys> Pos = { PosX, PosY, PosZ };
250 };
251
253 [[nodiscard]] const Eigen::Vector3d& lla_position() const { return _lla_position; }
254
256 [[nodiscard]] const double& latitude() const { return lla_position()(0); }
257
259 [[nodiscard]] const double& longitude() const { return lla_position()(1); }
260
262 [[nodiscard]] const double& altitude() const { return lla_position()(2); }
263
265 [[nodiscard]] const Eigen::Vector3d& e_position() const { return _e_position; }
266
268 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> e_positionStdev() const { return _e_positionStdev; }
269
271 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> n_positionStdev() const { return _n_positionStdev; }
272
274 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> e_CovarianceMatrix() const { return _e_covarianceMatrix; }
275
277 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> n_CovarianceMatrix() const { return _n_covarianceMatrix; }
278
279 // ###########################################################################################################
280 // Setter
281 // ###########################################################################################################
282
285 template<typename Derived>
286 void setPosition_e(const Eigen::MatrixBase<Derived>& e_position)
287 {
289 _lla_position = trafo::ecef2lla_WGS84(e_position);
290 }
291
294 template<typename Derived>
295 void setPosition_lla(const Eigen::MatrixBase<Derived>& lla_position)
296 {
297 _e_position = trafo::lla2ecef_WGS84(lla_position);
299 }
300
304 template<typename Derived, typename Derived2>
305 void setPositionAndStdDev_e(const Eigen::MatrixBase<Derived>& e_position, const Eigen::MatrixBase<Derived2>& e_positionCovarianceMatrix)
306 {
308 _e_positionStdev = e_positionCovarianceMatrix.diagonal().cwiseSqrt();
309 _n_positionStdev = (n_Quat_e() * e_positionCovarianceMatrix * e_Quat_n()).diagonal().cwiseSqrt();
310 }
311
315 template<typename Derived, typename Derived2>
316 void setPositionAndStdDev_lla(const Eigen::MatrixBase<Derived>& lla_position, const Eigen::MatrixBase<Derived2>& n_positionCovarianceMatrix)
317 {
319 _n_positionStdev = n_positionCovarianceMatrix.diagonal().cwiseSqrt();
320 _e_positionStdev = (e_Quat_n() * n_positionCovarianceMatrix * n_Quat_e()).diagonal().cwiseSqrt();
321 }
322
326 template<typename Derived>
327 void setPosCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
328 {
329 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
330 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
331
333 States::StateKeys>(e_covarianceMatrix,
337 * (*_e_covarianceMatrix)(States::Pos, States::Pos)
338 * e_Quat_n(),
340 }
341
345 template<typename Derived>
346 void setPosCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
347 {
348 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
349 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
350
352 States::StateKeys>(n_covarianceMatrix,
356 * (*_n_covarianceMatrix)(States::Pos, States::Pos)
357 * n_Quat_e(),
359 }
360
361 /* -------------------------------------------------------------------------------------------------------- */
362 /* Member variables */
363 /* -------------------------------------------------------------------------------------------------------- */
364
365 private:
367 Eigen::Vector3d _e_position{ std::nan(""), std::nan(""), std::nan("") };
369 Eigen::Vector3d _lla_position{ std::nan(""), std::nan(""), std::nan("") };
370
372 std::optional<Eigen::Vector3d> _e_positionStdev;
374 std::optional<Eigen::Vector3d> _n_positionStdev;
375
377 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _e_covarianceMatrix;
378
380 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _n_covarianceMatrix;
381};
382
383} // 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:28
static std::string type()
Returns the type of the data class.
Definition NodeData.hpp:45
Position, Velocity and Attitude Storage Class.
Definition Pos.hpp:30
void setPositionAndStdDev_e(const Eigen::MatrixBase< Derived > &e_position, const Eigen::MatrixBase< Derived2 > &e_positionCovarianceMatrix)
Set the Position in ECEF coordinates and its standard deviation.
Definition Pos.hpp:305
std::optional< KeyedMatrixXd< States::StateKeys, States::StateKeys > > _n_covarianceMatrix
Covariance matrix in local navigation coordinates.
Definition Pos.hpp:380
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:268
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition Pos.hpp:89
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition Pos.hpp:51
Eigen::Vector3d _e_position
Position in ECEF coordinates [m].
Definition Pos.hpp:367
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition Pos.hpp:78
bool setValueAt(size_t idx, double value) override
Set the value at the index.
Definition Pos.hpp:156
const double & latitude() const
Returns the latitude 𝜙 in [rad].
Definition Pos.hpp:256
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition Pos.hpp:45
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:277
Eigen::Quaterniond e_Quat_n() const
Returns the Quaternion from navigation to Earth-fixed frame.
Definition Pos.hpp:218
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:34
void setPosCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition Pos.hpp:346
std::optional< std::reference_wrapper< const KeyedMatrixXd< States::StateKeys, States::StateKeys > > > e_CovarianceMatrix() const
Returns the Covariance matrix in ECEF frame.
Definition Pos.hpp:274
std::optional< Eigen::Vector3d > _n_positionStdev
Standard deviation of Position in local navigation frame coordinates [m].
Definition Pos.hpp:374
Eigen::Quaterniond n_Quat_e() const
Returns the Quaternion from Earth-fixed frame to navigation.
Definition Pos.hpp:225
const Eigen::Vector3d & e_position() const
Returns the coordinates in [m].
Definition Pos.hpp:265
void setPositionAndStdDev_lla(const Eigen::MatrixBase< Derived > &lla_position, const Eigen::MatrixBase< Derived2 > &n_positionCovarianceMatrix)
Set the Position in LLA coordinates and its standard deviation.
Definition Pos.hpp:316
void setPosition_e(const Eigen::MatrixBase< Derived > &e_position)
Set the Position in coordinates.
Definition Pos.hpp:286
const Eigen::Vector3d & lla_position() const
Returns the latitude 𝜙, longitude λ and altitude (height above ground) in [rad, rad,...
Definition Pos.hpp:253
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition Pos.hpp:84
std::string getType() const override
Returns the type of the data class.
Definition Pos.hpp:41
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:271
std::optional< Eigen::Vector3d > _e_positionStdev
Standard deviation of Position in ECEF coordinates [m].
Definition Pos.hpp:372
Eigen::Vector3d _lla_position
Position in LatLonAlt coordinates [rad, rad, m].
Definition Pos.hpp:369
std::optional< KeyedMatrixXd< States::StateKeys, States::StateKeys > > _e_covarianceMatrix
Covariance matrix in ECEF coordinates.
Definition Pos.hpp:377
const double & altitude() const
Returns the altitude (height above ground) in [m].
Definition Pos.hpp:262
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition Pos.hpp:81
void setPosition_lla(const Eigen::MatrixBase< Derived > &lla_position)
Set the Position lla object.
Definition Pos.hpp:295
const double & longitude() const
Returns the longitude λ in [rad].
Definition Pos.hpp:259
void setPosCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition Pos.hpp:327
double northSouth
North/South deviation from the reference point [m].
Definition CommonLog.hpp:55
double eastWest
East/West deviation from the reference point [m].
Definition CommonLog.hpp:56
States.
Definition Pos.hpp:236
StateKeys
State Keys.
Definition Pos.hpp:242
@ PosX
Position ECEF_X [m].
Definition Pos.hpp:243
@ States_COUNT
Count.
Definition Pos.hpp:246
@ PosY
Position ECEF_Y [m].
Definition Pos.hpp:244
@ PosZ
Position ECEF_Z [m].
Definition Pos.hpp:245
static const std::vector< StateKeys > Pos
All position keys.
Definition Pos.hpp:249
States()=delete
Constructor.
Matrix which can be accessed by keys.