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 CMetricMapBuilderICP_H 00029 #define CMetricMapBuilderICP_H 00030 00031 #include <mrpt/slam/CMetricMapBuilder.h> 00032 #include <mrpt/slam/CICP.h> 00033 #include <mrpt/poses/CRobot2DPoseEstimator.h> 00034 00035 #include <mrpt/slam/link_pragmas.h> 00036 00037 00038 namespace mrpt 00039 { 00040 namespace slam 00041 { 00042 /** A class for very simple 2D SLAM based on ICP. This is a non-probabilistic pose tracking algorithm. 00043 * Map are stored as in files as binary dumps of "mrpt::slam::CSimpleMap" objects. The methods are 00044 * thread-safe. 00045 * \ingroup metric_slam_grp 00046 */ 00047 class SLAM_IMPEXP CMetricMapBuilderICP : public CMetricMapBuilder 00048 { 00049 public: 00050 /** Default constructor - Upon construction, you can set the parameters in ICP_options, then call "initialize". 00051 */ 00052 CMetricMapBuilderICP(); 00053 00054 /** Destructor: 00055 */ 00056 virtual ~CMetricMapBuilderICP(); 00057 00058 /** Algorithm configuration params 00059 */ 00060 struct SLAM_IMPEXP TConfigParams : public mrpt::utils::CLoadableOptions 00061 { 00062 /** Initializer */ 00063 TConfigParams (); 00064 virtual void loadFromConfigFile( 00065 const mrpt::utils::CConfigFileBase &source, 00066 const std::string §ion); 00067 virtual void dumpToTextStream( CStream &out) const; 00068 00069 /** (default:false) Match against the occupancy grid or the points map? The former is quicker but less precise. */ 00070 bool matchAgainstTheGrid; 00071 00072 double insertionLinDistance; //!< Minimum robot linear (m) displacement for a new observation to be inserted in the map. 00073 double insertionAngDistance; //!< Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be inserted in the map. 00074 double localizationLinDistance; //!< Minimum robot linear (m) displacement for a new observation to be used to do ICP-based localization (otherwise, dead-reckon with odometry). 00075 double localizationAngDistance;//!< Minimum robot angular (rad, deg when loaded from the .ini) displacement for a new observation to be used to do ICP-based localization (otherwise, dead-reckon with odometry). 00076 00077 double minICPgoodnessToAccept; //!< Minimum ICP goodness (0,1) to accept the resulting corrected position (default: 0.40) 00078 00079 /** What maps to create (at least one points map and/or a grid map are needed). 00080 * For the expected format in the .ini file when loaded with loadFromConfigFile(), see documentation of TSetOfMetricMapInitializers. 00081 */ 00082 TSetOfMetricMapInitializers mapInitializers; 00083 00084 }; 00085 00086 TConfigParams ICP_options; //!< Options for the ICP-SLAM application \sa ICP_params 00087 CICP::TConfigParams ICP_params; //!< Options for the ICP algorithm itself \sa ICP_options 00088 00089 /** Initialize the method, starting with a known location PDF "x0"(if supplied, set to NULL to left unmodified) and a given fixed, past map. 00090 * This method MUST be called if using the default constructor, after loading the configuration into ICP_options. In particular, TConfigParams::mapInitializers 00091 */ 00092 void initialize( 00093 const CSimpleMap &initialMap = CSimpleMap(), 00094 CPosePDF *x0 = NULL 00095 ); 00096 00097 /** Returns a copy of the current best pose estimation as a pose PDF. 00098 */ 00099 CPose3DPDFPtr getCurrentPoseEstimation() const; 00100 00101 /** Sets the "current map file", thus that map will be loaded if it exists or a new one will be created if it does not, and the updated map will be save to that file when destroying the object. 00102 */ 00103 void setCurrentMapFile( const char *mapFile ); 00104 00105 /** Appends a new action and observations to update this map: See the description of the class at the top of this page to see a more complete description. 00106 * \param action The estimation of the incremental pose change in the robot pose. 00107 * \param in_SF The set of observations that robot senses at the new pose. 00108 * See params in CMetricMapBuilder::options and CMetricMapBuilderICP::ICP_options 00109 * \sa processObservation 00110 */ 00111 void processActionObservation( 00112 CActionCollection &action, 00113 CSensoryFrame &in_SF ); 00114 00115 /** The main method of this class: Process one odometry or sensor observation. 00116 The new entry point of the algorithm (the old one was processActionObservation, which now is a wrapper to 00117 this method). 00118 * See params in CMetricMapBuilder::options and CMetricMapBuilderICP::ICP_options 00119 */ 00120 void processObservation(const CObservationPtr &obs); 00121 00122 00123 /** Fills "out_map" with the set of "poses"-"sensory-frames", thus the so far built map. 00124 */ 00125 void getCurrentlyBuiltMap(CSimpleMap &out_map) const; 00126 00127 00128 /** Returns the 2D points of current local map 00129 */ 00130 void getCurrentMapPoints( std::vector<float> &x, std::vector<float> &y); 00131 00132 /** Returns the map built so far. NOTE that for efficiency a pointer to the internal object is passed, DO NOT delete nor modify the object in any way, if desired, make a copy of ir with "duplicate()". 00133 */ 00134 CMultiMetricMap* getCurrentlyBuiltMetricMap(); 00135 00136 /** Returns just how many sensory-frames are stored in the currently build map. 00137 */ 00138 unsigned int getCurrentlyBuiltMapSize(); 00139 00140 /** A useful method for debugging: the current map (and/or poses) estimation is dumped to an image file. 00141 * \param file The output file name 00142 * \param formatEMF_BMP Output format = true:EMF, false:BMP 00143 */ 00144 void saveCurrentEstimationToImage(const std::string &file, bool formatEMF_BMP = true); 00145 00146 private: 00147 /** The set of observations that leads to current map: 00148 */ 00149 CSimpleMap SF_Poses_seq; 00150 00151 /** The metric map representation as a points map: 00152 */ 00153 CMultiMetricMap metricMap; 00154 00155 /** Current map file. 00156 */ 00157 std::string currentMapFile; 00158 00159 /** The pose estimation by the alignment algorithm (ICP). */ 00160 mrpt::poses::CRobot2DPoseEstimator m_lastPoseEst; //!< Last pose estimation (Mean) 00161 mrpt::math::CMatrixDouble33 m_lastPoseEst_cov; //!< Last pose estimation (covariance) 00162 00163 /** The estimated robot path: 00164 */ 00165 std::deque<mrpt::math::TPose2D> m_estRobotPath; 00166 mrpt::poses::CPose2D m_auxAccumOdometry; 00167 00168 /** Traveled distances from last map update / ICP-based localization. */ 00169 struct SLAM_IMPEXP TDist 00170 { 00171 TDist() : lin(0),ang(0) { } 00172 double lin; // meters 00173 double ang; // degrees 00174 }; 00175 TDist m_distSinceLastICP; 00176 std::map<std::string,TDist> m_distSinceLastInsertion; //!< Indexed by sensor label. 00177 bool m_there_has_been_an_odometry; 00178 void accumulateRobotDisplacementCounters(const CPose2D &Apose); 00179 00180 }; 00181 00182 } // End of namespace 00183 } // End of namespace 00184 00185 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |