MRPT  2.0.0
CBeaconMap.h
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 #pragma once
10 
12 #include <mrpt/maps/CBeacon.h>
13 #include <mrpt/maps/CMetricMap.h>
14 #include <mrpt/math/CMatrixF.h>
15 #include <mrpt/obs/obs_frwds.h>
17 
18 namespace mrpt::maps
19 {
20 /** A class for storing a map of 3D probabilistic beacons, using a Montecarlo,
21  *Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM).
22  * <br>
23  * The individual beacons are defined as mrpt::maps::CBeacon objects.
24  * <br>
25  * When invoking CBeaconMap::insertObservation(), landmarks will be extracted
26  *and fused into the map.
27  * The only currently supported observation type is
28  *mrpt::obs::CObservationBeaconRanges.
29  * See insertionOptions and likelihoodOptions for parameters used when
30  *creating and fusing beacon landmarks.
31  * <br>
32  * Use "TInsertionOptions::insertAsMonteCarlo" to select between 2 different
33  *behaviors:
34  * - Initial PDF of beacons: MonteCarlo, after convergence, pass to
35  *Gaussians; or
36  * - Initial PDF of beacons: SOG, after convergence, a single Gaussian.
37  *
38  * Refer to the papers: []
39  *
40  * \ingroup mrpt_maps_grp
41  * \sa CMetricMap
42  */
44 {
46 
47  public:
48  using TSequenceBeacons = std::deque<CBeacon>;
49  using iterator = std::deque<CBeacon>::iterator;
50  using const_iterator = std::deque<CBeacon>::const_iterator;
51 
52  protected:
53  /** The individual beacons */
55 
56  // See docs in base class
57  void internal_clear() override;
59  const mrpt::obs::CObservation& obs,
60  const mrpt::poses::CPose3D* robotPose = nullptr) override;
62  const mrpt::obs::CObservation& obs,
63  const mrpt::poses::CPose3D& takenFrom) override;
64 
65  public:
66  /** Constructor */
67  CBeaconMap();
68 
69  /** Resize the number of SOG modes */
70  void resize(const size_t N);
71 
72  /** Access to individual beacons */
73  const CBeacon& operator[](size_t i) const
74  {
75  ASSERT_(i < m_beacons.size());
76  return m_beacons[i];
77  }
78  /** Access to individual beacons */
79  const CBeacon& get(size_t i) const
80  {
81  ASSERT_(i < m_beacons.size());
82  return m_beacons[i];
83  }
84  /** Access to individual beacons */
85  CBeacon& operator[](size_t i)
86  {
87  ASSERT_(i < m_beacons.size());
88  return m_beacons[i];
89  }
90  /** Access to individual beacons */
91  CBeacon& get(size_t i)
92  {
93  ASSERT_(i < m_beacons.size());
94  return m_beacons[i];
95  }
96 
97  iterator begin() { return m_beacons.begin(); }
98  const_iterator begin() const { return m_beacons.begin(); }
99  iterator end() { return m_beacons.end(); }
100  const_iterator end() const { return m_beacons.end(); }
101  /** Inserts a copy of the given mode into the SOG */
102  void push_back(const CBeacon& m) { m_beacons.push_back(m); }
103  // See docs in base class
105  const mrpt::maps::CMetricMap* otherMap,
106  const mrpt::poses::CPose3D& otherMapPose,
107  const TMatchingRatioParams& params) const override;
108 
109  /** With this struct options are provided to the likelihood computations */
111  {
112  public:
113  void loadFromConfigFile(
114  const mrpt::config::CConfigFileBase& source,
115  const std::string& section) override; // See base docs
116  void dumpToTextStream(
117  std::ostream& out) const override; // See base docs
118 
119  /** The standard deviation used for Beacon ranges likelihood
120  * (default=0.08m).
121  */
122  double rangeStd = {0.08};
124 
125  /** This struct contains data for choosing the method by which new beacons
126  * are inserted in the map.
127  */
129  {
130  public:
131  /** Initilization of default parameters */
132  void loadFromConfigFile(
133  const mrpt::config::CConfigFileBase& source,
134  const std::string& section) override; // See base docs
135  void dumpToTextStream(
136  std::ostream& out) const override; // See base docs
137 
138  /** Insert a new beacon as a set of montecarlo samples (default=true),
139  * or, if false, as a sum of gaussians (see mrpt::maps::CBeacon).
140  * \sa MC_performResampling
141  */
142  bool insertAsMonteCarlo{true};
143 
144  /** Minimum and maximum elevation angles (in degrees) for inserting new
145  * beacons at the first observation: the default values (both 0), makes
146  * the beacons to be in the same horizontal plane that the sensors, that
147  * is, 2D SLAM - the min/max values are -90/90.
148  */
150 
151  /** Number of particles per meter of range, i.e. per meter of the
152  * "radius of the ring".
153  */
154  unsigned int MC_numSamplesPerMeter{1000};
155 
156  /** The threshold for the maximum std (X,Y,and Z) before colapsing the
157  * particles into a Gaussian PDF (default=0.4).
158  */
159  float MC_maxStdToGauss = {0.4f};
160 
161  /** Threshold for the maximum difference from the maximun (log) weight
162  * in the set of samples for erasing a given sample (default=5).
163  */
165 
166  /** If set to false (default), the samples will be generated the first
167  * time a beacon is observed, and their weights just updated
168  * subsequently - if set to "true", fewer samples will be required since
169  * the particles will be resamples when necessary, and a small "noise"
170  * will be added to avoid depletion.
171  */
172  bool MC_performResampling{false};
173 
174  /** The std.dev. of the Gaussian noise to be added to each sample after
175  * resampling, only if MC_performResampling=true.
176  */
178 
179  /** Threshold for the maximum difference from the maximun (log) weight
180  * in the SOG for erasing a given mode (default=20).
181  */
183 
184  /** A parameter for initializing 2D/3D SOGs
185  */
187 
188  /** Constant used to compute the std. dev. int the tangent direction
189  * when creating the Gaussians.
190  */
193 
194  /** Save to a MATLAB script which displays 3D error ellipses for the map.
195  * \param file The name of the file to save the script to.
196  * \param style The MATLAB-like string for the style of the lines (see
197  *'help plot' in MATLAB for possibilities)
198  * \param stdCount The ellipsoids will be drawn from the center to a given
199  *confidence interval in [0,1], e.g. 2 sigmas=0.95 (default is 2std = 0.95
200  *confidence intervals)
201  *
202  * \return Returns false if any error occured, true elsewere.
203  */
205  const std::string& file, const char* style = "b",
206  float confInterval = 0.95f) const;
207 
208  /** Returns the stored landmarks count.
209  */
210  size_t size() const;
211 
212  // See docs in base class
213  void determineMatching2D(
214  const mrpt::maps::CMetricMap* otherMap,
215  const mrpt::poses::CPose2D& otherMapPose,
216  mrpt::tfest::TMatchingPairList& correspondences,
217  const TMatchingParams& params,
218  TMatchingExtraResults& extraResults) const override;
219 
220  /** Perform a search for correspondences between "this" and another
221  * lansmarks map:
222  * Firsly, the landmarks' descriptor is used to find correspondences, then
223  * inconsistent ones removed by
224  * looking at their 3D poses.
225  * \param otherMap [IN] The other map.
226  * \param correspondences [OUT] The matched pairs between maps.
227  * \param correspondencesRatio [OUT] This is NumberOfMatchings /
228  * NumberOfLandmarksInTheAnotherMap
229  * \param otherCorrespondences [OUT] Will be returned with a vector
230  * containing "true" for the indexes of the other map's landmarks with a
231  * correspondence.
232  */
234  const mrpt::maps::CBeaconMap* otherMap,
235  mrpt::tfest::TMatchingPairList& correspondences,
236  float& correspondencesRatio,
237  std::vector<bool>& otherCorrespondences) const;
238 
239  /** Changes the reference system of the map to a given 3D pose.
240  */
242 
243  /** Changes the reference system of the map "otherMap" and save the result
244  * in "this" map.
245  */
247  const mrpt::poses::CPose3D& newOrg,
248  const mrpt::maps::CBeaconMap* otherMap);
249 
250  /** Returns true if the map is empty/no observation has been inserted.
251  */
252  bool isEmpty() const override;
253 
254  /** Simulates a reading toward each of the beacons in the landmarks map, if
255  * any.
256  * \param in_robotPose This robot pose is used to simulate the ranges to
257  * each beacon.
258  * \param in_sensorLocationOnRobot The 3D position of the sensor on the
259  * robot
260  * \param out_Observations The results will be stored here. NOTICE that the
261  * fields
262  * "CObservationBeaconRanges::minSensorDistance","CObservationBeaconRanges::maxSensorDistance"
263  * and "CObservationBeaconRanges::stdError" MUST BE FILLED OUT before
264  * calling this function.
265  * An observation will be generated for each beacon in the map, but notice
266  * that some of them may be missed if out of the sensor maximum range.
267  */
269  const mrpt::poses::CPose3D& in_robotPose,
270  const mrpt::poses::CPoint3D& in_sensorLocationOnRobot,
271  mrpt::obs::CObservationBeaconRanges& out_Observations) const;
272 
273  /** This virtual method saves the map to a file "filNamePrefix"+<
274  *some_file_extension >, as an image or in any other applicable way (Notice
275  *that other methods to save the map may be implemented in classes
276  *implementing this virtual interface).
277  * In the case of this class, these files are generated:
278  * - "filNamePrefix"+"_3D.m": A script for MATLAB for drawing landmarks
279  *as
280  *3D ellipses.
281  * - "filNamePrefix"+"_3D.3DScene": A 3D scene with a "ground plane
282  *grid"
283  *and the set of ellipsoids in 3D.
284  * - "filNamePrefix"+"_covs.m": A textual representation (see
285  *saveToTextFile)
286  */
288  const std::string& filNamePrefix) const override;
289 
290  /** Save a text file with a row per beacon, containing this 11 elements:
291  * - X Y Z: Mean values
292  * - VX VY VZ: Variances of each dimension (C11, C22, C33)
293  * - DET2D DET3D: Determinant of the 2D and 3D covariance matrixes.
294  * - C12, C13, C23: Cross covariances
295  */
296  void saveToTextFile(const std::string& fil) const;
297 
298  /** Returns a 3D object representing the map. */
299  void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr& outObj) const override;
300 
301  /** Returns a pointer to the beacon with the given ID, or nullptr if it does
302  * not exist. */
303  const CBeacon* getBeaconByID(CBeacon::TBeaconID id) const;
304  /** Returns a pointer to the beacon with the given ID, or nullptr if it does
305  * not exist. */
307 
309  /** Observations insertion options */
310  mrpt::maps::CBeaconMap::TInsertionOptions insertionOpts;
311  /** Probabilistic observation likelihood options */
312  mrpt::maps::CBeaconMap::TLikelihoodOptions likelihoodOpts;
314 
315 }; // End of class def.
316 
317 } // namespace mrpt::maps
bool isEmpty() const override
Returns true if the map is empty/no observation has been inserted.
Parameters for CMetricMap::compute3DMatchingRatio()
const_iterator end() const
Definition: CBeaconMap.h:100
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
float compute3DMatchingRatio(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose3D &otherMapPose, const TMatchingRatioParams &params) const override
Computes the ratio in [0,1] of correspondences between "this" and the "otherMap" map, whose 6D pose relative to "this" is "otherMapPose" In the case of a multi-metric map, this returns the average between the maps.
void getAs3DObject(mrpt::opengl::CSetOfObjects::Ptr &outObj) const override
Returns a 3D object representing the map.
This struct contains data for choosing the method by which new beacons are inserted in the map...
Definition: CBeaconMap.h:128
#define MAP_DEFINITION_START(_CLASS_NAME_)
Add a MAP_DEFINITION_START() ...
With this struct options are provided to the likelihood computations.
Definition: CBeaconMap.h:110
mrpt::vision::TStereoCalibParams params
Declares a class derived from "CObservation" that represents one (or more) range measurements to labe...
void internal_clear() override
Internal method called by clear()
Definition: CBeaconMap.cpp:95
bool MC_performResampling
If set to false (default), the samples will be generated the first time a beacon is observed...
Definition: CBeaconMap.h:172
void dumpToTextStream(std::ostream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
Definition: CBeaconMap.cpp:957
double maxElevation_deg
Minimum and maximum elevation angles (in degrees) for inserting new beacons at the first observation:...
Definition: CBeaconMap.h:149
TSequenceBeacons m_beacons
The individual beacons.
Definition: CBeaconMap.h:54
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
This class allows loading and storing values and vectors of different types from a configuration text...
void changeCoordinatesReference(const mrpt::poses::CPose3D &newOrg)
Changes the reference system of the map to a given 3D pose.
Definition: CBeaconMap.cpp:821
bool internal_insertObservation(const mrpt::obs::CObservation &obs, const mrpt::poses::CPose3D *robotPose=nullptr) override
Internal method called by insertObservation()
Definition: CBeaconMap.cpp:355
int64_t TBeaconID
The type for the IDs of landmarks.
Definition: CBeacon.h:42
Additional results from the determination of matchings between point clouds, etc., apart from the pairings themselves.
float SOG_maxDistBetweenGaussians
A parameter for initializing 2D/3D SOGs.
Definition: CBeaconMap.h:186
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
Definition: CBeaconMap.cpp:968
CBeaconMap()
Constructor.
Definition: CBeaconMap.cpp:88
A list of TMatchingPair.
Definition: TMatchingPair.h:70
A class for storing a map of 3D probabilistic beacons, using a Montecarlo, Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM).
Definition: CBeaconMap.h:43
float SOG_separationConstant
Constant used to compute the std.
Definition: CBeaconMap.h:191
void saveToTextFile(const std::string &fil) const
Save a text file with a row per beacon, containing this 11 elements:
void push_back(const CBeacon &m)
Inserts a copy of the given mode into the SOG.
Definition: CBeaconMap.h:102
A class used to store a 3D point.
Definition: CPoint3D.h:31
double internal_computeObservationLikelihood(const mrpt::obs::CObservation &obs, const mrpt::poses::CPose3D &takenFrom) override
Internal method called by computeObservationLikelihood()
Definition: CBeaconMap.cpp:146
CBeacon & operator[](size_t i)
Access to individual beacons.
Definition: CBeaconMap.h:85
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const CBeacon & operator[](size_t i) const
Access to individual beacons.
Definition: CBeaconMap.h:73
void determineMatching2D(const mrpt::maps::CMetricMap *otherMap, const mrpt::poses::CPose2D &otherMapPose, mrpt::tfest::TMatchingPairList &correspondences, const TMatchingParams &params, TMatchingExtraResults &extraResults) const override
Computes the matching between this and another 2D point map, which includes finding: ...
Definition: CBeaconMap.cpp:790
void loadFromConfigFile(const mrpt::config::CConfigFileBase &source, const std::string &section) override
Initilization of default parameters.
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:52
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
double rangeStd
The standard deviation used for Beacon ranges likelihood (default=0.08m).
Definition: CBeaconMap.h:122
void dumpToTextStream(std::ostream &out) const override
This method should clearly display all the contents of the structure in textual form, sending it to a std::ostream.
Definition: CBeaconMap.cpp:974
bool insertAsMonteCarlo
Insert a new beacon as a set of montecarlo samples (default=true), or, if false, as a sum of gaussian...
Definition: CBeaconMap.h:142
const CBeacon * getBeaconByID(CBeacon::TBeaconID id) const
Returns a pointer to the beacon with the given ID, or nullptr if it does not exist.
void resize(const size_t N)
Resize the number of SOG modes.
Definition: CBeaconMap.cpp:103
mrpt::maps::CBeaconMap::TLikelihoodOptions likelihoodOptions
std::deque< CBeacon >::const_iterator const_iterator
Definition: CBeaconMap.h:50
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const_iterator begin() const
Definition: CBeaconMap.h:98
bool saveToMATLABScript3D(const std::string &file, const char *style="b", float confInterval=0.95f) const
Save to a MATLAB script which displays 3D error ellipses for the map.
Definition: CBeaconMap.cpp:919
unsigned int MC_numSamplesPerMeter
Number of particles per meter of range, i.e.
Definition: CBeaconMap.h:154
std::deque< CBeacon > TSequenceBeacons
Definition: CBeaconMap.h:48
double MC_thresholdNegligible
Threshold for the maximum difference from the maximun (log) weight in the set of samples for erasing ...
Definition: CBeaconMap.h:164
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const override
This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >...
mrpt::maps::CBeaconMap::TInsertionOptions insertionOptions
float MC_maxStdToGauss
The threshold for the maximum std (X,Y,and Z) before colapsing the particles into a Gaussian PDF (def...
Definition: CBeaconMap.h:159
Parameters for the determination of matchings between point clouds, etc.
#define MAP_DEFINITION_END(_CLASS_NAME_)
void simulateBeaconReadings(const mrpt::poses::CPose3D &in_robotPose, const mrpt::poses::CPoint3D &in_sensorLocationOnRobot, mrpt::obs::CObservationBeaconRanges &out_Observations) const
Simulates a reading toward each of the beacons in the landmarks map, if any.
The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions...
Definition: CBeacon.h:35
float SOG_thresholdNegligible
Threshold for the maximum difference from the maximun (log) weight in the SOG for erasing a given mod...
Definition: CBeaconMap.h:182
std::deque< CBeacon >::iterator iterator
Definition: CBeaconMap.h:49
size_t size() const
Returns the stored landmarks count.
Definition: CBeaconMap.cpp:99
void computeMatchingWith3DLandmarks(const mrpt::maps::CBeaconMap *otherMap, mrpt::tfest::TMatchingPairList &correspondences, float &correspondencesRatio, std::vector< bool > &otherCorrespondences) const
Perform a search for correspondences between "this" and another lansmarks map: Firsly, the landmarks&#39; descriptor is used to find correspondences, then inconsistent ones removed by looking at their 3D poses.
Definition: CBeaconMap.cpp:843



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020