Main MRPT website > C++ reference for MRPT 1.9.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>
17 #include <mrpt/math/CPolygon.h>
19 
20 namespace mrpt
21 {
22 namespace hwdrivers
23 {
24 /** This is the base, abstract class for "software drivers" interfaces to 2D
25  * scanners (laser range finders).
26  * Physical devices may be interfaced through a serial port, a USB
27  * connection,etc. but this class
28  * abstract those details throught the "binding" of the specific scanner
29  * driver to a given I/O channel,
30  * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO".
31  * See also the derived classes.
32  *
33  * There is support for "exclusion polygons", areas where points, if detected,
34  * should be marked as invalid.
35  * Those areas are useful in cases where the scanner always detects part of
36  * the vehicle itself, and those
37  * points want to be ignored (see
38  * C2DRangeFinderAbstract::loadExclusionAreas).
39  *
40  * \sa comms::CSerialPort
41  * \ingroup mrpt_hwdrivers_grp
42  */
43 class C2DRangeFinderAbstract : public mrpt::utils::COutputLogger,
45 {
46  private:
50 
51  /** For being thread-safe.
52  */
54 
55  /** A dynamic object used as buffer in doProcess */
57 
58  /** A list of optional exclusion polygons, in coordinates relative to the
59  * vehicle, that is, taking into account the "sensorPose". */
62  /** A list of pairs of angles <init,end> such as all sensor ranges falling
63  * in those forbiden angles will be marked as invalid. */
64  std::vector<std::pair<double, double>> m_lstExclusionAngles;
65 
66  /** If true, shows a 3D window with a preview of the grabber data */
69 
70  protected:
71  /** The I/O channel (will be nullptr if not bound). */
73 
74  /** Should be call by derived classes at "loadConfig" (loads exclusion areas
75  *AND exclusion angles).
76  * This loads a sequence of vertices of a polygon given by its (x,y)
77  *coordinates relative to the vehicle, that is, taking into account the
78  *"sensorPose".
79  * - exclusionZone%u_x
80  * - exclusionZone%u_y
81  * for %u=1,2,3,...
82  * All points within the 2D polygon will be ignored, for any Z, unless an
83  *optional entry is found:
84  * - exclusionZone%u_z=[z_min z_max]
85  * In that case, only the points within the 2D polygon AND the given
86  *range in Z will be ignored.
87  *
88  * The number of zones is variable, but they must start at 1 and be
89  *consecutive.
90  *
91  * This also loads any other common params (e.g. 'preview')
92  * \sa filterByExclusionAreas
93  */
94  void loadCommonParams(
95  const mrpt::utils::CConfigFileBase& configSource,
96  const std::string& iniSection);
97 
98  /** Mark as invalid those points which (x,y) coordinates fall within the
99  * exclusion polygons.
100  * \sa loadExclusionAreas
101  */
103 
104  /** Mark as invalid those ranges in a set of forbiden angle ranges.
105  * \sa loadExclusionAreas
106  */
108 
109  /** Must be called inside the capture method to allow optional GUI preview
110  * of scans */
112 
113  public:
114  /** Default constructor */
116  /** Destructor */
117  virtual ~C2DRangeFinderAbstract();
118 
119  /** Enables GUI visualization in real-time */
120  void showPreview(bool enable = true) { m_showPreview = enable; }
121  /** Binds the object to a given I/O channel.
122  * The stream object must not be deleted before the destruction of this
123  * class.
124  * \sa comms::CSerialPort
125  */
126  void bindIO(mrpt::utils::CStream* streamIO);
127 
128  /** Get the last observation from the sensor, if available, and unmarks it
129  * as being "the last one" (thus a new scan must arrive or subsequent calls
130  * will find no new observations).
131  */
132  void getObservation(
133  bool& outThereIsObservation,
134  mrpt::obs::CObservation2DRangeScan& outObservation,
135  bool& hardwareError);
136 
137  /** Main method for a CGenericSensor */
138  void doProcess();
139 
140  /** Specific laser scanner "software drivers" must process here new data
141  * from the I/O stream, and, if a whole scan has arrived, return it.
142  * This method MUST BE CALLED in a timely fashion by the user to allow the
143  * proccessing of incoming data. It can be run in a different thread safely.
144  */
145  virtual void doProcessSimple(
146  bool& outThereIsObservation,
147  mrpt::obs::CObservation2DRangeScan& outObservation,
148  bool& hardwareError) = 0;
149 
150  /** Enables the scanning mode (which may depend on the specific laser
151  * device); this must be called before asking for observations to assure
152  * that the protocol has been initializated.
153  * \return If everything works "true", or "false" if there is any error.
154  */
155  virtual bool turnOn() = 0;
156 
157  /** Disables the scanning mode (this can be used to turn the device in low
158  * energy mode, if available)
159  * \return If everything works "true", or "false" if there is any error.
160  */
161  virtual bool turnOff() = 0;
162 
163 }; // End of class
164 } // End of namespace
165 } // End of namespace
166 
167 #endif
A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabbe...
virtual void doProcessSimple(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)=0
Specific laser scanner "software drivers" must process here new data from the I/O stream...
mrpt::obs::CObservation2DRangeScan m_lastObservation
utils::CStream * m_stream
The I/O channel (will be nullptr if not bound).
mrpt::gui::CDisplayWindow3D::Ptr m_win
virtual bool turnOn()=0
Enables the scanning mode (which may depend on the specific laser device); this must be called before...
std::mutex m_csChangeStream
For being thread-safe.
void filterByExclusionAreas(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons.
std::shared_ptr< CObservation2DRangeScan > Ptr
void filterByExclusionAngles(mrpt::obs::CObservation2DRangeScan &obs) const
Mark as invalid those ranges in a set of forbiden angle ranges.
This class allows loading and storing values and vectors of different types from a configuration text...
void getObservation(bool &outThereIsObservation, mrpt::obs::CObservation2DRangeScan &outObservation, bool &hardwareError)
Get the last observation from the sensor, if available, and unmarks it as being "the last one" (thus ...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
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 ...
void showPreview(bool enable=true)
Enables GUI visualization in real-time.
std::shared_ptr< CDisplayWindow3D > Ptr
void bindIO(mrpt::utils::CStream *streamIO)
Binds the object to a given I/O channel.
void loadCommonParams(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles)...
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::obs::CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys
A list of optional exclusion polygons, in coordinates relative to the vehicle, that is...
mrpt::obs::CObservation2DRangeScan::Ptr 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...
std::vector< std::pair< mrpt::math::CPolygon, std::pair< double, double > > > TListExclusionAreasWithRanges
Used in filterByExclusionAreas.
bool m_showPreview
If true, shows a 3D window with a preview of the grabber data.
void doProcess()
Main method for a CGenericSensor.
void processPreview(const mrpt::obs::CObservation2DRangeScan &obs)
Must be called inside the capture method to allow optional GUI preview of scans.
virtual bool turnOff()=0
Disables the scanning mode (this can be used to turn the device in low energy mode, if available)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019