00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Perception and Robotics | 00009 | research group, 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 00048 /** This is the base, abstract class for "software drivers" interfaces to 2D scanners (laser range finders). 00049 * Physical devices may be interfaced through a serial port, a USB connection,etc. but this class 00050 * abstract those details throught the "binding" of the specific scanner driver to a given I/O channel, 00051 * which must be set by calling "hwdrivers::C2DRangeFinderAbstract::bindIO". See also the derived classes. 00052 * 00053 * There is support for "exclusion polygons", areas where points, if detected, should be marked as invalid. 00054 * Those areas are useful in cases where the scanner always detects part of the vehicle itself, and those 00055 * points want to be ignored. 00056 * 00057 * \sa hwdrivers::CSerialPort 00058 */ 00059 class HWDLLIMPEXP C2DRangeFinderAbstract : public mrpt::utils::CDebugOutputCapable, public CGenericSensor 00060 { 00061 private: 00062 mrpt::slam::CObservation2DRangeScan m_lastObservation; 00063 bool m_lastObservationIsNew; 00064 bool m_hardwareError; 00065 00066 /** For being thread-safe. 00067 */ 00068 synch::CCriticalSection m_csChangeStream,m_csLastObservation; 00069 00070 mrpt::slam::CObservation2DRangeScanPtr m_nextObservation; //!< A dynamic object used as buffer in doProcess 00071 00072 std::vector<mrpt::math::CPolygon> m_lstExclusionPolys; //!< A list of optional exclusion polygons, in coordinates relative to the vehicle, that is, taking into account the "sensorPose". 00073 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. 00074 00075 00076 protected: 00077 /** The I/O channel (will be NULL if not bound). 00078 */ 00079 utils::CStream *m_stream; 00080 00081 /** Should be call by derived classes at "loadConfig" (loads exclusion areas AND exclusion angles). 00082 * 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". 00083 * - exclusionZone%u_x 00084 * - exclusionZone%u_y 00085 * for %u=1,2,3,... 00086 * The number of zones is variable, but they must start at 1 and be consecutive. 00087 * \sa filterByExclusionAreas 00088 */ 00089 void loadExclusionAreas( 00090 const mrpt::utils::CConfigFileBase &configSource, 00091 const std::string &iniSection ); 00092 00093 /** Mark as invalid those points which (x,y) coordinates fall within the exclusion polygons. 00094 * \sa loadExclusionAreas 00095 */ 00096 void filterByExclusionAreas( mrpt::slam::CObservation2DRangeScan &obs) const; 00097 00098 /** Mark as invalid those ranges in a set of forbiden angle ranges. 00099 * \sa loadExclusionAreas 00100 */ 00101 void filterByExclusionAngles( mrpt::slam::CObservation2DRangeScan &obs) const; 00102 00103 public: 00104 00105 /** Default constructor 00106 */ 00107 C2DRangeFinderAbstract(); 00108 00109 /** Destructor 00110 */ 00111 virtual ~C2DRangeFinderAbstract(); 00112 00113 /** Binds the object to a given I/O channel. 00114 * The stream object must not be deleted before the destruction of this class. 00115 * \sa hwdrivers::CSerialPort 00116 */ 00117 void bindIO( CStream *streamIO ); 00118 00119 /** 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). 00120 */ 00121 void getObservation( 00122 bool &outThereIsObservation, 00123 mrpt::slam::CObservation2DRangeScan &outObservation, 00124 bool &hardwareError ); 00125 00126 /** Main method for a CGenericSensor 00127 */ 00128 void doProcess(); 00129 00130 /** Specific laser scanner "software drivers" must process here new data from the I/O stream, and, if a whole scan has arrived, return it. 00131 * 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. 00132 */ 00133 virtual void doProcessSimple( 00134 bool &outThereIsObservation, 00135 mrpt::slam::CObservation2DRangeScan &outObservation, 00136 bool &hardwareError ) = 0; 00137 00138 /** 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. 00139 * \return If everything works "true", or "false" if there is any error. 00140 */ 00141 virtual bool turnOn() = 0; 00142 00143 /** Disables the scanning mode (this can be used to turn the device in low energy mode, if available) 00144 * \return If everything works "true", or "false" if there is any error. 00145 */ 00146 virtual bool turnOff() = 0; 00147 00148 00149 }; // End of class 00150 } // End of namespace 00151 } // End of namespace 00152 00153 00154 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:20:53 EDT 2009 |