MRPT  1.9.9
path_from_rtk_gps.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "topography-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/data_utils.h>
14 #include <mrpt/tfest/se3.h>
18 
19 #include <memory>
20 
21 #if MRPT_HAS_WXWIDGETS
22 #include <wx/app.h>
23 #include <wx/busyinfo.h>
24 #include <wx/log.h>
25 #include <wx/msgdlg.h>
26 #include <wx/progdlg.h>
27 #include <wx/string.h>
28 #endif // MRPT_HAS_WXWIDGETS
29 
30 using namespace std;
31 using namespace mrpt;
32 using namespace mrpt::obs;
33 using namespace mrpt::math;
34 using namespace mrpt::poses;
35 using namespace mrpt::system;
36 using namespace mrpt::tfest;
37 using namespace mrpt::config;
38 using namespace mrpt::topography;
39 
40 template <class T>
41 std::set<T> make_set(const T& v0, const T& v1)
42 {
43  std::set<T> s;
44  s.insert(v0);
45  s.insert(v1);
46  return s;
47 }
48 
49 /*---------------------------------------------------------------
50  path_from_rtk_gps
51  ---------------------------------------------------------------*/
54  const mrpt::obs::CRawlog& rawlog, size_t first, size_t last, bool isGUI,
55  bool disableGPSInterp, int PATH_SMOOTH_FILTER, TPathFromRTKInfo* outInfo)
56 {
58 
59 #if MRPT_HAS_WXWIDGETS
60  // Use a smart pointer so we are safe against exceptions:
61  std::unique_ptr<wxBusyCursor> waitCursorPtr;
62  if (isGUI) waitCursorPtr = std::make_unique<wxBusyCursor>();
63 #else
64  MRPT_UNUSED_PARAM(isGUI);
65 #endif
66 
67  // Go: generate the map:
68  ASSERT_(first <= last);
69  ASSERT_(last <= rawlog.size() - 1);
70 
71  set<string> lstGPSLabels;
72 
73  size_t count = 0;
74 
75  robot_path.clear();
76  robot_path.setMaxTimeInterpolation(std::chrono::seconds(
77  3)); // Max. seconds of GPS blackout not to interpolate.
79 
80  TPathFromRTKInfo outInfoTemp;
81  if (outInfo) *outInfo = outInfoTemp;
82 
83  map<string, map<Clock::time_point, TPoint3D>>
84  gps_paths; // label -> (time -> 3D local coords)
85 
86  bool abort = false;
87  bool ref_valid = false;
88 
89  // Load configuration block:
90  CConfigFileMemory memFil;
91  rawlog.getCommentTextAsConfigFile(memFil);
92 
94  memFil.read_double("GPS_ORIGIN", "lat_deg", 0),
95  memFil.read_double("GPS_ORIGIN", "lon_deg", 0),
96  memFil.read_double("GPS_ORIGIN", "height", 0));
97 
98  ref_valid = !ref.isClear();
99 
100  // Do we have info for the consistency test?
101  const double std_0 = memFil.read_double("CONSISTENCY_TEST", "std_0", 0);
102  bool doConsistencyCheck = std_0 > 0;
103 
104  // Do we have the "reference uncertainty" matrix W^\star ??
105  memFil.read_matrix("UNCERTAINTY", "W_star", outInfoTemp.W_star);
106  const bool doUncertaintyCovs = outInfoTemp.W_star.rows() != 0;
107  if (doUncertaintyCovs &&
108  (outInfoTemp.W_star.rows() != 6 || outInfoTemp.W_star.cols() != 6))
110  "ERROR: W_star matrix for uncertainty estimation is provided but "
111  "it's not a 6x6 matrix.");
112 
113 // ------------------------------------------
114 // Look for the 2 observations:
115 // ------------------------------------------
116 #if MRPT_HAS_WXWIDGETS
117  wxProgressDialog* progDia = nullptr;
118  if (isGUI)
119  {
120  progDia = new wxProgressDialog(
121  wxT("Building map"), wxT("Getting GPS observations..."),
122  (int)(last - first + 1), // range
123  nullptr, // parent
124  wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_AUTO_HIDE |
125  wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME);
126  }
127 #endif
128 
129  // The list with all time ordered gps's in valid RTK mode
130  using TListGPSs = std::map<
131  mrpt::Clock::time_point, std::map<std::string, CObservationGPS::Ptr>>;
132  TListGPSs list_gps_obs;
133 
134  map<string, size_t> GPS_RTK_reads; // label-># of RTK readings
135  map<string, TPoint3D>
136  GPS_local_coords_on_vehicle; // label -> local pose on the vehicle
137 
138  for (size_t i = first; !abort && i <= last; i++)
139  {
140  switch (rawlog.getType(i))
141  {
142  default:
143  break;
144 
145  case CRawlog::etObservation:
146  {
147  CObservation::Ptr o = rawlog.getAsObservation(i);
148 
149  if (o->GetRuntimeClass() == CLASS_ID(CObservationGPS))
150  {
152  std::dynamic_pointer_cast<CObservationGPS>(o);
153 
154  if (obs->has_GGA_datum &&
155  obs->getMsgByClass<gnss::Message_NMEA_GGA>()
156  .fields.fix_quality == 4)
157  {
158  // Add to the list:
159  list_gps_obs[obs->timestamp][obs->sensorLabel] = obs;
160 
161  lstGPSLabels.insert(obs->sensorLabel);
162  }
163 
164  // Save to GPS paths:
165  if (obs->has_GGA_datum &&
166  (obs->getMsgByClass<gnss::Message_NMEA_GGA>()
167  .fields.fix_quality == 4 ||
168  obs->getMsgByClass<gnss::Message_NMEA_GGA>()
169  .fields.fix_quality == 5))
170  {
171  GPS_RTK_reads[obs->sensorLabel]++;
172 
173  // map<string,TPoint3D> GPS_local_coords_on_vehicle; //
174  // label -> local pose on the vehicle
175  if (GPS_local_coords_on_vehicle.find(
176  obs->sensorLabel) ==
177  GPS_local_coords_on_vehicle.end())
178  GPS_local_coords_on_vehicle[obs->sensorLabel] =
179  TPoint3D(obs->sensorPose.asTPose());
180 
181  // map<string, map<Clock::time_point,TPoint3D> >
182  // gps_paths;
183  // //
184  // label -> (time -> 3D local coords)
185  gps_paths[obs->sensorLabel][obs->timestamp] = TPoint3D(
186  obs->getMsgByClass<gnss::Message_NMEA_GGA>()
188  obs->getMsgByClass<gnss::Message_NMEA_GGA>()
190  obs->getMsgByClass<gnss::Message_NMEA_GGA>()
192  }
193  }
194  }
195  break;
196  } // end switch type
197 
198  // Show progress:
199  if ((count++ % 100) == 0)
200  {
201 #if MRPT_HAS_WXWIDGETS
202  if (progDia)
203  {
204  if (!progDia->Update((int)(i - first))) abort = true;
205  wxTheApp->Yield();
206  }
207 #endif
208  }
209  } // end for i
210 
211 #if MRPT_HAS_WXWIDGETS
212  if (progDia)
213  {
214  delete progDia;
215  progDia = nullptr;
216  }
217 #endif
218 
219  // -----------------------------------------------------------
220  // At this point we already have the sensor positions, thus
221  // we can estimate the covariance matrix D:
222  //
223  // TODO: Generalize equations for # of GPS > 3
224  // -----------------------------------------------------------
225  map<set<string>, double> Ad_ij; // InterGPS distances in 2D
226  map<set<string>, double>
227  phi_ij; // Directions on XY of the lines between i-j
228  map<string, size_t>
229  D_cov_indexes; // Sensor label-> index in the matrix (first=0, ...)
230  map<size_t, string> D_cov_rev_indexes; // Reverse of D_cov_indexes
231 
232  CMatrixDouble D_cov; // square distances cov
233  CMatrixDouble D_cov_1; // square distances cov (inverse)
234  CVectorDouble D_mean; // square distances mean
235 
236  if (doConsistencyCheck && GPS_local_coords_on_vehicle.size() == 3)
237  {
238  unsigned int cnt = 0;
239  for (auto i = GPS_local_coords_on_vehicle.begin();
240  i != GPS_local_coords_on_vehicle.end(); ++i)
241  {
242  // Index tables:
243  D_cov_indexes[i->first] = cnt;
244  D_cov_rev_indexes[cnt] = i->first;
245  cnt++;
246 
247  for (auto j = i; j != GPS_local_coords_on_vehicle.end(); ++j)
248  {
249  if (i != j)
250  {
251  const TPoint3D& pi = i->second;
252  const TPoint3D& pj = j->second;
253  Ad_ij[make_set(i->first, j->first)] = pi.distanceTo(pj);
254  phi_ij[make_set(i->first, j->first)] =
255  atan2(pj.y - pi.y, pj.x - pi.x);
256  }
257  }
258  }
259  ASSERT_(D_cov_indexes.size() == 3 && D_cov_rev_indexes.size() == 3);
260 
261  D_cov.setSize(D_cov_indexes.size(), D_cov_indexes.size());
262  D_mean.resize(D_cov_indexes.size());
263 
264  // See paper for the formulas!
265  // TODO: generalize for N>3
266 
267  D_cov(0, 0) =
268  2 *
269  square(Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])]);
270  D_cov(1, 1) =
271  2 *
272  square(Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])]);
273  D_cov(2, 2) =
274  2 *
275  square(Ad_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])]);
276 
277  D_cov(1, 0) =
278  Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])] *
279  Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])] *
280  cos(phi_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])] -
281  phi_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])]);
282  D_cov(0, 1) = D_cov(1, 0);
283 
284  D_cov(2, 0) =
285  -Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])] *
286  Ad_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])] *
287  cos(phi_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])] -
288  phi_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])]);
289  D_cov(0, 2) = D_cov(2, 0);
290 
291  D_cov(2, 1) =
292  Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])] *
293  Ad_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])] *
294  cos(phi_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])] -
295  phi_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])]);
296  D_cov(1, 2) = D_cov(2, 1);
297 
298  D_cov *= 4 * square(std_0);
299 
300  D_cov_1 = D_cov.inverse_LLt();
301 
302  // cout << D_cov.inMatlabFormat() << endl;
303 
304  D_mean[0] =
305  square(Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[1])]);
306  D_mean[1] =
307  square(Ad_ij[make_set(D_cov_rev_indexes[0], D_cov_rev_indexes[2])]);
308  D_mean[2] =
309  square(Ad_ij[make_set(D_cov_rev_indexes[1], D_cov_rev_indexes[2])]);
310  }
311  else
312  doConsistencyCheck = false;
313 
314  // ------------------------------------------
315  // Look for the 2 observations:
316  // ------------------------------------------
317  int N_GPSs = list_gps_obs.size();
318 
319  if (N_GPSs)
320  {
321  // loop interpolate 1-out-of-5: this solves the issue with JAVAD GPSs
322  // that skip some readings at some times .0 .2 .4 .6 .8
323  if (list_gps_obs.size() > 4)
324  {
325  auto F = list_gps_obs.begin();
326  ++F;
327  ++F;
328  auto E = list_gps_obs.end();
329  --E;
330  --E;
331 
332  for (auto it = F; it != E; ++it)
333  {
334  // Now check if we have 3 gps with the same time stamp:
335  // const size_t N = i->second.size();
336  std::map<std::string, CObservationGPS::Ptr>& GPS = it->second;
337 
338  // Check if any in "lstGPSLabels" is missing here:
339  for (const auto& lstGPSLabel : lstGPSLabels)
340  {
341  // For each GPS in the current timestamp:
342  bool fnd = (GPS.find(lstGPSLabel) != GPS.end());
343 
344  if (fnd) continue; // this one is present.
345 
346  // Ok, we have "*l" missing in the set "*i".
347  // Try to interpolate from neighbors:
348  auto i_b1 = it;
349  --i_b1;
350  auto i_a1 = it;
351  ++i_a1;
352 
353  CObservationGPS::Ptr GPS_b1, GPS_a1;
354 
355  if (i_b1->second.find(lstGPSLabel) != i_b1->second.end())
356  GPS_b1 = i_b1->second.find(lstGPSLabel)->second;
357 
358  if (i_a1->second.find(lstGPSLabel) != i_a1->second.end())
359  GPS_a1 = i_a1->second.find(lstGPSLabel)->second;
360 
361  if (!disableGPSInterp && GPS_a1 && GPS_b1)
362  {
364  GPS_b1->timestamp, GPS_a1->timestamp) < 0.5)
365  {
366  auto new_gps = CObservationGPS::Create(*GPS_a1);
367  new_gps->sensorLabel = lstGPSLabel;
368 
369  // cout <<
370  // mrpt::system::timeLocalToString(GPS_b1->timestamp)
371  // << " " <<
372  // mrpt::system::timeLocalToString(GPS_a1->timestamp)
373  // << " " << *l;
374  // cout << endl;
375 
376  new_gps->getMsgByClass<gnss::Message_NMEA_GGA>()
377  .fields.longitude_degrees =
378  0.5 *
379  (GPS_a1->getMsgByClass<gnss::Message_NMEA_GGA>()
381  GPS_b1->getMsgByClass<gnss::Message_NMEA_GGA>()
382  .fields.longitude_degrees);
383  new_gps->getMsgByClass<gnss::Message_NMEA_GGA>()
384  .fields.latitude_degrees =
385  0.5 *
386  (GPS_a1->getMsgByClass<gnss::Message_NMEA_GGA>()
388  GPS_b1->getMsgByClass<gnss::Message_NMEA_GGA>()
389  .fields.latitude_degrees);
390  new_gps->getMsgByClass<gnss::Message_NMEA_GGA>()
391  .fields.altitude_meters =
392  0.5 *
393  (GPS_a1->getMsgByClass<gnss::Message_NMEA_GGA>()
395  GPS_b1->getMsgByClass<gnss::Message_NMEA_GGA>()
396  .fields.altitude_meters);
397 
398  new_gps->timestamp =
400  (GPS_a1->timestamp.time_since_epoch()
401  .count() +
402  GPS_b1->timestamp.time_since_epoch()
403  .count()) /
404  2));
405 
406  it->second[new_gps->sensorLabel] = new_gps;
407  }
408  }
409  }
410  } // end loop interpolate 1-out-of-5
411  }
412 
413 #if MRPT_HAS_WXWIDGETS
414  wxProgressDialog* progDia3 = nullptr;
415  if (isGUI)
416  {
417  progDia3 = new wxProgressDialog(
418  wxT("Building map"), wxT("Estimating 6D path..."),
419  N_GPSs, // range
420  nullptr, // parent
421  wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_AUTO_HIDE |
422  wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME |
423  wxPD_REMAINING_TIME);
424  }
425 #endif
426 
427  int idx_in_GPSs = 0;
428 
429  for (auto i = list_gps_obs.begin(); i != list_gps_obs.end();
430  ++i, idx_in_GPSs++)
431  {
432  // Now check if we have 3 gps with the same time stamp:
433  if (i->second.size() >= 3)
434  {
435  const size_t N = i->second.size();
436  std::map<std::string, CObservationGPS::Ptr>& GPS = i->second;
437  CVectorDouble X(N), Y(N), Z(N); // Global XYZ coordinates
438  std::map<string, size_t>
439  XYZidxs; // Sensor label -> indices in X Y Z
440 
441  if (!ref_valid) // get the reference lat/lon, if it's not set
442  // from rawlog configuration block.
443  {
444  ref_valid = true;
445  ref = GPS.begin()
446  ->second->getMsgByClass<gnss::Message_NMEA_GGA>()
447  .getAsStruct<TGeodeticCoords>();
448  }
449 
450  // Compute the XYZ coordinates of all sensors:
451  TMatchingPairList corrs;
452  unsigned int k;
453  std::map<std::string, CObservationGPS::Ptr>::iterator g_it;
454 
455  for (k = 0, g_it = GPS.begin(); g_it != GPS.end(); ++g_it, ++k)
456  {
457  TPoint3D P;
459  g_it->second->getMsgByClass<gnss::Message_NMEA_GGA>()
461  P, ref);
462 
463  // Correction of offsets:
464  const string sect =
465  string("OFFSET_") + g_it->second->sensorLabel;
466  P.x += memFil.read_double(sect, "x", 0);
467  P.y += memFil.read_double(sect, "y", 0);
468  P.z += memFil.read_double(sect, "z", 0);
469 
470  XYZidxs[g_it->second->sensorLabel] =
471  k; // Save index correspondence
472 
473  // Create the correspondence:
474  corrs.push_back(TMatchingPair(
475  k, k, // Indices
476  P.x, P.y, P.z, // "This"/Global coords
477  g_it->second->sensorPose.x(),
478  g_it->second->sensorPose.y(),
479  g_it->second->sensorPose
480  .z() // "other"/local coordinates
481  ));
482 
483  X[k] = P.x;
484  Y[k] = P.y;
485  Z[k] = P.z;
486  }
487 
488  if (doConsistencyCheck && GPS.size() == 3)
489  {
490  // XYZ[k] have the k'd final coordinates of each GPS
491  // GPS[k] are the CObservations:
492 
493  // Compute the inter-GPS square distances:
494  CVectorDouble iGPSdist2(3);
495 
496  // [0]: sq dist between:
497  // D_cov_rev_indexes[0],D_cov_rev_indexes[1]
498  TPoint3D P0(
499  X[XYZidxs[D_cov_rev_indexes[0]]],
500  Y[XYZidxs[D_cov_rev_indexes[0]]],
501  Z[XYZidxs[D_cov_rev_indexes[0]]]);
502  TPoint3D P1(
503  X[XYZidxs[D_cov_rev_indexes[1]]],
504  Y[XYZidxs[D_cov_rev_indexes[1]]],
505  Z[XYZidxs[D_cov_rev_indexes[1]]]);
506  TPoint3D P2(
507  X[XYZidxs[D_cov_rev_indexes[2]]],
508  Y[XYZidxs[D_cov_rev_indexes[2]]],
509  Z[XYZidxs[D_cov_rev_indexes[2]]]);
510 
511  iGPSdist2[0] = P0.sqrDistanceTo(P1);
512  iGPSdist2[1] = P0.sqrDistanceTo(P2);
513  iGPSdist2[2] = P1.sqrDistanceTo(P2);
514 
515  double mahaD = mrpt::math::mahalanobisDistance(
516  iGPSdist2, D_mean, D_cov_1);
517  outInfoTemp.mahalabis_quality_measure[i->first] = mahaD;
518 
519  // cout << "x: " << iGPSdist2 << " MU: " << D_mean << " ->
520  // " << mahaD << endl;
521  } // end consistency
522 
523  // Use a 6D matching method to estimate the location of the
524  // vehicle:
525  CPose3DQuat optimal_pose;
526  double optimal_scale;
527 
528  // "this" (reference map) -> GPS global coordinates
529  // "other" -> GPS local coordinates on the vehicle
531  corrs, optimal_pose, optimal_scale, true); // Force scale=1
532  // cout << "optimal pose: " << optimal_pose << " " <<
533  // optimal_scale << endl;
534  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.x());
535  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.y());
536  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.z());
537  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.quat().x());
538  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.quat().y());
539  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.quat().z());
540  MRPT_CHECK_NORMAL_NUMBER(optimal_pose.quat().r());
541 
542  // Final vehicle pose:
543  const CPose3D veh_pose = CPose3D(optimal_pose);
544 
545  // Add to the interpolator:
546  robot_path.insert(i->first, veh_pose);
547 
548  // If we have W_star, compute the pose uncertainty:
549  if (doUncertaintyCovs)
550  {
551  CPose3DPDFGaussian final_veh_uncert;
552  final_veh_uncert.mean.setFromValues(0, 0, 0, 0, 0, 0);
553  final_veh_uncert.cov = outInfoTemp.W_star;
554 
555  // Rotate the covariance according to the real vehicle pose:
556  final_veh_uncert.changeCoordinatesReference(veh_pose);
557 
558  outInfoTemp.vehicle_uncertainty[i->first] =
559  final_veh_uncert.cov;
560  }
561  }
562 
563  // Show progress:
564  if ((count++ % 100) == 0)
565  {
566 #if MRPT_HAS_WXWIDGETS
567  if (progDia3)
568  {
569  if (!progDia3->Update(idx_in_GPSs)) abort = true;
570  wxTheApp->Yield();
571  }
572 #endif
573  }
574  } // end for i
575 
576 #if MRPT_HAS_WXWIDGETS
577  if (progDia3)
578  {
579  delete progDia3;
580  progDia3 = nullptr;
581  }
582 #endif
583 
584  if (PATH_SMOOTH_FILTER > 0 && robot_path.size() > 1)
585  {
586  CPose3DInterpolator filtered_robot_path = robot_path;
587 
588  // Do Angles smoother filter of the path:
589  // ---------------------------------------------
590  const double MAX_DIST_TO_FILTER = 4.0;
591 
592  for (auto i = robot_path.begin(); i != robot_path.end(); ++i)
593  {
594  mrpt::math::TPose3D p = i->second;
595 
596  CVectorDouble pitchs, rolls; // The elements to average
597 
598  pitchs.push_back(p.pitch);
599  rolls.push_back(p.roll);
600 
601  auto q = i;
602  for (int k = 0;
603  k < PATH_SMOOTH_FILTER && q != robot_path.begin(); k++)
604  {
605  --q;
606  if (abs(mrpt::system::timeDifference(q->first, i->first)) <
607  MAX_DIST_TO_FILTER)
608  {
609  pitchs.push_back(q->second.pitch);
610  rolls.push_back(q->second.roll);
611  }
612  }
613  q = i;
614  for (int k = 0;
615  k < PATH_SMOOTH_FILTER && q != (--robot_path.end()); k++)
616  {
617  ++q;
618  if (abs(mrpt::system::timeDifference(q->first, i->first)) <
619  MAX_DIST_TO_FILTER)
620  {
621  pitchs.push_back(q->second.pitch);
622  rolls.push_back(q->second.roll);
623  }
624  }
625 
626  p.pitch = mrpt::math::averageWrap2Pi(pitchs);
627  p.roll = mrpt::math::averageWrap2Pi(rolls);
628 
629  // save in filtered path:
630  filtered_robot_path.insert(i->first, p);
631  }
632  // Replace:
633  robot_path = filtered_robot_path;
634 
635  } // end PATH_SMOOTH_FILTER
636 
637  } // end step generate 6D path
638 
639  // Here we can set best_gps_path (that with the max. number of RTK
640  // fixed/foat readings):
641  if (outInfo)
642  {
643  string bestLabel;
644  size_t bestNum = 0;
645  for (auto& GPS_RTK_read : GPS_RTK_reads)
646  {
647  if (GPS_RTK_read.second > bestNum)
648  {
649  bestNum = GPS_RTK_read.second;
650  bestLabel = GPS_RTK_read.first;
651  }
652  }
653  outInfoTemp.best_gps_path = gps_paths[bestLabel];
654 
655  // and transform to XYZ:
656  // Correction of offsets:
657  const string sect = string("OFFSET_") + bestLabel;
658  const double off_X = memFil.read_double(sect, "x", 0);
659  const double off_Y = memFil.read_double(sect, "y", 0);
660  const double off_Z = memFil.read_double(sect, "z", 0);
661 
662  // map<TTimeStamp,TPoint3D> best_gps_path; // time -> 3D local
663  // coords
664  for (auto& i : outInfoTemp.best_gps_path)
665  {
666  TPoint3D P;
667  TPoint3D& pl = i.second;
670  pl.x, pl.y, pl.z), // i->second.x,i->second.y,i->second.z,
671  // // lat, lon, heigh
672  P, // X Y Z
673  ref);
674 
675  pl.x = P.x + off_X;
676  pl.y = P.y + off_Y;
677  pl.z = P.z + off_Z;
678  }
679  } // end best_gps_path
680 
681  if (outInfo) *outInfo = outInfoTemp;
682 
683  MRPT_END
684 }
mrpt::math::CQuaternionDouble & quat()
Read/Write access to the quaternion representing the 3D rotation.
Definition: CPose3DQuat.h:58
std::chrono::duration< rep, period > duration
Definition: Clock.h:25
This class implements a config file-like interface over a memory-stored string list.
GLuint GLuint GLsizei count
Definition: glext.h:3532
double averageWrap2Pi(const CVectorDouble &angles)
Computes the average of a sequence of angles in radians taking into account the correct wrapping in t...
Definition: math.cpp:316
uint8_t fix_quality
NMEA standard values: 0 = invalid, 1 = GPS fix (SPS), 2 = DGPS fix, 3 = PPS fix, 4 = Real Time Kinema...
#define MRPT_START
Definition: exceptions.h:241
CPose3D mean
The mean value.
double x
X,Y,Z coordinates.
Definition: TPoint3D.h:83
double latitude_degrees
The measured latitude, in degrees (North:+ , South:-)
std::chrono::time_point< Clock > time_point
Definition: Clock.h:26
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
GLenum GLint ref
Definition: glext.h:4062
T y() const
Return y coordinate of the quaternion.
Definition: CQuaternion.h:89
GLint * first
Definition: glext.h:3833
void read_matrix(const std::string &section, const std::string &name, MATRIX_TYPE &outMatrix, const MATRIX_TYPE &defaultMatrix=MATRIX_TYPE(), bool failIfNotFound=false) const
Reads a configuration parameter as a matrix written in a matlab-like format - for example: "[2 3 4 ; ...
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3727
A set of geodetic coordinates: latitude, longitude and height, defined over a given geoid (typically...
Definition: data_types.h:192
STL namespace.
GLdouble s
Definition: glext.h:3682
void geodeticToENU_WGS84(const TGeodeticCoords &in_coords, mrpt::math::TPoint3D &out_ENU_point, const TGeodeticCoords &in_coords_origin)
Coordinates transformation from longitude/latitude/height to ENU (East-North-Up) X/Y/Z coordinates Th...
void setInterpolationMethod(TInterpolatorMethod method)
Change the method used to interpolate the robot path.
Used to return optional information from mrpt::topography::path_from_rtk_gps.
void push_back(const T &val)
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
double altitude_meters
The measured altitude, in meters (A).
This base provides a set of functions for maths stuff.
T r() const
Return r coordinate of the quaternion.
Definition: CQuaternion.h:85
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:84
#define MRPT_CHECK_NORMAL_NUMBER(v)
Throws an exception if the number is NaN, IND, or +/-INF, or return the same number otherwise...
Definition: exceptions.h:125
CObservation::Ptr getAsObservation(size_t index) const
Returns the i&#39;th element in the sequence, as being an observation, where index=0 is the first object...
Definition: CRawlog.cpp:102
std::map< mrpt::Clock::time_point, mrpt::math::CMatrixDouble66 > vehicle_uncertainty
The 6x6 covariance matrix for the uncertainty of each vehicle pose (may be empty if there is no W_sta...
double distanceTo(const TPoint3D &p) const
Point-to-point distance.
Definition: TPoint3D.h:162
A list of TMatchingPair.
Definition: TMatchingPair.h:70
double longitude_degrees
The measured longitude, in degrees (East:+ , West:-)
This class stores a rawlog (robotic datasets) in one of two possible formats:
Definition: CRawlog.h:65
This namespace contains representation of robot actions and observations.
double read_double(const std::string &section, const std::string &name, double defaultValue, bool failIfNotFound=false) const
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:45
Derived inverse_LLt() const
Returns the inverse of a symmetric matrix using LLt.
GLsizei const GLchar ** string
Definition: glext.h:4116
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
A structure for holding correspondences between two sets of points or points-like entities in 2D or 3...
Definition: TMatchingPair.h:31
mrpt::math::CMatrixDouble66 cov
The 6x6 covariance matrix.
void setMaxTimeInterpolation(const mrpt::Clock::duration &time)
Set value of the maximum time to consider interpolation.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
T x() const
Return x coordinate of the quaternion.
Definition: CQuaternion.h:87
GLfloat GLfloat v1
Definition: glext.h:4121
void clear()
Clears the current sequence of poses.
void path_from_rtk_gps(mrpt::poses::CPose3DInterpolator &robot_path, const mrpt::obs::CRawlog &rawlog, size_t rawlog_first, size_t rawlog_last, bool isGUI=false, bool disableGPSInterp=false, int path_smooth_filter_size=2, TPathFromRTKInfo *outInfo=nullptr)
Reconstruct the path of a vehicle equipped with 3 RTK GPSs.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:84
double sqrDistanceTo(const TPoint3D &p) const
Point-to-point distance, squared.
Definition: TPoint3D.h:169
GLfloat v0
Definition: glext.h:4119
std::set< T > make_set(const T &v0, const T &v1)
std::map< mrpt::Clock::time_point, mrpt::math::TPoint3D > best_gps_path
the path of the "best" GPS.
mrpt::math::CMatrixDouble W_star
The reference covariance matrix used to compute vehicle_uncertainty.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
#define MRPT_END
Definition: exceptions.h:245
VECTORLIKE1::Scalar mahalanobisDistance(const VECTORLIKE1 &X, const VECTORLIKE2 &MU, const MAT &COV)
Computes the mahalanobis distance of a vector X given the mean MU and the covariance inverse COV_inv ...
Definition: data_utils.h:57
TGEODETICCOORDS getAsStruct() const
Return the geodetic coords as a mrpt::topography::TGeodeticCoords structure (requires linking against...
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
Definition: CPose3D.cpp:256
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:23
content_t fields
Message content, accesible by individual fields.
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
bool se3_l2(const mrpt::tfest::TMatchingPairList &in_correspondences, mrpt::poses::CPose3DQuat &out_transform, double &out_scale, bool forceScaleToUnity=false)
Least-squares (L2 norm) solution to finding the optimal SE(3) transform between two reference frames ...
Definition: se3_l2.cpp:218
This class stores a time-stamped trajectory in SE(3) (CPose3D poses).
std::map< mrpt::Clock::time_point, double > mahalabis_quality_measure
A measure of the quality at each point (may be empty if not there is no enough information).
TEntryType getType(size_t index) const
Returns the type of a given element.
Definition: CRawlog.cpp:127
void insert(const mrpt::Clock::time_point &t, const pose_t &p)
Inserts a new pose in the sequence.
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
double timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
Definition: datetime.h:123
void resize(std::size_t N, bool zeroNewElements=false)
Lightweight 3D point.
Definition: TPoint3D.h:90
This namespace provides topography helper functions, coordinate transformations.
Definition: conversions.h:21
This class stores messages from GNSS or GNSS+IMU devices, from consumer-grade inexpensive GPS receive...
T z() const
Return z coordinate of the quaternion.
Definition: CQuaternion.h:91
size_t size() const
Returns the number of actions / observations object in the sequence.
Definition: CRawlog.cpp:85
Functions for estimating the optimal transformation between two frames of references given measuremen...
GLfloat GLfloat p
Definition: glext.h:6398
void getCommentTextAsConfigFile(mrpt::config::CConfigFileMemory &memCfg) const
Saves the block of comment text for the rawlog into the passed config file object.
Definition: CRawlog.cpp:548
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 6902d6456 Fri Jun 14 09:26:43 2019 +0200 at vie jun 14 09:30:16 CEST 2019