Main MRPT website > C++ reference for MRPT 1.9.9
PF_implementations_data.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 PF_implementations_data_H
10 #define PF_implementations_data_H
11 
16 #include <mrpt/poses/CPose3D.h>
19 #include <mrpt/slam/TKLDParams.h>
21 
22 namespace mrpt
23 {
24 namespace slam
25 {
26 // Frwd decl:
27 template <class PARTICLETYPE, class BINTYPE>
29  BINTYPE& outBin, const TKLDParams& opts,
30  const PARTICLETYPE* currentParticleValue = nullptr,
31  const mrpt::math::TPose3D* newPoseToBeInserted = nullptr);
32 
33 /** A set of common data shared by PF implementations for both SLAM and
34  * localization
35  * \ingroup mrpt_slam_grp
36  */
37 template <
38  class PARTICLE_TYPE, class PDF_TYPE,
39  class CParticleList = typename PDF_TYPE::CParticleList>
40 class PF_implementation : public mrpt::utils::COutputLogger
41 {
42  public:
43  PF_implementation() : mrpt::utils::COutputLogger("PF_implementation") {}
44 
45  /** \name Data members and methods used by generic PF implementations
46  @{ */
47 
52 
53  /** Used in al PF implementations. \sa
54  * PF_SLAM_implementation_gatherActionsCheckBothActObs */
56  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
58  /** Auxiliary variable used in the "pfAuxiliaryPFStandard" algorithm. */
60  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
62  /** Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm. */
63  mutable std::vector<mrpt::math::TPose3D>
66 
67  /** Compute w[i]*p(z_t | mu_t^i), with mu_t^i being
68  * the mean of the new robot pose
69  *
70  * \param action MUST be a "const CPose3D*"
71  * \param observation MUST be a "const CSensoryFrame*"
72  */
73  template <class BINTYPE> // Template arg. actually not used, just to allow
74  // giving the definition in another file later on
78  const void* action, const void* observation);
79 
80  /** @} */
81 
82  public:
83  /** \name Virtual methods that the PF_implementations assume exist.
84  @{ */
85 
86  /** Return the last robot pose in the i'th particle; is_valid_pose will be
87  * false if there is no such last pose.
88  * \exception std::exception on out-of-range particle index */
90  const size_t i, bool& is_valid_pose) const = 0;
91 
93  PARTICLE_TYPE* particleData,
94  const mrpt::math::TPose3D& newPose) const = 0;
95 
96  /** This is the default algorithm to efficiently replace one old set of
97  * samples by another new set.
98  * The method uses pointers to make fast copies the first time each
99  * particle is duplicated, then
100  * makes real copies for the next ones.
101  *
102  * Note that more efficient specializations might exist for specific
103  * particle data structs.
104  */
106  CParticleList& old_particles,
107  const std::vector<mrpt::math::TPose3D>& newParticles,
108  const std::vector<double>& newParticlesWeight,
109  const std::vector<size_t>& newParticlesDerivedFromIdx) const
110  {
111  // ---------------------------------------------------------------------------------
112  // Substitute old by new particle set:
113  // Old are in "m_particles"
114  // New are in "newParticles",
115  // "newParticlesWeight","newParticlesDerivedFromIdx"
116  // ---------------------------------------------------------------------------------
117  const size_t N = newParticles.size(), N_old = old_particles.size();
118  CParticleList newParticlesArray(N);
119 
120  // For efficiency, just copy the "CParticleData" from the old particle
121  // into the
122  // new one, but this can be done only once:
123  std::vector<bool> oldParticleAlreadyCopied(N_old, false);
124  std::vector<PARTICLE_TYPE*> oldParticleFirstCopies(N_old, nullptr);
125 
126  size_t i;
127  typename CParticleList::iterator newPartIt;
128  for (newPartIt = newParticlesArray.begin(), i = 0;
129  newPartIt != newParticlesArray.end(); ++newPartIt, ++i)
130  {
131  // The weight:
132  newPartIt->log_w = newParticlesWeight[i];
133 
134  // The data (CParticleData):
135  PARTICLE_TYPE* newPartData;
136  const size_t i_in_old = newParticlesDerivedFromIdx[i];
137  if (!oldParticleAlreadyCopied[i_in_old])
138  {
139  // The first copy of this old particle:
140  newPartData = old_particles[i_in_old].d.release();
141  oldParticleAlreadyCopied[i_in_old] = true;
142  oldParticleFirstCopies[i_in_old] = newPartData;
143  }
144  else
145  {
146  // Make a copy:
147  ASSERT_(oldParticleFirstCopies[i_in_old]);
148  newPartData =
149  new PARTICLE_TYPE(*oldParticleFirstCopies[i_in_old]);
150  }
151 
152  newPartIt->d.reset(newPartData);
153  } // end for "newPartIt"
154 
155  // Now add the new robot pose to the paths:
156  // (this MUST be done after the above loop, separately):
157  // Update the particle with the new pose: this part is caller-dependant
158  // and must be implemented there:
159  for (newPartIt = newParticlesArray.begin(), i = 0; i < N;
160  ++newPartIt, ++i)
162  newPartIt->d.get(), newParticles[i]);
163 
164  // Free those old m_particles not being copied into the new ones: not
165  // needed since use of smart ptr.
166 
167  // Copy into "m_particles"
168  old_particles.resize(newParticlesArray.size());
169  typename CParticleList::iterator trgPartIt;
170  for (newPartIt = newParticlesArray.begin(),
171  trgPartIt = old_particles.begin();
172  newPartIt != newParticlesArray.end(); ++newPartIt, ++trgPartIt)
173  {
174  trgPartIt->log_w = newPartIt->log_w;
175  trgPartIt->d.move_from(newPartIt->d);
176  }
177  } // end of PF_SLAM_implementation_replaceByNewParticleSet
178 
180  const typename mrpt::bayes::CParticleFilterData<
181  PARTICLE_TYPE>::CParticleList& particles,
182  const mrpt::obs::CSensoryFrame* sf) const
183  {
184  MRPT_UNUSED_PARAM(particles);
185  MRPT_UNUSED_PARAM(sf);
186  return true; // By default, always process the SFs.
187  }
188 
189  /** Make a specialization if needed, eg. in the first step in SLAM. */
191  {
192  return false; // By default, always allow the robot to move!
193  }
194 
195  /** Evaluate the observation likelihood for one particle at a given location
196  */
199  const size_t particleIndexForMap,
200  const mrpt::obs::CSensoryFrame& observation,
201  const mrpt::poses::CPose3D& x) const = 0;
202 
203  /** @} */
204 }; // end PF_implementation
205 
206 } // namespace slam
207 } // namespace mrpt
208 #endif
This virtual class defines the interface that any particles based PDF class must implement in order t...
This template class declares the array of particles and its internal data, managing some memory-relat...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: types_math.h:70
Represents a probabilistic 2D movement of the robot mobile base.
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 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:89
Declares a class that represents a Probability Density function (PDF) of a 3D pose .
An efficient generator of random samples drawn from a given 2D (CPosePDF) or 3D (CPose3DPDF) pose pro...
A set of common data shared by PF implementations for both SLAM and localization.
virtual void PF_SLAM_implementation_custom_update_particle_with_new_pose(PARTICLE_TYPE *particleData, const mrpt::math::TPose3D &newPose) const =0
virtual 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
This is the default algorithm to efficiently replace one old set of samples by another new set.
mrpt::math::CVectorDouble m_pfAuxiliaryPFOptimal_estimatedProb
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
virtual 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 =0
Evaluate the observation likelihood for one particle at a given location.
static double PF_SLAM_particlesEvaluator_AuxPFStandard(const mrpt::bayes::CParticleFilter::TParticleFilterOptions &PF_options, const mrpt::bayes::CParticleFilterCapable *obj, size_t index, const void *action, const void *observation)
Compute w[i]*p(z_t | mu_t^i), with mu_t^i being the mean of the new robot pose.
mrpt::poses::CPose3DPDFGaussian m_accumRobotMovement3D
virtual mrpt::math::TPose3D getLastPose(const size_t i, bool &is_valid_pose) const =0
Return the last robot pose in the i'th particle; is_valid_pose will be false if there is no such last...
std::vector< bool > m_pfAuxiliaryPFOptimal_maxLikMovementDrawHasBeenUsed
virtual bool PF_SLAM_implementation_skipRobotMovement() const
Make a specialization if needed, eg.
mrpt::math::CVectorDouble m_pfAuxiliaryPFStandard_estimatedProb
Auxiliary variable used in the "pfAuxiliaryPFStandard" algorithm.
mrpt::obs::CActionRobotMovement2D m_accumRobotMovement2D
mrpt::math::CVectorDouble m_pfAuxiliaryPFOptimal_maxLikelihood
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
std::vector< mrpt::math::TPose3D > m_pfAuxiliaryPFOptimal_maxLikDrawnMovement
Auxiliary variable used in the "pfAuxiliaryPFOptimal" algorithm.
virtual bool PF_SLAM_implementation_doWeHaveValidObservations(const typename mrpt::bayes::CParticleFilterData< PARTICLE_TYPE >::CParticleList &particles, const mrpt::obs::CSensoryFrame *sf) const
mrpt::poses::CPoseRandomSampler m_movementDrawer
Used in al PF implementations.
Option set for KLD algorithm.
Definition: TKLDParams.h:21
Scalar * iterator
Definition: eigen_plugins.h:26
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
GLuint index
Definition: glext.h:4054
GLenum GLint x
Definition: glext.h:3538
#define ASSERT_(f)
Definition: mrpt_macros.h:309
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
Definition: mrpt_macros.h:365
void KLF_loadBinFromParticle(BINTYPE &outBin, const TKLDParams &opts, const PARTICLETYPE *currentParticleValue=nullptr, const mrpt::math::TPose3D *newPoseToBeInserted=nullptr)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The configuration of a particle filter.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).



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