Main MRPT website > C++ reference for MRPT 1.9.9
CObservationOdometry.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 "obs-precomp.h" // Precompiled headers
11 
13 #include <mrpt/utils/CStream.h>
14 #include <mrpt/system/os.h>
15 
16 using namespace mrpt::obs;
17 using namespace mrpt::utils;
18 using namespace mrpt::poses;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 /** Constructor
24  */
26  : odometry(),
27  hasEncodersInfo(false),
28  encoderLeftTicks(0),
29  encoderRightTicks(0),
30  hasVelocities(false),
31  velocityLocal(.0, .0, .0)
32 {
33 }
34 
35 /*---------------------------------------------------------------
36  Implements the writing to a CStream capability of CSerializable objects
37  ---------------------------------------------------------------*/
39  mrpt::utils::CStream& out, int* version) const
40 {
41  MRPT_UNUSED_PARAM(out);
42  if (version)
43  *version = 2;
44  else
45  {
46  // The data
47  out << odometry << sensorLabel << timestamp
48  // Added in V1:
49  << hasEncodersInfo;
50  if (hasEncodersInfo) out << encoderLeftTicks << encoderRightTicks;
51 
52  out << hasVelocities;
53  if (hasVelocities) out << velocityLocal;
54  }
55 }
56 
57 /*---------------------------------------------------------------
58  Implements the reading from a CStream capability of CSerializable objects
59  ---------------------------------------------------------------*/
61 {
63  switch (version)
64  {
65  case 0:
66  case 1:
67  case 2:
68  {
69  in >> odometry >> sensorLabel >> timestamp;
70 
71  if (version >= 1)
72  {
73  in >> hasEncodersInfo;
74  if (hasEncodersInfo || version < 2)
75  in >> encoderLeftTicks >> encoderRightTicks;
76 
77  in >> hasVelocities;
78  if (version < 2)
79  {
80  float vx, w;
81  in >> vx >> w;
82  velocityLocal.vx = vx;
83  velocityLocal.vy = .0;
84  velocityLocal.omega = w;
85  }
86  else
87  { // v2
88  if (hasVelocities) in >> velocityLocal;
89  }
90  }
91  else
92  {
93  hasEncodersInfo = false;
94  encoderLeftTicks = encoderRightTicks = 0;
95  hasVelocities = false;
96  }
97  }
98  break;
99  default:
101  };
102 }
103 
105 {
107 
108  o << std::endl << "Odometry reading: " << odometry << std::endl;
109 
110  // Additional data:
111  if (hasEncodersInfo)
112  {
113  o << format(
114  " Encoder info: deltaL=%i deltaR=%i\n", encoderLeftTicks,
115  encoderRightTicks);
116  }
117  else
118  o << "Encoder info: Not available!\n";
119 
120  if (hasVelocities)
121  {
122  o << format("Velocity info: %s\n", velocityLocal.asString().c_str());
123  }
124  else
125  o << "Velocity info: Not available!\n";
126 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This namespace contains representation of robot actions and observations.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:19
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...
Definition: CPoint.h:17
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint in
Definition: glext.h:7274
An observation of the current (cumulative) odometry for a wheeled robot.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
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...
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 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019