Main MRPT website > C++ reference for MRPT 1.9.9
CLogFileRecord.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "nav-precomp.h" // Precomp header
11 
13 #include <mrpt/poses/CPoint2D.h>
14 #include <mrpt/utils/CStream.h>
18 
19 using namespace mrpt::nav;
20 
22 
23 /*---------------------------------------------------------------
24  Constructor
25  ---------------------------------------------------------------*/
27  : nPTGs(0),
28  nSelectedPTG(-1),
29  robotPoseLocalization(0, 0, 0),
30  robotPoseOdometry(0, 0, 0),
31  relPoseSense(0, 0, 0),
32  relPoseVelCmd(0, 0, 0),
33  WS_targets_relative(),
34  cur_vel(0, 0, 0),
35  cur_vel_local(0, 0, 0),
36  robotShape_radius(.0),
37  ptg_index_NOP(-1),
38  ptg_last_k_NOP(0),
39  rel_cur_pose_wrt_last_vel_cmd_NOP(0, 0, 0),
40  rel_pose_PTG_origin_wrt_sense_NOP(0, 0, 0)
41 {
42  infoPerPTG.clear();
43  WS_Obstacles.clear();
44 }
45 
46 /*---------------------------------------------------------------
47  writeToStream
48  ---------------------------------------------------------------*/
50  mrpt::utils::CStream& out, int* version) const
51 {
52  if (version)
53  *version = 26;
54  else
55  {
56  uint32_t i, n;
57 
58  // Version 0 ---------
59  n = infoPerPTG.size();
60  out << n;
61  for (i = 0; i < n; i++)
62  {
63  out << infoPerPTG[i].PTG_desc.c_str();
64 
65  uint32_t m = infoPerPTG[i].TP_Obstacles.size();
66  out << m;
67  if (m)
68  out.WriteBuffer(
69  (const void*)&(*infoPerPTG[i].TP_Obstacles.begin()),
70  m * sizeof(infoPerPTG[i].TP_Obstacles[0]));
71 
72  out << infoPerPTG[i]
73  .TP_Targets; // v8: CPoint2D -> TPoint2D. v26: vector
74  out << infoPerPTG[i].TP_Robot; // v17
75  out << infoPerPTG[i].timeForTPObsTransformation
76  << infoPerPTG[i].timeForHolonomicMethod; // made double in v12
77  out << infoPerPTG[i].desiredDirection << infoPerPTG[i].desiredSpeed
78  << infoPerPTG[i].evaluation; // made double in v12
79  // removed in v23: out << evaluation_org << evaluation_priority; //
80  // added in v21
81  out << infoPerPTG[i].HLFR;
82 
83  // Version 9: Removed security distances. Added optional field with
84  // PTG info.
85  const bool there_is_ptg_data = infoPerPTG[i].ptg ? true : false;
86  out << there_is_ptg_data;
87  if (there_is_ptg_data) out << infoPerPTG[i].ptg;
88 
89  // Was: out << infoPerPTG[i].clearance.raw_clearances; // v19
90  infoPerPTG[i].clearance.writeToStream(out); // v25
91  }
92  out << nSelectedPTG << WS_Obstacles;
93  out << WS_Obstacles_original; // v20
94 
95  // Removed v24: out << robotOdometryPose;
97 
98  out << WS_targets_relative; // v8, v26: vector
99  // v16:
100  out << ptg_index_NOP << ptg_last_k_NOP;
102  << rel_pose_PTG_origin_wrt_sense_NOP; // v24: CPose2D->TPose2D
103 
104  // Removed: v24. out << ptg_last_curRobotVelLocal; // v17
106 
107  if (ptg_index_NOP < 0)
108  out << cmd_vel /*v10*/ << cmd_vel_original; // v15
109 
110  // Previous values: REMOVED IN VERSION #6
111  n = robotShape_x.size();
112  out << n;
113  if (n)
114  {
115  out.WriteBuffer(
116  (const void*)&(*robotShape_x.begin()),
117  n * sizeof(robotShape_x[0]));
118  out.WriteBuffer(
119  (const void*)&(*robotShape_y.begin()),
120  n * sizeof(robotShape_y[0]));
121  }
122 
123  // Version 1 ---------
124  out << cur_vel << cur_vel_local; /*v10*/
125  // out << estimatedExecutionPeriod; // removed v13
126 
127  // Version 3 ----------
128  for (i = 0; i < infoPerPTG.size(); i++)
129  {
130  out << infoPerPTG[i].evalFactors; // v22: this is now a TParameters
131  }
132 
133  out << nPTGs; // v4
134  // out << timestamp; // removed v13
135  out << robotShape_radius; // v11
136  // out << cmd_vel_filterings; // added v12: Removed in v15
137 
138  out << values << timestamps; // v13
139 
140  out << relPoseSense
141  << relPoseVelCmd; // v14, v24 changed CPose2D->TPose2D
142 
143  // v15: cmd_vel converted from std::vector<double> into CSerializable
144  out << additional_debug_msgs; // v18
145 
146  navDynState.writeToStream(out); // v24
147  }
148 }
149 
150 /*---------------------------------------------------------------
151  readFromStream
152  ---------------------------------------------------------------*/
154 {
155  switch (version)
156  {
157  case 0:
158  case 1:
159  case 2:
160  case 3:
161  case 4:
162  case 5:
163  case 6:
164  case 7:
165  case 8:
166  case 9:
167  case 10:
168  case 11:
169  case 12:
170  case 13:
171  case 14:
172  case 15:
173  case 16:
174  case 17:
175  case 18:
176  case 19:
177  case 20:
178  case 21:
179  case 22:
180  case 23:
181  case 24:
182  case 25:
183  case 26:
184  {
185  // Version 0 --------------
186  uint32_t i, n;
187 
188  infoPerPTG.clear();
189 
190  in >> n;
191  infoPerPTG.resize(n);
192  for (i = 0; i < n; i++)
193  {
194  auto& ipp = infoPerPTG[i];
195  char str[256];
196  in >> str;
197  ipp.PTG_desc = std::string(str);
198 
199  int32_t m;
200  in >> m;
201  ipp.TP_Obstacles.resize(m);
202  if (m)
203  in.ReadBufferFixEndianness(&(*ipp.TP_Obstacles.begin()), m);
204 
205  ipp.TP_Targets.clear();
206  if (version >= 8)
207  {
208  if (version >= 26)
209  {
210  in >> ipp.TP_Targets;
211  }
212  else
213  {
215  in >> trg;
216  ipp.TP_Targets.push_back(trg);
217  }
218  }
219  else
220  {
222  in >> pos;
223  ipp.TP_Targets.push_back(mrpt::math::TPoint2D(pos));
224  }
225  if (version >= 17)
226  in >> ipp.TP_Robot;
227  else
228  ipp.TP_Robot = mrpt::math::TPoint2D(0, 0);
229 
230  if (version >= 12)
231  {
232  in >> ipp.timeForTPObsTransformation >>
233  ipp.timeForHolonomicMethod;
234  in >> ipp.desiredDirection >> ipp.desiredSpeed >>
235  ipp.evaluation;
236  }
237  else
238  {
239  in.ReadAsAndCastTo<float, double>(
240  ipp.timeForTPObsTransformation);
241  in.ReadAsAndCastTo<float, double>(
242  ipp.timeForHolonomicMethod);
243  in.ReadAsAndCastTo<float, double>(ipp.desiredDirection);
244  in.ReadAsAndCastTo<float, double>(ipp.desiredSpeed);
245  in.ReadAsAndCastTo<float, double>(ipp.evaluation);
246  }
247  if (version >= 21 && version < 23)
248  {
249  double evaluation_org, evaluation_priority;
250  in >> evaluation_org >> evaluation_priority;
251  }
252 
253  in >> ipp.HLFR;
254 
255  if (version >= 9) // Extra PTG info
256  {
257  ipp.ptg.reset();
258 
259  bool there_is_ptg_data;
260  in >> there_is_ptg_data;
261  if (there_is_ptg_data)
262  ipp.ptg = std::dynamic_pointer_cast<
263  CParameterizedTrajectoryGenerator>(in.ReadObject());
264  }
265 
266  if (version >= 19)
267  {
268  if (version < 25)
269  {
270  std::vector<std::map<double, double>> raw_clearances;
271  in >> raw_clearances;
272  ipp.clearance.resize(
273  raw_clearances.size(), raw_clearances.size());
274  for (size_t i = 0; i < raw_clearances.size(); i++)
275  ipp.clearance.get_path_clearance_decimated(i) =
276  raw_clearances[i];
277  }
278  else
279  {
280  ipp.clearance.readFromStream(in);
281  }
282  }
283  else
284  {
285  ipp.clearance.clear();
286  }
287  }
288 
290  if (version >= 20)
291  {
292  in >> WS_Obstacles_original; // v20
293  }
294  else
295  {
297  }
298 
299  if (version < 24)
300  {
301  mrpt::poses::CPose2D robotOdometryPose;
302  in >> robotOdometryPose;
303  robotPoseOdometry = robotOdometryPose;
304  robotPoseLocalization = robotOdometryPose;
305  }
306  else
307  {
309  }
310 
311  WS_targets_relative.clear();
312  if (version >= 8)
313  {
314  if (version >= 26)
315  {
317  }
318  else
319  {
321  in >> trg;
322  WS_targets_relative.push_back(trg);
323  }
324  }
325  else
326  {
328  in >> pos;
330  }
331 
332  if (version >= 16)
333  {
335  if (version >= 24)
336  {
339  }
340  else
341  {
342  mrpt::poses::CPose2D crel_cur_pose_wrt_last_vel_cmd_NOP,
343  crel_pose_PTG_origin_wrt_sense_NOP;
344  in >> crel_cur_pose_wrt_last_vel_cmd_NOP >>
345  crel_pose_PTG_origin_wrt_sense_NOP;
347  crel_cur_pose_wrt_last_vel_cmd_NOP;
349  crel_pose_PTG_origin_wrt_sense_NOP;
350  }
351  }
352  else
353  {
354  ptg_index_NOP = -1;
355  }
356  if (version >= 17 && version < 24)
357  {
359  }
360  if (version >= 24)
361  {
363  }
364 
365  if (version >= 10)
366  {
367  if (version >= 15)
368  {
369  if (ptg_index_NOP < 0) in >> cmd_vel;
370  }
371  else
372  {
373  std::vector<double> vel;
374  in >> vel;
375  if (vel.size() == 2)
378  else
381  for (size_t i = 0; i < cmd_vel->getVelCmdLength(); i++)
382  cmd_vel->setVelCmdElement(i, vel[i]);
383  }
384  }
385  else
386  {
387  float v, w;
388  in >> v >> w;
391  cmd_vel->setVelCmdElement(0, v);
392  cmd_vel->setVelCmdElement(0, w);
393  }
394 
395  if (version >= 15 && ptg_index_NOP < 0) in >> cmd_vel_original;
396 
397  if (version < 13)
398  {
399  float old_exec_time;
400  in >> old_exec_time;
401  values["executionTime"] = old_exec_time;
402  }
403 
404  if (version < 6)
405  {
406  mrpt::math::CVectorFloat prevV, prevW, prevSelPTG;
407 
408  // Previous values: (Removed in version 6)
409  in >> n;
410  prevV.resize(n);
411  if (n) in.ReadBufferFixEndianness(&(*prevV.begin()), n);
412 
413  in >> n;
414  prevW.resize(n);
415  if (n) in.ReadBufferFixEndianness(&(*prevW.begin()), n);
416 
417  in >> n;
418  prevSelPTG.resize(n);
419  if (n) in.ReadBufferFixEndianness(&(*prevSelPTG.begin()), n);
420  }
421 
422  in >> n;
423  robotShape_x.resize(n);
424  robotShape_y.resize(n);
425  if (n)
426  {
427  in.ReadBufferFixEndianness(&(*robotShape_x.begin()), n);
428  in.ReadBufferFixEndianness(&(*robotShape_y.begin()), n);
429  }
430 
431  if (version > 0)
432  { // Version 1 --------------
433  if (version >= 10)
434  {
435  in >> cur_vel >> cur_vel_local;
436  }
437  else
438  {
439  float actual_v, actual_w;
440  in >> actual_v >> actual_w;
441  cur_vel = mrpt::math::TTwist2D(0, 0, 0);
442  cur_vel_local =
443  mrpt::math::TTwist2D(actual_v, .0, actual_w);
444  }
445  }
446  else
447  { // Default values for old versions:
448  cur_vel = mrpt::math::TTwist2D(0, 0, 0);
449  }
450 
451  if (version < 13 && version > 1)
452  {
453  float old_estim_period;
454  in >> old_estim_period;
455  values["estimatedExecutionPeriod"] = old_estim_period;
456  }
457 
458  for (i = 0; i < infoPerPTG.size(); i++)
459  {
460  infoPerPTG[i].evalFactors.clear();
461  }
462  if (version > 2)
463  {
464  // Version 3..22 ----------
465  for (i = 0; i < infoPerPTG.size(); i++)
466  {
467  if (version < 22)
468  {
469  in >> n;
470  for (unsigned int j = 0; j < n; j++)
471  {
472  float f;
473  in >> f;
474  infoPerPTG[i].evalFactors[mrpt::format("f%u", j)] =
475  f;
476  }
477  }
478  else
479  {
480  in >> infoPerPTG[i].evalFactors;
481  }
482  }
483  }
484 
485  if (version > 3)
486  {
487  // Version 4 ----------
488  in >> nPTGs;
489  if (version < 9) // Old "securityDistances", now unused.
490  {
491  in >> n;
492  float dummy;
493  for (i = 0; i < n; i++) in >> dummy;
494  }
495  }
496  else
497  {
498  nPTGs = infoPerPTG.size();
499  }
500 
501  if (version > 4)
502  {
503  if (version < 10)
504  {
505  int32_t navigatorBehavior; // removed in v10
506  in >> navigatorBehavior;
507  }
508 
509  if (version < 6) // Removed in version 6:
510  {
511  mrpt::poses::CPoint2D doorCrossing_P1, doorCrossing_P2;
512  in >> doorCrossing_P1 >> doorCrossing_P2;
513  }
514  }
515 
516  if (version > 6 && version < 13)
517  {
519  in >> tt;
520  timestamps["tim_start_iteration"] = tt;
521  }
522 
523  if (version >= 11)
524  {
526  }
527  else
528  {
529  robotShape_radius = 0.5;
530  }
531 
532  if (version >= 12 && version < 15)
533  {
534  std::vector<std::vector<double>> dummy_cmd_vel_filterings;
535  in >> dummy_cmd_vel_filterings;
536  }
537 
538  if (version >= 13)
539  {
540  in >> values >> timestamps;
541  }
542  else
543  {
544  values.clear();
545  timestamps.clear();
546  }
547 
548  if (version >= 14)
549  {
550  if (version >= 24)
551  {
553  }
554  else
555  {
556  mrpt::poses::CPose2D crelPoseSense, crelPoseVelCmd;
557  in >> crelPoseSense >> crelPoseVelCmd;
558  relPoseSense = crelPoseSense;
559  relPoseVelCmd = crelPoseVelCmd;
560  }
561  }
562  else
563  {
565  }
566 
567  if (version >= 18)
569  else
570  additional_debug_msgs.clear();
571 
572  if (version >= 24)
574  else
575  {
576  navDynState =
579  if (!WS_targets_relative.empty())
581  }
582  }
583  break;
584  default:
586  };
587 }
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:32
mrpt::math::TPose2D rel_cur_pose_wrt_last_vel_cmd_NOP
int32_t nSelectedPTG
The selected PTG.
std::vector< mrpt::math::TPose2D > WS_targets_relative
Relative poses (wrt to robotPoseLocalization) for.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
mrpt::math::CVectorFloat robotShape_y
mrpt::math::TTwist2D cur_vel_local
The actual robot velocities in local (robot) coordinates, as read from sensors, in "m/sec" and "rad/s...
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:3582
std::map< std::string, mrpt::system::TTimeStamp > timestamps
Known values:
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
mrpt::math::TPose2D rel_pose_PTG_origin_wrt_sense_NOP
mrpt::math::TPose2D robotPoseOdometry
GLenum GLsizei n
Definition: glext.h:5074
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CStream.cpp:64
mrpt::math::TPose2D relPoseSense
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
uint32_t nPTGs
The number of PTGS:
A class for storing, saving and loading a reactive navigation log record for the CReactiveNavigationS...
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::math::CVectorFloat robotShape_x
The robot shape in WS.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
mrpt::nav::CParameterizedTrajectoryGenerator::TNavDynamicState ptg_last_navDynState
This is the base class for any user-defined PTG.
mrpt::math::TPose2D robotPoseLocalization
The robot pose (from odometry and from the localization/SLAM system).
mrpt::kinematics::CVehicleVelCmd::Ptr cmd_vel
The final motion command sent to robot, in "m/sec" and "rad/sec".
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
mrpt::math::TTwist2D curVelLocal
Current vehicle velocity (local frame of reference)
int16_t ptg_index_NOP
Negative means no NOP mode evaluation, so the rest of "NOP variables" should be ignored.
mrpt::math::TPose2D relTarget
Current relative target location.
mrpt::aligned_containers< TInfoPerPTG >::vector_t infoPerPTG
The info for each applied PTG: must contain "nPTGs * nSecDistances" elements.
mrpt::maps::CSimplePointsMap WS_Obstacles_original
GLsizei const GLchar ** string
Definition: glext.h:4101
A class used to store a 2D point.
Definition: CPoint2D.h:36
__int32 int32_t
Definition: rptypes.h:46
const GLdouble * v
Definition: glext.h:3678
mrpt::nav::CParameterizedTrajectoryGenerator::TNavDynamicState navDynState
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
mrpt::kinematics::CVehicleVelCmd::Ptr cmd_vel_original
Motion command as comes out from the PTG, before scaling speed limit filtering.
mrpt::math::TTwist2D cur_vel
The actual robot velocities in global (map) coordinates, as read from sensors, in "m/sec" and "rad/se...
GLuint in
Definition: glext.h:7274
Lightweight 2D pose.
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
mrpt::maps::CSimplePointsMap WS_Obstacles
The WS-Obstacles.
std::shared_ptr< CVehicleVelCmd > Ptr
unsigned __int32 uint32_t
Definition: rptypes.h:47
Lightweight 2D point.
Dynamic state that may affect the PTG path parameterization.
mrpt::math::TPose2D relPoseVelCmd
Kinematic model for Ackermann-like or differential-driven vehicles.
std::map< std::string, std::string > additional_debug_msgs
Additional debug traces.
double robotShape_radius
The circular robot radius.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019