0.2.0
Loading...
Searching...
No Matches
PosVel.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 <Eigen/src/Core/Matrix.h>
18
19namespace NAV
20{
22class PosVel : public Pos
23{
24 public:
27 [[nodiscard]] static std::string type()
28 {
29 return "PosVel";
30 }
31
34 [[nodiscard]] static std::vector<std::string> parentTypes()
35 {
36 auto parent = Pos::parentTypes();
37 parent.push_back(Pos::type());
38 return parent;
39 }
40
42 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
43 {
45 desc.reserve(GetStaticDescriptorCount());
46 desc.emplace_back("Velocity norm [m/s]");
47 desc.emplace_back("X velocity ECEF [m/s]");
48 desc.emplace_back("Y velocity ECEF [m/s]");
49 desc.emplace_back("Z velocity ECEF [m/s]");
50 desc.emplace_back("North velocity [m/s]");
51 desc.emplace_back("East velocity [m/s]");
52 desc.emplace_back("Down velocity [m/s]");
53 desc.emplace_back("X velocity ECEF StDev [m/s]");
54 desc.emplace_back("Y velocity ECEF StDev [m/s]");
55 desc.emplace_back("Z velocity ECEF StDev [m/s]");
56 desc.emplace_back("XY velocity StDev [m]");
57 desc.emplace_back("XZ velocity StDev [m]");
58 desc.emplace_back("YZ velocity StDev [m]");
59 desc.emplace_back("North velocity StDev [m/s]");
60 desc.emplace_back("East velocity StDev [m/s]");
61 desc.emplace_back("Down velocity StDev [m/s]");
62 desc.emplace_back("NE velocity StDev [m]");
63 desc.emplace_back("ND velocity StDev [m]");
64 desc.emplace_back("ED velocity StDev [m]");
65 return desc;
66 }
67
69 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return 39; }
70
72 [[nodiscard]] std::vector<std::string> staticDataDescriptors() const override { return GetStaticDataDescriptors(); }
73
75 [[nodiscard]] size_t staticDescriptorCount() const override { return GetStaticDescriptorCount(); }
76
80 [[nodiscard]] std::optional<double> getValueAt(size_t idx) const override
81 {
83 switch (idx)
84 {
85 case 0: // Latitude [deg]
86 case 1: // Longitude [deg]
87 case 2: // Altitude [m]
88 case 3: // North/South [m]
89 case 4: // East/West [m]
90 case 5: // X-ECEF [m]
91 case 6: // Y-ECEF [m]
92 case 7: // Z-ECEF [m]
93 case 8: // X-ECEF StDev [m]
94 case 9: // Y-ECEF StDev [m]
95 case 10: // Z-ECEF StDev [m]
96 case 11: // XY-ECEF StDev [m]
97 case 12: // XZ-ECEF StDev [m]
98 case 13: // YZ-ECEF StDev [m]
99 case 14: // North StDev [m]
100 case 15: // East StDev [m]
101 case 16: // Down StDev [m]
102 case 17: // NE StDev [m]
103 case 18: // ND StDev [m]
104 case 19: // ED StDev [m]
105 return Pos::getValueAt(idx);
106 case 20: // Velocity norm [m/s]
107 return e_velocity().norm();
108 case 21: // X velocity ECEF [m/s]
109 return e_velocity().x();
110 case 22: // Y velocity ECEF [m/s]
111 return e_velocity().y();
112 case 23: // Z velocity ECEF [m/s]
113 return e_velocity().z();
114 case 24: // North velocity [m/s]
115 return n_velocity().x();
116 case 25: // East velocity [m/s]
117 return n_velocity().y();
118 case 26: // Down velocity [m/s]
119 return n_velocity().z();
120 case 27: // X velocity ECEF StDev [m/s]
121 if (auto stDev = e_velocityStdev()) { return stDev->get().x(); }
122 break;
123 case 28: // Y velocity ECEF StDev [m/s]
124 if (auto stDev = e_velocityStdev()) { return stDev->get().z(); }
125 break;
126 case 29: // Z velocity ECEF StDev [m/s]
127 if (auto stDev = e_velocityStdev()) { return stDev->get().z(); }
128 break;
129 case 30: // XY velocity StDev [m]
130 if (e_CovarianceMatrix().has_value() && (*e_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*e_CovarianceMatrix())(States::VelX, States::VelY); }
131 break;
132 case 31: // XZ velocity StDev [m]
133 if (e_CovarianceMatrix().has_value() && (*e_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*e_CovarianceMatrix())(States::VelX, States::VelZ); }
134 break;
135 case 32: // YZ velocity StDev [m]
136 if (e_CovarianceMatrix().has_value() && (*e_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*e_CovarianceMatrix())(States::VelY, States::VelZ); }
137 break;
138 case 33: // North velocity StDev [m/s]
139 if (auto stDev = n_velocityStdev()) { return stDev->get().x(); }
140 break;
141 case 34: // East velocity StDev [m/s]
142 if (auto stDev = n_velocityStdev()) { return stDev->get().y(); }
143 break;
144 case 35: // Down velocity StDev [m/s]
145 if (auto stDev = n_velocityStdev()) { return stDev->get().z(); }
146 break;
147 case 36: // NE velocity StDev [m]
148 if (n_CovarianceMatrix().has_value() && (*n_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*n_CovarianceMatrix())(States::VelX, States::VelY); }
149 break;
150 case 37: // ND velocity StDev [m]
151 if (n_CovarianceMatrix().has_value() && (*n_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*n_CovarianceMatrix())(States::VelX, States::VelZ); }
152 break;
153 case 38: // ED velocity StDev [m]
154 if (n_CovarianceMatrix().has_value() && (*n_CovarianceMatrix()).get().hasAnyCols(States::Vel)) { return (*n_CovarianceMatrix())(States::VelY, States::VelZ); }
155 break;
156 default:
157 return std::nullopt;
158 }
159 return std::nullopt;
160 }
161
162 /* -------------------------------------------------------------------------------------------------------- */
163 /* Velocity */
164 /* -------------------------------------------------------------------------------------------------------- */
165
167 struct States
168 {
170 States() = delete;
171
184 inline static const std::vector<StateKeys> Pos = { PosX, PosY, PosZ };
186 inline static const std::vector<StateKeys> Vel = { States::VelX, States::VelY, States::VelZ };
188 inline static const std::vector<StateKeys> PosVel = { States::PosX, States::PosY, States::PosZ,
190 };
191
193 [[nodiscard]] const Eigen::Vector3d& e_velocity() const { return _e_velocity; }
194
196 [[nodiscard]] const Eigen::Vector3d& n_velocity() const { return _n_velocity; }
197
199 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> e_velocityStdev() const { return _e_velocityStdev; }
200
202 [[nodiscard]] std::optional<std::reference_wrapper<const Eigen::Vector3d>> n_velocityStdev() const { return _n_velocityStdev; }
203
205 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> e_CovarianceMatrix() const { return _e_covarianceMatrix; }
206
208 [[nodiscard]] std::optional<std::reference_wrapper<const KeyedMatrixXd<States::StateKeys, States::StateKeys>>> n_CovarianceMatrix() const { return _n_covarianceMatrix; }
209
210 // ###########################################################################################################
211 // Setter
212 // ###########################################################################################################
213
216 void setVelocity_e(const Eigen::Vector3d& e_velocity)
217 {
218 _e_velocity = e_velocity;
219 _n_velocity = n_Quat_e() * e_velocity;
220 }
221
224 void setVelocity_n(const Eigen::Vector3d& n_velocity)
225 {
226 _e_velocity = e_Quat_n() * n_velocity;
227 _n_velocity = n_velocity;
228 }
229
233 void setVelocityAndStdDev_e(const Eigen::Vector3d& e_velocity, const Eigen::Matrix3d& e_velocityCovarianceMatrix)
234 {
236 _e_velocityStdev = e_velocityCovarianceMatrix.diagonal().cwiseSqrt();
237 _n_velocityStdev = (n_Quat_e() * e_velocityCovarianceMatrix * e_Quat_n()).diagonal().cwiseSqrt();
238 }
239
243 void setVelocityAndStdDev_n(const Eigen::Vector3d& n_velocity, const Eigen::Matrix3d& n_velocityCovarianceMatrix)
244 {
246 _n_velocityStdev = n_velocityCovarianceMatrix.diagonal().cwiseSqrt();
247 _e_velocityStdev = (e_Quat_n() * n_velocityCovarianceMatrix * n_Quat_e()).diagonal().cwiseSqrt();
248 }
249
253 template<typename Derived>
254 void setPosVelCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
255 {
256 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 6, "This function needs a 6x6 matrix as input");
257 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 6, "This function needs a 6x6 matrix as input");
258
259 _e_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
260 States::StateKeys>(e_covarianceMatrix,
262 _n_covarianceMatrix = _e_covarianceMatrix;
263
264 Eigen::Quaterniond n_Quat_e = trafo::n_Quat_e(latitude(), longitude());
265 Eigen::Quaterniond e_Quat_n = trafo::e_Quat_n(latitude(), longitude());
266
267 (*_n_covarianceMatrix)(all, all).setZero();
268 (*_n_covarianceMatrix)(States::Pos, States::Pos) = n_Quat_e * (*_e_covarianceMatrix)(States::Pos, States::Pos) * e_Quat_n;
269 (*_n_covarianceMatrix)(States::Vel, States::Vel) = n_Quat_e * (*_e_covarianceMatrix)(States::Vel, States::Vel) * e_Quat_n;
270 }
271
275 template<typename Derived>
276 void setPosVelCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
277 {
278 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 6, "This function needs a 6x6 matrix as input");
279 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 6, "This function needs a 6x6 matrix as input");
280
281 _n_covarianceMatrix = KeyedMatrixXd<States::StateKeys,
282 States::StateKeys>(n_covarianceMatrix,
284 _e_covarianceMatrix = _n_covarianceMatrix;
285
286 Eigen::Quaterniond n_Quat_e = trafo::n_Quat_e(latitude(), longitude());
287 Eigen::Quaterniond e_Quat_n = trafo::e_Quat_n(latitude(), longitude());
288
289 (*_e_covarianceMatrix)(all, all).setZero();
290 (*_e_covarianceMatrix)(States::Pos, States::Pos) = e_Quat_n * (*_n_covarianceMatrix)(States::Pos, States::Pos) * n_Quat_e;
291 (*_e_covarianceMatrix)(States::Vel, States::Vel) = e_Quat_n * (*_n_covarianceMatrix)(States::Vel, States::Vel) * n_Quat_e;
292 }
293
294 /* -------------------------------------------------------------------------------------------------------- */
295 /* Member variables */
296 /* -------------------------------------------------------------------------------------------------------- */
297
298 private:
300 Eigen::Vector3d _e_velocity{ std::nan(""), std::nan(""), std::nan("") };
302 Eigen::Vector3d _n_velocity{ std::nan(""), std::nan(""), std::nan("") };
303
305 std::optional<Eigen::Vector3d> _e_velocityStdev;
307 std::optional<Eigen::Vector3d> _n_velocityStdev;
308
310 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _e_covarianceMatrix;
311
313 std::optional<KeyedMatrixXd<States::StateKeys, States::StateKeys>> _n_covarianceMatrix;
314};
315
316} // namespace NAV
#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
Position Storage Class.
Dynamic sized KeyedMatrix.
Definition KeyedMatrix.hpp:2055
Position, Velocity and Attitude Storage Class.
Definition PosVel.hpp:23
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition PosVel.hpp:69
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition PosVel.hpp:34
void setVelocityAndStdDev_e(const Eigen::Vector3d &e_velocity, const Eigen::Matrix3d &e_velocityCovarianceMatrix)
Set the Velocity in ECEF coordinates and its standard deviation.
Definition PosVel.hpp:233
const Eigen::Vector3d & n_velocity() const
Returns the velocity in [m/s], in navigation coordinates.
Definition PosVel.hpp:196
std::optional< std::reference_wrapper< const Eigen::Vector3d > > e_velocityStdev() const
Returns the standard deviation of the velocity in [m/s], in earth coordinates.
Definition PosVel.hpp:199
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition PosVel.hpp:42
void setVelocity_e(const Eigen::Vector3d &e_velocity)
Set the Velocity in the earth frame.
Definition PosVel.hpp:216
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition PosVel.hpp:72
static std::string type()
Returns the type of the data class.
Definition PosVel.hpp:27
std::optional< std::reference_wrapper< const Eigen::Vector3d > > n_velocityStdev() const
Returns the standard deviation of the velocity in [m/s], in navigation coordinates.
Definition PosVel.hpp:202
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition PosVel.hpp:75
void setPosVelCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition PosVel.hpp:254
std::optional< std::reference_wrapper< const KeyedMatrixXd< States::StateKeys, States::StateKeys > > > e_CovarianceMatrix() const
Returns the Covariance matrix in ECEF frame.
Definition PosVel.hpp:205
void setVelocity_n(const Eigen::Vector3d &n_velocity)
Set the Velocity in the NED frame.
Definition PosVel.hpp:224
const Eigen::Vector3d & e_velocity() const
Returns the velocity in [m/s], in earth coordinates.
Definition PosVel.hpp:193
std::optional< std::reference_wrapper< const KeyedMatrixXd< States::StateKeys, States::StateKeys > > > n_CovarianceMatrix() const
Returns the Covariance matrix in local navigation frame.
Definition PosVel.hpp:208
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition PosVel.hpp:80
void setVelocityAndStdDev_n(const Eigen::Vector3d &n_velocity, const Eigen::Matrix3d &n_velocityCovarianceMatrix)
Set the Velocity in NED coordinates and its standard deviation.
Definition PosVel.hpp:243
void setPosVelCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in NED coordinates.
Definition PosVel.hpp:276
Position, Velocity and Attitude Storage Class.
Definition Pos.hpp:29
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
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
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
Eigen::Quaterniond n_Quat_e() const
Returns the Quaternion from Earth-fixed frame to navigation.
Definition Pos.hpp:160
const double & longitude() const
Returns the longitude λ in [rad].
Definition Pos.hpp:194
States.
Definition PosVel.hpp:168
StateKeys
State Keys.
Definition PosVel.hpp:174
@ States_COUNT
Count.
Definition PosVel.hpp:181
@ PosY
Position ECEF_Y [m].
Definition PosVel.hpp:176
@ PosZ
Position ECEF_Z [m].
Definition PosVel.hpp:177
@ PosX
Position ECEF_X [m].
Definition PosVel.hpp:175
@ VelY
Velocity ECEF_Y [m/s].
Definition PosVel.hpp:179
@ VelZ
Velocity ECEF_Z [m/s].
Definition PosVel.hpp:180
@ VelX
Velocity ECEF_X [m/s].
Definition PosVel.hpp:178
States()=delete
Constructor.
static const std::vector< StateKeys > PosVel
Vector with all position and velocity state keys.
Definition PosVel.hpp:188
static const std::vector< StateKeys > Vel
All velocity keys.
Definition PosVel.hpp:186
static const std::vector< StateKeys > Pos
All position keys.
Definition PosVel.hpp:184