Main MRPT website > C++ reference for MRPT 1.5.6
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), encoderRightTicks(0),
29  hasVelocities(false),
30  velocityLocal(.0, .0, .0)
31 {
32 }
33 
34 
35 /*---------------------------------------------------------------
36  Implements the writing to a CStream capability of CSerializable objects
37  ---------------------------------------------------------------*/
39 {
40  MRPT_UNUSED_PARAM(out);
41  if (version)
42  *version = 2;
43  else
44  {
45  // The data
46  out << odometry
47  << sensorLabel
48  << timestamp
49  // Added in V1:
50  << hasEncodersInfo;
51  if (hasEncodersInfo)
52  out << encoderLeftTicks << encoderRightTicks;
53 
54  out << hasVelocities;
55  if (hasVelocities)
56  out << velocityLocal;
57  }
58 }
59 
60 /*---------------------------------------------------------------
61  Implements the reading from a CStream capability of CSerializable objects
62  ---------------------------------------------------------------*/
64 {
66  switch(version)
67  {
68  case 0:
69  case 1:
70  case 2:
71  {
72  in >> odometry
73  >> sensorLabel
74  >> timestamp;
75 
76  if (version>=1)
77  {
78  in >> hasEncodersInfo;
79  if (hasEncodersInfo || version < 2)
80  in >> encoderLeftTicks >> encoderRightTicks;
81 
82  in >> hasVelocities;
83  if (version < 2) {
84  float vx, w;
85  in >> vx >> w;
86  velocityLocal.vx = vx;
87  velocityLocal.vy = .0;
88  velocityLocal.omega = w;
89  }
90  else
91  {// v2
92  if (hasVelocities)
93  in >> velocityLocal;
94  }
95  }
96  else
97  {
98  hasEncodersInfo = false;
99  encoderLeftTicks = encoderRightTicks = 0;
100  hasVelocities = false;
101  }
102 
103  } break;
104  default:
106 
107  };
108 }
109 
111 {
113 
114  o << std::endl << "Odometry reading: " << odometry << std::endl;
115 
116  // Additional data:
117  if (hasEncodersInfo)
118  {
119  o << format(" Encoder info: deltaL=%i deltaR=%i\n", encoderLeftTicks, encoderRightTicks );
120  }
121  else o << "Encoder info: Not available!\n";
122 
123  if (hasVelocities)
124  {
125  o << format("Velocity info: %s\n", velocityLocal.asString().c_str());
126  }
127  else o << "Velocity info: Not available!\n";
128 
129 }
130 
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1797
GLuint in
Definition: glew.h:7146
virtual void getDescriptionAsText(std::ostream &o) const
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
#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.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
int version
Definition: mrpt_jpeglib.h:898
void getDescriptionAsText(std::ostream &o) const MRPT_OVERRIDE
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Declares a class that represents any robot's observation.
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
An observation of the current (cumulative) odometry for a wheeled robot.



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018