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>
17#include <Eigen/src/Core/MatrixBase.h>
18
19#include "NodeData/NodeData.hpp"
22#include "Navigation/Transformations/Units.hpp"
23
26#include "util/Assert.h"
27
28namespace NAV
29{
31class Pos : public NodeData
32{
33 public:
36 [[nodiscard]] static std::string type()
37 {
38 return "Pos";
39 }
40
43 [[nodiscard]] std::string getType() const override { return type(); }
44
47 [[nodiscard]] static std::vector<std::string> parentTypes()
48 {
49 return { NodeData::type() };
50 }
51
53 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
54 {
55 return {
56 "Latitude [deg]",
57 "Longitude [deg]",
58 "Altitude [m]",
59 "North/South [m]",
60 "East/West [m]",
61 "X-ECEF [m]",
62 "Y-ECEF [m]",
63 "Z-ECEF [m]",
64 "X-ECEF StDev [m]",
65 "Y-ECEF StDev [m]",
66 "Z-ECEF StDev [m]",
67 "XY-ECEF StDev [m]",
68 "XZ-ECEF StDev [m]",
69 "YZ-ECEF StDev [m]",
70 "North StDev [m]",
71 "East StDev [m]",
72 "Down StDev [m]",
73 "NE StDev [m]",
74 "ND StDev [m]",
75 "ED StDev [m]",
76 };
77 }
78
80 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return 20; }
81
83 [[nodiscard]] std::vector<std::string> staticDataDescriptors() const override { return GetStaticDataDescriptors(); }
84
86 [[nodiscard]] size_t staticDescriptorCount() const override { return GetStaticDescriptorCount(); }
87
91 [[nodiscard]] std::optional<double> getValueAt(size_t idx) const override
92 {
94 switch (idx)
95 {
96 case 0: // Latitude [deg]
97 return rad2deg(latitude());
98 case 1: // Longitude [deg]
99 return rad2deg(longitude());
100 case 2: // Altitude [m]
101 return altitude();
102 case 3: // North/South [m]
104 case 4: // East/West [m]
106 case 5: // X-ECEF [m]
107 return e_position().x();
108 case 6: // Y-ECEF [m]
109 return e_position().y();
110 case 7: // Z-ECEF [m]
111 return e_position().z();
112 case 8: // X-ECEF StDev [m]
113 if (auto stDev = e_positionStdev()) { return stDev->x(); }
114 break;
115 case 9: // Y-ECEF StDev [m]
116 if (auto stDev = e_positionStdev()) { return stDev->y(); }
117 break;
118 case 10: // Z-ECEF StDev [m]
119 if (auto stDev = e_positionStdev()) { return stDev->z(); }
120 break;
121 case 11: // XY-ECEF StDev [m]
122 if (_e_covarianceMatrix) { return std::sqrt(std::abs((*_e_covarianceMatrix)(Keys::PosX, Keys::PosY))); }
123 break;
124 case 12: // XZ-ECEF StDev [m]
125 if (_e_covarianceMatrix) { return std::sqrt(std::abs((*_e_covarianceMatrix)(Keys::PosX, Keys::PosZ))); }
126 break;
127 case 13: // YZ-ECEF StDev [m]
128 if (_e_covarianceMatrix) { return std::sqrt(std::abs((*_e_covarianceMatrix)(Keys::PosY, Keys::PosZ))); }
129 break;
130 case 14: // North StDev [m]
131 if (auto stDev = n_positionStdev()) { return stDev->x(); }
132 break;
133 case 15: // East StDev [m]
134 if (auto stDev = n_positionStdev()) { return stDev->y(); }
135 break;
136 case 16: // Down StDev [m]
137 if (auto stDev = n_positionStdev()) { return stDev->z(); }
138 break;
139 case 17: // NE StDev [m]
140 if (_n_covarianceMatrix) { return std::sqrt(std::abs((*_n_covarianceMatrix)(Keys::PosX, Keys::PosY))); }
141 break;
142 case 18: // ND StDev [m]
143 if (_n_covarianceMatrix) { return std::sqrt(std::abs((*_n_covarianceMatrix)(Keys::PosX, Keys::PosZ))); }
144 break;
145 case 19: // ED StDev [m]
146 if (_n_covarianceMatrix) { return std::sqrt(std::abs((*_n_covarianceMatrix)(Keys::PosY, Keys::PosZ))); }
147 break;
148 default:
149 return std::nullopt;
150 }
151 return std::nullopt;
152 }
153
158 [[nodiscard]] bool setValueAt(size_t idx, double value) override
159 {
161 switch (idx)
162 {
163 case 0: // Latitude [deg]
164 _lla_position(0) = deg2rad(value);
166 break;
167 case 1: // Longitude [deg]
168 _lla_position(1) = deg2rad(value);
170 break;
171 case 2: // Altitude [m]
172 _lla_position(2) = value;
174 break;
175 case 3: // North/South [m]
176 _e_position += e_Quat_n() * Eigen::Vector3d(value, 0.0, 0.0);
178 break;
179 case 4: // East/West [m]
180 _e_position += e_Quat_n() * Eigen::Vector3d(0.0, value, 0.0);
182 break;
183 case 5: // X-ECEF [m]
184 _e_position(0) = value;
186 break;
187 case 6: // Y-ECEF [m]
188 _e_position(1) = value;
190 break;
191 case 7: // Z-ECEF [m]
192 _e_position(2) = value;
194 break;
195 case 8: // X-ECEF StDev [m]
196 case 9: // Y-ECEF StDev [m]
197 case 10: // Z-ECEF StDev [m]
198 case 11: // XY-ECEF StDev [m]
199 case 12: // XZ-ECEF StDev [m]
200 case 13: // YZ-ECEF StDev [m]
201 case 14: // North StDev [m]
202 case 15: // East StDev [m]
203 case 16: // Down StDev [m]
204 case 17: // NE StDev [m]
205 case 18: // ND StDev [m]
206 case 19: // ED StDev [m]
207 default:
208 return false;
209 }
210
211 return true;
212 }
213
214 /* -------------------------------------------------------------------------------------------------------- */
215 /* Rotation Quaternions */
216 /* -------------------------------------------------------------------------------------------------------- */
217
220 [[nodiscard]] Eigen::Quaterniond e_Quat_n() const
221 {
223 }
224
227 [[nodiscard]] Eigen::Quaterniond n_Quat_e() const
228 {
229 return e_Quat_n().conjugate();
230 }
231
232 /* -------------------------------------------------------------------------------------------------------- */
233 /* Position */
234 /* -------------------------------------------------------------------------------------------------------- */
235
237 [[nodiscard]] const Eigen::Vector3d& lla_position() const { return _lla_position; }
238
240 [[nodiscard]] const double& latitude() const { return lla_position()(0); }
241
243 [[nodiscard]] const double& longitude() const { return lla_position()(1); }
244
246 [[nodiscard]] const double& altitude() const { return lla_position()(2); }
247
249 [[nodiscard]] const Eigen::Vector3d& e_position() const { return _e_position; }
250
252 [[nodiscard]] std::optional<Eigen::Vector3d> e_positionStdev() const
253 {
255 {
257 }
258 return std::nullopt;
259 }
260
262 [[nodiscard]] std::optional<Eigen::Vector3d> n_positionStdev() const
263 {
265 {
267 }
268 return std::nullopt;
269 }
270
272 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<Keys::MotionModelKey, Keys::MotionModelKey>>> e_CovarianceMatrix() const { return _e_covarianceMatrix; }
273
275 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<Keys::MotionModelKey, Keys::MotionModelKey>>> n_CovarianceMatrix() const { return _n_covarianceMatrix; }
276
277 // ###########################################################################################################
278 // Setter
279 // ###########################################################################################################
280
283 template<typename Derived>
284 void setPosition_e(const Eigen::MatrixBase<Derived>& e_position)
285 {
288 }
289
292 template<typename Derived>
293 void setPosition_lla(const Eigen::MatrixBase<Derived>& lla_position)
294 {
297 }
298
302 template<typename DerivedP, typename Derived>
303 void setPositionAndCov_e(const Eigen::MatrixBase<DerivedP>& e_position, const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
304 {
306 setPosCovarianceMatrix_e(e_covarianceMatrix);
307 }
308
312 template<typename DerivedP, typename Derived>
313 void setPositionAndCov_n(const Eigen::MatrixBase<DerivedP>& lla_position, const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
314 {
316 setPosCovarianceMatrix_n(n_covarianceMatrix);
317 }
318
322 template<typename Derived>
323 void setPosCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
324 {
325 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
326 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
327
329 e_covarianceMatrix, Keys::Pos<Keys::MotionModelKey>);
330
331 Eigen::Matrix3d J = n_Quat_e().toRotationMatrix();
332
334 J * e_covarianceMatrix * J.transpose(), Keys::Pos<Keys::MotionModelKey>);
335 }
336
340 template<typename Derived>
341 void setPosCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
342 {
343 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 3, "This function needs a 3x3 matrix as input");
344 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 3, "This function needs a 3x3 matrix as input");
345
347 n_covarianceMatrix, Keys::Pos<Keys::MotionModelKey>);
348
349 Eigen::Matrix3d J = e_Quat_n().toRotationMatrix();
350
352 J * n_covarianceMatrix * J.transpose(), Keys::Pos<Keys::MotionModelKey>);
353 }
354
355 /* -------------------------------------------------------------------------------------------------------- */
356 /* Member variables */
357 /* -------------------------------------------------------------------------------------------------------- */
358
359 protected:
361 std::optional<KeyedMatrixXd<Keys::MotionModelKey, Keys::MotionModelKey>> _e_covarianceMatrix;
362
364 std::optional<KeyedMatrixXd<Keys::MotionModelKey, Keys::MotionModelKey>> _n_covarianceMatrix;
365
366 private:
368 Eigen::Vector3d _e_position{ std::nan(""), std::nan(""), std::nan("") };
370 Eigen::Vector3d _lla_position{ std::nan(""), std::nan(""), std::nan("") };
371};
372
373} // 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.
Eigen::Vector3< typename Derived::Scalar > ecef2lla_WGS84(const Eigen::MatrixBase< Derived > &e_position)
Converts Earth-centered-Earth-fixed coordinates into latitude, longitude and altitude using WGS84.
Definition CoordinateFrames.hpp:420
Eigen::Quaternion< Scalar > e_Quat_n(const Scalar &latitude, const Scalar &longitude)
Quaternion for rotations from navigation to Earth-fixed frame.
Definition CoordinateFrames.hpp:305
Eigen::Vector3< typename Derived::Scalar > lla2ecef_WGS84(const Eigen::MatrixBase< Derived > &lla_position)
Converts latitude, longitude and altitude into Earth-centered-Earth-fixed coordinates using WGS84.
Definition CoordinateFrames.hpp:402
Motion System Model.
constexpr std::array< StateKeyType, 3 > Pos
All position keys.
Definition MotionModel.hpp:56
@ PosY
Position ECEF_Y [m].
Definition MotionModel.hpp:42
@ PosX
Position ECEF_X [m].
Definition MotionModel.hpp:41
@ PosZ
Position ECEF_Z [m].
Definition MotionModel.hpp:43
Abstract NodeData Class.
static LocalPosition calcLocalPosition(const Eigen::Vector3d &lla_position)
Calculate the local position offset from a reference point.
NodeData()=default
Default constructor.
static std::string type()
Returns the type of the data class.
Definition NodeData.hpp:45
Position Storage Class.
Definition Pos.hpp:32
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition Pos.hpp:91
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition Pos.hpp:53
Eigen::Vector3d _e_position
Position in ECEF coordinates [m].
Definition Pos.hpp:368
std::optional< std::reference_wrapper< const KeyedMatrixXd< Keys::MotionModelKey, Keys::MotionModelKey > > > e_CovarianceMatrix() const
Returns the Covariance matrix in ECEF frame.
Definition Pos.hpp:272
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition Pos.hpp:80
bool setValueAt(size_t idx, double value) override
Set the value at the index.
Definition Pos.hpp:158
const double & latitude() const
Returns the latitude 𝜙 in [rad].
Definition Pos.hpp:240
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition Pos.hpp:47
std::optional< std::reference_wrapper< const KeyedMatrixXd< Keys::MotionModelKey, Keys::MotionModelKey > > > n_CovarianceMatrix() const
Returns the Covariance matrix in local navigation frame.
Definition Pos.hpp:275
Eigen::Quaterniond e_Quat_n() const
Returns the Quaternion from navigation to Earth-fixed frame.
Definition Pos.hpp:220
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:36
std::optional< KeyedMatrixXd< Keys::MotionModelKey, Keys::MotionModelKey > > _e_covarianceMatrix
Covariance matrix in ECEF coordinates.
Definition Pos.hpp:361
std::optional< KeyedMatrixXd< Keys::MotionModelKey, Keys::MotionModelKey > > _n_covarianceMatrix
Covariance matrix in local navigation coordinates.
Definition Pos.hpp:364
void setPosCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in NED coordinates.
Definition Pos.hpp:341
void setPositionAndCov_n(const Eigen::MatrixBase< DerivedP > &lla_position, const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the position and the covariance matrix.
Definition Pos.hpp:313
Eigen::Quaterniond n_Quat_e() const
Returns the Quaternion from Earth-fixed frame to navigation.
Definition Pos.hpp:227
const Eigen::Vector3d & e_position() const
Returns the coordinates in [m].
Definition Pos.hpp:249
void setPositionAndCov_e(const Eigen::MatrixBase< DerivedP > &e_position, const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the position and the covariance matrix.
Definition Pos.hpp:303
void setPosition_e(const Eigen::MatrixBase< Derived > &e_position)
Set the Position in coordinates.
Definition Pos.hpp:284
const Eigen::Vector3d & lla_position() const
Returns the latitude 𝜙, longitude λ and altitude (height above ground) in [rad, rad,...
Definition Pos.hpp:237
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition Pos.hpp:86
std::optional< Eigen::Vector3d > n_positionStdev() const
Returns the standard deviation of the position in local navigation frame coordinates in [m].
Definition Pos.hpp:262
std::string getType() const override
Returns the type of the data class.
Definition Pos.hpp:43
std::optional< Eigen::Vector3d > e_positionStdev() const
Returns the standard deviation of the position in ECEF frame coordinates in [m].
Definition Pos.hpp:252
Eigen::Vector3d _lla_position
Position in LatLonAlt coordinates [rad, rad, m].
Definition Pos.hpp:370
const double & altitude() const
Returns the altitude (height above ground) in [m].
Definition Pos.hpp:246
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition Pos.hpp:83
void setPosition_lla(const Eigen::MatrixBase< Derived > &lla_position)
Set the Position lla object.
Definition Pos.hpp:293
const double & longitude() const
Returns the longitude λ in [rad].
Definition Pos.hpp:243
void setPosCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition Pos.hpp:323
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
Matrix which can be accessed by keys.
KeyedMatrixX< double, RowKeyType, ColKeyType > KeyedMatrixXd
Dynamic size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2313