0.4.1
Loading...
Searching...
No Matches
Imu.cpp
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
9#include "Imu.hpp"
10#include <imgui.h>
11
15
18
19namespace
20{
21
22void TrafoHelperMarker(const Eigen::Quaterniond& q)
23{
25 {
26 Eigen::Matrix3d dcm = q.toRotationMatrix();
27
28 ImGui::BeginHorizontal("Tooltip Horizontal");
29
30 ImGui::BeginVertical("Tooltip Vertical 1");
31 ImGui::Spring();
32 ImGui::TextUnformatted("(X Y Z)_b = ");
33 ImGui::Spring();
34 ImGui::EndVertical();
35
36 NAV::gui::widgets::MatrixView("quaternionAccel_bp", &dcm, GuiMatrixViewFlags_None, ImGuiTableFlags_Borders | ImGuiTableFlags_NoHostExtendX, "% -.1f");
37
38 ImGui::BeginVertical("Tooltip Vertical 2");
39 ImGui::Spring();
40 ImGui::TextUnformatted(" * (X Y Z)_p");
41 ImGui::Spring();
42 ImGui::EndVertical();
43
44 ImGui::EndHorizontal();
45
47 }
48}
49
50} // namespace
51
52NAV::Imu::Imu(std::string name)
53 : Node(std::move(name)) {}
54
56{
57 ImGui::SetNextItemOpen(false, ImGuiCond_Appearing);
58 if (ImGui::TreeNode(fmt::format("Imu Position & Rotation##{}", size_t(id)).c_str()))
59 {
60 ImGui::BeginDisabled(); // FIXME Not properly simulated and accounted for in the algorithms
61 std::array<float, 3> imuPos = { static_cast<float>(_imuPos.b_positionIMU_p().x()), static_cast<float>(_imuPos.b_positionIMU_p().y()), static_cast<float>(_imuPos.b_positionIMU_p().z()) };
62 if (ImGui::InputFloat3(fmt::format("Position [m]##{}", size_t(id)).c_str(), imuPos.data()))
63 {
65 _imuPos._b_positionIMU_p = Eigen::Vector3d(imuPos.at(0), imuPos.at(1), imuPos.at(2));
66 }
67 ImGui::EndDisabled();
68 ImGui::SameLine();
69 gui::widgets::HelpMarker("Position of the IMU sensor relative to the vehicle center of mass in the body coordinate frame.");
70
71 Eigen::Vector3d eulerAngelsIMU = rad2deg(trafo::quat2eulerZYX(_imuPos.p_quat_b()));
72 std::array<float, 3> imuRot = { static_cast<float>(eulerAngelsIMU.x()), static_cast<float>(eulerAngelsIMU.y()), static_cast<float>(eulerAngelsIMU.z()) };
73 if (ImGui::InputFloat3(fmt::format("Rotation [deg]##{}", size_t(id)).c_str(), imuRot.data()))
74 {
75 // (-180:180] x (-90:90] x (-180:180]
76 imuRot.at(0) = std::max(imuRot.at(0), -179.9999F);
77 imuRot.at(0) = std::min(imuRot.at(0), 180.0F);
78 imuRot.at(1) = std::max(imuRot.at(1), -89.9999F);
79 imuRot.at(1) = std::min(imuRot.at(1), 90.0F);
80 imuRot.at(2) = std::max(imuRot.at(2), -179.9999F);
81 imuRot.at(2) = std::min(imuRot.at(2), 180.0F);
82
84 _imuPos._b_quat_p = trafo::b_Quat_p(deg2rad(imuRot.at(0)), deg2rad(imuRot.at(1)), deg2rad(imuRot.at(2)));
85 }
86 ImGui::SameLine();
87 TrafoHelperMarker(_imuPos.b_quat_p());
88
89 ImGui::TreePop();
90 }
91}
92
93[[nodiscard]] json NAV::Imu::save() const
94{
95 LOG_TRACE("{}: called", nameId());
96
97 json j;
98
99 j["imuPos"] = _imuPos;
100
101 return j;
102}
103
105{
106 LOG_TRACE("{}: called", nameId());
107
108 if (j.contains("imuPos"))
109 {
110 j.at("imuPos").get_to(_imuPos);
111 }
112}
Transformation collection.
Save/Load the Nodes.
nlohmann::json json
json namespace
Text Help Marker (?) with Tooltip.
Abstract IMU Class.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Widgets related to Matrices.
@ GuiMatrixViewFlags_None
None.
Definition Matrix.hpp:26
json save() const override
Saves the node into a json object.
Definition Imu.cpp:93
void restore(const json &j) override
Restores the node from a json object.
Definition Imu.cpp:104
void guiConfig() override
ImGui config window which is shown on double click.
Definition Imu.cpp:55
Imu(const Imu &)=delete
Copy constructor.
ImuPos _imuPos
Position and rotation information for conversion from platform to body frame.
Definition Imu.hpp:57
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
void ApplyChanges()
Signals that there have been changes to the flow.
bool BeginHelpMarker(const char *symbol="(?)", float textWrapLength=35.0F)
Begins a Text Help Marker, e.g. '(?)', with custom content.
void EndHelpMarker(bool wrapText=true)
Ends a Text Help Marker with custom content.
void MatrixView(const char *label, const Eigen::Matrix< _Scalar, _Rows, _Cols > *matrix, GuiMatrixViewFlags flags=GuiMatrixViewFlags_None, ImGuiTableFlags tableFlags=ImGuiTableFlags_None, const char *format="%.6f")
Shows GUI elements to display the coefficients of a matrix.
Definition Matrix.hpp:49
void HelpMarker(const char *desc, const char *symbol="(?)")
Text Help Marker, e.g. '(?)', with Tooltip.
Eigen::Quaternion< Scalar > b_Quat_p(Scalar mountingAngleX, Scalar mountingAngleY, Scalar mountingAngleZ)
Quaternion for rotations from platform to body frame.
Eigen::Vector3< typename Derived::Scalar > quat2eulerZYX(const Eigen::QuaternionBase< Derived > &q)
Converts the quaternion to Euler rotation angles with rotation sequence ZYX.
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:27
constexpr auto deg2rad(const T &deg)
Convert Degree to Radians.
Definition Units.hpp:21
constexpr auto rad2deg(const T &rad)
Convert Radians to Degree.
Definition Units.hpp:39