0.3.0
Loading...
Searching...
No Matches
AttitudeModel.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 <array>
17#include <cmath>
18#include <cstdint>
19#include <imgui.h>
20#include <Eigen/Core>
21
24#include "Units.hpp"
27#include "MotionModel.hpp"
28
29namespace NAV
30{
31
33template<typename StateKeyType>
35{
36 public:
45
53 template<typename Scalar, int Size, typename Derived>
56 double dt,
57 const double& latitude,
58 const double& longitude,
59 const Eigen::QuaternionBase<Derived>& n_quat_b)
60 {
61 Phi.template block<4>(Att, Att).setIdentity();
62 Q.template block<4>(Att, Att) = calcProcessNoiseMatrix(dt, latitude, longitude, n_quat_b)(all, all);
63 }
64
71 template<typename Derived>
72 [[nodiscard]] std::pair<KeyedMatrix4d<StateKeyType>, KeyedMatrix4d<StateKeyType>>
73 calcPhiAndQ(double dt, const double& latitude, const double& longitude, const Eigen::QuaternionBase<Derived>& n_quat_b)
74 {
75 KeyedMatrix4d<StateKeyType> Phi(Eigen::Matrix4d::Zero(), Att, Att);
76 KeyedMatrix4d<StateKeyType> Q(Eigen::Matrix4d::Zero(), Att, Att);
77 updatePhiAndQ(Phi, Q, dt, latitude, longitude, n_quat_b);
78
79 return { Phi, Q };
80 }
81
87 bool ShowGui(float itemWidth, float unitWidth, const char* id)
88 {
89 bool changed = false;
90
91 if (gui::widgets::InputDouble3LWithUnit(fmt::format("{} of the angular velocity due to user motion (Roll, Pitch, Yaw)##{}",
95 ? "StdDev"
96 : "Variance",
97 id)
98 .c_str(),
99 itemWidth, unitWidth, _gui_covarianceAngularVelocity.data(), 0.0, std::numeric_limits<double>::max(),
101 "%.1e", ImGuiInputTextFlags_CharsScientific))
102 {
103 LOG_DEBUG("{}: _gui_covarianceAngularVelocity changed to {}", id, _gui_covarianceAngularVelocity.transpose());
104 LOG_DEBUG("{}: _gui_covarianceAngularVelocityUnit changed to {}", id, to_string(_gui_covarianceAngularVelocityUnit));
105 changed = true;
106 }
107
108 return changed;
109 }
110
111 private:
113 const std::array<StateKeyType, 4>& Att = Keys::Att<StateKeyType>;
114
120 template<typename Derived>
121 [[nodiscard]] KeyedMatrix4d<StateKeyType>
122 calcProcessNoiseMatrix(double dt, double latitude, double longitude, const Eigen::QuaternionBase<Derived>& n_quat_b) const
123 {
124 // Scaling matrix in n-frame
125 Eigen::Matrix3d S_n = _covarianceAngularVelocity.asDiagonal();
126
127 Eigen::Matrix4d n_covQuat_b = trafo::covRPY2quat(S_n, n_quat_b);
128 Eigen::Matrix4d e_J_n = trafo::covQuat2QuatJacobian(trafo::e_Quat_n(latitude, longitude));
129
130 // Scaling matrix in e-frame
131 Eigen::Matrix4d S_e = e_J_n * n_covQuat_b * e_J_n.transpose();
132
133 return { dt * S_e, Att, Att };
134 }
135
139 Eigen::Vector3d _gui_covarianceAngularVelocity = { 100.0, 100.0, 100.0 } /* [ deg / √(s) ] */;
140
143
147 friend void to_json(json& j, const AttitudeModel& data)
148 {
149 j = {
150 { "covarianceAngularVelocityUnit", data._gui_covarianceAngularVelocityUnit },
151 { "covarianceAngularVelocity", data._gui_covarianceAngularVelocity },
152 };
153 }
154
157 friend void from_json(const json& j, AttitudeModel& data)
158 {
159 if (j.contains("covarianceAngularVelocityUnit")) { j.at("covarianceAngularVelocityUnit").get_to(data._gui_covarianceAngularVelocityUnit); }
160 if (j.contains("covarianceAngularVelocity")) { j.at("covarianceAngularVelocity").get_to(data._gui_covarianceAngularVelocity); }
161 }
162};
163
164} // namespace NAV
Transformation collection.
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::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::Matrix4< typename Derived::Scalar > covRPY2quat(const Eigen::MatrixBase< Derived > &covRPY, const Eigen::QuaternionBase< DerivedQ > &n_quat_b)
Converts a covariance for an attitude represented in Euler angels (roll, pitch, yaw) into a covarianc...
Definition CoordinateFrames.hpp:195
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
double convertUnit(const double &value, Units::PositionUncertaintyUnits unit)
Converts the value depending on the unit provided.
Units used by the system model parameters.
CovarianceAngularVelocityUnits
Possible Units for the Standard deviation of the rotation velocity.
Definition Units.hpp:37
@ deg_sqrts
[ deg / √(s) ]
Definition Units.hpp:41
@ rad_sqrts
[ rad / √(s) ]
Definition Units.hpp:39
@ degsqrts_min
[ deg √(s) / min ]
Definition Units.hpp:43
Defines Widgets which allow the input of values and the selection of the unit.
std::string MakeComboItems()
Units separated by '\0' and terminated by double '\0'.
Definition InputWithUnit.hpp:28
InputWithUnitChange InputDouble3LWithUnit(const char *label, float itemWidth, float unitWidth, double v[3], double v_min, double v_max, U &combo_current_item, const char *combo_items_separated_by_zeros, const char *format="%.6f", ImGuiInputTextFlags flags=0, int combo_popup_max_height_in_items=-1)
Shows an InputText GUI element to modify the provided value and also set its unit.
Definition InputWithUnit.hpp:547
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
Motion System Model.
constexpr std::array< StateKeyType, 4 > Att
All attitude keys.
Definition MotionModel.hpp:62
const char * to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame)
Converts the enum to a string.
Attitude System Model.
Definition AttitudeModel.hpp:35
std::pair< KeyedMatrix4d< StateKeyType >, KeyedMatrix4d< StateKeyType > > calcPhiAndQ(double dt, const double &latitude, const double &longitude, const Eigen::QuaternionBase< Derived > &n_quat_b)
Calculates the state transition matrix (𝚽) and the process noise covariance matrix (𝐐)
Definition AttitudeModel.hpp:73
void initialize()
Initializes the attitude model.
Definition AttitudeModel.hpp:38
friend void from_json(const json &j, AttitudeModel &data)
Converts the provided json object into the data object.
Definition AttitudeModel.hpp:157
Eigen::Vector3d _gui_covarianceAngularVelocity
GUI selection for the Standard deviation of the angular velocity due to user motion (Roll,...
Definition AttitudeModel.hpp:139
void updatePhiAndQ(KeyedMatrix< Scalar, StateKeyType, StateKeyType, Size, Size > &Phi, KeyedMatrix< Scalar, StateKeyType, StateKeyType, Size, Size > &Q, double dt, const double &latitude, const double &longitude, const Eigen::QuaternionBase< Derived > &n_quat_b)
Updates the provided Phi, Q and G matrix.
Definition AttitudeModel.hpp:54
friend void to_json(json &j, const AttitudeModel &data)
Converts the provided data into a json object.
Definition AttitudeModel.hpp:147
Eigen::Vector3d _covarianceAngularVelocity
Covariance of the angular velocity due to user motion (Roll, Pitch, Yaw) [radΒ²/s].
Definition AttitudeModel.hpp:142
bool ShowGui(float itemWidth, float unitWidth, const char *id)
Shows a GUI.
Definition AttitudeModel.hpp:87
Units::CovarianceAngularVelocityUnits _gui_covarianceAngularVelocityUnit
Gui selection for the Unit of the input covarianceAngularVelocity.
Definition AttitudeModel.hpp:137
const std::array< StateKeyType, 4 > & Att
All attitude keys.
Definition AttitudeModel.hpp:113
KeyedMatrix4d< StateKeyType > calcProcessNoiseMatrix(double dt, double latitude, double longitude, const Eigen::QuaternionBase< Derived > &n_quat_b) const
Calculates the process noise matrix Q.
Definition AttitudeModel.hpp:122
Static sized KeyedMatrix.
Definition KeyedMatrix.hpp:1921
Matrix which can be accessed by keys.
KeyedMatrix< double, RowKeyType, ColKeyType, 4, 4 > KeyedMatrix4d
Static 4x4 squared size KeyedMatrix with double types.
Definition KeyedMatrix.hpp:2328
static const internal::all_t all
Used to request all rows or columns in KeyedMatrices.
Definition KeyedMatrix.hpp:1457