LoLaserRangeFinder.H

Go to the documentation of this file.
00001 /**
00002    \file Robots/LoBot/io/LoLaserRangeFinder.H
00003 
00004    \brief A wrapper around the URG API for interfacing with the Hokuyo
00005    line of laser range finders.
00006 
00007    This file defines a class that provides a higher-level API than the
00008    plain C API implemented by the URG library for retrieving distance
00009    measurements from a Hokuyo laser range finder.
00010 
00011    NOTE: The URG library in question is a heavily hacked version of
00012    Satofumi Kamimura's original URG library. It was produced by Manu
00013    Viswanathan and does away with the C++ and sample code parts of the
00014    original. It also collapses the original's libsystem and libconnection
00015    into a single liburg so that client programs need only link with this
00016    one library.
00017 */
00018 
00019 // //////////////////////////////////////////////////////////////////// //
00020 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00021 // by the University of Southern California (USC) and the iLab at USC.  //
00022 // See http://iLab.usc.edu for information about this project.          //
00023 // //////////////////////////////////////////////////////////////////// //
00024 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00025 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00026 // in Visual Environments, and Applications'' by Christof Koch and      //
00027 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00028 // pending; application number 09/912,225 filed July 23, 2001; see      //
00029 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00030 // //////////////////////////////////////////////////////////////////// //
00031 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00032 //                                                                      //
00033 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00034 // redistribute it and/or modify it under the terms of the GNU General  //
00035 // Public License as published by the Free Software Foundation; either  //
00036 // version 2 of the License, or (at your option) any later version.     //
00037 //                                                                      //
00038 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00039 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00040 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00041 // PURPOSE.  See the GNU General Public License for more details.       //
00042 //                                                                      //
00043 // You should have received a copy of the GNU General Public License    //
00044 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00045 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00046 // Boston, MA 02111-1307 USA.                                           //
00047 // //////////////////////////////////////////////////////////////////// //
00048 //
00049 // Primary maintainer for this file: mviswana usc edu
00050 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoLaserRangeFinder.H $
00051 // $Id: LoLaserRangeFinder.H 13037 2010-03-23 01:00:53Z mviswana $
00052 //
00053 
00054 #ifndef LOBOT_LASER_RANGE_FINDER_DOT_H
00055 #define LOBOT_LASER_RANGE_FINDER_DOT_H
00056 
00057 //------------------------------ HEADERS --------------------------------
00058 
00059 // lobot headers
00060 #include "Robots/LoBot/util/range.hh"
00061 
00062 // INVT image support
00063 #include "Image/Image.H"
00064 
00065 // URG headers
00066 #ifdef INVT_HAVE_LIBURG
00067 
00068 #include <urg/urg.h>
00069 
00070 #else // fake URG API just to let this class compile
00071 
00072 typedef int urg_t ;
00073 
00074 #endif
00075 
00076 //----------------------------- NAMESPACE -------------------------------
00077 
00078 namespace lobot {
00079 
00080 //------------------------- CLASS DEFINITION ----------------------------
00081 
00082 /**
00083    \class lobot::LaserRangeFinder
00084    \brief Encapsulation of liburg API for interfacing with Hokuyo laser
00085    range finders.
00086 
00087    This class provides a higher-level abstraction over liburg's plain C
00088    API for retrieving distance measurements from lobot's Hokuyo laser
00089    range finder. It takes care of the low-level details of correctly
00090    invoking the liburg API and allows clients to query for distance along
00091    a particular direction.
00092 */
00093 class LaserRangeFinder {
00094    // The URG "handle"
00095    urg_t m_handle ;
00096 
00097    // The buffer that will receive distance measurements from the device
00098    int   m_bufsiz ; // total size of receive buffer
00099    int   m_retsiz ; // actual number of measurements received per update
00100    long* m_buffer ;
00101 
00102    // What is the device's range?
00103    range<int> m_angle_range, m_distance_range ;
00104 
00105    // We don't need all the values returned in the receive buffer. On
00106    // update, we extract just those distances we actually need and store
00107    // them separately. This speeds up subsequent accesses because we
00108    // don't have to invoke any URG functions to make sense of the buffer.
00109    int* m_distances ;
00110 
00111 public:
00112    /// Initialization
00113    LaserRangeFinder(const std::string& device = "/dev/ttyACM0",
00114                     int baud_rate = 115200) ;
00115 
00116    /// Retrieve distance data from the laser range finder.
00117    void update() ;
00118 
00119    /// What is the distance measurement (in mm) along the specified
00120    /// direction (in degrees)? A negative value is returned if the angle
00121    /// is out of range. Zero degrees corresponds to the front of the
00122    /// device. Directions to the left are positive angles and those to
00123    /// the right are negative.
00124    int get_distance(int angle) const ;
00125 
00126    /// Retrieve the entire set of distances.
00127    Image<int> get_distances() const ;
00128 
00129    /// A convenience routine for returning the average distance for a
00130    /// range of angles.
00131    //@{
00132    float average_distance(int min, int max) const ;
00133    float average_distance(const range<int>& angles) const {
00134       return average_distance(angles.min(), angles.max()) ;
00135    }
00136    //@}
00137 
00138    /// A convenience routine for returning the maximum distance reading
00139    /// for a given range of angles.
00140    //@{
00141    int max_reading(int min, int max) const ;
00142    int max_reading(const range<int>& angles) const {
00143       return max_reading(angles.min(), angles.max()) ;
00144    }
00145    int max_reading() const {return max_reading(m_angle_range) ;}
00146    //@}
00147 
00148    /// What is the device's distance measurement range?
00149    //@{
00150    range<int> get_distance_range() const {return m_distance_range ;}
00151    int min_distance() const {return m_distance_range.min() ;}
00152    int max_distance() const {return m_distance_range.max() ;}
00153    //@}
00154 
00155    /// Retrieve the device's angular range.
00156    //@{
00157    range<int> get_angular_range() const {return m_angle_range ;}
00158    int min_angle() const {return m_angle_range.min() ;}
00159    int max_angle() const {return m_angle_range.max() ;}
00160    //@}
00161 
00162    /// Clean-up
00163    ~LaserRangeFinder() ;
00164 } ;
00165 
00166 //-----------------------------------------------------------------------
00167 
00168 } // end of namespace encapsulating this file's definitions
00169 
00170 #endif
00171 
00172 /* So things look consistent in everyone's emacs... */
00173 /* Local Variables: */
00174 /* indent-tabs-mode: nil */
00175 /* End: */
Generated on Sun May 8 08:05:54 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3