Main MRPT website > C++ reference for MRPT 1.9.9
CWirelessPowerGridMap2D.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 "maps-precomp.h" // Precomp header
11 
14 #include <mrpt/system/os.h>
15 #include <mrpt/utils/round.h>
16 #include <mrpt/utils/CTicTac.h>
17 #include <mrpt/utils/color_maps.h>
19 #include <mrpt/utils/CStream.h>
20 
21 using namespace mrpt;
22 using namespace mrpt::maps;
23 using namespace mrpt::obs;
24 using namespace mrpt::utils;
25 using namespace mrpt::poses;
26 using namespace std;
27 
28 // =========== Begin of Map definition ============
30  "CWirelessPowerGridMap2D,wifiGrid", mrpt::maps::CWirelessPowerGridMap2D)
31 
33  : min_x(-2),
34  max_x(2),
35  min_y(-2),
36  max_y(2),
37  resolution(0.10f),
38  mapType(CWirelessPowerGridMap2D::mrKernelDM)
39 {
40 }
41 
44  const std::string& sectionNamePrefix)
45 {
46  // [<sectionNamePrefix>+"_creationOpts"]
47  const std::string sSectCreation =
48  sectionNamePrefix + string("_creationOpts");
49  MRPT_LOAD_CONFIG_VAR(min_x, double, source, sSectCreation);
50  MRPT_LOAD_CONFIG_VAR(max_x, double, source, sSectCreation);
51  MRPT_LOAD_CONFIG_VAR(min_y, double, source, sSectCreation);
52  MRPT_LOAD_CONFIG_VAR(max_y, double, source, sSectCreation);
53  MRPT_LOAD_CONFIG_VAR(resolution, double, source, sSectCreation);
55  sSectCreation, "mapType", mapType);
56 
57  insertionOpts.loadFromConfigFile(
58  source, sectionNamePrefix + string("_insertOpts"));
59 }
60 
62  mrpt::utils::CStream& out) const
63 {
64  out.printf(
65  "MAP TYPE = %s\n",
68  .c_str());
69  LOADABLEOPTS_DUMP_VAR(min_x, double);
70  LOADABLEOPTS_DUMP_VAR(max_x, double);
71  LOADABLEOPTS_DUMP_VAR(min_y, double);
72  LOADABLEOPTS_DUMP_VAR(max_y, double);
73  LOADABLEOPTS_DUMP_VAR(resolution, double);
74 
75  this->insertionOpts.dumpToTextStream(out);
76 }
77 
81 {
83  *dynamic_cast<const CWirelessPowerGridMap2D::TMapDefinition*>(&_def);
85  def.mapType, def.min_x, def.max_x, def.min_y, def.max_y,
86  def.resolution);
87  obj->insertionOptions = def.insertionOpts;
88  return obj;
89 }
90 // =========== End of Map definition Block =========
91 
94 
95 /*---------------------------------------------------------------
96  Constructor
97  ---------------------------------------------------------------*/
99  TMapRepresentation mapType, double x_min, double x_max, double y_min,
100  double y_max, double resolution)
101  : CRandomFieldGridMap2D(mapType, x_min, x_max, y_min, y_max, resolution),
102  insertionOptions()
103 {
104  // Set the grid to initial values (and adjusts the KF covariance matrix!)
105  // Also, calling clear() is mandatory to end initialization of our base
106  // class (read note in CRandomFieldGridMap2D::CRandomFieldGridMap2D)
108 }
109 
110 CWirelessPowerGridMap2D::~CWirelessPowerGridMap2D() {}
111 /*---------------------------------------------------------------
112  clear
113  ---------------------------------------------------------------*/
115 {
116  // Just do the generic clear:
118 
119  // Anything else special for this derived class?
120  // ...
121 }
122 
123 /*---------------------------------------------------------------
124  insertObservation
125  ---------------------------------------------------------------*/
127  const CObservation* obs, const CPose3D* robotPose)
128 {
129  MRPT_START
130 
131  CPose2D robotPose2D;
132  CPose3D robotPose3D;
133 
134  if (robotPose)
135  {
136  robotPose2D = CPose2D(*robotPose);
137  robotPose3D = (*robotPose);
138  }
139  else
140  {
141  // Default values are (0,0,0)
142  }
143 
145  {
146  /********************************************************************
147  OBSERVATION TYPE: CObservationWirelessPower
148  ********************************************************************/
149  const CObservationWirelessPower* o =
150  static_cast<const CObservationWirelessPower*>(obs);
151  float sensorReading;
152 
153  // Compute the 3D sensor pose in world coordinates:
154  CPose2D sensorPose = CPose2D(robotPose3D + o->sensorPoseOnRobot);
155 
156  sensorReading = o->power;
157 
158  // Normalization:
159  sensorReading = (sensorReading - insertionOptions.R_min) /
160  (insertionOptions.R_max - insertionOptions.R_min);
161 
162  // Update the gross estimates of mean/vars for the whole reading history
163  // (see IROS2009 paper):
165  (sensorReading +
169  (square(sensorReading - m_average_normreadings_mean) +
173 
174  // Finally, do the actual map update with that value:
176  sensorReading,
177  mrpt::math::TPoint2D(sensorPose.x(), sensorPose.y()));
178 
179  return true; // Done!
180 
181  } // end if "CObservationWirelessPower"
182 
183  return false;
184 
185  MRPT_END
186 }
187 
188 /*---------------------------------------------------------------
189  computeObservationLikelihood
190  ---------------------------------------------------------------*/
192  const CObservation* obs, const CPose3D& takenFrom)
193 {
194  MRPT_UNUSED_PARAM(obs);
195  MRPT_UNUSED_PARAM(takenFrom);
196 
197  THROW_EXCEPTION("Not implemented yet!");
198 }
199 
200 /*---------------------------------------------------------------
201  Implements the writing to a CStream capability of CSerializable objects
202  ---------------------------------------------------------------*/
204  mrpt::utils::CStream& out, int* version) const
205 {
206  if (version)
207  *version = 5;
208  else
209  {
211 
212  // To ensure compatibility: The size of each cell:
213  uint32_t n = static_cast<uint32_t>(sizeof(TRandomFieldCell));
214  out << n;
215 
216  // Save the map contents:
217  n = static_cast<uint32_t>(m_map.size());
218  out << n;
219 
220 // Save the "m_map": This requires special handling for big endian systems:
221 #if MRPT_IS_BIG_ENDIAN
222  for (uint32_t i = 0; i < n; i++)
223  {
224  out << m_map[i].kf_mean << m_map[i].dm_mean
225  << m_map[i].dmv_var_mean;
226  }
227 #else
228  // Little endian: just write all at once:
229  out.WriteBuffer(
230  &m_map[0], sizeof(m_map[0]) *
231  m_map.size()); // TODO: Do this endianness safe!!
232 #endif
233 
234  // Version 1: Save the insertion options:
235  out << uint8_t(m_mapType) << m_cov << m_stackedCov;
236 
237  out << insertionOptions.sigma << insertionOptions.cutoffRadius
238  << insertionOptions.R_min << insertionOptions.R_max
239  << insertionOptions.KF_covSigma
240  << insertionOptions.KF_initialCellStd
241  << insertionOptions.KF_observationModelNoise
242  << insertionOptions.KF_defaultCellMeanValue
243  << insertionOptions.KF_W_size;
244 
245  // New in v3:
248 
249  out << genericMapParams; // v4
250  }
251 }
252 
253 // Aux struct used below (must be at global scope for STL):
255 {
256  float mean, std;
257  float w, wr;
258 };
259 
260 /*---------------------------------------------------------------
261  Implements the reading from a CStream capability of CSerializable objects
262  ---------------------------------------------------------------*/
264  mrpt::utils::CStream& in, int version)
265 {
266  switch (version)
267  {
268  case 0:
269  case 1:
270  case 2:
271  case 3:
272  case 4:
273  case 5:
274  {
275  dyngridcommon_readFromStream(in, version < 5);
276 
277  // To ensure compatibility: The size of each cell:
278  uint32_t n;
279  in >> n;
280 
281  if (version < 2)
282  { // Converter from old versions <=1
283  ASSERT_(
284  n == static_cast<uint32_t>(sizeof(TOldCellTypeInVersion1)));
285  // Load the map contents in an aux struct:
286  in >> n;
287  vector<TOldCellTypeInVersion1> old_map(n);
288  in.ReadBuffer(&old_map[0], sizeof(old_map[0]) * old_map.size());
289 
290  // Convert to newer format:
291  m_map.resize(n);
292  for (size_t k = 0; k < n; k++)
293  {
294  m_map[k].kf_mean =
295  (old_map[k].w != 0) ? old_map[k].wr : old_map[k].mean;
296  m_map[k].kf_std =
297  (old_map[k].w != 0) ? old_map[k].w : old_map[k].std;
298  }
299  }
300  else
301  {
303  n, static_cast<uint32_t>(sizeof(TRandomFieldCell)));
304  // Load the map contents:
305  in >> n;
306  m_map.resize(n);
307 
308 // Read the note in writeToStream()
309 #if MRPT_IS_BIG_ENDIAN
310  for (uint32_t i = 0; i < n; i++)
311  in >> m_map[i].kf_mean >> m_map[i].dm_mean >>
312  m_map[i].dmv_var_mean;
313 #else
314  // Little endian: just read all at once:
315  in.ReadBuffer(&m_map[0], sizeof(m_map[0]) * m_map.size());
316 #endif
317  }
318 
319  // Version 1: Insertion options:
320  if (version >= 1)
321  {
322  uint8_t i;
323  in >> i;
325 
326  in >> m_cov >> m_stackedCov;
327 
328  in >> insertionOptions.sigma >> insertionOptions.cutoffRadius >>
329  insertionOptions.R_min >> insertionOptions.R_max >>
330  insertionOptions.KF_covSigma >>
331  insertionOptions.KF_initialCellStd >>
332  insertionOptions.KF_observationModelNoise >>
333  insertionOptions.KF_defaultCellMeanValue >>
334  insertionOptions.KF_W_size;
335  }
336 
337  if (version >= 3)
338  {
339  uint64_t N;
343  }
344 
345  if (version >= 4) in >> genericMapParams;
346 
348  }
349  break;
350  default:
352  };
353 }
354 
355 /*---------------------------------------------------------------
356  TInsertionOptions
357  ---------------------------------------------------------------*/
359 /*---------------------------------------------------------------
360  dumpToTextStream
361  ---------------------------------------------------------------*/
363  mrpt::utils::CStream& out) const
364 {
365  out.printf(
366  "\n----------- [CWirelessPowerGridMap2D::TInsertionOptions] "
367  "------------ \n\n");
368  internal_dumpToTextStream_common(
369  out); // Common params to all random fields maps:
370 
371  out.printf("\n");
372 }
373 
374 /*---------------------------------------------------------------
375  loadFromConfigFile
376  ---------------------------------------------------------------*/
378  const mrpt::utils::CConfigFileBase& iniFile, const std::string& section)
379 {
380  // Common data fields for all random fields maps:
381  internal_loadFromConfigFile_common(iniFile, section);
382 }
383 
384 /*---------------------------------------------------------------
385  getAs3DObject
386 ---------------------------------------------------------------*/
388  mrpt::opengl::CSetOfObjects::Ptr& outObj) const
389 {
390  MRPT_START
393  MRPT_END
394 }
#define ASSERT_EQUAL_(__A, __B)
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
IMPLEMENTS_SERIALIZABLE(CWirelessPowerGridMap2D, CRandomFieldGridMap2D, mrpt::maps) CWirelessPowerGridMap2D
CWirelessPowerGridMap2D(TMapRepresentation mapType=mrKernelDM, double x_min=-2, double x_max=2, double y_min=-2, double y_max=2, double resolution=0.1)
Constructor.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map.
bool enableSaveAs3DObject
(Default=true) If false, calling CMetricMap::getAs3DObject() will have no effects ...
mrpt::maps::CWirelessPowerGridMap2D::TInsertionOptions insertionOptions
#define THROW_EXCEPTION(msg)
GLenum GLsizei n
Definition: glext.h:5074
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
void dumpToTextStream(mrpt::utils::CStream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer.
Definition: CStream.cpp:64
bool internal_insertObservation(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D *robotPose=nullptr) override
Internal method called by insertObservation()
mrpt::math::CMatrixD m_cov
The whole covariance matrix, used for the Kalman Filter map representation.
TMapRepresentation
The type of map representation to be used, see CRandomFieldGridMap2D for a discussion.
STL namespace.
TMapGenericParams genericMapParams
Common params to all maps.
Definition: CMetricMap.h:281
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:189
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
virtual void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map (mean)
This class allows loading and storing values and vectors of different types from a configuration text...
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:55
static mrpt::maps::CMetricMap * internal_CreateFromMapDefinition(const mrpt::maps::TMetricMapInitializer &def)
TMapRepresentation m_mapType
The map representation type of this map, as passed in the constructor.
unsigned char uint8_t
Definition: rptypes.h:41
CWirelessPowerGridMap2D represents a PDF of wifi concentrations over a 2D area.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
#define MRPT_END
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
The contents of each cell in a CRandomFieldGridMap2D map.
A helper class that can convert an enum value into its textual representation, and viceversa...
Definition: TEnumType.h:38
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void loadFromConfigFile_map_specific(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) override
Load all map-specific params.
std::vector< TRandomFieldCell > m_map
The cells.
Definition: CDynamicGrid.h:44
double power
The power or signal strength as sensed by the Wifi receiver (In percentage: [0-100]) ...
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
This namespace contains representation of robot actions and observations.
GLsizei const GLchar ** string
Definition: glext.h:4101
This represents a measurement of the wireless strength perceived by the robot.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
bool m_hasToRecoverMeanAndCov
Only for the KF2 implementation.
mrpt::maps::CWirelessPowerGridMap2D::TInsertionOptions insertionOpts
#define MRPT_START
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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...
#define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS)
Registers one map class into TMetricMapInitializer factory.
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:55
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
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
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
Definition: CObject.h:103
virtual void internal_clear() override
Erase all the contents of the map.
mrpt::maps::CWirelessPowerGridMap2D::TMapRepresentation mapType
The kind of map representation (see CWirelessPowerGridMap2D::CWirelessPowerGridMap2D) ...
GLuint in
Definition: glext.h:7274
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
#define ASSERT_(f)
mrpt::poses::CPose3D sensorPoseOnRobot
The location of the sensing antenna on the robot coordinate framework.
void dyngridcommon_writeToStream(mrpt::utils::CStream &out) const
Definition: CDynamicGrid.h:348
mrpt::math::CMatrixD m_stackedCov
The compressed band diagonal matrix for the KF2 implementation.
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
unsigned __int32 uint32_t
Definition: rptypes.h:47
void dyngridcommon_readFromStream(mrpt::utils::CStream &in, bool cast_from_float=false)
Definition: CDynamicGrid.h:355
Lightweight 2D point.
double min_x
See CWirelessPowerGridMap2D::CWirelessPowerGridMap2D.
double internal_computeObservationLikelihood(const mrpt::obs::CObservation *obs, const mrpt::poses::CPose3D &takenFrom) override
Internal method called by computeObservationLikelihood()
void dumpToTextStream_map_specific(mrpt::utils::CStream &out) const override
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
Definition: CStream.cpp:597
void internal_clear() override
Erase all the contents of the map.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
void insertIndividualReading(const double sensorReading, const mrpt::math::TPoint2D &point, const bool update_map=true, const bool time_invariant=true, const double reading_stddev=.0)
Direct update of the map with a reading in a given position of the map, using the appropriate method ...



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