00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 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 */ 00060 class HWDRIVERS_IMPEXP C2DRangeFinderAbstract : public mrpt::utils::CDebugOutputCapable, public mrpt::hwdrivers::CGenericSensor 00061 { 00062 private: 00063 CObservation2DRangeScan m_lastObservation; 00064 bool m_lastObservationIsNew; 00065 bool m_hardwareError; 00066 00067 /** For being thread-safe. 00068 */ 00069 synch::CCriticalSection m_csChangeStream,m_csLastObservation; 00070 00071 CObservation2DRangeScanPtr m_nextObservation; //!< A dynamic object used as buffer in doProcess 00072 00073 CObservation2DRangeScan::TListExclusionAreasWithRanges m_lstExclusionPolys; //!< A list of optional exclusion polygons, in coordinates relative to the vehicle, that is, taking into account the "sensorPose". 00074 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. 00075 00076 00077 protected: 00078 /** The I/O channel (will be NULL if not bound). 00079 */ 00080 utils::CStream *m_stream; 00081 00082 /** Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles). 00083 * 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". 00084 * - exclusionZone%u_x 00085 * - exclusionZone%u_y 00086 * for %u=1,2,3,... 00087 * All points within the 2D polygon will be ignored, for any Z, unless an optional entry is found: 00088 * - exclusionZone%u_z=[z_min z_max] 00089 * In that case, only the points within the 2D polygon AND the given range in Z will be ignored. 00090 * 00091 * The number of zones is variable, but they must start at 1 and be consecutive. 00092 * \sa filterByExclusionAreas 00093 */ 00094 void loadExclusionAreas( 00095 const mrpt::utils::CConfigFileBase &configSource, 00096 const std::string &iniSection ); 00097 00098 /** Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons. 00099 * \sa loadExclusionAreas 00100 */ 00101 void filterByExclusionAreas( CObservation2DRangeScan &obs) const; 00102 00103 /** Mark as invalid those ranges in a set of forbiden angle ranges. 00104 * \sa loadExclusionAreas 00105 */ 00106 void filterByExclusionAngles( CObservation2DRangeScan &obs) const; 00107 00108 public: 00109 00110 /** Default constructor 00111 */ 00112 C2DRangeFinderAbstract(); 00113 00114 /** Destructor 00115 */ 00116 virtual ~C2DRangeFinderAbstract(); 00117 00118 /** Binds the object to a given I/O channel. 00119 * The stream object must not be deleted before the destruction of this class. 00120 * \sa hwdrivers::CSerialPort 00121 */ 00122 void bindIO( CStream *streamIO ); 00123 00124 /** 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). 00125 */ 00126 void getObservation( 00127 bool &outThereIsObservation, 00128 CObservation2DRangeScan &outObservation, 00129 bool &hardwareError ); 00130 00131 /** Main method for a CGenericSensor 00132 */ 00133 void doProcess(); 00134 00135 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00136 * 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. 00137 */ 00138 virtual void doProcessSimple( 00139 bool &outThereIsObservation, 00140 CObservation2DRangeScan &outObservation, 00141 bool &hardwareError ) = 0; 00142 00143 /** 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. 00144 * \return If everything works "true", or "false" if there is any error. 00145 */ 00146 virtual bool turnOn() = 0; 00147 00148 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00149 * \return If everything works "true", or "false" if there is any error. 00150 */ 00151 virtual bool turnOff() = 0; 00152 00153 00154 }; // End of class 00155 } // End of namespace 00156 } // End of namespace 00157 00158 00159 #endif
Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011 |