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 00029 #ifndef CBoardENoses_H 00030 #define CBoardENoses_H 00031 00032 #include <mrpt/hwdrivers/CInterfaceFTDI.h> 00033 #include <mrpt/hwdrivers/CSerialPort.h> 00034 #include <mrpt/hwdrivers/CGenericSensor.h> 00035 00036 #include <mrpt/slam/CObservationGasSensors.h> 00037 #include <mrpt/utils/CConfigFileBase.h> 00038 00039 00040 namespace mrpt 00041 { 00042 namespace hwdrivers 00043 { 00044 /** A class for interfacing an e-Noses via a FTDI USB link. 00045 * Implemented for the board v1.0 designed by 2007 @ ISA (University of Malaga). 00046 * 00047 * \code 00048 * PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS: 00049 * ------------------------------------------------------- 00050 * [supplied_section_name] 00051 * USB_serialname=ENOSE001 // USB FTDI pipe: will open only if COM_port_* are not set or empty 00052 * 00053 * COM_port_WIN = COM1 // Serial port to connect to. 00054 * COM_port_LIN = ttyS0 00055 * 00056 * COM_baudRate = 115200 00057 * 00058 * ; 3D position (in meters) of the master +slave eNoses 00059 * enose_poses_x=<MASTER X> <SLAVE#1 X> <SLAVE#2 X> <SLAVE#3 X>... 00060 * enose_poses_y=<MASTER Y> <SLAVE#1 Y> <SLAVE#2 Y> <SLAVE#3 Y>... 00061 * enose_poses_z=<MASTER Z> <SLAVE#1 Z> <SLAVE#2 Z> <SLAVE#3 Z>... 00062 * 00063 * ; 3D pose angles (in degrees) of the master +slave eNoses 00064 * enose_poses_yaw=<MASTER YAW> <SLAVE#1 YAW> <SLAVE#2 YAW> <SLAVE#3 YAW>... 00065 * enose_poses_pitch=<MASTER PITCH> <SLAVE#1 PITCH> <SLAVE#2 PITCH> <SLAVE#3 PITCH>... 00066 * enose_poses_roll=<MASTER ROLL> <SLAVE#1 ROLL> <SLAVE#2 ROLL> <SLAVE#3 ROLL>... 00067 * 00068 * \endcode 00069 * 00070 */ 00071 class HWDRIVERS_IMPEXP CBoardENoses : public mrpt::hwdrivers::CGenericSensor 00072 { 00073 DEFINE_GENERIC_SENSOR(CBoardENoses) 00074 00075 protected: 00076 /** A copy of the device serial number (to open the USB FTDI chip) 00077 */ 00078 std::string m_usbSerialNumber; 00079 mrpt::system::TTimeStamp initial_timestamp; 00080 bool first_reading; 00081 00082 std::string m_COM_port; //!< If not an empty string (default), will open that serial port, otherwise will try to open USB FTDI device "m_usbSerialNumber" 00083 unsigned int m_COM_baud; //!< Default=115200 00084 00085 00086 // Only one of these two streams will be !=NULL and open for each specific eNose board! 00087 /** FTDI comms pipe (when not in serial port mode) */ 00088 CInterfaceFTDI *m_stream_FTDI; 00089 /** Serial port comms */ 00090 CSerialPort *m_stream_SERIAL; 00091 00092 /** The 3D pose of the master + N slave eNoses on the robot (meters & radians) */ 00093 std::vector<float> enose_poses_x,enose_poses_y,enose_poses_z,enose_poses_yaw,enose_poses_pitch,enose_poses_roll; 00094 00095 /** Tries to connect to the USB device (if disconnected). 00096 * \return NULL on error, otherwise a stream to be used for comms. 00097 */ 00098 mrpt::utils::CStream* checkConnectionAndConnect(); 00099 00100 /** Loads specific configuration for the device from a given source of configuration parameters, for example, an ".ini" file, loading from the section "[iniSection]" (see utils::CConfigFileBase and derived classes) 00101 * See hwdrivers::CBoardENoses for the possible parameters 00102 */ 00103 void loadConfig_sensorSpecific( 00104 const mrpt::utils::CConfigFileBase &configSource, 00105 const std::string §ion ); 00106 00107 public: 00108 /** Constructor 00109 * \param serialNumberUSBdevice The serial number (text) of the device to open. 00110 * The constructor will try to open the device. You can check if it failed calling "isOpen()". 00111 */ 00112 CBoardENoses( ); 00113 00114 /** Destructor 00115 */ 00116 virtual ~CBoardENoses(); 00117 00118 /** Set the active chamber (afected by poluted air) on the device 00119 * \return true on success, false on communications errors or device not found. 00120 */ 00121 bool setActiveChamber( unsigned char chamber ); 00122 00123 /** Query the firmware version on the device (can be used to test communications). 00124 * \return true on success, false on communications errors or device not found. 00125 */ 00126 bool queryFirmwareVersion( std::string &out_firmwareVersion ); 00127 00128 /** Request the master eNose the latest readings from all the eNoses. 00129 * The output observation contains a valid timestamp and 3D positions if "loadConfig" has been called previously. 00130 * \return true if OK, false if there were any error. 00131 */ 00132 bool getObservation( mrpt::slam::CObservationGasSensors &outObservation ); 00133 00134 00135 /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data) 00136 * It is thread safe, i.e. you can call this from one thread, then to other methods from other threads. 00137 */ 00138 void doProcess(); 00139 00140 /** Tries to open the camera, after setting all the parameters with a call to loadConfig. 00141 * \exception This method must throw an exception with a descriptive message if some critical error is found. 00142 */ 00143 virtual void initialize(); 00144 00145 00146 00147 /** If not an empty string, will open that serial port, otherwise will try to open USB FTDI device "m_usbSerialNumber" 00148 * The default is an empty string. Example strings: "COM1", "ttyUSB0", ... 00149 */ 00150 inline void setSerialPort(const std::string &port) { m_COM_port = port; } 00151 inline std::string getSerialPort() const { return m_COM_port; } 00152 00153 /** Set the serial port baud rate (default: 115200) */ 00154 inline void setSerialPortBaud(unsigned int baud) { m_COM_baud=baud; } 00155 inline unsigned int getSerialPortBaud() const { return m_COM_baud; } 00156 00157 00158 }; // end of class 00159 } // end of namespace 00160 } // end of namespace 00161 00162 00163 #endif 00164 00165
Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011 |