0.3.0
Loading...
Searching...
No Matches
PosVelAtt.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
18#include "Navigation/Transformations/Units.hpp"
20
21namespace NAV
22{
24class PosVelAtt : public PosVel
25{
26 public:
29 [[nodiscard]] static std::string type()
30 {
31 return "PosVelAtt";
32 }
33
36 [[nodiscard]] std::string getType() const override { return type(); }
37
40 [[nodiscard]] static std::vector<std::string> parentTypes()
41 {
42 auto parent = PosVel::parentTypes();
43 parent.push_back(PosVel::type());
44 return parent;
45 }
46
48 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors()
49 {
51 desc.reserve(GetStaticDescriptorCount());
52 desc.emplace_back("Roll [deg]");
53 desc.emplace_back("Pitch [deg]");
54 desc.emplace_back("Yaw [deg]");
55 desc.emplace_back("Roll StdDev [deg]");
56 desc.emplace_back("Pitch StdDev [deg]");
57 desc.emplace_back("Yaw StdDev [deg]");
58 desc.emplace_back("n_Quat_b x");
59 desc.emplace_back("n_Quat_b y");
60 desc.emplace_back("n_Quat_b z");
61 desc.emplace_back("n_Quat_b w");
62 desc.emplace_back("n_Quat_b x StdDev");
63 desc.emplace_back("n_Quat_b y StdDev");
64 desc.emplace_back("n_Quat_b z StdDev");
65 desc.emplace_back("n_Quat_b w StdDev");
66 return desc;
67 }
68
70 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return PosVel::GetStaticDescriptorCount() + 14; }
71
73 [[nodiscard]] std::vector<std::string> staticDataDescriptors() const override { return GetStaticDataDescriptors(); }
74
76 [[nodiscard]] size_t staticDescriptorCount() const override { return GetStaticDescriptorCount(); }
77
81 [[nodiscard]] std::optional<double> getValueAt(size_t idx) const override
82 {
84 if (idx < PosVel::GetStaticDescriptorCount()) { return PosVel::getValueAt(idx); }
85 switch (idx)
86 {
87 case PosVel::GetStaticDescriptorCount() + 0: // Roll [deg]
88 if (_n_Quat_b.norm() != 0) { return rad2deg(rollPitchYaw().x()); }
89 break;
90 case PosVel::GetStaticDescriptorCount() + 1: // Pitch [deg]
91 if (_n_Quat_b.norm() != 0) { return rad2deg(rollPitchYaw().y()); }
92 break;
93 case PosVel::GetStaticDescriptorCount() + 2: // Yaw [deg]
94 if (_n_Quat_b.norm() != 0) { return rad2deg(rollPitchYaw().z()); }
95 break;
96 case PosVel::GetStaticDescriptorCount() + 3: // Roll StdDev [deg]
98 {
100 return rad2deg(std::sqrt(covRPY(0, 0)));
101 }
102 break;
103 case PosVel::GetStaticDescriptorCount() + 4: // Pitch StdDev [deg]
105 {
107 return rad2deg(std::sqrt(covRPY(1, 1)));
108 }
109 break;
110 case PosVel::GetStaticDescriptorCount() + 5: // Yaw StdDev [deg]
112 {
114 return rad2deg(std::sqrt(covRPY(2, 2)));
115 }
116 break;
117 case PosVel::GetStaticDescriptorCount() + 6: // n_Quat_b x
118 if (_n_Quat_b.norm() != 0) { return _n_Quat_b.x(); }
119 break;
120 case PosVel::GetStaticDescriptorCount() + 7: // n_Quat_b y
121 if (_n_Quat_b.norm() != 0) { return _n_Quat_b.y(); }
122 break;
123 case PosVel::GetStaticDescriptorCount() + 8: // n_Quat_b z
124 if (_n_Quat_b.norm() != 0) { return _n_Quat_b.z(); }
125 break;
126 case PosVel::GetStaticDescriptorCount() + 9: // n_Quat_b w
127 if (_n_Quat_b.norm() != 0) { return _n_Quat_b.w(); }
128 break;
129 case PosVel::GetStaticDescriptorCount() + 10: // n_Quat_b x StdDev
131 break;
132 case PosVel::GetStaticDescriptorCount() + 11: // n_Quat_b y StdDev
134 break;
135 case PosVel::GetStaticDescriptorCount() + 12: // n_Quat_b z StdDev
137 break;
138 case PosVel::GetStaticDescriptorCount() + 13: // n_Quat_b w StdDev
140 break;
141 default:
142 return std::nullopt;
143 }
144 return std::nullopt;
145 }
146
151 [[nodiscard]] bool setValueAt(size_t idx, double value) override
152 {
154 if (idx < PosVel::GetStaticDescriptorCount()) { return PosVel::setValueAt(idx, value); }
155 // switch (idx)
156 // {
157 // case PosVel::GetStaticDescriptorCount() + 0: // Roll [deg]
158 // case PosVel::GetStaticDescriptorCount() + 1: // Pitch [deg]
159 // case PosVel::GetStaticDescriptorCount() + 2: // Yaw [deg]
160 // case PosVel::GetStaticDescriptorCount() + 3: // Quaternion::w
161 // case PosVel::GetStaticDescriptorCount() + 4: // Quaternion::x
162 // case PosVel::GetStaticDescriptorCount() + 5: // Quaternion::y
163 // case PosVel::GetStaticDescriptorCount() + 6: // Quaternion::z
164 // default:
165 // }
166
167 return false;
168 }
169
170 /* -------------------------------------------------------------------------------------------------------- */
171 /* Rotation Quaternions */
172 /* -------------------------------------------------------------------------------------------------------- */
173
176 [[nodiscard]] const Eigen::Quaterniond& n_Quat_b() const
177 {
178 return _n_Quat_b;
179 }
180
183 [[nodiscard]] Eigen::Quaterniond b_Quat_n() const
184 {
185 return n_Quat_b().conjugate();
186 }
187
190 [[nodiscard]] const Eigen::Quaterniond& e_Quat_b() const
191 {
192 return _e_Quat_b;
193 }
194
197 [[nodiscard]] Eigen::Quaterniond b_Quat_e() const
198 {
199 return e_Quat_b().conjugate();
200 }
201
204 [[nodiscard]] Eigen::Vector3d rollPitchYaw() const
205 {
207 }
208
210 [[nodiscard]] std::optional<Eigen::Vector4d> e_QuatStdev() const
211 {
213 {
215 }
216 return std::nullopt;
217 }
218
220 [[nodiscard]] std::optional<Eigen::Vector4d> n_QuatStdev() const
221 {
223 {
225 }
226 return std::nullopt;
227 }
228
229 // ###########################################################################################################
230 // Setter
231 // ###########################################################################################################
232
235 template<typename Derived>
236 void setAttitude_e_Quat_b(const Eigen::QuaternionBase<Derived>& e_Quat_b)
237 {
240 }
241
244 template<typename Derived>
245 void setAttitude_n_Quat_b(const Eigen::QuaternionBase<Derived>& n_Quat_b)
246 {
249 }
250
255 template<typename DerivedP, typename DerivedV, typename DerivedA>
256 void setPosVelAtt_e(const Eigen::MatrixBase<DerivedP>& e_position, const Eigen::MatrixBase<DerivedV>& e_velocity, const Eigen::QuaternionBase<DerivedA>& e_Quat_b)
257 {
261 }
262
267 template<typename DerivedP, typename DerivedV, typename DerivedA>
268 void setPosVelAtt_n(const Eigen::MatrixBase<DerivedP>& lla_position, const Eigen::MatrixBase<DerivedV>& n_velocity, const Eigen::QuaternionBase<DerivedA>& n_Quat_b)
269 {
273 }
274
280 template<typename DerivedP, typename DerivedV, typename DerivedA, typename Derived>
281 void setPosVelAttAndCov_e(const Eigen::MatrixBase<DerivedP>& e_position, const Eigen::MatrixBase<DerivedV>& e_velocity,
282 const Eigen::QuaternionBase<DerivedA>& e_Quat_b, const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
283 {
287 setPosVelAttCovarianceMatrix_e(e_covarianceMatrix);
288 }
289
295 template<typename DerivedP, typename DerivedV, typename DerivedA, typename Derived>
296 void setPosVelAttAndCov_n(const Eigen::MatrixBase<DerivedP>& lla_position, const Eigen::MatrixBase<DerivedV>& n_velocity,
297 const Eigen::QuaternionBase<DerivedA>& n_Quat_b, const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
298 {
302 setPosVelAttCovarianceMatrix_n(n_covarianceMatrix);
303 }
304
308 template<typename Derived>
309 void setPosVelAttCovarianceMatrix_e(const Eigen::MatrixBase<Derived>& e_covarianceMatrix)
310 {
311 INS_ASSERT_USER_ERROR(e_covarianceMatrix.rows() == 10, "This function needs a 10x10 matrix as input");
312 INS_ASSERT_USER_ERROR(e_covarianceMatrix.cols() == 10, "This function needs a 10x10 matrix as input");
313
315 e_covarianceMatrix, Keys::PosVelAtt<Keys::MotionModelKey>);
316
317 Eigen::Quaterniond n_q_e = n_Quat_e();
318 Eigen::Matrix<double, 10, 10> J = Eigen::Matrix<double, 10, 10>::Zero();
319 J.block<3, 3>(0, 0) = n_q_e.toRotationMatrix();
320 J.block<3, 3>(3, 3) = n_q_e.toRotationMatrix();
321 J.block<4, 4>(6, 6) = trafo::covQuat2QuatJacobian(n_q_e);
322
324 J * e_covarianceMatrix * J.transpose(), Keys::PosVelAtt<Keys::MotionModelKey>);
325 }
326
330 template<typename Derived>
331 void setPosVelAttCovarianceMatrix_n(const Eigen::MatrixBase<Derived>& n_covarianceMatrix)
332 {
333 INS_ASSERT_USER_ERROR(n_covarianceMatrix.rows() == 10, "This function needs a 10x10 matrix as input");
334 INS_ASSERT_USER_ERROR(n_covarianceMatrix.cols() == 10, "This function needs a 10x10 matrix as input");
335
337 n_covarianceMatrix, Keys::PosVelAtt<Keys::MotionModelKey>);
338
339 Eigen::Quaterniond e_q_n = e_Quat_n();
340 Eigen::Matrix<double, 10, 10> J = Eigen::Matrix<double, 10, 10>::Zero();
341 J.block<3, 3>(0, 0) = e_q_n.toRotationMatrix();
342 J.block<3, 3>(3, 3) = e_q_n.toRotationMatrix();
343 J.block<4, 4>(6, 6) = trafo::covQuat2QuatJacobian(e_q_n);
344
346 J * n_covarianceMatrix * J.transpose(), Keys::PosVelAtt<Keys::MotionModelKey>);
347 }
348
349 /* -------------------------------------------------------------------------------------------------------- */
350 /* Member variables */
351 /* -------------------------------------------------------------------------------------------------------- */
352
353 private:
355 Eigen::Quaterniond _e_Quat_b{ 0, 0, 0, 0 };
357 Eigen::Quaterniond _n_Quat_b{ 0, 0, 0, 0 };
358};
359
360} // 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
Transformation collection.
Eigen::Matrix3< typename Derived::Scalar > covQuat2RPY(const Eigen::MatrixBase< Derived > &covQuat, const Eigen::QuaternionBase< DerivedQ > &n_quat_b)
Converts a covariance for an attitude represented in quaternion form into a covariance for Euler ange...
Definition CoordinateFrames.hpp:241
Eigen::Matrix< typename Derived::Scalar, 4, 4 > covQuat2QuatJacobian(const Eigen::QuaternionBase< Derived > &beta_quat_alpha)
Calculates the Jacobian to convert an attitude represented in quaternions from one frame into another...
Definition CoordinateFrames.hpp:250
Eigen::Vector3< typename Derived::Scalar > quat2eulerZYX(const Eigen::QuaternionBase< Derived > &q)
Converts the quaternion to Euler rotation angles with rotation sequence ZYX.
Definition CoordinateFrames.hpp:141
constexpr std::array< StateKeyType, 4 > Att
All attitude keys.
Definition MotionModel.hpp:62
@ AttQ0
w: Real (scalar) part of the Quaternion
Definition MotionModel.hpp:50
@ AttQ3
z: Coefficient of k
Definition MotionModel.hpp:49
@ AttQ1
x: Coefficient of i
Definition MotionModel.hpp:47
@ AttQ2
y: Coefficient of j
Definition MotionModel.hpp:48
constexpr std::array< StateKeyType, 10 > PosVelAtt
Vector with all position velocity and attitude keys.
Definition MotionModel.hpp:70
Position and Velocity Storage Class.
Position, Velocity and Attitude Storage Class.
Definition PosVelAtt.hpp:25
Eigen::Quaterniond b_Quat_n() const
Returns the Quaternion from navigation to body frame (NED)
Definition PosVelAtt.hpp:183
size_t staticDescriptorCount() const override
Get the amount of descriptors.
Definition PosVelAtt.hpp:76
std::vector< std::string > staticDataDescriptors() const override
Returns a vector of data descriptors.
Definition PosVelAtt.hpp:73
void setAttitude_e_Quat_b(const Eigen::QuaternionBase< Derived > &e_Quat_b)
Set the Quaternion from body to earth frame.
Definition PosVelAtt.hpp:236
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition PosVelAtt.hpp:48
void setPosVelAttCovarianceMatrix_e(const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the Covariance matrix in ECEF coordinates.
Definition PosVelAtt.hpp:309
std::optional< Eigen::Vector4d > e_QuatStdev() const
Returns the standard deviation of the Quaternion body to earth frame (x, y, z, w)
Definition PosVelAtt.hpp:210
static constexpr size_t GetStaticDescriptorCount()
Get the amount of descriptors.
Definition PosVelAtt.hpp:70
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition PosVelAtt.hpp:81
void setPosVelAttAndCov_e(const Eigen::MatrixBase< DerivedP > &e_position, const Eigen::MatrixBase< DerivedV > &e_velocity, const Eigen::QuaternionBase< DerivedA > &e_Quat_b, const Eigen::MatrixBase< Derived > &e_covarianceMatrix)
Set the position, velocity, attitude and the covariance matrix.
Definition PosVelAtt.hpp:281
Eigen::Quaterniond _n_Quat_b
Quaternion body to navigation frame (roll, pitch, yaw)
Definition PosVelAtt.hpp:357
void setAttitude_n_Quat_b(const Eigen::QuaternionBase< Derived > &n_Quat_b)
Set the Quaternion from body to navigation frame.
Definition PosVelAtt.hpp:245
void setPosVelAtt_n(const Eigen::MatrixBase< DerivedP > &lla_position, const Eigen::MatrixBase< DerivedV > &n_velocity, const Eigen::QuaternionBase< DerivedA > &n_Quat_b)
Set the position, velocity and attitude.
Definition PosVelAtt.hpp:268
void setPosVelAttAndCov_n(const Eigen::MatrixBase< DerivedP > &lla_position, const Eigen::MatrixBase< DerivedV > &n_velocity, const Eigen::QuaternionBase< DerivedA > &n_Quat_b, const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the position, velocity, attitude and the covariance matrix.
Definition PosVelAtt.hpp:296
const Eigen::Quaterniond & n_Quat_b() const
Returns the Quaternion from body to navigation frame (NED)
Definition PosVelAtt.hpp:176
bool setValueAt(size_t idx, double value) override
Set the value at the index.
Definition PosVelAtt.hpp:151
static std::string type()
Returns the type of the data class.
Definition PosVelAtt.hpp:29
void setPosVelAttCovarianceMatrix_n(const Eigen::MatrixBase< Derived > &n_covarianceMatrix)
Set the Covariance matrix in NED coordinates.
Definition PosVelAtt.hpp:331
Eigen::Quaterniond b_Quat_e() const
Returns the Quaternion from Earth-fixed to body frame.
Definition PosVelAtt.hpp:197
void setPosVelAtt_e(const Eigen::MatrixBase< DerivedP > &e_position, const Eigen::MatrixBase< DerivedV > &e_velocity, const Eigen::QuaternionBase< DerivedA > &e_Quat_b)
Set the position, velocity and attitude.
Definition PosVelAtt.hpp:256
Eigen::Quaterniond _e_Quat_b
Quaternion body to earth frame.
Definition PosVelAtt.hpp:355
Eigen::Vector3d rollPitchYaw() const
Returns the Roll, Pitch and Yaw angles in [rad].
Definition PosVelAtt.hpp:204
std::string getType() const override
Returns the type of the data class.
Definition PosVelAtt.hpp:36
const Eigen::Quaterniond & e_Quat_b() const
Returns the Quaternion from body to Earth-fixed frame.
Definition PosVelAtt.hpp:190
static std::vector< std::string > parentTypes()
Returns the parent types of the data class.
Definition PosVelAtt.hpp:40
std::optional< Eigen::Vector4d > n_QuatStdev() const
Returns the standard deviation of the Quaternion body to navigation frame (roll, pitch,...
Definition PosVelAtt.hpp:220
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
static std::vector< std::string > GetStaticDataDescriptors()
Returns a vector of data descriptors.
Definition PosVel.hpp:46
static std::string type()
Returns the type of the data class.
Definition PosVel.hpp:27
const Eigen::Vector3d & e_velocity() const
Returns the velocity in [m/s], in earth coordinates.
Definition PosVel.hpp:208
std::optional< double > getValueAt(size_t idx) const override
Get the value at the index.
Definition PosVel.hpp:84
void setVelocity_n(const Eigen::MatrixBase< Derived > &n_velocity)
Set the Velocity in the NED frame.
Definition PosVel.hpp:249
void setVelocity_e(const Eigen::MatrixBase< Derived > &e_velocity)
Set the Velocity in the earth frame.
Definition PosVel.hpp:240
Eigen::Quaterniond e_Quat_n() const
Returns the Quaternion from navigation to Earth-fixed frame.
Definition Pos.hpp:220
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