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 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 * \endcode 00066 * 00067 * \ingroup mrpt_hwdrivers_grp 00068 */ 00069 class HWDRIVERS_IMPEXP CBoardSonars : public hwdrivers::CInterfaceFTDIMessages, public CGenericSensor 00070 { 00071 DEFINE_GENERIC_SENSOR(CBoardSonars) 00072 00073 public: 00074 /** Constructor 00075 */ 00076 CBoardSonars(); 00077 00078 /** Destructor 00079 */ 00080 virtual ~CBoardSonars(){} 00081 00082 /** Query the firmware version on the device (can be used to test communications). 00083 * \return true on success, false on communications errors or device not found. 00084 */ 00085 bool queryFirmwareVersion( std::string &out_firmwareVersion ); 00086 00087 /** Request the latest range measurements. 00088 * \return true on success, false on communications errors or device not found. 00089 */ 00090 bool getObservation( mrpt::slam::CObservationRange &obs ); 00091 00092 /** Requests a command of "change address" for a given SRF10 device. 00093 * currentAddress and newAddress are the I2C addresses in the range 0 to 15 (mapped to 0xE0 to 0xFE internally). 00094 * \return true on success, false on communications errors or device not found. 00095 */ 00096 bool programI2CAddress( uint8_t currentAddress, uint8_t newAddress ); 00097 00098 /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data) 00099 * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.rip 00100 */ 00101 void doProcess(); 00102 00103 protected: 00104 /** A copy of the device serial number (to open the USB FTDI chip) 00105 */ 00106 std::string m_usbSerialNumber; 00107 00108 /** A value between 0 and 16, for gains between 40 and 700 (not linear). 00109 */ 00110 uint8_t m_gain; 00111 00112 /** The maximum range in meters, used for the internal device timer (value between 4cm and 11m). 00113 */ 00114 float m_maxRange; 00115 00116 /** The order in which sonars will be fired, indexed by their I2C addresses [0,15]. 00117 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00118 */ 00119 std::vector<int32_t> m_firingOrder; 00120 00121 /** The individual gains of the sonars, indexed by their I2C addresses [0,15]. 00122 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00123 */ 00124 std::map<uint16_t,int32_t> m_sonarGains; 00125 00126 /** The poses of the sonars: x[m] y[m] z[m] yaw[deg] pitch[deg] roll[deg] 00127 * Up to 16 devices, but you can put any number of devices (from 1 to 16). 00128 */ 00129 std::map<uint16_t,mrpt::math::TPose3D> m_sonarPoses; 00130 00131 /** The minimum time between sonar pings (in seconds). 00132 */ 00133 float m_minTimeBetweenPings; 00134 00135 /** Tries to connect to the USB device (if disconnected). 00136 * \return True on connection OK, false on error. 00137 */ 00138 bool checkConnectionAndConnect(); 00139 00140 /** Sends the configuration (max range, gain,...) to the USB board. Used internally after a successfull connection. 00141 * \return true on success, false on communications errors or device not found. 00142 */ 00143 bool sendConfigCommands(); 00144 00145 /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, 00146 * loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes) 00147 * See hwdrivers::CBoardSonars for the possible parameters 00148 */ 00149 void loadConfig_sensorSpecific( const mrpt::utils::CConfigFileBase &configSource, 00150 const std::string &iniSection ); 00151 00152 00153 00154 }; // End of class 00155 } // End of namespace 00156 } // End of namespace 00157 00158 00159 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |