Main MRPT website > C++ reference for MRPT 1.9.9
CObservationBeaconRanges.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 
12 #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 /** Default constructor.
24  */
26  : minSensorDistance(0),
27  maxSensorDistance(1e2f),
28  stdError(1e-2f),
29  sensedData(),
30  auxEstimatePose()
31 {
32 }
33 
34 /*---------------------------------------------------------------
35  Implements the writing to a CStream capability of CSerializable objects
36  ---------------------------------------------------------------*/
38  mrpt::utils::CStream& out, int* version) const
39 {
40  if (version)
41  *version = 3;
42  else
43  {
44  uint32_t i, n;
45 
46  // The data
47  out << minSensorDistance << maxSensorDistance << stdError;
48 
49  n = sensedData.size();
50  out << n;
51  for (i = 0; i < n; i++)
52  out << sensedData[i].sensorLocationOnRobot
53  << sensedData[i].sensedDistance << sensedData[i].beaconID;
54 
55  out << auxEstimatePose;
56 
57  out << sensorLabel << timestamp;
58  }
59 }
60 
61 /*---------------------------------------------------------------
62  Implements the reading from a CStream capability of CSerializable objects
63  ---------------------------------------------------------------*/
65  mrpt::utils::CStream& in, int version)
66 {
67  switch (version)
68  {
69  case 0:
70  case 1:
71  case 2:
72  case 3:
73  {
74  uint32_t i, n, id;
75 
76  // The data
77  in >> minSensorDistance >> maxSensorDistance >> stdError;
78 
79  in >> n;
80  sensedData.resize(n);
81  for (i = 0; i < n; i++)
82  {
83  in >> sensedData[i].sensorLocationOnRobot >>
84  sensedData[i].sensedDistance;
85  in >> id;
86  sensedData[i].beaconID = id;
87  }
88 
89  if (version >= 1) in >> auxEstimatePose;
90 
91  if (version >= 2)
92  in >> sensorLabel;
93  else
94  sensorLabel = "";
95 
96  if (version >= 3)
97  in >> timestamp;
98  else
99  timestamp = INVALID_TIMESTAMP;
100  }
101  break;
102  default:
104  };
105 }
106 
107 /*---------------------------------------------------------------
108  Implements the writing to a CStream capability of CSerializable objects
109  ---------------------------------------------------------------*/
111 {
112  printf("[CObservationBeaconRanges::debugPrintOut] Dumping:\n");
113  printf(
114  "[CObservationBeaconRanges::debugPrintOut] minSensorDistance:\t%f\n",
115  minSensorDistance);
116  printf(
117  "[CObservationBeaconRanges::debugPrintOut] maxSensorDistance:\t%f:\n",
118  maxSensorDistance);
119  printf(
120  "[CObservationBeaconRanges::debugPrintOut] stdError:\t%f\n", stdError);
121  printf(
122  "[CObservationBeaconRanges::debugPrintOut] %u ranges:\n",
123  static_cast<unsigned>(sensedData.size()));
124 
125  size_t i, n = sensedData.size();
126  for (i = 0; i < n; i++)
127  printf(
128  "[CObservationBeaconRanges::debugPrintOut] \tID[%u]: %f\n",
129  sensedData[i].beaconID, sensedData[i].sensedDistance);
130 }
131 
132 /*---------------------------------------------------------------
133  getSensorPose
134  ---------------------------------------------------------------*/
136 {
137  if (!sensedData.empty())
138  out_sensorPose = CPose3D(sensedData[0].sensorLocationOnRobot);
139  else
140  out_sensorPose = CPose3D(0, 0, 0);
141 }
142 
143 /*---------------------------------------------------------------
144  setSensorPose
145  ---------------------------------------------------------------*/
147 {
148  size_t i, n = sensedData.size();
149  if (n)
150  for (i = 0; i < n; i++)
151  sensedData[i].sensorLocationOnRobot = CPoint3D(newSensorPose);
152 }
153 
154 /*---------------------------------------------------------------
155  getSensedRangeByBeaconID
156  ---------------------------------------------------------------*/
158 {
159  for (size_t i = 0; i < sensedData.size(); i++)
160  if (sensedData[i].beaconID == beaconID)
161  return sensedData[i].sensedDistance;
162  return 0;
163 }
164 
166 {
167  using namespace std;
169 
170  o << "Auxiliary estimated pose (if available): " << auxEstimatePose << endl;
171 
172  o << format("minSensorDistance=%f m\n", minSensorDistance);
173  o << format("maxSensorDistance=%f m\n", maxSensorDistance);
174  o << format("stdError=%f m\n\n", stdError);
175 
176  o << format(
177  "There are %u range measurements:\n\n", (unsigned)sensedData.size());
178 
179  o << " BEACON RANGE SENSOR POSITION ON ROBOT \n";
180  o << "------------------------------------------------\n";
182  sensedData.begin();
183  it != sensedData.end(); it++)
184  {
185  o << format(
186  " %i %.04f (%.03f,%.03f,%.03f)\n", (int)it->beaconID,
187  it->sensedDistance, it->sensorLocationOnRobot.x(),
188  it->sensorLocationOnRobot.y(), it->sensorLocationOnRobot.z());
189  }
190 }
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
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...
GLenum GLsizei n
Definition: glext.h:5074
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Declares a class derived from "CObservation" that represents one (or more) range measurements to labe...
STL namespace.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
float getSensedRangeByBeaconID(int32_t beaconID)
Easy look-up into the vector sensedData, returns the range for a given beacon, or 0 if the beacon is ...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#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
A class used to store a 3D point.
Definition: CPoint3D.h:32
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:16
__int32 int32_t
Definition: rptypes.h:46
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:41
GLuint id
Definition: glext.h:3909
GLuint in
Definition: glext.h:7274
void debugPrintOut()
Prints out the contents of the object.
unsigned __int32 uint32_t
Definition: rptypes.h:47
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
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