0.2.0
Loading...
Searching...
No Matches
UlogFile.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// Already in 'FileReader.hpp'
17// #include <string>
18// #include <vector>
19// #include <fstream>
20
21#include <map>
22#include <variant>
23
26
27namespace NAV
28{
30class UlogFile : public Imu, public FileReader
31{
32 public:
36 ~UlogFile() override;
38 UlogFile(const UlogFile&) = delete;
40 UlogFile(UlogFile&&) = delete;
42 UlogFile& operator=(const UlogFile&) = delete;
45
47 [[nodiscard]] static std::string typeStatic();
48
50 [[nodiscard]] std::string type() const override;
51
53 [[nodiscard]] static std::string category();
54
57 void guiConfig() override;
58
60 [[nodiscard]] json save() const override;
61
64 void restore(const json& j) override;
65
67 bool resetNode() override;
68
71 {
72 uint8_t multi_id;
73 std::string message_name;
74 };
75
76 private:
77 constexpr static size_t OUTPUT_PORT_INDEX_IMUOBS_1 = 0;
78 constexpr static size_t OUTPUT_PORT_INDEX_IMUOBS_2 = 1;
79 constexpr static size_t OUTPUT_PORT_INDEX_POSVELATT = 2;
80
82 bool initialize() override;
83
85 void deinitialize() override;
86
89 [[nodiscard]] std::shared_ptr<const NodeData> pollData();
90
93 [[nodiscard]] FileType determineFileType() override;
94
96 void readHeader() override;
97
101 void readInformationMessage(uint16_t msgSize, char msgType);
102
106 void readInformationMessageMulti(uint16_t msgSize, char msgType);
107
111 void readParameterMessage(uint16_t msgSize, char msgType);
112
116 void readParameterMessageDefault(uint16_t msgSize, char msgType);
117
119 struct DataField
120 {
121 std::string type;
122 std::string name;
123 };
124
126 std::unordered_map<std::string, std::vector<DataField>> _messageFormats;
127
129 struct SensorAccel
130 {
131 uint64_t timestamp;
132 uint64_t timestamp_sample;
133 uint32_t device_id;
134 float x;
135 float y;
136 float z;
137 float temperature;
138 uint32_t error_count;
139 std::array<uint8_t, 3> clip_counter;
140
141 static constexpr uint8_t padding = 5;
142 };
143
145 struct SensorGyro
146 {
147 uint64_t timestamp;
148 uint64_t timestamp_sample;
149 uint32_t device_id;
150 float x;
151 float y;
152 float z;
153 float temperature;
154 uint32_t error_count;
155 };
156
158 struct SensorMag
159 {
160 uint64_t timestamp;
161 uint64_t timestamp_sample;
162 uint32_t device_id;
163 float x;
164 float y;
165 float z;
166 float temperature;
167 uint32_t error_count;
168 bool is_external;
169
170 static constexpr uint8_t padding = 7;
171 };
172
174 struct VehicleGpsPosition
175 {
176 uint64_t timestamp;
177 uint64_t time_utc_usec;
178 int32_t lat;
179 int32_t lon;
180 int32_t alt;
181 int32_t alt_ellipsoid;
182 float s_variance_m_s;
183 float c_variance_rad;
184 float eph;
185 float epv;
186 float hdop;
187 float vdop;
188 int32_t noise_per_ms;
189 int32_t jamming_indicator;
190 float vel_m_s;
191 float vel_n_m_s;
192 float vel_e_m_s;
193 float vel_d_m_s;
194 float cog_rad;
195 int32_t timestamp_time_relative;
196 float heading;
197 float heading_offset;
198 uint8_t fix_type;
199 bool vel_ned_valid;
200 uint8_t satellites_used;
201
202 static constexpr uint8_t padding = 5;
203 };
204
206 struct VehicleAttitude
207 {
208 uint64_t timestamp;
209 std::array<float, 4> q;
210 std::array<float, 4> delta_q_reset;
211 uint8_t quat_reset_counter;
212
213 static constexpr uint8_t padding = 7;
214 };
215
217 struct VehicleAirData
218 {
219 uint64_t timestamp;
220 uint64_t timestamp_sample;
221 uint32_t baro_device_id;
222 float baro_alt_meter;
223 float baro_temp_celcius;
224 float baro_pressure_pa;
225 float rho;
226
227 static constexpr uint8_t padding = 4;
228 };
229
231 struct VehicleControlMode
232 {
233 uint64_t timestamp;
234 bool flag_armed;
235 bool flag_external_manual_override_ok;
236 bool flag_control_manual_enabled;
237 bool flag_control_auto_enabled;
238 bool flag_control_offboard_enabled;
239 bool flag_control_rates_enabled;
240 bool flag_control_attitude_enabled;
241 bool flag_control_yawrate_override_enabled;
242 bool flag_control_rattitude_enabled;
243 bool flag_control_force_enabled;
244 bool flag_control_acceleration_enabled;
245 bool flag_control_velocity_enabled;
246 bool flag_control_position_enabled;
247 bool flag_control_altitude_enabled;
248 bool flag_control_climb_rate_enabled;
249 bool flag_control_termination_enabled;
250 bool flag_control_fixed_hdg_enabled;
251
252 static constexpr uint8_t padding = 7;
253 };
254
256 struct VehicleStatus
257 {
258 uint64_t timestamp;
259 uint64_t nav_state_timestamp;
260 uint32_t onboard_control_sensors_present;
261 uint32_t onboard_control_sensors_enabled;
262 uint32_t onboard_control_sensors_health;
263 uint8_t nav_state;
264 uint8_t arming_state;
265 uint8_t hil_state;
266 bool failsafe;
267 uint8_t system_type;
268 uint8_t system_id;
269 uint8_t component_id;
270 uint8_t vehicle_type;
271 bool is_vtol;
272 bool is_vtol_tailsitter;
273 bool vtol_fw_permanent_stab;
274 bool in_transition_mode;
275 bool in_transition_to_fw;
276 bool rc_signal_lost;
277 uint8_t rc_input_mode;
278 bool data_link_lost;
279 uint8_t data_link_lost_counter;
280 bool high_latency_data_link_lost;
281 bool engine_failure;
282 bool mission_failure;
283 uint8_t failure_detector_status;
284 uint8_t latest_arming_reason;
285 uint8_t latest_disarming_reason;
286 std::array<uint8_t, 5> _padding0;
287 };
288
290 struct Cpuload
291 {
292 uint64_t timestamp;
293 float load;
294 float ram_usage;
295 };
296
298 std::unordered_map<uint16_t, SubscriptionData> _subscribedMessages;
299
301 struct MeasurementData
302 {
303 uint8_t multi_id;
304 std::string message_name;
305 std::variant<SensorAccel, SensorGyro, SensorMag, VehicleGpsPosition, VehicleAttitude> data;
306 };
307
309 std::multimap<uint64_t, MeasurementData> _epochData;
310
313 int8_t enoughImuDataAvailable();
314
317 std::array<std::multimap<uint64_t, NAV::UlogFile::MeasurementData>::iterator, 2> findPosVelAttData();
318
320 struct
321 {
322 uint64_t timeSinceStartup{};
324 } lastGnssTime;
325};
326} // namespace NAV
Abstract File Reader class.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Abstract IMU Class.
Abstract File Reader class.
Definition FileReader.hpp:31
FileType
File Type Enumeration.
Definition FileReader.hpp:35
Abstract IMU Class.
Definition Imu.hpp:24
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
File Reader for ULog files ('.ulg')
Definition UlogFile.hpp:31
UlogFile & operator=(const UlogFile &)=delete
Copy assignment operator.
InsTime gnssTime
Absolute timestamp.
Definition UlogFile.hpp:323
static std::string category()
String representation of the Class Category.
uint64_t timeSinceStartup
Relative timestamp.
Definition UlogFile.hpp:322
json save() const override
Saves the node into a json object.
UlogFile(UlogFile &&)=delete
Move constructor.
UlogFile & operator=(UlogFile &&)=delete
Move assignment operator.
void restore(const json &j) override
Restores the node from a json object.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
bool resetNode() override
Resets the node. Moves the read cursor to the start.
~UlogFile() override
Destructor.
std::string type() const override
String representation of the Class Type.
UlogFile()
Default constructor.
UlogFile(const UlogFile &)=delete
Copy constructor.
Combined (sensor-)message name with unique ID.
Definition UlogFile.hpp:71
uint8_t multi_id
the same message format can have multiple instances, for example if the system has two sensors of the...
Definition UlogFile.hpp:72
std::string message_name
message name to subscribe to
Definition UlogFile.hpp:73