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 CObservation2DRangeScan_H 00029 #define CObservation2DRangeScan_H 00030 00031 #include <mrpt/utils/CSerializable.h> 00032 #include <mrpt/slam/CObservation.h> 00033 #include <mrpt/poses/CPose3D.h> 00034 #include <mrpt/poses/CPose2D.h> 00035 00036 #include <mrpt/slam/CMetricMap.h> 00037 00038 #include <mrpt/math/CPolygon.h> 00039 00040 00041 namespace mrpt 00042 { 00043 namespace slam 00044 { 00045 /** Auxiliary struct that holds all the relevant *geometry* information about a 2D scan. 00046 * This class is used in CSinCosLookUpTableFor2DScans 00047 * \ingroup mrpt_obs_grp 00048 * \sa CObservation2DRangeScan and CObservation2DRangeScan::getScanProperties */ 00049 struct OBS_IMPEXP T2DScanProperties { 00050 size_t nRays; 00051 double aperture; 00052 bool rightToLeft; 00053 }; 00054 bool OBS_IMPEXP operator<(const T2DScanProperties&a, const T2DScanProperties&b); //!< Order operator, so T2DScanProperties can appear in associative STL containers. 00055 00056 00057 00058 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP) 00059 00060 /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner). 00061 * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers. 00062 * 00063 * These are the most important data fields: 00064 * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters). 00065 * - CObservation2DRangeScan::validRange -> A vector (of <b>identical size</b> than <i>scan<i>), has non-zeros for those ranges than are valid (i.e. will be zero for non-reflected rays, etc.) 00066 * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg). 00067 * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin). 00068 * 00069 * \sa CObservation, CPointsMap, T2DScanProperties 00070 * \ingroup mrpt_obs_grp 00071 */ 00072 class OBS_IMPEXP CObservation2DRangeScan : public CObservation 00073 { 00074 // This must be added to any CSerializable derived class: 00075 DEFINE_SERIALIZABLE( CObservation2DRangeScan ) 00076 00077 public: 00078 typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas 00079 typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas 00080 00081 /** Default constructor */ 00082 CObservation2DRangeScan( ); 00083 00084 /** Destructor */ 00085 virtual ~CObservation2DRangeScan( ); 00086 00087 00088 /** @name Scan data 00089 @{ */ 00090 00091 /** The range values of the scan, in meters. 00092 */ 00093 std::vector<float> scan; 00094 00095 /** It's false (=0) on no reflected rays, referenced to elements in "scan" 00096 * (Added in the streamming version #1 of the class) 00097 */ 00098 std::vector<char> validRange; 00099 00100 /** The aperture of the range finder, in radians (typically M_PI = 180 degrees). 00101 */ 00102 float aperture; 00103 00104 /** The scanning direction 00105 */ 00106 bool rightToLeft; 00107 00108 /** The maximum range allowed by the device, in meters (e.g. 80m, 50m,...) 00109 */ 00110 float maxRange; 00111 00112 /** The 6D pose of the sensor on the robot. 00113 */ 00114 CPose3D sensorPose; 00115 00116 /** The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid. 00117 */ 00118 float stdError; 00119 00120 /** The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid. 00121 * (Added in the streamming version #4 of the class) 00122 */ 00123 float beamAperture; 00124 00125 /** If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in "pitch" (=-"elevation") between the beginning and the end of the scan (the sensorPose member stands for the pose at the beginning of the scan). 00126 */ 00127 double deltaPitch; 00128 00129 /** Fill out a T2DScanProperties structure with the parameters of this scan */ 00130 void getScanProperties(T2DScanProperties& p) const; 00131 00132 /** @} */ 00133 00134 00135 /** @name Cached points map 00136 @{ */ 00137 00138 protected: 00139 /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap(). 00140 * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries. 00141 */ 00142 mutable mrpt::slam::CMetricMapPtr m_cachedMap; 00143 00144 void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap() 00145 00146 public: 00147 00148 /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise. 00149 * Usage: 00150 * \code 00151 * mrpt::slam::CPointsMap *map = obs->getAuxPointsMap<mrpt::slam::CPointsMap>(); 00152 * \endcode 00153 * \sa buildAuxPointsMap 00154 */ 00155 template <class POINTSMAP> 00156 inline const POINTSMAP* getAuxPointsMap() const { 00157 return static_cast<const POINTSMAP*>(m_cachedMap.pointer()); 00158 } 00159 00160 /** Returns a cached points map representing this laser scan, building it upon the first call. 00161 * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params. 00162 * Usage: 00163 * \code 00164 * mrpt::slam::CPointsMap *map = obs->buildAuxPointsMap<mrpt::slam::CPointsMap>(&options or NULL); 00165 * \endcode 00166 * \sa getAuxPointsMap 00167 */ 00168 template <class POINTSMAP> 00169 inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const { 00170 if (!m_cachedMap.present()) internal_buildAuxPointsMap(options); 00171 return static_cast<const POINTSMAP*>(m_cachedMap.pointer()); 00172 } 00173 00174 /** @} */ 00175 00176 00177 00178 /** Return true if the laser scanner is "horizontal", so it has an absolute value of "pitch" and "roll" less or equal to the given tolerance (in rads, default=0) (with the normal vector either upwards or downwards). 00179 */ 00180 bool isPlanarScan(const double tolerance = 0) const; 00181 00182 /** A general method to retrieve the sensor pose on the robot. 00183 * Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases. 00184 * \sa setSensorPose 00185 */ 00186 void getSensorPose( CPose3D &out_sensorPose ) const { out_sensorPose = sensorPose; } 00187 00188 00189 /** A general method to change the sensor pose on the robot. 00190 * Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases. 00191 * \sa getSensorPose 00192 */ 00193 void setSensorPose( const CPose3D &newSensorPose ) { sensorPose = newSensorPose; } 00194 00195 /** A general method to truncate the scan by defining a minimum valid distance and a maximum valid angle as well as minimun and maximum heights 00196 (NOTE: the laser z-coordinate must be provided). 00197 */ 00198 void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 ); 00199 00200 /** Mark as invalid sensed points that fall within any of a set of "exclusion areas", given in coordinates relative to the vehicle (taking into account "sensorPose"). 00201 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00202 */ 00203 void filterByExclusionAreas( const TListExclusionAreas &areas ); 00204 00205 /** Mark as invalid sensed points that fall within any of a set of "exclusion areas", given in coordinates relative to the vehicle (taking into account "sensorPose"), AND such as the Z coordinate of the point falls in the range [min,max] associated to each exclusion polygon. 00206 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00207 */ 00208 void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas ); 00209 00210 /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>. 00211 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00212 */ 00213 void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles ); 00214 00215 }; // End of class def. 00216 00217 00218 } // End of namespace 00219 00220 namespace utils 00221 { 00222 using namespace ::mrpt::slam; 00223 // Specialization must occur in the same namespace 00224 MRPT_DECLARE_TTYPENAME_PTR(CObservation2DRangeScan) 00225 } 00226 00227 } // End of namespace 00228 00229 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |