Main MRPT website > C++ reference for MRPT 1.5.9
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-2017, 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>
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  */
38  class HWDRIVERS_IMPEXP C2DRangeFinderAbstract : public mrpt::utils::COutputLogger, public mrpt::hwdrivers::CGenericSensor
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
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
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 ...
mrpt::obs::CObservation2DRangeScan m_lastObservation
This class provides simple critical sections functionality.
OBSERVATION_T::Ptr getObservation(mrpt::obs::CSensoryFramePtr &observations, mrpt::obs::CObservationPtr &observation, bool priority_to_sf=true)
Given an mrpt::obs::CSensoryFrame and a mrpt::obs::CObservation pointer if a OBSERVATION_T type obser...
Definition: obs_utils.h:32
utils::CStream * m_stream
The I/O channel (will be NULL if not bound).
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > > > TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
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.
GLsizei const GLchar ** string
Definition: glext.h:3919
mrpt::obs::CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys
A list of optional exclusion polygons, in coordinates relative to the vehicle, that is...
mrpt::obs::CObservation2DRangeScanPtr m_nextObservation
A dynamic object used as buffer in doProcess.
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.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
bool m_showPreview
If true, shows a 3D window with a preview of the grabber data.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020