00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef C2DRangeFinderAbstract_H 00029 #define C2DRangeFinderAbstract_H 00030 00031 #include <mrpt/utils/CStream.h> 00032 #include <mrpt/synch.h> 00033 #include <mrpt/utils/CDebugOutputCapable.h> 00034 #include <mrpt/slam/CObservation2DRangeScan.h> 00035 #include <mrpt/utils/CConfigFileBase.h> 00036 00037 #include <mrpt/hwdrivers/link_pragmas.h> 00038 #include <mrpt/hwdrivers/CGenericSensor.h> 00039 00040 #include <mrpt/math/CPolygon.h> 00041 00042 namespace mrpt 00043 { 00044 namespace hwdrivers 00045 { 00046 using namespace mrpt::utils; 00047 using namespace mrpt::slam; 00048 00049 /** This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finders). 00050 * Physical devices may be interfaced through a serial port, a USB connection,etc. but this class 00051 * abstract those details throught the "binding" of the specific scanner driver to a given I/O channel, 00052 * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO". See also the derived classes. 00053 * 00054 * There is support for "exclusion polygons", areas where points, if detected, should be marked as invalid. 00055 * Those areas are useful in cases where the scanner always detects part of the vehicle itself, and those 00056 * points want to be ignored (see C2DRangeFinderAbstract::loadExclusionAreas). 00057 * 00058 * \sa hwdrivers::CSerialPort 00059 * \ingroup mrpt_hwdrivers_grp 00060 */ 00061 class HWDRIVERS_IMPEXP C2DRangeFinderAbstract : public mrpt::utils::CDebugOutputCapable, public mrpt::hwdrivers::CGenericSensor 00062 { 00063 private: 00064 CObservation2DRangeScan m_lastObservation; 00065 bool m_lastObservationIsNew; 00066 bool m_hardwareError; 00067 00068 /** For being thread-safe. 00069 */ 00070 synch::CCriticalSection m_csChangeStream,m_csLastObservation; 00071 00072 CObservation2DRangeScanPtr m_nextObservation; //!< A dynamic object used as buffer in doProcess 00073 00074 CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys; //!< A list of optional exclusion polygons, in coordinates relative to the vehicle, that is, taking into account the "sensorPose". 00075 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. 00076 00077 00078 protected: 00079 /** The I/O channel (will be NULL if not bound). 00080 */ 00081 utils::CStream *m_stream; 00082 00083 /** Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles). 00084 * 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". 00085 * - exclusionZone%u_x 00086 * - exclusionZone%u_y 00087 * for %u=1,2,3,... 00088 * All points within the 2D polygon will be ignored, for any Z, unless an optional entry is found: 00089 * - exclusionZone%u_z=[z_min z_max] 00090 * In that case, only the points within the 2D polygon AND the given range in Z will be ignored. 00091 * 00092 * The number of zones is variable, but they must start at 1 and be consecutive. 00093 * \sa filterByExclusionAreas 00094 */ 00095 void loadExclusionAreas( 00096 const mrpt::utils::CConfigFileBase &configSource, 00097 const std::string &iniSection ); 00098 00099 /** Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons. 00100 * \sa loadExclusionAreas 00101 */ 00102 void filterByExclusionAreas( CObservation2DRangeScan &obs) const; 00103 00104 /** Mark as invalid those ranges in a set of forbiden angle ranges. 00105 * \sa loadExclusionAreas 00106 */ 00107 void filterByExclusionAngles( CObservation2DRangeScan &obs) const; 00108 00109 public: 00110 00111 /** Default constructor 00112 */ 00113 C2DRangeFinderAbstract(); 00114 00115 /** Destructor 00116 */ 00117 virtual ~C2DRangeFinderAbstract(); 00118 00119 /** Binds the object to a given I/O channel. 00120 * The stream object must not be deleted before the destruction of this class. 00121 * \sa hwdrivers::CSerialPort 00122 */ 00123 void bindIO( CStream *streamIO ); 00124 00125 /** 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). 00126 */ 00127 void getObservation( 00128 bool &outThereIsObservation, 00129 CObservation2DRangeScan &outObservation, 00130 bool &hardwareError ); 00131 00132 /** Main method for a CGenericSensor 00133 */ 00134 void doProcess(); 00135 00136 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00137 * 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. 00138 */ 00139 virtual void doProcessSimple( 00140 bool &outThereIsObservation, 00141 CObservation2DRangeScan &outObservation, 00142 bool &hardwareError ) = 0; 00143 00144 /** 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. 00145 * \return If everything works "true", or "false" if there is any error. 00146 */ 00147 virtual bool turnOn() = 0; 00148 00149 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00150 * \return If everything works "true", or "false" if there is any error. 00151 */ 00152 virtual bool turnOff() = 0; 00153 00154 00155 }; // End of class 00156 } // End of namespace 00157 } // End of namespace 00158 00159 00160 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |