Main MRPT website > C++ reference
MRPT logo
CMultiMetricMapPDF.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CMultiMetricMapPDF_H
00029 #define CMultiMetricMapPDF_H
00030 
00031 #include <mrpt/slam/CMultiMetricMap.h>
00032 #include <mrpt/slam/CSimpleMap.h>
00033 #include <mrpt/poses/CPosePDFParticles.h>
00034 #include <mrpt/poses/CPose3DPDFParticles.h>
00035 
00036 #include <mrpt/poses/CPoseRandomSampler.h>
00037 
00038 #include <mrpt/bayes/CParticleFilterCapable.h>
00039 #include <mrpt/utils/CLoadableOptions.h>
00040 #include <mrpt/slam/CICP.h>
00041 
00042 #include <mrpt/slam/PF_implementations_data.h>
00043 
00044 #include <mrpt/slam/link_pragmas.h>
00045 
00046 namespace mrpt
00047 {
00048 namespace slam
00049 {
00050         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CRBPFParticleData, mrpt::utils::CSerializable, SLAM_IMPEXP )
00051 
00052         /** Auxiliary class used in mrpt::slam::CMultiMetricMapPDF
00053          * \ingroup mrpt_slam_grp
00054           */
00055         class SLAM_IMPEXP CRBPFParticleData : public mrpt::utils::CSerializable
00056         {
00057                 // This must be added to any CSerializable derived class:
00058                 DEFINE_SERIALIZABLE( CRBPFParticleData )
00059         public:
00060                 CRBPFParticleData( const TSetOfMetricMapInitializers *mapsInitializers = NULL ) :
00061                   mapTillNow( mapsInitializers ),
00062                   robotPath()
00063                 {
00064                 }
00065 
00066                 CMultiMetricMap                 mapTillNow;
00067                 std::deque<TPose3D>             robotPath;
00068         };
00069 
00070 
00071         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CMultiMetricMapPDF, mrpt::utils::CSerializable, SLAM_IMPEXP )
00072 
00073         /** 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).
00074          *   This class is used internally by the map building algorithm in "mrpt::slam::CMetricMapBuilderRBPF"
00075          *
00076          * \sa mrpt::slam::CMetricMapBuilderRBPF
00077          * \ingroup metric_slam_grp
00078          */
00079         class SLAM_IMPEXP CMultiMetricMapPDF :
00080                 public mrpt::utils::CSerializable,
00081                 public mrpt::bayes::CParticleFilterData<CRBPFParticleData>,
00082                 public mrpt::bayes::CParticleFilterCapable,
00083                 public mrpt::slam::PF_implementation<CRBPFParticleData,CMultiMetricMapPDF>
00084         {
00085                 friend class CMetricMapBuilderRBPF;
00086                 //template <class PARTICLE_TYPE, class MYSELF> friend class PF_implementation;
00087 
00088                 // This must be added to any CSerializable derived class:
00089                 DEFINE_SERIALIZABLE( CMultiMetricMapPDF )
00090 
00091                 // This uses CParticleFilterData to implement some methods required for CParticleFilterCapable:
00092                 IMPLEMENT_PARTICLE_FILTER_CAPABLE(CRBPFParticleData);
00093 
00094         protected:
00095                 /** The PF algorithm implementation.
00096                   */
00097                 void  prediction_and_update_pfStandardProposal(
00098                         const mrpt::slam::CActionCollection     * action,
00099                         const mrpt::slam::CSensoryFrame         * observation,
00100                         const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
00101 
00102                 /** The PF algorithm implementation.
00103                   */
00104                 void  prediction_and_update_pfOptimalProposal(
00105                         const mrpt::slam::CActionCollection     * action,
00106                         const mrpt::slam::CSensoryFrame         * observation,
00107                         const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
00108 
00109                 /** The PF algorithm implementation.
00110                   */
00111                 void  prediction_and_update_pfAuxiliaryPFOptimal(
00112                         const mrpt::slam::CActionCollection     * action,
00113                         const mrpt::slam::CSensoryFrame         * observation,
00114                         const bayes::CParticleFilter::TParticleFilterOptions &PF_options );
00115 
00116 
00117         private:
00118                 /** Internal buffer for the averaged map.
00119                   */
00120                 CMultiMetricMap                 averageMap;
00121                 bool                                    averageMapIsUpdated;
00122 
00123                 /** The SFs and their corresponding pose estimations:
00124                  */
00125                 CSimpleMap      SFs;
00126 
00127                 /** A mapping between indexes in the SFs to indexes in the robot paths from particles.
00128                   */
00129                 std::vector<uint32_t>   SF2robotPath;
00130 
00131 
00132                 /** Entropy aux. function
00133                   */
00134                 float  H(float p);
00135 
00136         public:
00137 
00138                 /** The struct for passing extra simulation parameters to the prediction/update stage
00139                  *    when running a particle filter.
00140                  * \sa prediction_and_update
00141                  */
00142                 struct SLAM_IMPEXP TPredictionParams : public utils::CLoadableOptions
00143                 {
00144                         /** Default settings method.
00145                           */
00146                         TPredictionParams();
00147 
00148                         /** See utils::CLoadableOptions
00149                           */
00150                         void  loadFromConfigFile(
00151                                 const mrpt::utils::CConfigFileBase  &source,
00152                                 const std::string &section);
00153 
00154                         /** See utils::CLoadableOptions
00155                           */
00156                         void  dumpToTextStream(CStream  &out) const;
00157 
00158                         /** [pf optimal proposal only]  Only for PF algorithm=2 (Exact "pfOptimalProposal")
00159                          *   Select the map on which to calculate the optimal
00160                          *    proposal distribution. Values:
00161                          *   0: Gridmap   -> Uses Scan matching-based approximation (based on Stachniss' work)
00162                          *   1: Landmarks -> Uses matching to approximate optimal
00163                          *   2: Beacons   -> Used for exact optimal proposal in RO-SLAM
00164                          *   3: Pointsmap -> Uses Scan matching-based approximation with a map of points (based on Stachniss' work)
00165                          *  Default = 0
00166                          */
00167                         int             pfOptimalProposal_mapSelection;
00168 
00169 
00170                         /** [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).
00171                           */
00172                         float           ICPGlobalAlign_MinQuality;
00173 
00174                         /** [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.
00175                           */
00176                         COccupancyGridMap2D::TLikelihoodOptions         update_gridMapLikelihoodOptions;
00177 
00178                         TKLDParams              KLD_params;
00179 
00180                         CICP::TConfigParams             icp_params; //!< ICP parameters, used only when "PF_algorithm=2" in the particle filter.
00181 
00182                 } options;
00183 
00184                 /** Constructor
00185                   */
00186                 CMultiMetricMapPDF(
00187                         const bayes::CParticleFilter::TParticleFilterOptions    &opts = bayes::CParticleFilter::TParticleFilterOptions(),
00188                         const mrpt::slam::TSetOfMetricMapInitializers               *mapsInitializers = NULL,
00189                         const TPredictionParams                                             *predictionOptions = NULL );
00190 
00191                 /** Destructor
00192                  */
00193                 virtual ~CMultiMetricMapPDF();
00194 
00195                 /** Clear all elements of the maps, and restore all paths to a single starting pose */
00196                 void  clear( const CPose2D &initialPose );
00197 
00198                 /** Clear all elements of the maps, and restore all paths to a single starting pose */
00199                 void  clear( const CPose3D &initialPose );
00200 
00201                  /** Returns the estimate of the robot pose as a particles PDF for the instant of time "timeStep", from 0 to N-1.
00202                   * \sa getEstimatedPosePDF
00203                   */
00204                 void  getEstimatedPosePDFAtTime(
00205                         size_t                          timeStep,
00206                         CPose3DPDFParticles &out_estimation ) const;
00207 
00208                  /** Returns the current estimate of the robot pose, as a particles PDF.
00209                   * \sa getEstimatedPosePDFAtTime
00210                   */
00211                 void  getEstimatedPosePDF( CPose3DPDFParticles  &out_estimation ) const;
00212 
00213                 /** 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.
00214                   */
00215                 CMultiMetricMap * getCurrentMetricMapEstimation( );
00216 
00217                 /** Returns a pointer to the current most likely map (associated to the most likely particle).
00218                   */
00219                 CMultiMetricMap  * getCurrentMostLikelyMetricMap( );
00220 
00221                 /** Get the number of CSensoryFrame inserted into the internal member SFs */
00222                 size_t  getNumberOfObservationsInSimplemap() const { return SFs.size(); }
00223 
00224                 /** Insert an observation to the map, at each particle's pose and to each particle's metric map.
00225                   * \param sf The SF to be inserted
00226                   */
00227                 void  insertObservation(CSensoryFrame   &sf);
00228 
00229                 /** Return the path (in absolute coordinate poses) for the i'th particle.
00230                   * \exception On index out of bounds
00231                   */
00232                 void  getPath(size_t i, std::deque<math::TPose3D> &out_path) const;
00233 
00234                 /** 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.
00235                   */
00236                 double  getCurrentEntropyOfPaths();
00237 
00238                 /** Returns the joint entropy estimation over paths and maps, acording to "Information Gain-based Exploration Using" by C. Stachniss, G. Grissetti and W.Burgard.
00239                   */
00240                 double  getCurrentJointEntropy();
00241 
00242                 /** Update the poses estimation of the member "SFs" according to the current path belief.
00243                   */
00244                 void  updateSensoryFrameSequence();
00245 
00246                 /** 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).
00247                   */
00248                 void  saveCurrentPathEstimationToTextFile( const std::string  &fil );
00249 
00250                 /** An index [0,1] measuring how much information an observation aports to the map (Typ. threshold=0.07)
00251                   */
00252                 float                                           newInfoIndex;
00253 
00254          private:
00255                 /** Rebuild the "expected" grid map. Used internally, do not call
00256                   */
00257                 void  rebuildAverageMap();
00258 
00259 
00260 
00261         //protected:
00262         public:
00263                         /** \name Virtual methods that the PF_implementations assume exist.
00264                             @{ */
00265 
00266                         /** Return a pointer to the last robot pose in the i'th particle (or NULL if it's a path and it's empty). */
00267                         const TPose3D * getLastPose(const size_t i) const;
00268 
00269                         void PF_SLAM_implementation_custom_update_particle_with_new_pose(
00270                                 CParticleDataContent *particleData,
00271                                 const TPose3D &newPose) const;
00272 
00273                         // The base implementation is fine for this class.
00274                         // void PF_SLAM_implementation_replaceByNewParticleSet( ...
00275 
00276                         bool PF_SLAM_implementation_doWeHaveValidObservations(
00277                                 const CParticleList     &particles,
00278                                 const CSensoryFrame *sf) const;
00279 
00280                         bool PF_SLAM_implementation_skipRobotMovement() const;
00281 
00282                         /** Evaluate the observation likelihood for one particle at a given location */
00283                         double PF_SLAM_computeObservationLikelihoodForParticle(
00284                                 const CParticleFilter::TParticleFilterOptions   &PF_options,
00285                                 const size_t                    particleIndexForMap,
00286                                 const CSensoryFrame             &observation,
00287                                 const CPose3D                   &x ) const;
00288                         /** @} */
00289 
00290 
00291         }; // End of class def.
00292 
00293         } // End of namespace
00294 } // End of namespace
00295 
00296 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011