Main MRPT website > C++ reference
MRPT logo
CObservation2DRangeScan.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CObservation2DRangeScan_H
10 #define CObservation2DRangeScan_H
11 
13 #include <mrpt/slam/CObservation.h>
14 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/slam/CMetricMap.h>
16 #include <mrpt/math/CPolygon.h>
17 
18 namespace mrpt
19 {
20 namespace slam
21 {
22  /** Auxiliary struct that holds all the relevant *geometry* information about a 2D scan.
23  * This class is used in CSinCosLookUpTableFor2DScans
24  * \ingroup mrpt_obs_grp
25  * \sa CObservation2DRangeScan and CObservation2DRangeScan::getScanProperties */
27  size_t nRays;
28  double aperture;
30  };
31  bool OBS_IMPEXP operator<(const T2DScanProperties&a, const T2DScanProperties&b); //!< Order operator, so T2DScanProperties can appear in associative STL containers.
32 
33 
34 
36 
37  /** A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser scanner).
38  * The data structures are generic enough to hold a wide variety of 2D scanners and "3D" planar rotating 2D lasers.
39  *
40  * These are the most important data fields:
41  * - CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters).
42  * - 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.)
43  * - CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg).
44  * - CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin).
45  *
46  * \sa CObservation, CPointsMap, T2DScanProperties
47  * \ingroup mrpt_obs_grp
48  */
50  {
51  // This must be added to any CSerializable derived class:
53 
54  public:
55  typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas; //!< Used in filterByExclusionAreas
56  typedef std::vector<std::pair<mrpt::math::CPolygon,std::pair<double,double> > > TListExclusionAreasWithRanges; //!< Used in filterByExclusionAreas
57 
58  /** Default constructor */
60 
61  /** Destructor */
62  virtual ~CObservation2DRangeScan( );
63 
64 
65  /** @name Scan data
66  @{ */
67 
68  /** The range values of the scan, in meters.
69  */
70  std::vector<float> scan;
71 
72  /** It's false (=0) on no reflected rays, referenced to elements in "scan"
73  * (Added in the streamming version #1 of the class)
74  */
75  std::vector<char> validRange;
76 
77  /** The aperture of the range finder, in radians (typically M_PI = 180 degrees).
78  */
79  float aperture;
80 
81  /** The scanning direction
82  */
83  bool rightToLeft;
84 
85  /** The maximum range allowed by the device, in meters (e.g. 80m, 50m,...)
86  */
87  float maxRange;
88 
89  /** The 6D pose of the sensor on the robot.
90  */
91  CPose3D sensorPose;
92 
93  /** The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid.
94  */
95  float stdError;
96 
97  /** The aperture of each beam, in radians, used to insert "thick" rays in the occupancy grid.
98  * (Added in the streamming version #4 of the class)
99  */
100  float beamAperture;
101 
102  /** 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).
103  */
104  double deltaPitch;
105 
106  /** Fill out a T2DScanProperties structure with the parameters of this scan */
107  void getScanProperties(T2DScanProperties& p) const;
108 
109  /** @} */
110 
111 
112  /** @name Cached points map
113  @{ */
114 
115  protected:
116  /** A points map, build only under demand by the methods getAuxPointsMap() and buildAuxPointsMap().
117  * It's a generic smart pointer to avoid depending here in the library mrpt-obs on classes on other libraries.
118  */
119  mutable mrpt::slam::CMetricMapPtr m_cachedMap;
120 
121  void internal_buildAuxPointsMap( const void *options = NULL ) const; //!< Internal method, used from buildAuxPointsMap()
122 
123  public:
124 
125  /** Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or NULL otherwise.
126  * Usage:
127  * \code
128  * mrpt::slam::CPointsMap *map = obs->getAuxPointsMap<mrpt::slam::CPointsMap>();
129  * \endcode
130  * \sa buildAuxPointsMap
131  */
132  template <class POINTSMAP>
133  inline const POINTSMAP* getAuxPointsMap() const {
134  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
135  }
136 
137  /** Returns a cached points map representing this laser scan, building it upon the first call.
138  * \param options Can be NULL to use default point maps' insertion options, or a pointer to a "CPointsMap::TInsertionOptions" structure to override some params.
139  * Usage:
140  * \code
141  * mrpt::slam::CPointsMap *map = obs->buildAuxPointsMap<mrpt::slam::CPointsMap>(&options or NULL);
142  * \endcode
143  * \sa getAuxPointsMap
144  */
145  template <class POINTSMAP>
146  inline const POINTSMAP *buildAuxPointsMap( const void *options = NULL ) const {
147  if (!m_cachedMap.present()) internal_buildAuxPointsMap(options);
148  return static_cast<const POINTSMAP*>(m_cachedMap.pointer());
149  }
150 
151  /** @} */
152 
153 
154 
155  /** 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).
156  */
157  bool isPlanarScan(const double tolerance = 0) const;
158 
159  /** A general method to retrieve the sensor pose on the robot.
160  * Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases.
161  * \sa setSensorPose
162  */
163  void getSensorPose( CPose3D &out_sensorPose ) const { out_sensorPose = sensorPose; }
164 
165 
166  /** A general method to change the sensor pose on the robot.
167  * Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases.
168  * \sa getSensorPose
169  */
170  void setSensorPose( const CPose3D &newSensorPose ) { sensorPose = newSensorPose; }
171 
172  /** 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
173  (NOTE: the laser z-coordinate must be provided).
174  */
175  void truncateByDistanceAndAngle(float min_distance, float max_angle, float min_height = 0, float max_height = 0, float h = 0 );
176 
177  /** 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").
178  * \sa C2DRangeFinderAbstract::loadExclusionAreas
179  */
180  void filterByExclusionAreas( const TListExclusionAreas &areas );
181 
182  /** 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.
183  * \sa C2DRangeFinderAbstract::loadExclusionAreas
184  */
185  void filterByExclusionAreas( const TListExclusionAreasWithRanges &areas );
186 
187  /** Mark as invalid the ranges in any of a given set of "forbiden angle ranges", given as pairs<min_angle,max_angle>.
188  * \sa C2DRangeFinderAbstract::loadExclusionAreas
189  */
190  void filterByExclusionAngles( const std::vector<std::pair<double,double> > &angles );
191 
192  }; // End of class def.
193  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CObservation2DRangeScan, CObservation, OBS_IMPEXP)
194 
195 
196  } // End of namespace
197 
198  namespace utils
199  {
200  using namespace ::mrpt::slam;
201  // Specialization must occur in the same namespace
202  MRPT_DECLARE_TTYPENAME_PTR(CObservation2DRangeScan)
203  }
204 
205 } // End of namespace
206 
207 #endif
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > > > TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
STL namespace.
#define MRPT_DECLARE_TTYPENAME_PTR(_TYPE)
Definition: TTypeName.h:68
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
void getSensorPose(CPose3D &out_sensorPose) const
A general method to retrieve the sensor pose on the robot.
std::vector< mrpt::math::CPolygon > TListExclusionAreas
Used in filterByExclusionAreas.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
void setSensorPose(const CPose3D &newSensorPose)
A general method to change the sensor pose on the robot.
Declares a class that represents any robot's observation.
Definition: CObservation.h:52
const POINTSMAP * buildAuxPointsMap(const void *options=NULL) const
Returns a cached points map representing this laser scan, building it upon the first call...
bool operator<(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Auxiliary struct that holds all the relevant geometry information about a 2D scan.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014