0.4.1
Loading...
Searching...
No Matches
MatrixLogger.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 "MatrixLogger.hpp"
10
11#include "util/Logger.hpp"
12
13#include <iomanip> // std::setprecision
14#include "util/Eigen.hpp"
15
17
19namespace nm = NAV::NodeManager;
21
23 : Node(typeStatic())
24{
25 LOG_TRACE("{}: called", name);
26
28
29 _hasConfig = true;
30 _guiConfigDefaultWindowSize = { 380, 70 };
31
32 nm::CreateInputPin(this, "write", Pin::Type::Matrix, { "Eigen::MatrixXd" }, &MatrixLogger::writeMatrix);
33}
34
36{
37 LOG_TRACE("{}: called", nameId());
38}
39
41{
42 return "MatrixLogger";
43}
44
45std::string NAV::MatrixLogger::type() const
46{
47 return typeStatic();
48}
49
51{
52 return "Data Logger";
53}
54
56{
57 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
58 {
61 }
62
64 {
66 }
67}
68
69[[nodiscard]] json NAV::MatrixLogger::save() const
70{
71 LOG_TRACE("{}: called", nameId());
72
73 json j;
74
75 j["FileWriter"] = FileWriter::save();
76
77 return j;
78}
79
81{
82 LOG_TRACE("{}: called", nameId());
83
84 if (j.contains("FileWriter"))
85 {
86 FileWriter::restore(j.at("FileWriter"));
87 }
88}
89
91{
92 _filestream.flush();
93}
94
96{
97 LOG_TRACE("{}: called", nameId());
98
100 {
101 return false;
102 }
103
105
106 _headerWritten = false;
107
108 return true;
109}
110
112{
113 LOG_TRACE("{}: called", nameId());
114
116}
117
118void NAV::MatrixLogger::writeMatrix(const InsTime& insTime, size_t pinIdx)
119{
120 constexpr int gpsCyclePrecision = 3;
121 constexpr int gpsTimePrecision = 12;
122 constexpr int valuePrecision = 12;
123
124 if (!_headerWritten)
125 {
126 _filestream << "Time [s],GpsCycle,GpsWeek,GpsTow [s]";
127 }
128
129 if (auto* sourcePin = inputPins.at(pinIdx).link.getConnectedPin())
130 {
131 // Matrix
132 if (sourcePin->dataIdentifier.front() == "Eigen::MatrixXd")
133 {
135 value && !insTime.empty())
136 {
137 if (!_headerWritten)
138 {
139 for (int row = 0; row < value->v->rows(); row++)
140 {
141 for (int col = 0; col < value->v->cols(); col++)
142 {
143 _filestream << ",[" << row << ";" << col << "]";
144 }
145 }
146 _filestream << std::endl; // NOLINT(performance-avoid-endl)
147 _headerWritten = true;
148 }
149
150 _filestream << std::setprecision(valuePrecision) << std::round(calcTimeIntoRun(insTime) * 1e9) / 1e9;
151 _filestream << "," << std::fixed << std::setprecision(gpsCyclePrecision) << insTime.toGPSweekTow().gpsCycle;
152 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().gpsWeek;
153 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().tow;
154 _filestream << std::setprecision(valuePrecision);
155
156 for (int row = 0; row < value->v->rows(); row++)
157 {
158 for (int col = 0; col < value->v->cols(); col++)
159 {
160 _filestream << "," << (*value->v)(row, col);
161 }
162 }
163 _filestream << "\n";
164 }
165 }
166 else
167 {
168 releaseInputValue(pinIdx);
169 }
170 }
171}
Vector space operations.
Save/Load the Nodes.
nlohmann::json json
json namespace
Utility class for logging to console and file.
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Data Logger for matrices.
Manages all Nodes.
Keeps track of the current real/simulation time.
static bool ShowOriginInput(const char *id)
Shows a GUI to input a origin location.
void initialize() const
Initialize the common log variables.
Definition CommonLog.cpp:51
static double calcTimeIntoRun(const InsTime &insTime)
Calculates the relative time into he run.
Definition CommonLog.cpp:70
@ ASCII
Ascii text data.
FileType _fileType
File Type.
void deinitialize()
Deinitialize the file reader.
bool guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
void restore(const json &j)
Restores the node from a json object.
json save() const
Saves the node into a json object.
bool initialize()
Initialize the file reader.
std::ofstream _filestream
File stream to write the file.
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
constexpr InsTime_GPSweekTow toGPSweekTow(TimeSystem timesys=GPST) const
Converts this time object into a different format.
Definition InsTime.hpp:854
constexpr bool empty() const
Checks if the Time object has a value.
Definition InsTime.hpp:1089
void deinitialize() override
Deinitialize the node.
static std::string typeStatic()
String representation of the Class Type.
MatrixLogger()
Default constructor.
static std::string category()
String representation of the Class Category.
json save() const override
Saves the node into a json object.
~MatrixLogger() override
Destructor.
void writeMatrix(const InsTime &insTime, size_t pinIdx)
Write a matrix to the file.
bool _headerWritten
Flag whether the header was written.
void flush() override
Function called by the flow executer after finishing to flush out remaining data.
static constexpr size_t INPUT_PORT_INDEX_MATRIX
Matrix.
void restore(const json &j) override
Restores the node from a json object.
std::string type() const override
String representation of the Class Type.
void guiConfig() override
ImGui config window which is shown on double click.
bool initialize() override
Initialize the node.
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:395
void releaseInputValue(size_t portIndex)
Unblocks the connected node. Has to be called when the input value should be released and getInputVal...
Definition Node.cpp:148
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::optional< InputPin::IncomingLink::ValueWrapper< T > > getInputValue(size_t portIndex) const
Get Input Value connected on the pin. Only const data types.
Definition Node.hpp:290
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
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
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.
void ApplyChanges()
Signals that there have been changes to the flow.
int32_t gpsCycle
Contains GPS cycle in GPS standard time [GPST].
Definition InsTime.hpp:370
int32_t gpsWeek
Contains GPS week in GPS standard time [GPST].
Definition InsTime.hpp:371
long double tow
Contains GPS time of week in seconds in GPS standard time [GPST].
Definition InsTime.hpp:372
@ Matrix
Matrix Object.
Definition Pin.hpp:58