0.3.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]] std::string getType() const override { return type(); }
35
38 [[nodiscard]] static std::vector<std::string> parentTypes()
39 {
40 auto parent = Pos::parentTypes();
41 parent.push_back(Pos::type());
42 return parent;
43 }
44
46 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
47 {
49 desc.reserve(GetStaticDescriptorCount());
50 desc.emplace_back("Velocity norm [m/s]");
51 desc.emplace_back("X velocity ECEF [m/s]");
52 desc.emplace_back("Y velocity ECEF [m/s]");
53 desc.emplace_back("Z velocity ECEF [m/s]");
54 desc.emplace_back("North velocity [m/s]");
55 desc.emplace_back("East velocity [m/s]");
56 desc.emplace_back("Down velocity [m/s]");
57 desc.emplace_back("X velocity ECEF StDev [m/s]");
58 desc.emplace_back("Y velocity ECEF StDev [m/s]");
59 desc.emplace_back("Z velocity ECEF StDev [m/s]");
60 desc.emplace_back("XY velocity StDev [m]");
61 desc.emplace_back("XZ velocity StDev [m]");
62 desc.emplace_back("YZ velocity StDev [m]");
63 desc.emplace_back("North velocity StDev [m/s]");
64 desc.emplace_back("East velocity StDev [m/s]");
65 desc.emplace_back("Down velocity StDev [m/s]");
66 desc.emplace_back("NE velocity StDev [m]");
67 desc.emplace_back("ND velocity StDev [m]");
68 desc.emplace_back("ED velocity StDev [m]");
69 return desc;
70 }
71
73 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return Pos::GetStaticDescriptorCount() + 19; }
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 if (idx < Pos::GetStaticDescriptorCount()) { return Pos::getValueAt(idx); }
88 switch (idx)
89 {
90 case Pos::GetStaticDescriptorCount() + 0: // Velocity norm [m/s]
91 return e_velocity().norm();
92 case Pos::GetStaticDescriptorCount() + 1: // X velocity ECEF [m/s]
93 return e_velocity().x();
94 case Pos::GetStaticDescriptorCount() + 2: // Y velocity ECEF [m/s]
95 return e_velocity().y();
96 case Pos::GetStaticDescriptorCount() + 3: // Z velocity ECEF [m/s]
97 return e_velocity().z();
98 case Pos::GetStaticDescriptorCount() + 4: // North velocity [m/s]
99 return n_velocity().x();
100 case Pos::GetStaticDescriptorCount() + 5: // East velocity [m/s]
101 return n_velocity().y();
102 case Pos::GetStaticDescriptorCount() + 6: // Down velocity [m/s]
103 return n_velocity().z();
104 case Pos::GetStaticDescriptorCount() + 7: // X velocity ECEF StDev [m/s]
105 if (auto stDev = e_velocityStdev()) { return stDev->x(); }
106 break;
107 case Pos::GetStaticDescriptorCount() + 8: // Y velocity ECEF StDev [m/s]
108 if (auto stDev = e_velocityStdev()) { return stDev->y(); }
109 break;
110 case Pos::GetStaticDescriptorCount() + 9: // Z velocity ECEF StDev [m/s]
111 if (auto stDev = e_velocityStdev()) { return stDev->z(); }
112 break;
113 case Pos::GetStaticDescriptorCount() + 10: // XY velocity StDev [m]
115 break;
116 case Pos::GetStaticDescriptorCount() + 11: // XZ velocity StDev [m]
118 break;
119 case Pos::GetStaticDescriptorCount() + 12: // YZ velocity StDev [m]
121 break;
122 case Pos::GetStaticDescriptorCount() + 13: // North velocity StDev [m/s]
123 if (auto stDev = n_velocityStdev()) { return stDev->x(); }
124 break;
125 case Pos::GetStaticDescriptorCount() + 14: // East velocity StDev [m/s]
126 if (auto stDev = n_velocityStdev()) { return stDev->y(); }
127 break;
128 case Pos::GetStaticDescriptorCount() + 15: // Down velocity StDev [m/s]
129 if (auto stDev = n_velocityStdev()) { return stDev->z(); }
130 break;
131 case Pos::GetStaticDescriptorCount() + 16: // NE velocity StDev [m]
133 break;
134 case Pos::GetStaticDescriptorCount() + 17: // ND velocity StDev [m]
136 break;
137 case Pos::GetStaticDescriptorCount() + 18: // ED velocity StDev [m]
139 break;
140 default:
141 return std::nullopt;
142 }
143 return std::nullopt;
144 }
145
150 [[nodiscard]] bool setValueAt(size_t idx, double value) override
151 {
153 if (idx < Pos::GetStaticDescriptorCount()) { return Pos::setValueAt(idx, value); }
154 switch (idx)
155 {
156 case Pos::GetStaticDescriptorCount() + 0: // Velocity norm [m/s]
157 _e_velocity = value * _e_velocity.normalized();
158 _n_velocity = value * _n_velocity.normalized();
159 break;
160 case Pos::GetStaticDescriptorCount() + 1: // X velocity ECEF [m/s]
161 _e_velocity(0) = value;
163 break;
164 case Pos::GetStaticDescriptorCount() + 2: // Y velocity ECEF [m/s]
165 _e_velocity(1) = value;
167 break;
168 case Pos::GetStaticDescriptorCount() + 3: // Z velocity ECEF [m/s]
169 _e_velocity(2) = value;
171 break;
172 case Pos::GetStaticDescriptorCount() + 4: // North velocity [m/s]
173 _n_velocity(0) = value;
175 break;
176 case Pos::GetStaticDescriptorCount() + 5: // East velocity [m/s]
177 _n_velocity(1) = value;
179 break;
180 case Pos::GetStaticDescriptorCount() + 6: // Down velocity [m/s]
181 _n_velocity(2) = value;
183 break;
184 case Pos::GetStaticDescriptorCount() + 7: // X velocity ECEF StDev [m/s]
185 case Pos::GetStaticDescriptorCount() + 8: // Y velocity ECEF StDev [m/s]
186 case Pos::GetStaticDescriptorCount() + 9: // Z velocity ECEF StDev [m/s]
187 case Pos::GetStaticDescriptorCount() + 10: // XY velocity StDev [m]
188 case Pos::GetStaticDescriptorCount() + 11: // XZ velocity StDev [m]
189 case Pos::GetStaticDescriptorCount() + 12: // YZ velocity StDev [m]
190 case Pos::GetStaticDescriptorCount() + 13: // North velocity StDev [m/s]
191 case Pos::GetStaticDescriptorCount() + 14: // East velocity StDev [m/s]
192 case Pos::GetStaticDescriptorCount() + 15: // Down velocity StDev [m/s]
193 case Pos::GetStaticDescriptorCount() + 16: // NE velocity StDev [m]
194 case Pos::GetStaticDescriptorCount() + 17: // ND velocity StDev [m]
195 case Pos::GetStaticDescriptorCount() + 18: // ED velocity StDev [m]
196 default:
197 return false;
198 }
199
200 return true;
201 }
202
203 /* -------------------------------------------------------------------------------------------------------- */
204 /* Velocity */
205 /* -------------------------------------------------------------------------------------------------------- */
206
208 [[nodiscard]] const Eigen::Vector3d& e_velocity() const { return _e_velocity; }
209
211 [[nodiscard]] const Eigen::Vector3d& n_velocity() const { return _n_velocity; }
212
214 [[nodiscard]] std::optional<Eigen::Vector3d> e_velocityStdev() const
215 {
217 {
219 }
220 return std::nullopt;
221 }
222
224 [[nodiscard]] std::optional<Eigen::Vector3d> n_velocityStdev() const
225 {
227 {
229 }
230 return std::nullopt;
231 }
232
233 // ###########################################################################################################
234 // Setter
235 // ###########################################################################################################
236
239 template<typename Derived>
240 void setVelocity_e(const Eigen::MatrixBase<Derived>& e_velocity)
241 {
244 }
245
248 template<typename Derived>
249 void setVelocity_n(const Eigen::MatrixBase<Derived>& n_velocity)
250 {
253 }
254
258 template<typename DerivedP, typename DerivedV>
259 void setPosVel_e(const Eigen::MatrixBase<DerivedP>& e_position, const Eigen::MatrixBase<DerivedV>& e_velocity)
260 {
263 }
264
268 template<typename DerivedP, typename DerivedV>
269 void setPosVel_n(const Eigen::MatrixBase<DerivedP>& lla_position, const Eigen::MatrixBase<DerivedV>& n_velocity)
270 {
273 }
274
279 template<typename DerivedP, typename DerivedV, typename Derived>
280 void setPosVelAndCov_e(const Eigen::MatrixBase<DerivedP>& e_position, const Eigen::MatrixBase<DerivedV>& e_velocity,
281 const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
282 {
285 setPosVelCovarianceMatrix_e(e_covarianceMatrix);
286 }
287
292 template<typename DerivedP, typename DerivedV, typename Derived>
293 void setPosVelAndCov_n(const Eigen::MatrixBase<DerivedP>& lla_position, const Eigen::MatrixBase<DerivedV>& n_velocity,
294 const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
295 {
298 setPosVelCovarianceMatrix_n(n_covarianceMatrix);
299 }
300
304 template<typename Derived>
305 void setPosVelCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
306 {
307 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 6, "This function needs a 6x6 matrix as input");
308 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 6, "This function needs a 6x6 matrix as input");
309
311 e_covarianceMatrix, Keys::PosVel<Keys::MotionModelKey>);
312
313 Eigen::Quaterniond n_q_e = n_Quat_e();
314 Eigen::Matrix<double, 6, 6> J = Eigen::Matrix<double, 6, 6>::Zero();
315 J.block<3, 3>(0, 0) = n_q_e.toRotationMatrix();
316 J.block<3, 3>(3, 3) = n_q_e.toRotationMatrix();
317
319 J * e_covarianceMatrix * J.transpose(), Keys::PosVel<Keys::MotionModelKey>);
320 }
321
325 template<typename Derived>
326 void setPosVelCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
327 {
328 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 6, "This function needs a 6x6 matrix as input");
329 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 6, "This function needs a 6x6 matrix as input");
330
332 n_covarianceMatrix, Keys::PosVel<Keys::MotionModelKey>);
333
334 Eigen::Quaterniond e_q_n = e_Quat_n();
335 Eigen::Matrix<double, 6, 6> J = Eigen::Matrix<double, 6, 6>::Zero();
336 J.block<3, 3>(0, 0) = e_q_n.toRotationMatrix();
337 J.block<3, 3>(3, 3) = e_q_n.toRotationMatrix();
338
340 J * n_covarianceMatrix * J.transpose(), Keys::PosVel<Keys::MotionModelKey>);
341 }
342
343 /* -------------------------------------------------------------------------------------------------------- */
344 /* Member variables */
345 /* -------------------------------------------------------------------------------------------------------- */
346
347 private:
349 Eigen::Vector3d _e_velocity{ std::nan(""), std::nan(""), std::nan("") };
351 Eigen::Vector3d _n_velocity{ std::nan(""), std::nan(""), std::nan("") };
352};
353
354} // 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
@ VelZ
Velocity ECEF_Z [m/s].
Definition MotionModel.hpp:46
@ VelY
Velocity ECEF_Y [m/s].
Definition MotionModel.hpp:45
@ VelX
Velocity ECEF_X [m/s].
Definition MotionModel.hpp:44
constexpr std::array< StateKeyType, 6 > PosVel
Vector with all position and velocity keys.
Definition MotionModel.hpp:66
constexpr std::array< StateKeyType, 3 > Vel
All velocity keys.
Definition MotionModel.hpp:59
Position Storage Class.
Position and Velocity Storage Class.
Definition PosVel.hpp:23
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition PosVel.hpp:73
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition PosVel.hpp:38
const Eigen::Vector3d & n_velocity() const
Returns the velocity in [m/s], in navigation coordinates.
Definition PosVel.hpp:211
bool setValueAt(size_t idx, double value) override
Set the value at the index.
Definition PosVel.hpp:150
std::string getType() const override
Returns the type of the data class.
Definition PosVel.hpp:34
std::optional< Eigen::Vector3d > e_velocityStdev() const
Returns the standard deviation of the velocity in [m/s], in earth coordinates.
Definition PosVel.hpp:214
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition PosVel.hpp:46
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition PosVel.hpp:76
static std::string type()
Returns the type of the data class.
Definition PosVel.hpp:27
void setPosVel_e(const Eigen::MatrixBase< DerivedP > &e_position, const Eigen::MatrixBase< DerivedV > &e_velocity)
Set the position and velocity.
Definition PosVel.hpp:259
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition PosVel.hpp:79
void setPosVelCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition PosVel.hpp:305
Eigen::Vector3d _e_velocity
Velocity in earth coordinates [m/s].
Definition PosVel.hpp:349
Eigen::Vector3d _n_velocity
Velocity in navigation coordinates [m/s].
Definition PosVel.hpp:351
const Eigen::Vector3d & e_velocity() const
Returns the velocity in [m/s], in earth coordinates.
Definition PosVel.hpp:208
std::optional< Eigen::Vector3d > n_velocityStdev() const
Returns the standard deviation of the velocity in [m/s], in navigation coordinates.
Definition PosVel.hpp:224
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition PosVel.hpp:84
void setPosVelAndCov_n(const Eigen::MatrixBase< DerivedP > &lla_position, const Eigen::MatrixBase< DerivedV > &n_velocity, const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the position, velocity and the covariance matrix.
Definition PosVel.hpp:293
void setVelocity_n(const Eigen::MatrixBase< Derived > &n_velocity)
Set the Velocity in the NED frame.
Definition PosVel.hpp:249
void setPosVel_n(const Eigen::MatrixBase< DerivedP > &lla_position, const Eigen::MatrixBase< DerivedV > &n_velocity)
Set the position and velocity.
Definition PosVel.hpp:269
void setVelocity_e(const Eigen::MatrixBase< Derived > &e_velocity)
Set the Velocity in the earth frame.
Definition PosVel.hpp:240
void setPosVelAndCov_e(const Eigen::MatrixBase< DerivedP > &e_position, const Eigen::MatrixBase< DerivedV > &e_velocity, const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the position, velocity and the covariance matrix.
Definition PosVel.hpp:280
void setPosVelCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in NED coordinates.
Definition PosVel.hpp:326
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
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
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition Pos.hpp:47
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
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 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
void setPosition_lla(const Eigen::MatrixBase< Derived > &lla_position)
Set the Position lla object.
Definition Pos.hpp:293
KeyedMatrixX< double, RowKeyType, ColKeyType > KeyedMatrixXd
Dynamic size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2313