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