Main MRPT website > C++ reference
MRPT logo
C2DRangeFinderAbstract.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 C2DRangeFinderAbstract_H
10 #define C2DRangeFinderAbstract_H
11 
12 #include <mrpt/utils/CStream.h>
13 #include <mrpt/synch.h>
19 #include <mrpt/math/CPolygon.h>
21 
22 namespace mrpt
23 {
24  namespace hwdrivers
25  {
26  using namespace mrpt::utils;
27  using namespace mrpt::slam;
28 
29  /** This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finders).
30  * Physical devices may be interfaced through a serial port, a USB connection,etc. but this class
31  * abstract those details throught the "binding" of the specific scanner driver to a given I/O channel,
32  * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO". See also the derived classes.
33  *
34  * There is support for "exclusion polygons", areas where points, if detected, should be marked as invalid.
35  * Those areas are useful in cases where the scanner always detects part of the vehicle itself, and those
36  * points want to be ignored (see C2DRangeFinderAbstract::loadExclusionAreas).
37  *
38  * \sa hwdrivers::CSerialPort
39  * \ingroup mrpt_hwdrivers_grp
40  */
42  {
43  private:
47 
48  /** For being thread-safe.
49  */
51 
52  CObservation2DRangeScanPtr m_nextObservation; //!< A dynamic object used as buffer in doProcess
53 
54  CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys; //!< A list of optional exclusion polygons, in coordinates relative to the vehicle, that is, taking into account the "sensorPose".
55  std::vector<std::pair<double,double> > m_lstExclusionAngles; //!< A list of pairs of angles <init,end> such as all sensor ranges falling in those forbiden angles will be marked as invalid.
56 
57  bool m_showPreview; //!< If true, shows a 3D window with a preview of the grabber data
58  mrpt::gui::CDisplayWindow3DPtr m_win;
59 
60  protected:
61  utils::CStream *m_stream; //!< The I/O channel (will be NULL if not bound).
62 
63  /** Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles).
64  * This loads a sequence of vertices of a polygon given by its (x,y) coordinates relative to the vehicle, that is, taking into account the "sensorPose".
65  * - exclusionZone%u_x
66  * - exclusionZone%u_y
67  * for %u=1,2,3,...
68  * All points within the 2D polygon will be ignored, for any Z, unless an optional entry is found:
69  * - exclusionZone%u_z=[z_min z_max]
70  * In that case, only the points within the 2D polygon AND the given range in Z will be ignored.
71  *
72  * The number of zones is variable, but they must start at 1 and be consecutive.
73  *
74  * This also loads any other common params (e.g. 'preview')
75  * \sa filterByExclusionAreas
76  */
77  void loadCommonParams(
78  const mrpt::utils::CConfigFileBase &configSource,
79  const std::string &iniSection );
80 
81  /** Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons.
82  * \sa loadExclusionAreas
83  */
84  void filterByExclusionAreas( CObservation2DRangeScan &obs) const;
85 
86  /** Mark as invalid those ranges in a set of forbiden angle ranges.
87  * \sa loadExclusionAreas
88  */
89  void filterByExclusionAngles( CObservation2DRangeScan &obs) const;
90 
91  /** Must be called inside the capture method to allow optional GUI preview of scans */
92  void processPreview(const mrpt::slam::CObservation2DRangeScan &obs);
93 
94  public:
95  C2DRangeFinderAbstract(); //!< Default constructor
96  virtual ~C2DRangeFinderAbstract(); //!< Destructor
97 
98  void showPreview(bool enable=true) { m_showPreview=enable; } //!< Enables GUI visualization in real-time
99 
100  /** Binds the object to a given I/O channel.
101  * The stream object must not be deleted before the destruction of this class.
102  * \sa hwdrivers::CSerialPort
103  */
104  void bindIO( CStream *streamIO );
105 
106  /** Get the last observation from the sensor, if available, and unmarks it as being "the last one" (thus a new scan must arrive or subsequent calls will find no new observations).
107  */
108  void getObservation(
109  bool &outThereIsObservation,
110  CObservation2DRangeScan &outObservation,
111  bool &hardwareError );
112 
113  void doProcess(); //!< Main method for a CGenericSensor
114 
115  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
116  * This method MUST BE CALLED in a timely fashion by the user to allow the proccessing of incoming data. It can be run in a different thread safely.
117  */
118  virtual void doProcessSimple(
119  bool &outThereIsObservation,
120  CObservation2DRangeScan &outObservation,
121  bool &hardwareError ) = 0;
122 
123  /** Enables the scanning mode (which may depend on the specific laser device); this must be called before asking for observations to assure that the protocol has been initializated.
124  * \return If everything works "true", or "false" if there is any error.
125  */
126  virtual bool turnOn() = 0;
127 
128  /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
129  * \return If everything works "true", or "false" if there is any error.
130  */
131  virtual bool turnOff() = 0;
132 
133 
134  }; // End of class
135  } // End of namespace
136 } // End of namespace
137 
138 
139 #endif
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
std::vector< std::pair< double, double > > m_lstExclusionAngles
A list of pairs of angles such as all sensor ranges falling in those forbiden angles will ...
This class provides simple critical sections functionality.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
CObservation2DRangeScanPtr m_nextObservation
A dynamic object used as buffer in doProcess.
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > > > TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
utils::CStream * m_stream
The I/O channel (will be NULL if not bound).
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
This class allows loading and storing values and vectors of different types from a configuration text...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
void showPreview(bool enable=true)
Enables GUI visualization in real-time.
This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finder...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool m_showPreview
If true, shows a 3D window with a preview of the grabber data.
CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys
A list of optional exclusion polygons, in coordinates relative to the vehicle, that is...
#define HWDRIVERS_IMPEXP
This base class provides a common printf-like method to send debug information to std::cout...



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