MRPT  2.0.2
CObservationOdometry.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-2020, 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 "obs-precomp.h" // Precompiled headers
11 
14 #include <mrpt/system/os.h>
15 
16 using namespace mrpt::obs;
17 using namespace mrpt::poses;
18 
19 // This must be added to any CSerializable class implementation file.
21 
22 /** Constructor
23  */
25  : odometry(),
26 
27  velocityLocal(.0, .0, .0)
28 {
29 }
30 
31 uint8_t CObservationOdometry::serializeGetVersion() const { return 2; }
33 {
34  // The data
35  out << odometry << sensorLabel
36  << timestamp
37  // Added in V1:
38  << hasEncodersInfo;
39  if (hasEncodersInfo) out << encoderLeftTicks << encoderRightTicks;
40  out << hasVelocities;
41  if (hasVelocities) out << velocityLocal;
42 }
43 
45  mrpt::serialization::CArchive& in, uint8_t version)
46 {
47  switch (version)
48  {
49  case 0:
50  case 1:
51  case 2:
52  {
53  in >> odometry >> sensorLabel >> timestamp;
54 
55  if (version >= 1)
56  {
57  in >> hasEncodersInfo;
58  if (hasEncodersInfo || version < 2)
59  in >> encoderLeftTicks >> encoderRightTicks;
60 
61  in >> hasVelocities;
62  if (version < 2)
63  {
64  float vx, w;
65  in >> vx >> w;
66  velocityLocal.vx = vx;
67  velocityLocal.vy = .0;
68  velocityLocal.omega = w;
69  }
70  else
71  { // v2
72  if (hasVelocities) in >> velocityLocal;
73  }
74  }
75  else
76  {
77  hasEncodersInfo = false;
78  encoderLeftTicks = encoderRightTicks = 0;
79  hasVelocities = false;
80  }
81  }
82  break;
83  default:
85  };
86 }
87 
88 void CObservationOdometry::getDescriptionAsText(std::ostream& o) const
89 {
91 
92  o << std::endl << "Odometry reading: " << odometry << std::endl;
93 
94  // Additional data:
95  if (hasEncodersInfo)
96  {
97  o << format(
98  " Encoder info: deltaL=%i deltaR=%i\n", encoderLeftTicks,
99  encoderRightTicks);
100  }
101  else
102  o << "Encoder info: Not available!\n";
103 
104  if (hasVelocities)
105  {
106  o << format("Velocity info: %s\n", velocityLocal.asString().c_str());
107  }
108  else
109  o << "Velocity info: Not available!\n";
110 }
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
This namespace contains representation of robot actions and observations.
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
An observation of the current (cumulative) odometry for a wheeled robot.
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020