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