00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 00046 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP) 00047 00048 /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner). 00049 * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers. 00050 * 00051 * These are the most important data fields: 00052 * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters). 00053 * - 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.) 00054 * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg). 00055 * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin). 00056 * 00057 * \sa CObservation, CPointsMap 00058 */ 00059 class OBS_IMPEXP CObservation2DRangeScan : public CObservation 00060 { 00061 // This must be added to any CSerializable derived class: 00062 DEFINE_SERIALIZABLE( CObservation2DRangeScan ) 00063 00064 public: 00065 typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas 00066 typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas 00067 00068 /** Default constructor */ 00069 CObservation2DRangeScan( ); 00070 00071 /** Destructor */ 00072 virtual ~CObservation2DRangeScan( ); 00073 00074 00075 /** @name Scan data 00076 @{ */ 00077 00078 /** The range values of the scan, in meters. 00079 */ 00080 std::vector<float> scan; 00081 00082 /** It's false (=0) on no reflected rays, referenced to elements in "scan" 00083 * (Added in the streamming version #1 of the class) 00084 */ 00085 std::vector<char> validRange; 00086 00087 /** The aperture of the range finder, in radians (typically M_PI = 180 degrees). 00088 */ 00089 float aperture; 00090 00091 /** The scanning direction 00092 */ 00093 bool rightToLeft; 00094 00095 /** The maximum range allowed by the device, in meters (e.g. 80m, 50m,...) 00096 */ 00097 float maxRange; 00098 00099 /** The 6D pose of the sensor on the robot. 00100 */ 00101 CPose3D sensorPose; 00102 00103 /** The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid. 00104 */ 00105 float stdError; 00106 00107 /** The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid. 00108 * (Added in the streamming version #4 of the class) 00109 */ 00110 float beamAperture; 00111 00112 /** 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). 00113 */ 00114 double deltaPitch; 00115 00116 /** @} */ 00117 00118 00119 /** @name Cached points map 00120 @{ */ 00121 00122 protected: 00123 /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap(). 00124 * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries. 00125 */ 00126 mutable mrpt::slam::CMetricMapPtr m_cachedMap; 00127 00128 void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap() 00129 00130 public: 00131 00132 /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise. 00133 * Usage: 00134 * \code 00135 * mrpt::slam::CPointsMap *map = obs->getAuxPointsMap<mrpt::slam::CPointsMap>(); 00136 * \endcode 00137 * \sa buildAuxPointsMap 00138 */ 00139 template <class POINTSMAP> 00140 inline const POINTSMAP* getAuxPointsMap() const { 00141 return static_cast<const POINTSMAP*>(m_cachedMap.pointer()); 00142 } 00143 00144 /** Returns a cached points map representing this laser scan, building it upon the first call. 00145 * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params. 00146 * Usage: 00147 * \code 00148 * mrpt::slam::CPointsMap *map = obs->buildAuxPointsMap<mrpt::slam::CPointsMap>(&options or NULL); 00149 * \endcode 00150 * \sa getAuxPointsMap 00151 */ 00152 template <class POINTSMAP> 00153 inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const { 00154 if (!m_cachedMap.present()) internal_buildAuxPointsMap(options); 00155 return static_cast<const POINTSMAP*>(m_cachedMap.pointer()); 00156 } 00157 00158 /** @} */ 00159 00160 00161 00162 /** 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). 00163 */ 00164 bool isPlanarScan(const double tolerance = 0) const; 00165 00166 /** A general method to retrieve the sensor pose on the robot. 00167 * Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases. 00168 * \sa setSensorPose 00169 */ 00170 void getSensorPose( CPose3D &out_sensorPose ) const { out_sensorPose = sensorPose; } 00171 00172 00173 /** A general method to change the sensor pose on the robot. 00174 * Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases. 00175 * \sa getSensorPose 00176 */ 00177 void setSensorPose( const CPose3D &newSensorPose ) { sensorPose = newSensorPose; } 00178 00179 /** 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 00180 (NOTE: the laser z-coordinate must be provided). 00181 */ 00182 void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 ); 00183 00184 /** 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"). 00185 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00186 */ 00187 void filterByExclusionAreas( const TListExclusionAreas &areas ); 00188 00189 /** 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. 00190 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00191 */ 00192 void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas ); 00193 00194 /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>. 00195 * \sa C2DRangeFinderAbstract::loadExclusionAreas 00196 */ 00197 void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles ); 00198 00199 }; // End of class def. 00200 00201 00202 } // End of namespace 00203 00204 namespace utils 00205 { 00206 using namespace ::mrpt::slam; 00207 // Specialization must occur in the same namespace 00208 MRPT_DECLARE_TTYPENAME_PTR(CObservation2DRangeScan) 00209 } 00210 00211 } // End of namespace 00212 00213 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011 |