MRPT  2.0.4
C2DRangeFinderAbstract.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
14 #include <mrpt/math/CPolygon.h>
18 
19 namespace mrpt::hwdrivers
20 {
21 /** This is the base, abstract class for "software drivers" interfaces to 2D
22  * scanners (laser range finders).
23  * Physical devices may be interfaced through a serial port, a USB
24  * connection,etc. but this class
25  * abstract those details throught the "binding" of the specific scanner
26  * driver to a given I/O channel,
27  * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO".
28  * See also the derived classes.
29  *
30  * There is support for "exclusion polygons", areas where points, if detected,
31  * should be marked as invalid.
32  * Those areas are useful in cases where the scanner always detects part of
33  * the vehicle itself, and those
34  * points want to be ignored (see
35  * C2DRangeFinderAbstract::loadExclusionAreas).
36  *
37  * \sa comms::CSerialPort
38  * \ingroup mrpt_hwdrivers_grp
39  */
42 {
43  private:
46  bool m_hardwareError{false};
47 
48  /** For being thread-safe.
49  */
51 
52  /** A dynamic object used as buffer in doProcess */
54 
55  /** A list of optional exclusion polygons, in coordinates relative to the
56  * vehicle, that is, taking into account the "sensorPose". */
59  /** A list of pairs of angles <init,end> such as all sensor ranges falling
60  * in those forbiden angles will be marked as invalid. */
61  std::vector<std::pair<double, double>> m_lstExclusionAngles;
62 
63  /** If true, shows a 3D window with a preview of the grabber data */
64  bool m_showPreview{false};
66 
67  protected:
68  /** The I/O channel (will be nullptr if not bound). */
70 
71  /** Should be call by derived classes at "loadConfig" (loads exclusion areas
72  *AND exclusion angles).
73  * This loads a sequence of vertices of a polygon given by its (x,y)
74  *coordinates relative to the vehicle, that is, taking into account the
75  *"sensorPose".
76  * - exclusionZone%u_x
77  * - exclusionZone%u_y
78  * for %u=1,2,3,...
79  * All points within the 2D polygon will be ignored, for any Z, unless an
80  *optional entry is found:
81  * - exclusionZone%u_z=[z_min z_max]
82  * In that case, only the points within the 2D polygon AND the given
83  *range in Z will be ignored.
84  *
85  * The number of zones is variable, but they must start at 1 and be
86  *consecutive.
87  *
88  * This also loads any other common params (e.g. 'preview')
89  * \sa filterByExclusionAreas
90  */
91  void loadCommonParams(
92  const mrpt::config::CConfigFileBase& configSource,
93  const std::string& iniSection);
94 
95  /** Mark as invalid those points which (x,y) coordinates fall within the
96  * exclusion polygons.
97  * \sa loadExclusionAreas
98  */
100 
101  /** Mark as invalid those ranges in a set of forbiden angle ranges.
102  * \sa loadExclusionAreas
103  */
105 
106  /** Must be called inside the capture method to allow optional GUI preview
107  * of scans */
109 
110  public:
111  /** Default constructor */
113  /** Destructor */
114  ~C2DRangeFinderAbstract() override;
115 
116  /** Enables GUI visualization in real-time */
117  void showPreview(bool enable = true) { m_showPreview = enable; }
118  /** Binds the object to a given I/O channel.
119  * The stream object must not be deleted before the destruction of this
120  * class.
121  * \sa comms::CSerialPort
122  */
123  void bindIO(const std::shared_ptr<mrpt::io::CStream>& streamIO);
124 
125  /** Get the last observation from the sensor, if available, and unmarks it
126  * as being "the last one" (thus a new scan must arrive or subsequent calls
127  * will find no new observations).
128  */
129  void getObservation(
130  bool& outThereIsObservation,
131  mrpt::obs::CObservation2DRangeScan& outObservation,
132  bool& hardwareError);
133 
134  /** Main method for a CGenericSensor */
135  void doProcess() override;
136 
137  /** Specific laser scanner "software drivers" must process here new data
138  * from the I/O stream, and, if a whole scan has arrived, return it.
139  * This method MUST BE CALLED in a timely fashion by the user to allow the
140  * proccessing of incoming data. It can be run in a different thread safely.
141  */
142  virtual void doProcessSimple(
143  bool& outThereIsObservation,
144  mrpt::obs::CObservation2DRangeScan& outObservation,
145  bool& hardwareError) = 0;
146 
147  /** Enables the scanning mode (which may depend on the specific laser
148  * device); this must be called before asking for observations to assure
149  * that the protocol has been initializated.
150  * \return If everything works "true", or "false" if there is any error.
151  */
152  virtual bool turnOn() = 0;
153 
154  /** Disables the scanning mode (this can be used to turn the device in low
155  * energy mode, if available)
156  * \return If everything works "true", or "false" if there is any error.
157  */
158  virtual bool turnOff() = 0;
159 
160  /** Returns the empirical, filtered estimation for the period at which whole
161  * scans are being returned from calls to doProcessSimple()
162  * \note: Units: seconds */
164 
165  protected:
166  /** Must be called from doProcessSimple() implementations */
168 
169  /** Must be called from doProcessSimple() implementations.
170  * Returns true if ok, false if this seems strange and should
171  * return an error condition to the user. */
173 
174  private:
175  /// Used in internal_notifyGoodScanNow()
177  /// Updated in internal_notifyGoodScanNow()
179  /// Used in internal_notifyNoScanReceived()
181 
182 }; // End of class
183 } // namespace mrpt::hwdrivers
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
void bindIO(const std::shared_ptr< mrpt::io::CStream > &streamIO)
Binds the object to a given I/O channel.
mrpt::gui::CDisplayWindow3D::Ptr m_win
void internal_notifyGoodScanNow()
Must be called from doProcessSimple() implementations.
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.
mrpt::system::TTimeStamp m_last_good_scan
Used in internal_notifyGoodScanNow()
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.
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 ...
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:40
double m_estimated_scan_period
Updated in internal_notifyGoodScanNow()
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 doProcess() override
Main method for a CGenericSensor.
void showPreview(bool enable=true)
Enables GUI visualization in real-time.
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::shared_ptr< mrpt::io::CStream > m_stream
The I/O channel (will be nullptr if not bound).
bool internal_notifyNoScanReceived()
Must be called from doProcessSimple() implementations.
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)...
int m_failure_waiting_scan_counter
Used in internal_notifyNoScanReceived()
void processPreview(const mrpt::obs::CObservation2DRangeScan &obs)
Must be called inside the capture method to allow optional GUI preview of scans.
~C2DRangeFinderAbstract() override
Destructor.
virtual bool turnOff()=0
Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
Definition: datetime.h:43
double getEstimatedScanPeriod() const
Returns the empirical, filtered estimation for the period at which whole scans are being returned fro...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020