Main MRPT website > C++ reference
MRPT logo
CBoardENoses.h
Go to the documentation of this file.
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 
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                   * \ingroup mrpt_hwdrivers_grp
00071                   */
00072                 class HWDRIVERS_IMPEXP CBoardENoses : public mrpt::hwdrivers::CGenericSensor
00073                 {
00074                         DEFINE_GENERIC_SENSOR(CBoardENoses)
00075 
00076                 protected:
00077                         /** A copy of the device serial number (to open the USB FTDI chip)
00078                           */
00079                         std::string             m_usbSerialNumber;
00080                         mrpt::system::TTimeStamp initial_timestamp;
00081                         bool first_reading;
00082 
00083                         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"
00084                         unsigned int    m_COM_baud;      //!< Default=115200
00085 
00086 
00087                         // Only one of these two streams will be !=NULL and open for each specific eNose board!
00088                         /**  FTDI comms pipe (when not in serial port mode) */
00089                         CInterfaceFTDI  *m_stream_FTDI;
00090                         /**  Serial port comms */
00091                         CSerialPort             *m_stream_SERIAL;
00092 
00093                         /** The 3D pose of the master + N slave eNoses on the robot (meters & radians) */
00094                         std::vector<float>      enose_poses_x,enose_poses_y,enose_poses_z,enose_poses_yaw,enose_poses_pitch,enose_poses_roll;
00095 
00096                         /** Tries to connect to the USB device (if disconnected).
00097                           * \return NULL on error, otherwise a stream to be used for comms.
00098                           */
00099                         mrpt::utils::CStream*   checkConnectionAndConnect();
00100 
00101                         /** 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)
00102                           *  See hwdrivers::CBoardENoses for the possible parameters
00103                           */
00104                         void  loadConfig_sensorSpecific(
00105                                 const mrpt::utils::CConfigFileBase &configSource,
00106                                 const std::string                       &section );
00107 
00108                 public:
00109                         /** Constructor
00110                           * \param serialNumberUSBdevice The serial number (text) of the device to open.
00111                           *  The constructor will try to open the device. You can check if it failed calling "isOpen()".
00112                           */
00113                         CBoardENoses( );
00114 
00115                         /** Destructor
00116                           */
00117                         virtual ~CBoardENoses();
00118 
00119                         /** Set the active chamber (afected by poluted air) on the device
00120                           * \return true on success, false on communications errors or device not found.
00121                           */
00122                         bool    setActiveChamber( unsigned char chamber );
00123 
00124                         /** Query the firmware version on the device (can be used to test communications).
00125                           * \return true on success, false on communications errors or device not found.
00126                           */
00127                         bool    queryFirmwareVersion( std::string &out_firmwareVersion );
00128 
00129                         /** Request the master eNose the latest readings from all the eNoses.
00130                           *  The output observation contains a valid timestamp and 3D positions if "loadConfig" has been called previously.
00131                           * \return true if OK, false if there were any error.
00132                           */
00133                         bool getObservation( mrpt::slam::CObservationGasSensors &outObservation );
00134 
00135 
00136                         /** This method should be called periodically (at least at 1Hz to capture ALL the real-time data)
00137                         *  It is thread safe, i.e. you can call this from one thread, then to other methods from other threads.
00138                         */
00139                         void  doProcess();
00140 
00141                         /** Tries to open the camera, after setting all the parameters with a call to loadConfig.
00142                           *  \exception This method must throw an exception with a descriptive message if some critical error is found.
00143                           */
00144                         virtual void initialize();
00145 
00146 
00147 
00148                         /** If not an empty string, will open that serial port, otherwise will try to open USB FTDI device "m_usbSerialNumber"
00149                           *  The default is an empty string. Example strings: "COM1", "ttyUSB0", ...
00150                           */
00151                         inline void setSerialPort(const std::string &port) { m_COM_port = port; }
00152                         inline std::string getSerialPort() const { return m_COM_port; }
00153 
00154                         /** Set the serial port baud rate (default: 115200) */
00155                         inline void setSerialPortBaud(unsigned int baud) { m_COM_baud=baud; }
00156                         inline unsigned int getSerialPortBaud() const { return m_COM_baud; }
00157 
00158 
00159                 }; // end of class
00160         } // end of namespace
00161 } // end of namespace
00162 
00163 
00164 #endif
00165 
00166 



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011