-
Notifications
You must be signed in to change notification settings - Fork 0
/
logreader2.hpp
389 lines (283 loc) · 10.5 KB
/
logreader2.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <typeinfo>
#include <vector>
#include <ostream>
#include <iomanip>
//#include "utf8.h"
//
//#include <locale>
//#include <codecvt>
using namespace std;
//bool nops = false;
vector<string> SepString(string input,char defSeparator,vector<string> separators)
{
vector<string> res;
// cout<<input<<endl;
//replace all non-default with the first one
for (unsigned int i = 0; i < separators.size(); i++)
{
size_t pos = input.find(separators.at(i));
// cout<<pos<<",";
if(pos > -1)
{
input.replace(pos,1,&defSeparator);
}
}
// cout<<endl;
//now split off the separators
std::istringstream split(input);
//all elegant: https://goo.gl/TpgLBM --- thank you user 560648
for (std::string temp; std::getline(split, temp, defSeparator); res.push_back(temp));
// if (res.size()>23 && res.at(0) == "#MARK1PVAA" )
// {cout<<input<<endl;nops = true;}
return res;
}
vector<vector<string>> logreaderBasic(string logname,vector<string> separators,char defSeparator)
{
vector<vector<string>> res;
vector<string> temp;
std::ifstream data;
data.open(logname);
string line;
// std::locale utf8_locale(locale(), new codecvt_utf8<wchar_t>);
// data.imbue(utf8_locale);
unsigned line_count = 1;
while (std::getline(data,line))
{
// string::iterator end_it = utf8::find_invalid(line.begin(), line.end());
// if (end_it != line.end()) {
// cout << "Invalid UTF-8 encoding detected at line " << line_count << "\n";
// cout << "This part is fine: " << string(line.begin(), end_it) << "\n";
// line_count++;
// }
temp = SepString(line,defSeparator,separators);
// if (nops)
// {cout<<line;nops=false;}
res.push_back(temp);
temp.clear();
}
data.close();
//cout<<res.size()<<endl;
return res;
}
struct gpsTimeB
{
int week;
double seconds;
};
//struct that contains the INS/GNSS observations
struct obs2
{
gpsTimeB obsTime;
//position
double lat;
double lgt;
double h;
//velocity
double velE;
double velN;
double velU;
//attitude
double pitch; //along Y axis ("phi")
double roll; //along X axis ("omega")
double azimuth; //along Z axis ("kappa")
//status
string status,type;
};
//struct that contains the covariance matrices of the INS/GNSS observations
struct obsCov2
{
gpsTimeB covTime;
double pos_mvc[3][3];
double vel_mvc[3][3];
double att_mvc[3][3];
};
//struct that contains all the others of the INS nested
struct obsWcov2
{
obs2 observation;
obsCov2 obsCovariances;
};
struct survData2
{
bool bugstatus=false;
std::vector<obsWcov2> pvaWcov;
vector<obs2> pva;
vector<obsCov2> covs;
vector<vector<string>> data;
//any non-comma field separator must be HERE
vector<string> otherSeparators = {";","*"};
//comma is the default separator, but if it was changed, change here too
char separator = ',';
vector<double> diffTimes;
survData2(string logname,bool gen_log);
void dataSplitter(void);
void dataInterpolation(void);
};
void survData2::dataSplitter()
{
//ofstream pvaTimes("obsTimes.txt");
//ofstream covTimes("covsTimes.txt");
//ofstream outNav("navData.txt");
//because of some bug nb = no-bug
// int nb = 0;
size_t np = 4;
//failsafe
if (data.empty())
{
return;
}
for (unsigned int i = 0; i < data.size(); i++)
{
//one for each message
if (data.at(i).at(0) == "#MARK1PVAA")
{
obs2 tempObs;
tempObs.lat = strtod(data.at(i).at(12).c_str(),nullptr); //12
if (fabs(tempObs.lat) > 90)
{
cout<<data.at(i).size()<<",";
cout<<"bug"<<endl;
bugstatus = true;
// nb = 1;
}
tempObs.lgt = strtod(data.at(i).at(13).c_str(),nullptr); //13
tempObs.h = strtod(data.at(i).at(14).c_str(),nullptr); //14
tempObs.velE = strtod(data.at(i).at(16).c_str(),nullptr); //16
tempObs.velN = strtod(data.at(i).at(15).c_str(),nullptr); //15
tempObs.velU = strtod(data.at(i).at(17).c_str(),nullptr); //17
tempObs.roll = strtod(data.at(i).at(18).c_str(),nullptr); //18
tempObs.pitch = strtod(data.at(i).at(19).c_str(),nullptr); //19
tempObs.azimuth = strtod(data.at(i).at(20).c_str(),nullptr); //20
tempObs.status = data.at(i).at(21); //21
tempObs.obsTime.week = atoi(data.at(i).at(10).c_str()); //10
tempObs.obsTime.seconds = strtod(data.at(i).at(11).c_str(),nullptr); //11
tempObs.type = "MARKPVA";
// pvaTimes<< setprecision(15) << tempObs.obsTime.seconds<<" "<<i<<endl;
// outNav<<setprecision(15)<< tempObs.lat<<" "<<tempObs.lgt<<" "<<tempObs.h<<" "<<tempObs.pitch<<" "<<tempObs.roll<<" "<<tempObs.azimuth<<endl;
pva.push_back(tempObs);
}
if (data.at(i).at(0) == "%INSCOVSA")
{
obsCov2 tempCov;
//attitude covariances
tempCov.att_mvc[0][0] = strtod(data.at(i).at(5).c_str(),nullptr);
tempCov.att_mvc[0][1] = strtod(data.at(i).at(6).c_str(),nullptr);
tempCov.att_mvc[0][2] = strtod(data.at(i).at(7).c_str(),nullptr);
tempCov.att_mvc[1][0] = strtod(data.at(i).at(8).c_str(),nullptr);
tempCov.att_mvc[1][1] = strtod(data.at(i).at(9).c_str(),nullptr);
tempCov.att_mvc[1][2] = strtod(data.at(i).at(10).c_str(),nullptr);
tempCov.att_mvc[2][0] = strtod(data.at(i).at(11).c_str(),nullptr);
tempCov.att_mvc[2][1] = strtod(data.at(i).at(12).c_str(),nullptr);
tempCov.att_mvc[2][2] = strtod(data.at(i).at(13).c_str(),nullptr);
//position covariances
tempCov.pos_mvc[0][0] = strtod(data.at(i).at(14).c_str(),nullptr); //xx
tempCov.pos_mvc[0][1] = strtod(data.at(i).at(15).c_str(),nullptr);
tempCov.pos_mvc[0][2] = strtod(data.at(i).at(16).c_str(),nullptr);
tempCov.pos_mvc[1][0] = strtod(data.at(i).at(17).c_str(),nullptr);
tempCov.pos_mvc[1][1] = strtod(data.at(i).at(18).c_str(),nullptr); //yy
tempCov.pos_mvc[1][2] = strtod(data.at(i).at(19).c_str(),nullptr);
tempCov.pos_mvc[2][0] = strtod(data.at(i).at(20).c_str(),nullptr);
tempCov.pos_mvc[2][1] = strtod(data.at(i).at(21).c_str(),nullptr);
tempCov.pos_mvc[2][2] = strtod(data.at(i).at(22).c_str(),nullptr); //zz
//velocity covariances
tempCov.vel_mvc[0][0] = strtod(data.at(i).at(23).c_str(),nullptr);
tempCov.vel_mvc[0][1] = strtod(data.at(i).at(24).c_str(),nullptr);
tempCov.vel_mvc[0][2] = strtod(data.at(i).at(25).c_str(),nullptr);
tempCov.vel_mvc[1][0] = strtod(data.at(i).at(26).c_str(),nullptr);
tempCov.vel_mvc[1][1] = strtod(data.at(i).at(27).c_str(),nullptr);
tempCov.vel_mvc[1][2] = strtod(data.at(i).at(28).c_str(),nullptr);
tempCov.vel_mvc[2][0] = strtod(data.at(i).at(29).c_str(),nullptr);
tempCov.vel_mvc[2][1] = strtod(data.at(i).at(30).c_str(),nullptr);
tempCov.vel_mvc[2][2] = strtod(data.at(i).at(31).c_str(),nullptr);
tempCov.covTime.week = atoi(data.at(i).at(1).c_str());
tempCov.covTime.seconds = strtod(data.at(i).at(4).c_str(),nullptr);
// covTimes<< setprecision(15) << tempCov.covTime.seconds<<" "<<i<<endl;
covs.push_back(tempCov);
}
}
}
void survData2::dataInterpolation()
{
unsigned int pMinN,pMinP;
double delta;
obsWcov2 temp;
for(unsigned int i = 0; i<pva.size(); i++)
{
double minN = -1000;
double minP = 1000;
temp.observation = pva.at(i);
//calculating the difference in times
for (unsigned int j = 0; j<covs.size(); j++)
{
delta = pva.at(i).obsTime.seconds - covs.at(j).covTime.seconds;
// if (pva.at(i).obsTime.seconds == 0.00 || covs.at(j).covTime.seconds == 0.00)
// {
// cout<<"zero detectado!!"<<endl;
// }
if (delta <= 0 && delta > minN)
{
minN = delta;
pMinN=j;
}
if (delta >= 0 && delta < minP)
{
minP = delta;
pMinP=j;
}
}
// cout<<minN<<" "<<minP<<" ";
//assingning the nearest neighbour
// cout<<minN<<" "<<minP<<" "<<pMinN<<" "<<pMinP<<endl;
if (fabs(minN) <= fabs(minP))
{
temp.obsCovariances = covs.at(pMinN);
// cout<<"neg"<<endl;
}
else
{
temp.obsCovariances = covs.at(pMinP);
// cout<<"pos"<<endl;
}
pvaWcov.push_back(temp);
}
}
survData2::survData2(string logname,bool gen_log)
{
data = logreaderBasic(logname,otherSeparators,separator);
dataSplitter();
dataInterpolation();
ofstream poses;
for (unsigned int i = 0; i<pvaWcov.size(); i++)
{
if (i > 0)
{
double tempDiff = fabs(pvaWcov.at(i).observation.obsTime.seconds - pvaWcov.at(i-1).observation.obsTime.seconds);
diffTimes.push_back(tempDiff);
}
if(gen_log)
{
// cout<<pvaWcov.at(i).observation.h<<endl;
if (i == 0)
{
poses.open("poses.txt");
poses<<"lat,lgt,h,roll,pitch,azimuth,varPos,varOri,weektime"<<endl;
}
poses<<std::setprecision(15)<<pvaWcov.at(i).observation.lat<<","<<pvaWcov.at(i).observation.lgt<<","<<pvaWcov.at(i).observation.h<<",";
poses<<pvaWcov.at(i).observation.roll<<","<<pvaWcov.at(i).observation.pitch<<","<<pvaWcov.at(i).observation.azimuth<<",";
poses<<(pvaWcov.at(i).obsCovariances.pos_mvc[0][0]+pvaWcov.at(i).obsCovariances.pos_mvc[1][1]+pvaWcov.at(i).obsCovariances.pos_mvc[2][2])/3<<",";
poses<<(pvaWcov.at(i).obsCovariances.att_mvc[0][0]+pvaWcov.at(i).obsCovariances.att_mvc[1][1]+pvaWcov.at(i).obsCovariances.att_mvc[2][2])/3<<",";
poses<<pvaWcov.at(i).observation.obsTime.seconds<<endl;
}
}
cout<<"total: "<<pvaWcov.size()<<" "<<pva.size()<<endl;
if(bugstatus)
{
cout<<"bug 01 encontrado!"<<endl;
}
}