Main MRPT website > C++ reference
MRPT logo
CObservation2DRangeScan.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CObservation2DRangeScan_H
29 #define CObservation2DRangeScan_H
30 
32 #include <mrpt/slam/CObservation.h>
33 #include <mrpt/poses/CPose3D.h>
34 #include <mrpt/poses/CPose2D.h>
35 
36 #include <mrpt/slam/CMetricMap.h>
37 
38 #include <mrpt/math/CPolygon.h>
39 
40 
41 namespace mrpt
42 {
43 namespace slam
44 {
45  /** Auxiliary struct that holds all the relevant *geometry* information about a 2D scan.
46  * This class is used in CSinCosLookUpTableFor2DScans
47  * \ingroup mrpt_obs_grp
48  * \sa CObservation2DRangeScan and CObservation2DRangeScan::getScanProperties */
50  size_t nRays;
51  double aperture;
53  };
54  bool OBS_IMPEXP operator<(const T2DScanProperties&a, const T2DScanProperties&b); //!< Order operator, so T2DScanProperties can appear in associative STL containers.
55 
56 
57 
59 
60  /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner).
61  * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers.
62  *
63  * These are the most important data fields:
64  * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters).
65  * - 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.)
66  * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg).
67  * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin).
68  *
69  * \sa CObservation, CPointsMap, T2DScanProperties
70  * \ingroup mrpt_obs_grp
71  */
73  {
74  // This must be added to any CSerializable derived class:
76 
77  public:
78  typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas
79  typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas
80 
81  /** Default constructor */
83 
84  /** Destructor */
85  virtual ~CObservation2DRangeScan( );
86 
87 
88  /** @name Scan data
89  @{ */
90 
91  /** The range values of the scan, in meters.
92  */
93  std::vector<float> scan;
94 
95  /** It's false (=0) on no reflected rays, referenced to elements in "scan"
96  * (Added in the streamming version #1 of the class)
97  */
98  std::vector<char> validRange;
99 
100  /** The aperture of the range finder, in radians (typically M_PI = 180 degrees).
101  */
102  float aperture;
103 
104  /** The scanning direction
105  */
106  bool rightToLeft;
107 
108  /** The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
109  */
110  float maxRange;
111 
112  /** The 6D pose of the sensor on the robot.
113  */
114  CPose3D sensorPose;
115 
116  /** The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
117  */
118  float stdError;
119 
120  /** The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid.
121  * (Added in the streamming version #4 of the class)
122  */
123  float beamAperture;
124 
125  /** 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).
126  */
127  double deltaPitch;
128 
129  /** Fill out a T2DScanProperties structure with the parameters of this scan */
130  void getScanProperties(T2DScanProperties& p) const;
131 
132  /** @} */
133 
134 
135  /** @name Cached points map
136  @{ */
137 
138  protected:
139  /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
140  * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries.
141  */
142  mutable mrpt::slam::CMetricMapPtr m_cachedMap;
143 
144  void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap()
145 
146  public:
147 
148  /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
149  * Usage:
150  * \code
151  * mrpt::slam::CPointsMap *map = obs->getAuxPointsMap<mrpt::slam::CPointsMap>();
152  * \endcode
153  * \sa buildAuxPointsMap
154  */
155  template <class POINTSMAP>
156  inline const POINTSMAP* getAuxPointsMap() const {
157  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
158  }
159 
160  /** Returns a cached points map representing this laser scan, building it upon the first call.
161  * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params.
162  * Usage:
163  * \code
164  * mrpt::slam::CPointsMap *map = obs->buildAuxPointsMap<mrpt::slam::CPointsMap>(&options or NULL);
165  * \endcode
166  * \sa getAuxPointsMap
167  */
168  template <class POINTSMAP>
169  inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const {
170  if (!m_cachedMap.present()) internal_buildAuxPointsMap(options);
171  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
172  }
173 
174  /** @} */
175 
176 
177 
178  /** 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).
179  */
180  bool isPlanarScan(const double tolerance = 0) const;
181 
182  /** A general method to retrieve the sensor pose on the robot.
183  * Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases.
184  * \sa setSensorPose
185  */
186  void getSensorPose( CPose3D &out_sensorPose ) const { out_sensorPose = sensorPose; }
187 
188 
189  /** A general method to change the sensor pose on the robot.
190  * Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases.
191  * \sa getSensorPose
192  */
193  void setSensorPose( const CPose3D &newSensorPose ) { sensorPose = newSensorPose; }
194 
195  /** 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
196  (NOTE: the laser z-coordinate must be provided).
197  */
198  void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 );
199 
200  /** 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").
201  * \sa C2DRangeFinderAbstract::loadExclusionAreas
202  */
203  void filterByExclusionAreas( const TListExclusionAreas &areas );
204 
205  /** 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.
206  * \sa C2DRangeFinderAbstract::loadExclusionAreas
207  */
208  void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas );
209 
210  /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>.
211  * \sa C2DRangeFinderAbstract::loadExclusionAreas
212  */
213  void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles );
214 
215  }; // End of class def.
216 
217 
218  } // End of namespace
219 
220  namespace utils
221  {
222  using namespace ::mrpt::slam;
223  // Specialization must occur in the same namespace
224  MRPT_DECLARE_TTYPENAME_PTR(CObservation2DRangeScan)
225  }
226 
227 } // End of namespace
228 
229 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013