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 CBeaconMap_H 00029 #define CBeaconMap_H 00030 00031 #include <mrpt/slam/CMetricMap.h> 00032 #include <mrpt/slam/CBeacon.h> 00033 #include <mrpt/utils/CSerializable.h> 00034 #include <mrpt/math/CMatrix.h> 00035 #include <mrpt/utils/CDynamicGrid.h> 00036 #include <mrpt/utils/CLoadableOptions.h> 00037 00038 #include <mrpt/maps/link_pragmas.h> 00039 00040 namespace mrpt 00041 { 00042 namespace slam 00043 { 00044 using namespace mrpt::utils; 00045 using namespace mrpt::math; 00046 00047 class CObservationBeaconRanges; 00048 00049 00050 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CBeaconMap, CMetricMap ,MAPS_IMPEXP ) 00051 00052 /** A class for storing a map of 3D probabilistic beacons, using a Montecarlo, Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM). 00053 * <br> 00054 * The individual beacons are defined as mrpt::slam::CBeacon objects. 00055 * <br> 00056 * When invoking CBeaconMap::insertObservation(), landmarks will be extracted and fused into the map. 00057 * The only currently supported observation type is mrpt::slam::CObservationBeaconRanges. 00058 * See insertionOptions and likelihoodOptions for parameters used when creating and fusing beacon landmarks. 00059 * <br> 00060 * Use "TInsertionOptions::insertAsMonteCarlo" to select between 2 different behaviors: 00061 * - Initial PDF of beacons: MonteCarlo, after convergence, pass to Gaussians; or 00062 * - Initial PDF of beacons: SOG, after convergence, a single Gaussian. 00063 * 00064 * Refer to the papers: [] 00065 * 00066 * \ingroup mrpt_maps_grp 00067 * \sa CMetricMap 00068 */ 00069 class MAPS_IMPEXP CBeaconMap : public CMetricMap 00070 { 00071 // This must be added to any CSerializable derived class: 00072 DEFINE_SERIALIZABLE( CBeaconMap ) 00073 00074 public: 00075 typedef std::deque<CBeacon> TSequenceBeacons; 00076 typedef std::deque<CBeacon>::iterator iterator; 00077 typedef std::deque<CBeacon>::const_iterator const_iterator; 00078 00079 protected: 00080 /** The individual beacons */ 00081 TSequenceBeacons m_beacons; 00082 00083 /** Clear the map, erasing all landmarks. 00084 */ 00085 virtual void internal_clear(); 00086 00087 /** Insert the observation information into this map. This method must be implemented 00088 * in derived classes. 00089 * \param obs The observation 00090 * \param robotPose The 3D pose of the robot mobile base in the map reference system, or NULL (default) if you want to use CPose2D(0,0,deg) 00091 * 00092 * \sa CObservation::insertObservationInto 00093 */ 00094 virtual bool internal_insertObservation( const CObservation *obs, const CPose3D *robotPose = NULL ); 00095 00096 public: 00097 /** Constructor */ 00098 CBeaconMap(); 00099 00100 void resize(const size_t N); //!< Resize the number of SOG modes 00101 00102 /** Access to individual beacons */ 00103 const CBeacon& operator [](size_t i) const { 00104 ASSERT_(i<m_beacons.size()) 00105 return m_beacons[i]; 00106 } 00107 /** Access to individual beacons */ 00108 const CBeacon& get(size_t i) const{ 00109 ASSERT_(i<m_beacons.size()) 00110 return m_beacons[i]; 00111 } 00112 /** Access to individual beacons */ 00113 CBeacon& operator [](size_t i) { 00114 ASSERT_(i<m_beacons.size()) 00115 return m_beacons[i]; 00116 } 00117 /** Access to individual beacons */ 00118 CBeacon& get(size_t i) { 00119 ASSERT_(i<m_beacons.size()) 00120 return m_beacons[i]; 00121 } 00122 00123 iterator begin() { return m_beacons.begin(); } 00124 const_iterator begin() const { return m_beacons.begin(); } 00125 iterator end() { return m_beacons.end(); } 00126 const_iterator end() const { return m_beacons.end(); } 00127 00128 /** Inserts a copy of the given mode into the SOG */ 00129 void push_back(const CBeacon& m) { 00130 m_beacons.push_back( m ); 00131 } 00132 00133 /** Computes the ratio in [0,1] of correspondences between "this" and the "otherMap" map, whose 6D pose relative to "this" is "otherMapPose" 00134 * In the case of a multi-metric map, this returns the average between the maps. This method always return 0 for grid maps. 00135 * \param otherMap [IN] The other map to compute the matching with. 00136 * \param otherMapPose [IN] The 6D pose of the other map as seen from "this". 00137 * \param minDistForCorr [IN] The minimum distance between 2 non-probabilistic map elements for counting them as a correspondence. 00138 * \param minMahaDistForCorr [IN] The minimum Mahalanobis distance between 2 probabilistic map elements for counting them as a correspondence. 00139 * 00140 * \return The matching ratio [0,1] 00141 * \sa computeMatchingWith2D 00142 */ 00143 float compute3DMatchingRatio( 00144 const CMetricMap *otherMap, 00145 const CPose3D &otherMapPose, 00146 float minDistForCorr = 0.10f, 00147 float minMahaDistForCorr = 2.0f 00148 ) const; 00149 00150 /** With this struct options are provided to the likelihood computations. 00151 */ 00152 struct MAPS_IMPEXP TLikelihoodOptions : public utils::CLoadableOptions 00153 { 00154 public: 00155 /** Initilization of default parameters 00156 */ 00157 TLikelihoodOptions(); 00158 00159 /** See utils::CLoadableOptions 00160 */ 00161 void loadFromConfigFile( 00162 const mrpt::utils::CConfigFileBase &source, 00163 const std::string §ion); 00164 00165 /** See utils::CLoadableOptions 00166 */ 00167 void dumpToTextStream(CStream &out) const; 00168 00169 /** The standard deviation used for Beacon ranges likelihood (default=0.08m). 00170 */ 00171 float rangeStd; 00172 00173 } likelihoodOptions; 00174 00175 /** This struct contains data for choosing the method by which new beacons are inserted in the map. 00176 */ 00177 struct MAPS_IMPEXP TInsertionOptions : public utils::CLoadableOptions 00178 { 00179 public: 00180 /** Initilization of default parameters 00181 */ 00182 TInsertionOptions(); 00183 00184 /** See utils::CLoadableOptions 00185 */ 00186 void loadFromConfigFile( 00187 const mrpt::utils::CConfigFileBase &source, 00188 const std::string §ion); 00189 00190 /** See utils::CLoadableOptions 00191 */ 00192 void dumpToTextStream(CStream &out) const; 00193 00194 /** Insert a new beacon as a set of montecarlo samples (default=true), or, if false, as a sum of gaussians (see mrpt::slam::CBeacon). 00195 * \sa MC_performResampling 00196 */ 00197 bool insertAsMonteCarlo; 00198 00199 /** Minimum and maximum elevation angles (in degrees) for inserting new beacons at the first observation: the default values (both 0), makes the beacons to be in the same horizontal plane that the sensors, that is, 2D SLAM - the min/max values are -90/90. 00200 */ 00201 float maxElevation_deg,minElevation_deg; 00202 00203 /** Number of particles per meter of range, i.e. per meter of the "radius of the ring". 00204 */ 00205 unsigned int MC_numSamplesPerMeter; 00206 00207 /** The threshold for the maximum std (X,Y,and Z) before colapsing the particles into a Gaussian PDF (default=0,4). 00208 */ 00209 float MC_maxStdToGauss; 00210 00211 /** Threshold for the maximum difference from the maximun (log) weight in the set of samples for erasing a given sample (default=5). 00212 */ 00213 float MC_thresholdNegligible; 00214 00215 /** If set to false (default), the samples will be generated the first time a beacon is observed, and their weights just updated subsequently - if set to "true", fewer samples will be required since the particles will be resamples when necessary, and a small "noise" will be added to avoid depletion. 00216 */ 00217 bool MC_performResampling; 00218 00219 /** The std.dev. of the Gaussian noise to be added to each sample after resampling, only if MC_performResampling=true. 00220 */ 00221 float MC_afterResamplingNoise; 00222 00223 /** Threshold for the maximum difference from the maximun (log) weight in the SOG for erasing a given mode (default=20). 00224 */ 00225 float SOG_thresholdNegligible; 00226 00227 /** A parameter for initializing 2D/3D SOGs 00228 */ 00229 float SOG_maxDistBetweenGaussians; 00230 00231 /** Constant used to compute the std. dev. int the tangent direction when creating the Gaussians. 00232 */ 00233 float SOG_separationConstant; 00234 00235 } insertionOptions; 00236 00237 /** Save to a MATLAB script which displays 3D error ellipses for the map. 00238 * \param file The name of the file to save the script to. 00239 * \param style The MATLAB-like string for the style of the lines (see 'help plot' in MATLAB for posibilities) 00240 * \param stdCount The ellipsoids will be drawn from the center to a given confidence interval in [0,1], e.g. 2 sigmas=0.95 (default is 2std = 0.95 confidence intervals) 00241 * 00242 * \return Returns false if any error occured, true elsewere. 00243 */ 00244 bool saveToMATLABScript3D( 00245 std::string file, 00246 const char *style="b", 00247 float confInterval = 0.95f ) const; 00248 00249 00250 /** Returns the stored landmarks count. 00251 */ 00252 size_t size() const; 00253 00254 00255 /** Computes the (logarithmic) likelihood that a given observation was taken from a given pose in the world being modeled with this map. 00256 * 00257 * In the current implementation, this method behaves in a different way according to the nature of 00258 * the observation's class: 00259 * - "mrpt::slam::CObservation2DRangeScan": This calls "computeLikelihood_RSLC_2007". 00260 * - "mrpt::slam::CObservationStereoImages": This calls "computeLikelihood_SIFT_LandmarkMap". 00261 * 00262 * \param takenFrom The robot's pose the observation is supposed to be taken from. 00263 * \param obs The observation. 00264 * \return This method returns a likelihood value > 0. 00265 * 00266 * \sa Used in particle filter algorithms, see: CMultiMetricMapPDF::update 00267 */ 00268 double computeObservationLikelihood( const CObservation *obs, const CPose3D &takenFrom ); 00269 00270 /** Computes the matchings between this and another 2D points map. 00271 This includes finding: 00272 - The set of points pairs in each map 00273 - The mean squared distance between corresponding pairs. 00274 This method is the most time critical one into the ICP algorithm. 00275 00276 * \param otherMap [IN] The other map to compute the matching with. 00277 * \param otherMapPose [IN] The pose of the other map as seen from "this". 00278 * \param maxDistForCorrespondence [IN] Maximum 2D linear distance between two points to be matched. 00279 * \param maxAngularDistForCorrespondence [IN] In radians: The aim is to allow larger distances to more distant correspondences. 00280 * \param angularDistPivotPoint [IN] The point used to calculate distances from in both maps. 00281 * \param correspondences [OUT] The detected matchings pairs. 00282 * \param correspondencesRatio [OUT] The ratio [0,1] of points in otherMap with at least one correspondence. 00283 * \param sumSqrDist [OUT] The sum of all matched points squared distances.If undesired, set to NULL, as default. 00284 * \param covariance [OUT] The resulting matching covariance 3x3 matrix, or NULL if undesired. 00285 * \param onlyKeepTheClosest [IN] If set to true, only the closest correspondence will be returned. If false (default) all are returned. 00286 * 00287 * \sa compute3DMatchingRatio 00288 */ 00289 void computeMatchingWith2D( 00290 const CMetricMap *otherMap, 00291 const CPose2D &otherMapPose, 00292 float maxDistForCorrespondence, 00293 float maxAngularDistForCorrespondence, 00294 const CPose2D &angularDistPivotPoint, 00295 TMatchingPairList &correspondences, 00296 float &correspondencesRatio, 00297 float *sumSqrDist = NULL, 00298 bool onlyKeepTheClosest = false, 00299 bool onlyUniqueRobust = false, 00300 const size_t decimation_other_map_points = 1, 00301 const size_t offset_other_map_points = 0 ) const; 00302 00303 /** Perform a search for correspondences between "this" and another lansmarks map: 00304 * Firsly, the landmarks' descriptor is used to find correspondences, then inconsistent ones removed by 00305 * looking at their 3D poses. 00306 * \param otherMap [IN] The other map. 00307 * \param correspondences [OUT] The matched pairs between maps. 00308 * \param correspondencesRatio [OUT] This is NumberOfMatchings / NumberOfLandmarksInTheAnotherMap 00309 * \param otherCorrespondences [OUT] Will be returned with a vector containing "true" for the indexes of the other map's landmarks with a correspondence. 00310 */ 00311 void computeMatchingWith3DLandmarks( 00312 const mrpt::slam::CBeaconMap *otherMap, 00313 TMatchingPairList &correspondences, 00314 float &correspondencesRatio, 00315 std::vector<bool> &otherCorrespondences) const; 00316 00317 /** Changes the reference system of the map to a given 3D pose. 00318 */ 00319 void changeCoordinatesReference( const CPose3D &newOrg ); 00320 00321 /** Changes the reference system of the map "otherMap" and save the result in "this" map. 00322 */ 00323 void changeCoordinatesReference( const CPose3D &newOrg, const mrpt::slam::CBeaconMap *otherMap ); 00324 00325 00326 /** Returns true if the map is empty/no observation has been inserted. 00327 */ 00328 bool isEmpty() const; 00329 00330 /** Simulates a reading toward each of the beacons in the landmarks map, if any. 00331 * \param in_robotPose This robot pose is used to simulate the ranges to each beacon. 00332 * \param in_sensorLocationOnRobot The 3D position of the sensor on the robot 00333 * \param out_Observations The results will be stored here. NOTICE that the fields "CObservationBeaconRanges::minSensorDistance","CObservationBeaconRanges::maxSensorDistance" and "CObservationBeaconRanges::stdError" MUST BE FILLED OUT before calling this function. 00334 * An observation will be generated for each beacon in the map, but notice that some of them may be missed if out of the sensor maximum range. 00335 */ 00336 void simulateBeaconReadings( 00337 const CPose3D &in_robotPose, 00338 const CPoint3D &in_sensorLocationOnRobot, 00339 CObservationBeaconRanges &out_Observations ) const; 00340 00341 /** This virtual method saves the map to a file "filNamePrefix"+< some_file_extension >, as an image or in any other applicable way (Notice that other methods to save the map may be implemented in classes implementing this virtual interface). 00342 * In the case of this class, these files are generated: 00343 * - "filNamePrefix"+"_3D.m": A script for MATLAB for drawing landmarks as 3D ellipses. 00344 * - "filNamePrefix"+"_3D.3DScene": A 3D scene with a "ground plane grid" and the set of ellipsoids in 3D. 00345 * - "filNamePrefix"+"_covs.m": A textual representation (see saveToTextFile) 00346 */ 00347 void saveMetricMapRepresentationToFile( 00348 const std::string &filNamePrefix ) const; 00349 00350 /** Save a text file with a row per beacon, containing this 11 elements: 00351 * - X Y Z: Mean values 00352 * - VX VY VZ: Variances of each dimension (C11, C22, C33) 00353 * - DET2D DET3D: Determinant of the 2D and 3D covariance matrixes. 00354 * - C12, C13, C23: Cross covariances 00355 */ 00356 void saveToTextFile(const std::string &fil) const; 00357 00358 /** Returns a 3D object representing the map. 00359 */ 00360 void getAs3DObject ( mrpt::opengl::CSetOfObjectsPtr &outObj ) const; 00361 00362 /** Returns a pointer to the beacon with the given ID, or NULL if it does not exist. 00363 */ 00364 const CBeacon * getBeaconByID( CBeacon::TBeaconID id ) const; 00365 00366 /** Returns a pointer to the beacon with the given ID, or NULL if it does not exist. 00367 */ 00368 CBeacon * getBeaconByID( CBeacon::TBeaconID id ); 00369 00370 }; // End of class def. 00371 00372 00373 } // End of namespace 00374 } // End of namespace 00375 00376 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |