LoFastSLAM.H

00001 /**
00002    \file  Robots/LoBot/misc/LoFastSLAM.H
00003    \brief An implementation of the grid-based FastSLAM algorithm.
00004 
00005    This file defines a class that implements the FastSLAM algorithm for
00006    building an occupancy grid map while simultaneously localizing the
00007    robot within that map.
00008 */
00009 
00010 // //////////////////////////////////////////////////////////////////// //
00011 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00012 // by the University of Southern California (USC) and the iLab at USC.  //
00013 // See http://iLab.usc.edu for information about this project.          //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00016 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00017 // in Visual Environments, and Applications'' by Christof Koch and      //
00018 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00019 // pending; application number 09/912,225 filed July 23, 2001; see      //
00020 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00021 // //////////////////////////////////////////////////////////////////// //
00022 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00025 // redistribute it and/or modify it under the terms of the GNU General  //
00026 // Public License as published by the Free Software Foundation; either  //
00027 // version 2 of the License, or (at your option) any later version.     //
00028 //                                                                      //
00029 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00030 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00031 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00032 // PURPOSE.  See the GNU General Public License for more details.       //
00033 //                                                                      //
00034 // You should have received a copy of the GNU General Public License    //
00035 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00036 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00037 // Boston, MA 02111-1307 USA.                                           //
00038 // //////////////////////////////////////////////////////////////////// //
00039 //
00040 // Primary maintainer for this file: mviswana usc edu
00041 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/slam/LoFastSLAM.H $
00042 // $Id: LoFastSLAM.H 13575 2010-06-17 01:42:18Z mviswana $
00043 //
00044 
00045 #ifndef LOBOT_FASTSLAM_DOT_H
00046 #define LOBOT_FASTSLAM_DOT_H
00047 
00048 //------------------------------ HEADERS --------------------------------
00049 
00050 // lobot headers
00051 #include "Robots/LoBot/slam/LoParticle.H"
00052 #include "Robots/LoBot/slam/LoOccGrid.H"
00053 #include "Robots/LoBot/slam/LoPose.H"
00054 #include "Robots/LoBot/slam/LoOdometry.H"
00055 #include "Robots/LoBot/io/LoLRFData.H"
00056 
00057 // Boost headers
00058 #include <boost/shared_ptr.hpp>
00059 
00060 // Standard C++ headers
00061 #include <vector>
00062 
00063 //----------------------------- NAMESPACE -------------------------------
00064 
00065 namespace lobot {
00066 
00067 //------------------------- CLASS DEFINITION ----------------------------
00068 
00069 /**
00070    \class lobot::FastSLAM
00071    \brief An implementation of the grid-based FastSLAM algorithm.
00072 
00073    This class implements the FastSLAM algorithm for building an occupancy
00074    grid map while simultaneously localizing the robot within this map.
00075 */
00076 class FastSLAM {
00077    // Prevent copy and assignment
00078    FastSLAM(const FastSLAM&) ;
00079    FastSLAM& operator=(const FastSLAM&) ;
00080 
00081    /// The FastSLAM algorithm is a Rao-Blackwellized particle filter.
00082    /// Thus, it needs a list of particles to get its work done.
00083    //@{
00084    typedef std::vector<Particle> Particles ;
00085    std::vector<Particle> m_particles ;
00086    //@}
00087 
00088    /// When the particle filter arrives at some incorrect state estimate,
00089    /// it is important that it be able to extricate itself from that
00090    /// erroneous state and move towards the correct state. To help with
00091    /// this goal, we introduce random particles spread all over the state
00092    /// space in the hope that, eventually, one of these will be near the
00093    /// correct state and get a high weight, thus, "guiding" the filter to
00094    /// the correct state.
00095    ///
00096    /// Obviously, it would be detrimental to the filter's performance to
00097    /// introduce a lot of random particles or to introduce them when the
00098    /// filter is in the correct state. To determine when random particles
00099    /// are necessary, we keep track of the short and long-term averages
00100    /// of the particle weights. When the short-term average performs
00101    /// poorly w.r.t. the long-term average, we inject random particles
00102    /// with a frequency proportional to the ratio of the
00103    /// short-to-long-term particle weight average.
00104    ///
00105    /// This technique is described in Chapter 8, section 8.3.5, pages 256
00106    /// through 260 of "Probabilistic Robotics" by Thrun, Burgard and Fox.
00107    float m_w_slow, m_w_fast ;
00108 
00109 public:
00110    /// In the grid-based version of FastSLAM, each particle needs to
00111    /// carry its own copy of the occupancy map being built. As this can
00112    /// result in a rather large computational and memory burden, it is
00113    /// crucial to reduce the total number of particles required to
00114    /// effectively perform the SLAM operation.
00115    ///
00116    /// One way to do that is to eschew raw odometry in favour of
00117    /// something more precise such as 2D scan matching based on laser
00118    /// range finder measurements. The Robolocust implementation of
00119    /// FastSLAM does in fact use scan matching.
00120    ///
00121    /// Therefore, during initialization, the client must supply an
00122    /// initial LRF scan.
00123    FastSLAM(const LRFData&) ;
00124 
00125    /// This implementation of FastSLAM can be configured to forgo the
00126    /// mapping operation and perform localization only. In that case, the
00127    /// user must supply a known occupancy grid map, which will be used to
00128    /// exercise the Monte Carlo Localization component of FastSLAM.
00129    ///
00130    /// This constructor is identical to the previous one except that it
00131    /// expects to be given a known map for localization only mode.
00132    FastSLAM(const LRFData&, const boost::shared_ptr<OccGrid>&) ;
00133 
00134    /// This method updates the occupancy map and current pose given the
00135    /// latest (raw) odometry (i.e., control input) and LRF readings
00136    /// (i.e., sensor data).
00137    void update(const Odometry&, const LRFData&) ;
00138 
00139 private:
00140    /// This method updates the short and long-term averages of the
00141    /// particle weights. The ratio of the short-to-long-term averages is
00142    /// used to determine when to introduce random particles to help deal
00143    /// with mislocalizations and also the overall number of random
00144    /// particles to be injected during resampling.
00145    void update_averages() ;
00146 
00147 public:
00148    /// As mentioned earlier, in grid-based FastSLAM, each particle
00149    /// carries its own copy of both the occupancy map being built as well
00150    /// as the robot's current pose. These methods return the current best
00151    /// hypothesis of the actual map or pose by applying a robust mean
00152    /// procedure that works like so:
00153    ///
00154    /// First, we find the particle with maximum weight. Then, we find the
00155    /// K particles whose states most closely match that of the max
00156    /// particle. The final state is computed as the average of these K
00157    /// states.
00158    ///
00159    /// NOTE: K is specified in the Robolocust config file as a percentage
00160    /// of the total number of particles.
00161    //@{
00162    OccGrid current_map()  const ;
00163    Pose    current_pose() const ;
00164    //@}
00165 
00166    /// Visualization support: return a list of Particle::Viz structures
00167    /// so that the client knows the current pose hypotheses and their
00168    /// corresponding weights.
00169    std::vector<Particle::Viz> viz() const ;
00170 
00171    /// Clean-up.
00172    ~FastSLAM() ;
00173 } ;
00174 
00175 //-----------------------------------------------------------------------
00176 
00177 } // end of namespace encapsulating this file's definitions
00178 
00179 #endif
00180 
00181 /* So things look consistent in everyone's emacs... */
00182 /* Local Variables: */
00183 /* indent-tabs-mode: nil */
00184 /* End: */
Generated on Sun May 8 08:41:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3