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 CBoardSonars_H 00029 #define CBoardSonars_H 00030 00031 #include <mrpt/hwdrivers/CInterfaceFTDIMessages.h> 00032 #include <mrpt/hwdrivers/CGenericSensor.h> 00033 #include <mrpt/synch.h> 00034 #include <mrpt/utils/CDebugOutputCapable.h> 00035 #include <mrpt/utils/CConfigFileBase.h> 00036 #include <mrpt/slam/CObservationRange.h> 00037 00038 namespace mrpt 00039 { 00040 namespace hwdrivers 00041 { 00042 /** This "software driver" implements the communication protocol for interfacing a Ultrasonic range finder SRF10 through a custom USB board. 00043 * 00044 * In this class the "bind" is ignored since it is designed for USB connections only, thus it internally generate the required object for simplicity of use. 00045 * The serial number of the USB device is used to open it on the first call to "doProcess", thus you must call "loadConfig" before this, or manually 00046 * call "setDeviceSerialNumber". The default serial number is "SONAR001" 00047 * 00048 * Warning: Avoid defining an object of this class in a global scope if you want to catch all potential 00049 * exceptions during the constructors (like USB interface DLL not found, etc...) 00050 * 00051 * \code 00052 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00053 * ------------------------------------------------------- 00054 * [supplied_section_name] 00055 * USB_serialNumber=SONAR001 00056 * gain=6 ; Value between 0 and 16, for analog gains between 40 and 700. 00057 * maxRange=4.0 ; In meters, used for device internal timer. 00058 * minTimeBetweenPings=0.3 ; In seconds 00059 * 00060 * ; The order in which sonars will be fired, indexed by their I2C addresses [0,15] 00061 * ; Up to 16 devices, but you can put any number of devices (from 1 to 16). 00062 * firingOrder=0 1 2 3 00063 * 00064 * 00065 * ¡¡¡FALTA PONER UNA ESTRUCTURILLA PARA ALMACENAR LA POSE3D DE LOS 16 SONARES SOBRE EL ROBOT!!! 00066 * 00067 * \endcode 00068 * 00069 */ 00070 class HWDLLIMPEXP CBoardSonars : public hwdrivers::CInterfaceFTDIMessages, public CGenericSensor 00071 { 00072 DEFINE_GENERIC_SENSOR(CBoardSonars) 00073 00074 public: 00075 /** Constructor 00076 */ 00077 CBoardSonars(); 00078 00079 /** Destructor 00080 */ 00081 ~CBoardSonars(){} 00082 00083 /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, 00084 * loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes) 00085 * See hwdrivers::CBoardSonars for the possible parameters 00086 */ 00087 void loadConfig( const mrpt::utils::CConfigFileBase &configSource, 00088 const std::string &iniSection ); 00089 00090 /** Query the firmware version on the device (can be used to test communications). 00091 * \return true on success, false on communications errors or device not found. 00092 */ 00093 bool queryFirmwareVersion( std::string &out_firmwareVersion ); 00094 00095 /** Request the latest range measurements. 00096 * \return true on success, false on communications errors or device not found. 00097 */ 00098 bool getObservation( mrpt::slam::CObservationRange &obs ); 00099 00100 /** Requests a command of "change address" for a given SRF10 device. 00101 * currentAddress and newAddress are the I2C addresses in the range 0 to 15 (mapped to 0xE0 to 0xFE internally). 00102 * \return true on success, false on communications errors or device not found. 00103 */ 00104 bool programI2CAddress( uint8_t currentAddress, uint8_t newAddress ); 00105 00106 /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data) 00107 * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.rip 00108 */ 00109 void doProcess(); 00110 00111 protected: 00112 /** A copy of the device serial number (to open the USB FTDI chip) 00113 */ 00114 std::string m_usbSerialNumber; 00115 00116 /** A value between 0 and 16, for gains between 40 and 700 (not linear). 00117 */ 00118 uint8_t m_gain; 00119 00120 /** The maximum range in meters, used for the internal device timer (value between 4cm and 11m). 00121 */ 00122 float m_maxRange; 00123 00124 /** The order in which sonars will be fired, indexed by their I2C addresses [0,15]. 00125 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00126 */ 00127 std::vector<int32_t> m_firingOrder; 00128 00129 /** The individual gains of the sonars, indexed by their I2C addresses [0,15]. 00130 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00131 */ 00132 std::map<uint16_t,int32_t> m_sonarGains; 00133 //std::vector<int32_t> m_sonarGains; 00134 00135 /** The poses of the sonars: x[m] y[m] z[m] yaw[deg] pitch[deg] roll[deg] 00136 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00137 */ 00138 //std::vector<mrpt::math::TPose3D> m_sonarPoses; 00139 std::map<uint16_t,mrpt::math::TPose3D> m_sonarPoses; 00140 00141 /** The minimum time between sonar pings (in seconds). 00142 */ 00143 float m_minTimeBetweenPings; 00144 00145 /** Tries to connect to the USB device (if disconnected). 00146 * \return True on connection OK, false on error. 00147 */ 00148 bool checkConnectionAndConnect(); 00149 00150 /** Sends the configuration (max range, gain,...) to the USB board. Used internally after a successfull connection. 00151 * \return true on success, false on communications errors or device not found. 00152 */ 00153 bool sendConfigCommands(); 00154 00155 00156 00157 }; // End of class 00158 } // End of namespace 00159 } // End of namespace 00160 00161 00162 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:27:43 EDT 2009 |