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



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Tue Mar 3 09:15:16 UTC 2020