0.4.1
Loading...
Searching...
No Matches
ImuIntegrator.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 "ImuIntegrator.hpp"
10
11#include "util/Logger.hpp"
12
16
19
21#include <imgui_internal.h>
22
23#include "util/Eigen.hpp"
24
25#include "NodeRegistry.hpp"
27namespace nm = NAV::NodeManager;
29
30#include <algorithm>
31
33 : Node(typeStatic())
34{
35 LOG_TRACE("{}: called", name);
36
37 _hasConfig = true;
38 _guiConfigDefaultWindowSize = { 422, 146 };
39
41 [](const Node* node, const InputPin& inputPin) {
42 const auto* imuIntegrator = static_cast<const ImuIntegrator*>(node); // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
43 return !inputPin.queue.empty() && imuIntegrator->_inertialIntegrator.hasInitialPosition();
44 });
46
48}
49
54
56{
57 return "ImuIntegrator";
58}
59
60std::string NAV::ImuIntegrator::type() const
61{
62 return typeStatic();
63}
64
66{
67 return "Data Processor";
68}
69
77
78[[nodiscard]] json NAV::ImuIntegrator::save() const
79{
80 LOG_TRACE("{}: called", nameId());
81
82 json j;
83
84 j["inertialIntegrator"] = _inertialIntegrator;
85 j["preferAccelerationOverDeltaMeasurements"] = _preferAccelerationOverDeltaMeasurements;
86
87 return j;
88}
89
91{
92 LOG_TRACE("{}: called", nameId());
93
94 if (j.contains("inertialIntegrator"))
95 {
96 j.at("inertialIntegrator").get_to(_inertialIntegrator);
97 }
98 if (j.contains("preferAccelerationOverDeltaMeasurements"))
99 {
100 j.at("preferAccelerationOverDeltaMeasurements").get_to(_preferAccelerationOverDeltaMeasurements);
101 }
102}
103
105{
106 LOG_TRACE("{}: called", nameId());
107
108 _inertialIntegrator.reset();
109
110 LOG_DEBUG("ImuIntegrator initialized");
111
112 return true;
113}
114
116{
117 LOG_TRACE("{}: called", nameId());
118}
119
121{
122 auto nodeData = queue.extract_front();
123 if (nodeData->insTime.empty())
124 {
125 LOG_ERROR("{}: Can't set new imuObs__t0 because the observation has no time tag (insTime)", nameId());
126 return;
127 }
128
129 std::shared_ptr<NAV::PosVelAtt> integratedPosVelAtt = nullptr;
130
132 && NAV::NodeRegistry::NodeDataTypeAnyIsChildOf(inputPins.at(INPUT_PORT_INDEX_IMU_OBS).link.getConnectedPin()->dataIdentifier, { ImuObsWDelta::type() }))
133 {
134 auto obs = std::static_pointer_cast<const ImuObsWDelta>(nodeData);
135 LOG_DATA("{}: recvImuObsWDelta at time [{}]", nameId(), obs->insTime.toYMDHMS());
136
137 integratedPosVelAtt = _inertialIntegrator.calcInertialSolutionDelta(obs->insTime, obs->dtime, obs->dvel, obs->dtheta, obs->imuPos, nameId().c_str());
138 }
139 else
140 {
141 auto obs = std::static_pointer_cast<const ImuObs>(nodeData);
142 LOG_DATA("{}: recvImuObs at time [{}]", nameId(), obs->insTime.toYMDHMS());
143
144 integratedPosVelAtt = _inertialIntegrator.calcInertialSolution(obs->insTime, obs->p_acceleration, obs->p_angularRate, obs->imuPos, nameId().c_str());
145 }
146
147 if (integratedPosVelAtt)
148 {
149 LOG_DATA("{}: e_position = {}", nameId(), integratedPosVelAtt->e_position().transpose());
150 LOG_DATA("{}: e_velocity = {}", nameId(), integratedPosVelAtt->e_velocity().transpose());
151 LOG_DATA("{}: rollPitchYaw = {}", nameId(), rad2deg(integratedPosVelAtt->rollPitchYaw()).transpose());
153 }
154}
155
157{
158 auto posVelAtt = std::static_pointer_cast<const PosVelAtt>(queue.extract_front());
159 inputPins[INPUT_PORT_INDEX_POS_VEL_ATT_INIT].queueBlocked = true;
161
162 LOG_DATA("{}: recvPosVelAttInit at time [{}]", nameId(), posVelAtt->insTime.toYMDHMS());
163
164 if (!_inertialIntegrator.hasInitialPosition())
165 {
166 _inertialIntegrator.setInitialState(*posVelAtt, nameId().c_str());
167 LOG_DATA("{}: e_position = {}", nameId(), posVelAtt->e_position().transpose());
168 LOG_DATA("{}: e_velocity = {}", nameId(), posVelAtt->e_velocity().transpose());
169 LOG_DATA("{}: rollPitchYaw = {}", nameId(), rad2deg(posVelAtt->rollPitchYaw()).transpose());
170
172 }
173}
Holds all Constants.
Vector space operations.
Save/Load the Nodes.
nlohmann::json json
json namespace
Text Help Marker (?) with Tooltip.
Integrates ImuObs Data.
Data storage class for one VectorNavImu observation.
Parent Class for all IMU Observations.
Utility class for logging to console and file.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Simple Math functions.
Manages all Nodes.
Utility class which specifies available nodes.
Position, Velocity and Attitude Storage Class.
static constexpr size_t INPUT_PORT_INDEX_POS_VEL_ATT_INIT
Flow (PosVelAtt)
void deinitialize() override
Deinitialize the node.
void recvObservation(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Function.
bool _preferAccelerationOverDeltaMeasurements
Prefer the raw acceleration measurements over the deltaVel & deltaTheta values.
static std::string category()
String representation of the Class Category.
static std::string typeStatic()
String representation of the Class Type.
void restore(const json &j) override
Restores the node from a json object.
std::string type() const override
String representation of the Class Type.
ImuIntegrator()
Default constructor.
void guiConfig() override
ImGui config window which is shown on double click.
bool initialize() override
Initialize the node.
~ImuIntegrator() override
Destructor.
static constexpr size_t OUTPUT_PORT_INDEX_INERTIAL_NAV_SOL
Flow (InertialNavSol)
void recvPosVelAttInit(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Function for the PosVelAtt initial values.
json save() const override
Saves the node into a json object.
InertialIntegrator _inertialIntegrator
Inertial Integrator.
static constexpr size_t INPUT_PORT_INDEX_IMU_OBS
Flow (ImuObs)
static std::string type()
Returns the type of the data class.
static std::string type()
Returns the type of the data class.
Definition ImuObs.hpp:33
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:397
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:180
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
static std::string type()
Returns the type of the data class.
Definition PosVelAtt.hpp:29
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
bool NodeDataTypeAnyIsChildOf(const std::vector< std::string > &childTypes, const std::vector< std::string > &parentTypes)
Checks if any of the provided child types is a child of any of the provided parent types.
void ApplyChanges()
Signals that there have been changes to the flow.
bool InertialIntegratorGui(const char *label, InertialIntegrator &integrator, bool &preferAccelerationOverDeltaMeasurements, float width)
Shows a GUI for advanced configuration of the InertialIntegrator.
constexpr auto rad2deg(const T &rad)
Convert Radians to Degree.
Definition Units.hpp:39
@ Flow
NodeData Trigger.
Definition Pin.hpp:52