Main MRPT website > C++ reference for MRPT 1.9.9
CMonteCarloLocalization2D.h
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 #ifndef CMonteCarloLocalization2D_H
10 #define CMonteCarloLocalization2D_H
11 
15 #include <mrpt/obs/obs_frwds.h>
16 
18 
19 namespace mrpt
20 {
21 namespace maps
22 {
23 class COccupancyGridMap2D;
24 }
25 
26 /** \ingroup mrpt_slam_grp */
27 namespace slam
28 {
29 /** Declares a class that represents a Probability Density Function (PDF) over a
30  * 2D pose (x,y,phi), using a set of weighted samples.
31  *
32  * This class also implements particle filtering for robot localization. See
33  * the MRPT
34  * application "app/pf-localization" for an example of usage.
35  *
36  * \sa CMonteCarloLocalization3D, CPose2D, CPosePDF, CPoseGaussianPDF,
37  * \ingroup mrpt_slam_grp
38  */
40  : public PF_implementation<
41  mrpt::poses::CPose2D, mrpt::poses::CPosePDFParticles>
42 {
43  public:
47 
49 
50  /** MCL parameters */
52 
53  /** Constructor
54  * \param M The number of m_particles.
55  */
56  CMonteCarloLocalization2D(size_t M = 1);
57 
58  /** Destructor */
60 
61  /** Reset the PDF to an uniformly distributed one, but only in the
62  * free-space
63  * of a given 2D occupancy-grid-map. Orientation is randomly generated in
64  * the whole 2*PI range.
65  * \param theMap The occupancy grid map
66  * \param freeCellsThreshold The minimum free-probability to consider a
67  * cell as empty (default is 0.7)
68  * \param particlesCount If set to -1 the number of m_particles remains
69  * unchanged.
70  * \param x_min The limits of the area to look for free cells.
71  * \param x_max The limits of the area to look for free cells.
72  * \param y_min The limits of the area to look for free cells.
73  * \param y_max The limits of the area to look for free cells.
74  * \param phi_min The limits of the area to look for free cells.
75  * \param phi_max The limits of the area to look for free cells.
76  * \sa resetDeterm32inistic
77  * \exception std::exception On any error (no free cell found in map,
78  * map=nullptr, etc...)
79  */
82  const double freeCellsThreshold = 0.7, const int particlesCount = -1,
83  const double x_min = -1e10f, const double x_max = 1e10f,
84  const double y_min = -1e10f, const double y_max = 1e10f,
85  const double phi_min = -M_PI, const double phi_max = M_PI);
86 
87  /** Update the m_particles, predicting the posterior of robot pose and map
88  * after a movement command.
89  * This method has additional configuration parameters in "options".
90  * Performs the update stage of the RBPF, using the sensed CSensoryFrame:
91  *
92  * \param action This is a pointer to CActionCollection, containing the
93  * pose change the robot has been commanded.
94  * \param observation This must be a pointer to a CSensoryFrame object,
95  * with robot sensed observations.
96  *
97  * \sa options
98  */
99  template <class T>
101  const mrpt::obs::CActionCollection* actions,
102  const mrpt::obs::CSensoryFrame* observation,
104  {
105  MRPT_START
106 
107  if (observation)
108  { // A map MUST be supplied!
110  if (!options.metricMap)
111  ASSERT_(
112  options.metricMaps.size() ==
114  }
115 
116  T::template PF_SLAM_implementation<
119  actions, observation, PF_options, options.KLD_params, *this);
120 
121  MRPT_END
122  }
123  // protected:
124  /** \name Virtual methods that the PF_implementations assume exist.
125  @{ */
126  /** Return the robot pose for the i'th particle. is_valid is
127  * always true in this class. */
129  const size_t i, bool& is_valid_pose) const override;
130 
132  CParticleDataContent* particleData,
133  const mrpt::math::TPose3D& newPose) const override;
134 
135  // We'll redefine this one:
137  CParticleList& old_particles,
138  const std::vector<mrpt::math::TPose3D>& newParticles,
139  const std::vector<double>& newParticlesWeight,
140  const std::vector<size_t>& newParticlesDerivedFromIdx) const override;
141 
142  /** Evaluate the observation likelihood for one particle at a given location
143  */
146  const size_t particleIndexForMap,
147  const mrpt::obs::CSensoryFrame& observation,
148  const mrpt::poses::CPose3D& x) const override;
149  /** @} */
150 
151  void executeOn(
153  const mrpt::obs::CActionCollection* action,
154  const mrpt::obs::CSensoryFrame* observation,
157 
158 }; // End of class def.
159 
160 } // namespace slam
161 } // namespace mrpt
162 
163 #endif
#define M_PI
Definition: bits.h:92
CParticleList m_particles
The array of particles.
std::deque< CParticleData > CParticleList
Use this type to refer to the list of particles m_particles.
CPose2D CParticleDataContent
This is the type inside the corresponding CParticleData class.
This class acts as a common interface to the different interfaces (see CParticleFilter::TParticleFilt...
TParticleFilterAlgorithm
Defines different types of particle filter algorithms.
A class for storing an occupancy grid map.
Declares a class for storing a collection of robot actions.
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:55
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:41
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x,...
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x,...
void executeOn(mrpt::bayes::CParticleFilter &pf, const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, mrpt::bayes::CParticleFilter::TParticleFilterStats *stats, mrpt::bayes::CParticleFilter::TParticleFilterAlgorithm PF_algorithm)
void resetUniformFreeSpace(mrpt::maps::COccupancyGridMap2D *theMap, const double freeCellsThreshold=0.7, const int particlesCount=-1, const double x_min=-1e10f, const double x_max=1e10f, const double y_min=-1e10f, const double y_max=1e10f, const double phi_min=-M_PI, const double phi_max=M_PI)
Reset the PDF to an uniformly distributed one, but only in the free-space of a given 2D occupancy-gri...
void PF_SLAM_implementation_custom_update_particle_with_new_pose(CParticleDataContent *particleData, const mrpt::math::TPose3D &newPose) const override
mrpt::poses::CPosePDFParticles::CParticleDataContent CParticleDataContent
void PF_SLAM_implementation_replaceByNewParticleSet(CParticleList &old_particles, const std::vector< mrpt::math::TPose3D > &newParticles, const std::vector< double > &newParticlesWeight, const std::vector< size_t > &newParticlesDerivedFromIdx) const override
TMonteCarloLocalizationParams options
MCL parameters.
mrpt::math::TPose3D getLastPose(const size_t i, bool &is_valid_pose) const override
Return the robot pose for the i'th particle.
mrpt::poses::CPosePDFParticles m_poseParticles
mrpt::poses::CPosePDFParticles::CParticleList CParticleList
double PF_SLAM_computeObservationLikelihoodForParticle(const mrpt::bayes::CParticleFilter::TParticleFilterOptions &PF_options, const size_t particleIndexForMap, const mrpt::obs::CSensoryFrame &observation, const mrpt::poses::CPose3D &x) const override
Evaluate the observation likelihood for one particle at a given location.
void prediction_and_update(const mrpt::obs::CActionCollection *actions, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options)
Update the m_particles, predicting the posterior of robot pose and map after a movement command.
A set of common data shared by PF implementations for both SLAM and localization.
GLenum GLint x
Definition: glext.h:3538
#define MRPT_START
Definition: mrpt_macros.h:425
#define ASSERT_(f)
Definition: mrpt_macros.h:309
#define MRPT_END
Definition: mrpt_macros.h:429
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The configuration of a particle filter.
Statistics for being returned from the "execute" method.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
The struct for passing extra simulation parameters to the prediction stage when running a particle fi...
TKLDParams KLD_params
Parameters for dynamic sample size, KLD method.
mrpt::maps::TMetricMapList metricMaps
[update stage] Alternative way (if metricMap==nullptr): A metric map is supplied for each particle: T...
mrpt::maps::CMetricMap * metricMap
[update stage] Must be set to a metric map used to estimate the likelihood of observations
Auxiliary structure used in KLD-sampling in particle filters.



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST