Main MRPT website > C++ reference
MRPT logo
C2DRangeFinderAbstract.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef C2DRangeFinderAbstract_H
29 #define C2DRangeFinderAbstract_H
30 
31 #include <mrpt/utils/CStream.h>
32 #include <mrpt/synch.h>
36 
39 
40 #include <mrpt/math/CPolygon.h>
41 
42 namespace mrpt
43 {
44  namespace hwdrivers
45  {
46  using namespace mrpt::utils;
47  using namespace mrpt::slam;
48 
49  /** This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finders).
50  * Physical devices may be interfaced through a serial port, a USB connection,etc. but this class
51  * abstract those details throught the "binding" of the specific scanner driver to a given I/O channel,
52  * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO". See also the derived classes.
53  *
54  * There is support for "exclusion polygons", areas where points, if detected, should be marked as invalid.
55  * Those areas are useful in cases where the scanner always detects part of the vehicle itself, and those
56  * points want to be ignored (see C2DRangeFinderAbstract::loadExclusionAreas).
57  *
58  * \sa hwdrivers::CSerialPort
59  * \ingroup mrpt_hwdrivers_grp
60  */
62  {
63  private:
67 
68  /** For being thread-safe.
69  */
71 
72  CObservation2DRangeScanPtr m_nextObservation; //!< A dynamic object used as buffer in doProcess
73 
74  CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys; //!< A list of optional exclusion polygons, in coordinates relative to the vehicle, that is, taking into account the "sensorPose".
75  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.
76 
77 
78  protected:
79  /** The I/O channel (will be NULL if not bound).
80  */
82 
83  /** Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles).
84  * 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".
85  * - exclusionZone%u_x
86  * - exclusionZone%u_y
87  * for %u=1,2,3,...
88  * All points within the 2D polygon will be ignored, for any Z, unless an optional entry is found:
89  * - exclusionZone%u_z=[z_min z_max]
90  * In that case, only the points within the 2D polygon AND the given range in Z will be ignored.
91  *
92  * The number of zones is variable, but they must start at 1 and be consecutive.
93  * \sa filterByExclusionAreas
94  */
95  void loadExclusionAreas(
96  const mrpt::utils::CConfigFileBase &configSource,
97  const std::string &iniSection );
98 
99  /** Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons.
100  * \sa loadExclusionAreas
101  */
102  void filterByExclusionAreas( CObservation2DRangeScan &obs) const;
103 
104  /** Mark as invalid those ranges in a set of forbiden angle ranges.
105  * \sa loadExclusionAreas
106  */
107  void filterByExclusionAngles( CObservation2DRangeScan &obs) const;
108 
109  public:
110 
111  /** Default constructor
112  */
114 
115  /** Destructor
116  */
117  virtual ~C2DRangeFinderAbstract();
118 
119  /** Binds the object to a given I/O channel.
120  * The stream object must not be deleted before the destruction of this class.
121  * \sa hwdrivers::CSerialPort
122  */
123  void bindIO( CStream *streamIO );
124 
125  /** 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).
126  */
127  void getObservation(
128  bool &outThereIsObservation,
129  CObservation2DRangeScan &outObservation,
130  bool &hardwareError );
131 
132  /** Main method for a CGenericSensor
133  */
134  void doProcess();
135 
136  /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it.
137  * 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.
138  */
139  virtual void doProcessSimple(
140  bool &outThereIsObservation,
141  CObservation2DRangeScan &outObservation,
142  bool &hardwareError ) = 0;
143 
144  /** 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.
145  * \return If everything works "true", or "false" if there is any error.
146  */
147  virtual bool turnOn() = 0;
148 
149  /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available)
150  * \return If everything works "true", or "false" if there is any error.
151  */
152  virtual bool turnOff() = 0;
153 
154 
155  }; // End of class
156  } // End of namespace
157 } // End of namespace
158 
159 
160 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013