0.2.0
Loading...
Searching...
No Matches
Mechanization.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 <Eigen/Core>
19#include <Eigen/Dense>
20
27#include "util/Logger.hpp"
28
29#include <cmath>
30
31namespace NAV
32{
50template<typename DerivedA, typename DerivedB>
51Eigen::Vector4<typename DerivedA::Scalar> calcTimeDerivativeFor_e_Quat_b(const Eigen::MatrixBase<DerivedA>& b_omega_eb,
52 const Eigen::MatrixBase<DerivedB>& e_Quat_b_coeffs)
53{
54 // Angular rates in matrix form (Titterton (2005), eq. (11.35))
55 Eigen::Matrix4<typename DerivedA::Scalar> A;
56
57 // clang-format off
58 A << 0.0 , -b_omega_eb(0), -b_omega_eb(1), -b_omega_eb(2),
59 b_omega_eb(0), 0.0 , b_omega_eb(2), -b_omega_eb(1),
60 b_omega_eb(1), -b_omega_eb(2), 0.0 , b_omega_eb(0),
61 b_omega_eb(2), b_omega_eb(1), -b_omega_eb(0), 0.0 ;
62 // clang-format on
63
64 // Propagation of an attitude Quaternion with time (Titterton, ch. 11.2.5, eq. 11.33-11.35, p. 319)
65 return 0.5 * A * e_Quat_b_coeffs; // (w, x, y, z)
66}
67
85template<typename DerivedA, typename DerivedB, typename DerivedC, typename DerivedD>
86Eigen::Vector3<typename DerivedA::Scalar> e_calcTimeDerivativeForVelocity(const Eigen::MatrixBase<DerivedA>& e_measuredForce,
87 const Eigen::MatrixBase<DerivedB>& e_coriolisAcceleration,
88 const Eigen::MatrixBase<DerivedC>& e_gravitation,
89 const Eigen::MatrixBase<DerivedD>& e_centrifugalAcceleration)
90{
91 return e_measuredForce
92 - e_coriolisAcceleration
93 + e_gravitation
94 - e_centrifugalAcceleration;
95}
96
107template<typename Derived>
108Eigen::Vector3<typename Derived::Scalar> e_calcTimeDerivativeForPosition(const Eigen::MatrixBase<Derived>& e_velocity)
109{
110 return e_velocity;
111}
112
118template<typename Scalar, typename = std::enable_if_t<std::is_floating_point_v<Scalar>>>
119Eigen::Vector<Scalar, 10> e_calcPosVelAttDerivative(const Eigen::Vector<Scalar, 10>& y, const Eigen::Vector<Scalar, 6>& z, const PosVelAttDerivativeConstants<Scalar>& c, Scalar /* t */ = 0.0)
120{
121 // 0 1 2 3 4 5 6 7 8 9
122 // ∂/∂t [w, x, y, z, v_x, v_y, v_z, x, y, z]^T
123 Eigen::Vector<Scalar, 10> y_dot = Eigen::Vector<Scalar, 10>::Zero();
124
125 Eigen::Vector3<Scalar> lla_position = trafo::ecef2lla_WGS84(y.template segment<3>(7));
126
127 Eigen::Quaternion<Scalar> e_Quat_b{ y(0), y(1), y(2), y(3) };
128 e_Quat_b.normalize();
129 Eigen::Quaternion<Scalar> n_Quat_e = trafo::n_Quat_e(lla_position(0), lla_position(1));
130
131 Eigen::Quaternion<Scalar> b_Quat_e = e_Quat_b.conjugate();
132 Eigen::Quaternion<Scalar> e_Quat_n = n_Quat_e.conjugate();
133
134 LOG_DATA("e_velocity = {} [m/s]", y.template segment<3>(4).transpose());
135 LOG_DATA("e_position = {} [m]", y.template segment<3>(7).transpose());
136
137 // ω_eb_b = ω_ib_b - C_be * ω_ie_e
138 Eigen::Vector3<Scalar> b_omega_eb = z.template segment<3>(3)
139 - b_Quat_e * (c.angularRateEarthRotationCompensationEnabled ? InsConst<>::e_omega_ie : Eigen::Vector3<Scalar>::Zero());
140 LOG_DATA("b_omega_eb = {} [rad/s]", b_omega_eb.transpose());
141
142 // Coriolis acceleration in [m/s^2] (acceleration due to motion in rotating reference frame)
143 Eigen::Vector3<Scalar> e_coriolisAcceleration = c.coriolisAccelerationCompensationEnabled
144 ? e_calcCoriolisAcceleration(InsConst<>::e_omega_ie, y.template segment<3>(4))
145 : Eigen::Vector3<Scalar>::Zero();
146 LOG_DATA("e_coriolisAcceleration = {} [m/s^2]", e_coriolisAcceleration.transpose());
147 // Centrifugal acceleration in [m/s^2] (acceleration that makes a body follow a curved path)
148 Eigen::Vector3<Scalar> e_centrifugalAcceleration = c.centrifgalAccelerationCompensationEnabled
149 ? e_calcCentrifugalAcceleration(y.template segment<3>(7), InsConst<>::e_omega_ie)
150 : Eigen::Vector3<Scalar>::Zero();
151 LOG_DATA("e_centrifugalAcceleration = {} [m/s^2]", e_centrifugalAcceleration.transpose());
152
153 Eigen::Vector3<Scalar> e_gravitation = e_Quat_n * n_calcGravitation(lla_position, c.gravitationModel);
154 LOG_DATA("e_gravitation = {} [m/s^2] ({})", e_gravitation.transpose(), to_string(c.gravitationModel));
155
156 y_dot.template segment<4>(0) = calcTimeDerivativeFor_e_Quat_b(b_omega_eb, // ω_eb_b Body rate with respect to the ECEF frame, expressed in the body frame
157 y.template segment<4>(0)); // e_Quat_b_coeffs Coefficients of the quaternion e_Quat_b in order w, x, y, z (q = w + ix + jy + kz)
158
159 y_dot.template segment<3>(4) = e_calcTimeDerivativeForVelocity(e_Quat_b * z.template segment<3>(0), // f_n Specific force vector as measured by a triad of accelerometers and resolved into ECEF frame coordinates
160 e_coriolisAcceleration, // Coriolis acceleration in ECEF coordinates in [m/s^2]
161 e_gravitation, // Local gravitation vector (caused by effects of mass attraction) in ECEF frame coordinates [m/s^2]
162 e_centrifugalAcceleration); // Centrifugal acceleration in ECEF coordinates in [m/s^2]
163
164 y_dot.template segment<3>(7) = e_calcTimeDerivativeForPosition(y.template segment<3>(4)); // Velocity with respect to the Earth in ECEF frame coordinates [m/s]
165
166 LOG_DATA("e_Quat_b_dot = {} ", y_dot.template segment<4>(0).transpose());
167 LOG_DATA("e_velocity_dot = {} [m/s^2]", y_dot.template segment<3>(4).transpose());
168 LOG_DATA("e_position_dot = {} [m/s]", y_dot.template segment<3>(7).transpose());
169
170 return y_dot;
171}
172
173} // namespace NAV
Holds all Constants.
Transformation collection.
Eigen::Vector4< typename DerivedA::Scalar > calcTimeDerivativeFor_e_Quat_b(const Eigen::MatrixBase< DerivedA > &b_omega_eb, const Eigen::MatrixBase< DerivedB > &e_Quat_b_coeffs)
Calculates the time derivative of the quaternion e_Quat_b.
Definition Mechanization.hpp:51
Eigen::Vector< Scalar, 10 > e_calcPosVelAttDerivative(const Eigen::Vector< Scalar, 10 > &y, const Eigen::Vector< Scalar, 6 > &z, const PosVelAttDerivativeConstants< Scalar > &c, Scalar=0.0)
Calculates the derivative of the quaternion, velocity and position in ECEF coordinates.
Definition Mechanization.hpp:119
Eigen::Vector3< typename DerivedA::Scalar > e_calcTimeDerivativeForVelocity(const Eigen::MatrixBase< DerivedA > &e_measuredForce, const Eigen::MatrixBase< DerivedB > &e_coriolisAcceleration, const Eigen::MatrixBase< DerivedC > &e_gravitation, const Eigen::MatrixBase< DerivedD > &e_centrifugalAcceleration)
Calculates the time derivative of the velocity in ECEF frame coordinates.
Definition Mechanization.hpp:86
Eigen::Vector3< typename Derived::Scalar > e_calcTimeDerivativeForPosition(const Eigen::MatrixBase< Derived > &e_velocity)
Calculates the time derivative of the ECEF position.
Definition Mechanization.hpp:108
Functions concerning the ellipsoid model.
Different Gravity Models.
Eigen::Vector3< typename Derived::Scalar > n_calcGravitation(const Eigen::MatrixBase< Derived > &lla_position, GravitationModel gravitationModel=GravitationModel::EGM96)
Calculates the gravitation (acceleration due to mass attraction of the Earth)
Definition Gravity.hpp:193
Inertial Navigation Helper Functions.
Eigen::Vector3< typename DerivedA::Scalar > e_calcCoriolisAcceleration(const Eigen::MatrixBase< DerivedA > &e_omega_ie, const Eigen::MatrixBase< DerivedB > &e_velocity)
Calculates the coriolis acceleration in [m/s^2] (acceleration due to motion in rotating reference fra...
Definition Functions.hpp:107
Eigen::Vector3< typename DerivedA::Scalar > e_calcCentrifugalAcceleration(const Eigen::MatrixBase< DerivedA > &e_position, const Eigen::MatrixBase< DerivedB > &e_omega_ie=InsConst< typename DerivedB::Scalar >::e_omega_ie)
Calculates the centrifugal acceleration in [m/s^2] (acceleration that makes a body follow a curved pa...
Definition Functions.hpp:72
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Simple Math functions.
Inertial Navigation Mechanization Functions.
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
Constants.
Definition Constants.hpp:26
Values needed to calculate the PosVelAttDerivative for the local-navigation frame.
Definition Mechanization.hpp:27
bool centrifgalAccelerationCompensationEnabled
Apply the centrifugal acceleration compensation to the measured accelerations.
Definition Mechanization.hpp:30
bool angularRateEarthRotationCompensationEnabled
Apply the Earth rotation rate compensation to the measured angular rates.
Definition Mechanization.hpp:31
GravitationModel gravitationModel
Gravity Model to use.
Definition Mechanization.hpp:28
bool coriolisAccelerationCompensationEnabled
Apply the Coriolis acceleration compensation to the measured accelerations.
Definition Mechanization.hpp:29