Main MRPT website > C++ reference
MRPT logo
CMultiMetricMapPDF.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CMultiMetricMapPDF_H
29 #define CMultiMetricMapPDF_H
30 
32 #include <mrpt/slam/CSimpleMap.h>
35 
37 
40 #include <mrpt/slam/CICP.h>
41 
43 
44 #include <mrpt/slam/link_pragmas.h>
45 
46 namespace mrpt
47 {
48 namespace slam
49 {
51 
52  /** Auxiliary class used in mrpt::slam::CMultiMetricMapPDF
53  * \ingroup mrpt_slam_grp
54  */
55  class SLAM_IMPEXP CRBPFParticleData : public mrpt::utils::CSerializable
56  {
57  // This must be added to any CSerializable derived class:
59  public:
60  CRBPFParticleData( const TSetOfMetricMapInitializers *mapsInitializers = NULL ) :
61  mapTillNow( mapsInitializers ),
62  robotPath()
63  {
64  }
65 
67  std::deque<TPose3D> robotPath;
68  };
69 
70 
72 
73  /** Declares a class that represents a Rao-Blackwellized set of particles for solving the SLAM problem (This class is the base of RBPF-SLAM applications).
74  * This class is used internally by the map building algorithm in "mrpt::slam::CMetricMapBuilderRBPF"
75  *
76  * \sa mrpt::slam::CMetricMapBuilderRBPF
77  * \ingroup metric_slam_grp
78  */
80  public mrpt::utils::CSerializable,
81  public mrpt::bayes::CParticleFilterData<CRBPFParticleData>,
82  public mrpt::bayes::CParticleFilterCapable,
83  public mrpt::slam::PF_implementation<CRBPFParticleData,CMultiMetricMapPDF>
84  {
85  friend class CMetricMapBuilderRBPF;
86  //template <class PARTICLE_TYPE, class MYSELF> friend class PF_implementation;
87 
88  // This must be added to any CSerializable derived class:
89  DEFINE_SERIALIZABLE( CMultiMetricMapPDF )
90 
91  // This uses CParticleFilterData to implement some methods required for CParticleFilterCapable:
92  IMPLEMENT_PARTICLE_FILTER_CAPABLE(CRBPFParticleData);
93 
94  protected:
95  /** The PF algorithm implementation.
96  */
97  void prediction_and_update_pfStandardProposal(
98  const mrpt::slam::CActionCollection * action,
99  const mrpt::slam::CSensoryFrame * observation,
100  const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
101 
102  /** The PF algorithm implementation.
103  */
104  void prediction_and_update_pfOptimalProposal(
105  const mrpt::slam::CActionCollection * action,
106  const mrpt::slam::CSensoryFrame * observation,
107  const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
108 
109  /** The PF algorithm implementation.
110  */
111  void prediction_and_update_pfAuxiliaryPFOptimal(
112  const mrpt::slam::CActionCollection * action,
113  const mrpt::slam::CSensoryFrame * observation,
114  const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
115 
116 
117  private:
118  /** Internal buffer for the averaged map.
119  */
120  CMultiMetricMap averageMap;
121  bool averageMapIsUpdated;
122 
123  /** The SFs and their corresponding pose estimations:
124  */
126 
127  /** A mapping between indexes in the SFs to indexes in the robot paths from particles.
128  */
129  std::vector<uint32_t> SF2robotPath;
130 
131 
132  /** Entropy aux. function
133  */
134  float H(float p);
135 
136  public:
137 
138  /** The struct for passing extra simulation parameters to the prediction/update stage
139  * when running a particle filter.
140  * \sa prediction_and_update
141  */
143  {
144  /** Default settings method.
145  */
147 
148  /** See utils::CLoadableOptions
149  */
150  void loadFromConfigFile(
151  const mrpt::utils::CConfigFileBase &source,
152  const std::string &section);
153 
154  /** See utils::CLoadableOptions
155  */
156  void dumpToTextStream(CStream &out) const;
157 
158  /** [pf optimal proposal only] Only for PF algorithm=2 (Exact "pfOptimalProposal")
159  * Select the map on which to calculate the optimal
160  * proposal distribution. Values:
161  * 0: Gridmap -> Uses Scan matching-based approximation (based on Stachniss' work)
162  * 1: Landmarks -> Uses matching to approximate optimal
163  * 2: Beacons -> Used for exact optimal proposal in RO-SLAM
164  * 3: Pointsmap -> Uses Scan matching-based approximation with a map of points (based on Stachniss' work)
165  * Default = 0
166  */
168 
169 
170  /** [prediction stage][pf optimal proposal only] If useICPGlobalAlign_withGrid=true, this is the minimum quality ratio [0,1] of the alignment such as it will be accepted. Otherwise, raw odometry is used for those bad cases (default=0.7).
171  */
173 
174  /** [update stage] If the likelihood is computed through the occupancy grid map, then this structure is passed to the map when updating the particles weights in the update stage.
175  */
177 
179 
180  CICP::TConfigParams icp_params; //!< ICP parameters, used only when "PF_algorithm=2" in the particle filter.
181 
182  } options;
183 
184  /** Constructor
185  */
186  CMultiMetricMapPDF(
188  const mrpt::slam::TSetOfMetricMapInitializers *mapsInitializers = NULL,
189  const TPredictionParams *predictionOptions = NULL );
190 
191  /** Destructor
192  */
193  virtual ~CMultiMetricMapPDF();
194 
195  /** Clear all elements of the maps, and restore all paths to a single starting pose */
196  void clear( const CPose2D &initialPose );
197 
198  /** Clear all elements of the maps, and restore all paths to a single starting pose */
199  void clear( const CPose3D &initialPose );
200 
201  /** Returns the estimate of the robot pose as a particles PDF for the instant of time "timeStep", from 0 to N-1.
202  * \sa getEstimatedPosePDF
203  */
204  void getEstimatedPosePDFAtTime(
205  size_t timeStep,
206  CPose3DPDFParticles &out_estimation ) const;
207 
208  /** Returns the current estimate of the robot pose, as a particles PDF.
209  * \sa getEstimatedPosePDFAtTime
210  */
211  void getEstimatedPosePDF( CPose3DPDFParticles &out_estimation ) const;
212 
213  /** Returns the weighted averaged map based on the current best estimation. If you need a persistent copy of this object, please use "CSerializable::duplicate" and use the copy.
214  */
215  CMultiMetricMap * getCurrentMetricMapEstimation( );
216 
217  /** Returns a pointer to the current most likely map (associated to the most likely particle).
218  */
219  CMultiMetricMap * getCurrentMostLikelyMetricMap( );
220 
221  /** Get the number of CSensoryFrame inserted into the internal member SFs */
222  size_t getNumberOfObservationsInSimplemap() const { return SFs.size(); }
223 
224  /** Insert an observation to the map, at each particle's pose and to each particle's metric map.
225  * \param sf The SF to be inserted
226  */
227  void insertObservation(CSensoryFrame &sf);
228 
229  /** Return the path (in absolute coordinate poses) for the i'th particle.
230  * \exception On index out of bounds
231  */
232  void getPath(size_t i, std::deque<math::TPose3D> &out_path) const;
233 
234  /** Returns the current entropy of paths, computed as the average entropy of poses along the path, where entropy of each pose estimation is computed as the entropy of the gaussian approximation covariance.
235  */
236  double getCurrentEntropyOfPaths();
237 
238  /** Returns the joint entropy estimation over paths and maps, acording to "Information Gain-based Exploration Using" by C. Stachniss, G. Grissetti and W.Burgard.
239  */
240  double getCurrentJointEntropy();
241 
242  /** Update the poses estimation of the member "SFs" according to the current path belief.
243  */
244  void updateSensoryFrameSequence();
245 
246  /** A logging utility: saves the current path estimation for each particle in a text file (a row per particle, each 3-column-entry is a set [x,y,phi], respectively).
247  */
248  void saveCurrentPathEstimationToTextFile( const std::string &fil );
249 
250  /** An index [0,1] measuring how much information an observation aports to the map (Typ. threshold=0.07)
251  */
253 
254  private:
255  /** Rebuild the "expected" grid map. Used internally, do not call
256  */
257  void rebuildAverageMap();
258 
259 
260 
261  //protected:
262  public:
263  /** \name Virtual methods that the PF_implementations assume exist.
264  @{ */
265 
266  /** Return a pointer to the last robot pose in the i'th particle (or NULL if it's a path and it's empty). */
267  const TPose3D * getLastPose(const size_t i) const;
268 
269  void PF_SLAM_implementation_custom_update_particle_with_new_pose(
270  CParticleDataContent *particleData,
271  const TPose3D &newPose) const;
272 
273  // The base implementation is fine for this class.
274  // void PF_SLAM_implementation_replaceByNewParticleSet( ...
275 
276  bool PF_SLAM_implementation_doWeHaveValidObservations(
277  const CParticleList &particles,
278  const CSensoryFrame *sf) const;
279 
280  bool PF_SLAM_implementation_skipRobotMovement() const;
281 
282  /** Evaluate the observation likelihood for one particle at a given location */
283  double PF_SLAM_computeObservationLikelihoodForParticle(
284  const CParticleFilter::TParticleFilterOptions &PF_options,
285  const size_t particleIndexForMap,
286  const CSensoryFrame &observation,
287  const CPose3D &x ) const;
288  /** @} */
289 
290 
291  }; // End of class def.
292 
293  } // End of namespace
294 } // End of namespace
295 
296 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013