0.5.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
19
21 : Node(typeStatic())
22{
23 LOG_TRACE("{}: called", name);
24
26
27 _hasConfig = true;
28 _guiConfigDefaultWindowSize = { 380, 70 };
29
30 CreateInputPin("write", Pin::Type::Matrix, { "Eigen::MatrixXd" }, &MatrixLogger::writeMatrix);
31}
32
34{
35 LOG_TRACE("{}: called", nameId());
36}
37
39{
40 return "MatrixLogger";
41}
42
43std::string NAV::MatrixLogger::type() const
44{
45 return typeStatic();
46}
47
49{
50 return "Data Logger";
51}
52
54{
55 if (FileWriter::guiConfig(".csv", { ".csv" }, size_t(id), nameId()))
56 {
59 }
60
62 {
64 }
65}
66
67[[nodiscard]] json NAV::MatrixLogger::save() const
68{
69 LOG_TRACE("{}: called", nameId());
70
71 json j;
72
73 j["FileWriter"] = FileWriter::save();
74
75 return j;
76}
77
79{
80 LOG_TRACE("{}: called", nameId());
81
82 if (j.contains("FileWriter"))
83 {
84 FileWriter::restore(j.at("FileWriter"));
85 }
86}
87
89{
90 _filestream.flush();
91}
92
94{
95 LOG_TRACE("{}: called", nameId());
96
98 {
99 return false;
100 }
101
103
104 _headerWritten = false;
105
106 return true;
107}
108
110{
111 LOG_TRACE("{}: called", nameId());
112
114}
115
116void NAV::MatrixLogger::writeMatrix(const InsTime& insTime, size_t pinIdx)
117{
118 constexpr int gpsCyclePrecision = 3;
119 constexpr int gpsTimePrecision = 12;
120 constexpr int valuePrecision = 12;
121
122 if (!_headerWritten)
123 {
124 _filestream << "Time [s],GpsCycle,GpsWeek,GpsTow [s]";
125 }
126
127 if (auto* sourcePin = inputPins.at(pinIdx).link.getConnectedPin())
128 {
129 // Matrix
130 if (sourcePin->dataIdentifier.front() == "Eigen::MatrixXd")
131 {
133 value && !insTime.empty())
134 {
135 if (!_headerWritten)
136 {
137 for (int row = 0; row < value->v->rows(); row++)
138 {
139 for (int col = 0; col < value->v->cols(); col++)
140 {
141 _filestream << ",[" << row << ";" << col << "]";
142 }
143 }
144 _filestream << std::endl; // NOLINT(performance-avoid-endl)
145 _headerWritten = true;
146 }
147
148 _filestream << std::setprecision(valuePrecision) << std::round(calcTimeIntoRun(insTime) * 1e9) / 1e9;
149 _filestream << "," << std::fixed << std::setprecision(gpsCyclePrecision) << insTime.toGPSweekTow().gpsCycle;
150 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().gpsWeek;
151 _filestream << "," << std::defaultfloat << std::setprecision(gpsTimePrecision) << insTime.toGPSweekTow().tow;
152 _filestream << std::setprecision(valuePrecision);
153
154 for (int row = 0; row < value->v->rows(); row++)
155 {
156 for (int col = 0; col < value->v->cols(); col++)
157 {
158 _filestream << "," << (*value->v)(row, col);
159 }
160 }
161 _filestream << "\n";
162 }
163 }
164 else
165 {
166 releaseInputValue(pinIdx);
167 }
168 }
169}
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.
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:465
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:147
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
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:509
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
InputPin * CreateInputPin(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.
Definition Node.cpp:252
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
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