Main MRPT website > C++ reference
MRPT logo

CLMS100eth.h

Go to the documentation of this file.
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 CLMS100ETH_H
00030 #define CLMS100ETH_H
00031 
00032 #include <mrpt/utils.h>
00033 #include <mrpt/hwdrivers/C2DRangeFinderAbstract.h>
00034 
00035 namespace mrpt
00036 {
00037     namespace hwdrivers
00038     {
00039                 using namespace std;
00040                 using namespace mrpt::hwdrivers;
00041                 using namespace mrpt::utils;
00042                 using namespace mrpt::slam;
00043 
00044         /** This "software driver" implements the communication protocol for interfacing a SICK LMS100 laser scanners through an ethernet controller.
00045           *   This class does not need to be bind, i.e. you do not need to call C2DRangeFinderAbstract::bindIO.
00046           *   Connection is established when user call the turnOn() method. You can pass to the class's constructor the LMS100 's ip address and port.
00047           *   Device will be configured with the following parameters :
00048           * - Start Angle : -45 deg (imposed by hardware)
00049           * - Stop Angle : +225 deg (imposed by hardware)
00050           * - Apperture : 270 deg (imposed by hardware)
00051           * - Angular resolution : 0.25 deg
00052           * - Scan frequency : 25 Hz
00053           * - Max Range : 20m (imposed by hardware).
00054           *
00055           * <b>Important note:</b> SICK LMS 1xx devices have two levels of configuration. In its present implementation, this class only handles one of them, so
00056           *    <b>before using this class</b>, you must "pre-configure" your scanner with the SICK's software "SOAP" (this software ships with the device),
00057           *    and set the framerate with this software. Of course, you have to pre-configure the device just once, then save that configuration in its flash memory.
00058           *
00059           * To get a laser scan you must proceed like that :
00060           * \code
00061           *     CLMS200Eth laser(string("192.168.0.10"), 1234);
00062           *     laser.turnOn();
00063           *     bool isOutObs, hardwareError;
00064           *     CObservation2DRangeScan outObs;
00065           *     laser.doProcessSimple(isOutObs, outObs, hardwareError);
00066           * \endcode
00067           *
00068           * The sensor pose on the vehicle could be loaded from an ini configuration file with :
00069           *  \code
00070           *  PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
00071           * -------------------------------------------------------
00072           *   [supplied_section_name]
00073                   *       ip_address = 192.168.0.50 ;a string wich is the SICK's ip adress (default is 192.168.0.1)
00074                   *   TCP_port = 1234                   ; an integer value : the tcp ip port on wich the sick is listening (default is 2111).
00075           *   pose_x=0.21       ; Laser range scaner 3D position in the robot (meters)
00076           *   pose_y=0
00077           *   pose_z=0.34
00078           *   pose_yaw=0        ; Angles in degrees
00079           *   pose_pitch=0
00080           *   pose_roll=0
00081           *  \endcode
00082           * This class doesn't configure the SICK LMS sensor, it is recomended to configure the sensor via the
00083           * the SICK software : SOPAS.
00084           * \note This class was contributed by Adrien Barral - Robopec (France)
00085           */
00086         class HWDRIVERS_IMPEXP CLMS100Eth : C2DRangeFinderAbstract
00087         {
00088             DEFINE_GENERIC_SENSOR(CLMS100Eth)
00089             public:
00090                 /** Constructor.
00091                  * Note that there is default arguments, here you can customize IP Adress and TCP Port of your device.
00092                  */
00093                 CLMS100Eth(string _ip=string("192.168.0.1"), unsigned int _port=2111);
00094                 /** Destructor.
00095                  * Close communcation with the device, and free memory.
00096                  */
00097                 virtual ~CLMS100Eth();
00098                 /** This function acquire a laser scan from the device. If an error occured, hardwareError will be set to true.
00099                  * The new laser scan will be stored in the outObservation argument.
00100                  *
00101                  * \exception This method throw exception if the frame received from the LMS 100 contain the following bad parameters :
00102                  *  * Status is not OK
00103                  *  * Data in the scan aren't DIST1 (may be RSSIx or DIST2).
00104                  */
00105                 void doProcessSimple(bool &outThereIsObservation, CObservation2DRangeScan &outObservation, bool &hardwareError);
00106 
00107                 /** This method must be called before trying to get a laser scan.
00108                  */
00109                 bool turnOn();
00110                 /** This method could be called manually to stop communication with the device. Method is also called by destructor.
00111                  */
00112                 bool turnOff();
00113                 /** A method to set the sensor pose on the robot.
00114                  */
00115                 void setSensorPose(CPose3D& _pose);
00116 
00117                                 /** This method should be called periodically. Period depend on the process_rate in the configuration file.
00118                                  */
00119                                 void  doProcess();
00120 
00121                                 /** Initialize the sensor according to the parameters previously read in the configuration file.
00122                                  */
00123                                 void initialize();
00124         private :
00125             string                  m_ip;
00126             unsigned int            m_port;
00127             CClientTCPSocket        m_client;
00128             bool                    m_turnedOn;
00129             string                                      m_cmd;
00130             bool                    m_connected;
00131             unsigned int            m_scanFrequency;    // en hertz
00132             double                  m_angleResolution;  // en degrés
00133             double                  m_startAngle;       // degrés
00134             double                  m_stopAngle;        // degrés
00135             CPose3D                 m_sensorPose;
00136             double                  m_maxRange;
00137             double                  m_beamApperture;
00138 
00139             void generateCmd(const char *cmd);
00140             bool checkIsConnected();
00141             bool decodeLogIn(char *msg);
00142             bool decodeScanCfg(istringstream& stream);
00143             bool decodeScanDataCfg(istringstream& stream);
00144             bool decodeScan(char *buf, CObservation2DRangeScan& outObservation);
00145             void sendCommand(const char *cmd);
00146             void roughPrint( char *msg );
00147 
00148 
00149                 protected:
00150             /** Load sensor pose on the robot, or keep the default sensor pose.
00151              */
00152             void  loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource,
00153                              const std::string    &iniSection );
00154 
00155         };
00156     }
00157 }
00158 #endif // CLMS100ETH_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011