00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 CBeacon_H 00029 #define CBeacon_H 00030 00031 #include <mrpt/utils/CSerializable.h> 00032 #include <mrpt/math/CMatrix.h> 00033 #include <mrpt/system/os.h> 00034 #include <mrpt/utils/CStringList.h> 00035 #include <mrpt/poses/CPoint3D.h> 00036 #include <mrpt/poses/CPointPDFParticles.h> 00037 #include <mrpt/poses/CPointPDFGaussian.h> 00038 #include <mrpt/poses/CPointPDFSOG.h> 00039 00040 namespace mrpt 00041 { 00042 namespace slam 00043 { 00044 using namespace mrpt::poses; 00045 using namespace mrpt::utils; 00046 00047 class CBeaconMap; 00048 DEFINE_SERIALIZABLE_PRE( CBeacon ) 00049 00050 /** The class for storing individual "beacon landmarks" under a variety of 3D position PDF distributions. 00051 * This class is used for storage within the class CBeaconMap. 00052 * The class implements the same methods than the interface "CPointPDF", and invoking them actually becomes 00053 * a mapping into the methods of the current PDF representation of the beacon, selectable by means of "m_typePDF" 00054 * \sa CBeaconMap, CPointPDFSOG 00055 */ 00056 class MRPTDLLIMPEXP CBeacon : public CPointPDF 00057 { 00058 // This must be added to any CSerializable derived class: 00059 DEFINE_SERIALIZABLE( CBeacon ) 00060 00061 public: 00062 /** The type for the IDs of landmarks. 00063 */ 00064 typedef int64_t TBeaconID; 00065 00066 /** See m_typePDF 00067 */ 00068 enum TTypePDF { pdfMonteCarlo = 0, pdfGauss, pdfSOG }; 00069 00070 /** Which one of the different 3D point PDF is currently used in this object: montecarlo, gaussian, or a sum of gaussians. 00071 * \sa m_location 00072 */ 00073 TTypePDF m_typePDF; 00074 00075 /** The individual PDF, if m_typePDF=pdfMonteCarlo (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon). 00076 */ 00077 CPointPDFParticles m_locationMC; 00078 00079 /** The individual PDF, if m_typePDF=pdfGauss (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon). 00080 */ 00081 CPointPDFGaussian m_locationGauss; 00082 00083 /** The individual PDF, if m_typePDF=pdfSOG (publicly accesible for ease of use, but the CPointPDF interface is also implemented in CBeacon). 00084 */ 00085 CPointPDFSOG m_locationSOG; 00086 00087 /** An ID for the landmark (see details next...) 00088 * This ID was introduced in the version 3 of this class (21/NOV/2006), and its aim is 00089 * to provide a way for easily establishing correspondences between landmarks detected 00090 * in sequential image frames. Thus, the management of this field should be: 00091 * - In 'servers' (classes/modules/... that detect landmarks from images): A different ID must be assigned to every landmark (e.g. a sequential counter), BUT only in the case of being sure of the correspondence of one landmark with another one in the past (e.g. tracking). 00092 * - In 'clients': This field can be ignored, but if it is used, the advantage is solving the correspondence between landmarks detected in consequentive instants of time: Two landmarks with the same ID <b>correspond</b> to the same physical feature, BUT it should not be expected the inverse to be always true. 00093 * 00094 * Note that this field is never fill out automatically, it must be set by the programmer if used. 00095 */ 00096 TBeaconID m_ID; 00097 00098 /** Default constructor 00099 */ 00100 CBeacon(); 00101 00102 /** Virtual destructor 00103 */ 00104 virtual ~CBeacon(); 00105 00106 /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF). 00107 * \sa getCovariance 00108 */ 00109 void getMean(CPoint3D &mean_point) const; 00110 00111 /** Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once. 00112 * \sa getMean 00113 */ 00114 void getCovarianceAndMean(CMatrixDouble33 &cov,CPoint3D &mean_point) const; 00115 00116 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) 00117 */ 00118 void copyFrom(const CPointPDF &o); 00119 00120 /** Save PDF's particles to a text file. See derived classes for more information about the format of generated files. 00121 */ 00122 void saveToTextFile(const std::string &file) const; 00123 00124 /** This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which 00125 * "to project" the current pdf. Result PDF substituted the currently stored one in the object. 00126 */ 00127 void changeCoordinatesReference( const CPose3D &newReferenceBase ); 00128 00129 /** Saves a 3D representation of the beacon into a given OpenGL scene 00130 */ 00131 void getAs3DObject( mrpt::opengl::CSetOfObjectsPtr &outObj ) const; 00132 00133 /** Gets a set of MATLAB commands which draw the current state of the beacon: 00134 */ 00135 void getAsMatlabDrawCommands( utils::CStringList &out_Str ) const; 00136 00137 /** Draw a sample from the pdf. 00138 */ 00139 void drawSingleSample(CPoint3D &outSample) const; 00140 00141 /** Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!) 00142 * \param p1 The first distribution to fuse 00143 * \param p2 The second distribution to fuse 00144 * \param minMahalanobisDistToDrop If set to different of 0, the result of very separate Gaussian modes (that will result in negligible components) in SOGs will be dropped to reduce the number of modes in the output. 00145 */ 00146 void bayesianFusion( CPointPDF &p1, CPointPDF &p2, const double &minMahalanobisDistToDrop = 0); 00147 00148 00149 /** Compute the observation model p(z_t|x_t) for a given observation (range value), and return it as an approximate SOG. 00150 * Note that if the beacon is a SOG itself, the number of gaussian modes will be square. 00151 * As a speed-up, if a "center point"+"maxDistanceFromCenter" is supplied (maxDistanceFromCenter!=0), those modes farther than this sphere will be discarded. 00152 * Parameters such as the stdSigma of the sensor are gathered from "myBeaconMap" 00153 * The result is one "ring" for each Gaussian mode that represent the beacon position in this object. 00154 * The position of the sensor on the robot is used to shift the resulting densities such as they represent the position of the robot, not the sensor. 00155 * \sa CBeaconMap::insertionOptions, generateRingSOG 00156 */ 00157 void generateObservationModelDistribution( 00158 const float &sensedRange, 00159 CPointPDFSOG &outPDF, 00160 const CBeaconMap *myBeaconMap, 00161 const CPoint3D &sensorPntOnRobot, 00162 const CPoint3D ¢erPoint = CPoint3D(0,0,0), 00163 const float &maxDistanceFromCenter = 0 00164 ) const; 00165 00166 /** This static method returns a SOG with ring-shape (or as a 3D sphere) that can be used to initialize a beacon if observed the first time. 00167 * sensorPnt is the center of the ring/sphere, i.e. the absolute position of the range sensor. 00168 * If clearPreviousContentsOutPDF=false, the SOG modes will be added to the current contents of outPDF 00169 * If the 3x3 matrix covarianceCompositionToAdd is provided, it will be add to every Gaussian (to model the composition of uncertainty). 00170 * \sa generateObservationModelDistribution 00171 */ 00172 static void generateRingSOG( 00173 const float &sensedRange, 00174 CPointPDFSOG &outPDF, 00175 const CBeaconMap *myBeaconMap, 00176 const CPoint3D &sensorPnt, 00177 const CMatrixDouble33 *covarianceCompositionToAdd = NULL, 00178 bool clearPreviousContentsOutPDF = true, 00179 const CPoint3D ¢erPoint = CPoint3D(0,0,0), 00180 const float &maxDistanceFromCenter = 0 00181 ); 00182 00183 00184 }; // End of class definition 00185 00186 00187 } // End of namespace 00188 } // End of namespace 00189 00190 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:32:05 EDT 2009 |