00001 /** 00002 \file Robots/LoBot/control/LoOpenPath.H 00003 \brief A behaviour for steering the robot based on the open path 00004 algorithm. 00005 00006 This file defines a class that implements the open path algorithm for 00007 steering the robot towards the longest open path that will accommodate 00008 the robot's width given the current set of distance readings from the 00009 laser range finder. 00010 00011 The open path algorithm is described in the following paper: 00012 00013 von Wahlde, R., Wiedenman, N., Brown, W. A., Viqueira, C. 00014 An Open-Path Obstacle Avoidance Algorithm Using Scanning Laser 00015 Range Data 00016 U. S. Army Research Laboratory, Report number ARL-MR-0715 00017 00018 The above paper is rather abstruse and unnecessarily complicated. This 00019 implementation uses the open path idea but does not follow the 00020 description in the paper. 00021 */ 00022 00023 // //////////////////////////////////////////////////////////////////// // 00024 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00025 // by the University of Southern California (USC) and the iLab at USC. // 00026 // See http://iLab.usc.edu for information about this project. // 00027 // //////////////////////////////////////////////////////////////////// // 00028 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00029 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00030 // in Visual Environments, and Applications'' by Christof Koch and // 00031 // Laurent Itti, California Institute of Technology, 2001 (patent // 00032 // pending; application number 09/912,225 filed July 23, 2001; see // 00033 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00034 // //////////////////////////////////////////////////////////////////// // 00035 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00036 // // 00037 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00038 // redistribute it and/or modify it under the terms of the GNU General // 00039 // Public License as published by the Free Software Foundation; either // 00040 // version 2 of the License, or (at your option) any later version. // 00041 // // 00042 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00043 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00044 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00045 // PURPOSE. See the GNU General Public License for more details. // 00046 // // 00047 // You should have received a copy of the GNU General Public License // 00048 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00049 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00050 // Boston, MA 02111-1307 USA. // 00051 // //////////////////////////////////////////////////////////////////// // 00052 // 00053 // Primary maintainer for this file: mviswana usc edu 00054 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/control/LoOpenPath.H $ 00055 // $Id: LoOpenPath.H 13812 2010-08-21 04:04:10Z mviswana $ 00056 // 00057 00058 #ifndef LOBOT_OPEN_PATH_BEHAVIOUR_DOT_H 00059 #define LOBOT_OPEN_PATH_BEHAVIOUR_DOT_H 00060 00061 //------------------------------ HEADERS -------------------------------- 00062 00063 // lobot headers 00064 #include "Robots/LoBot/control/LoBehavior.H" 00065 #include "Robots/LoBot/control/LoTurnArbiter.H" 00066 00067 #include "Robots/LoBot/io/LoLRFData.H" 00068 #include "Robots/LoBot/misc/factory.hh" 00069 #include "Robots/LoBot/util/triple.hh" 00070 00071 // Standard C++ headers 00072 #include <map> 00073 00074 //----------------------------- NAMESPACE ------------------------------- 00075 00076 namespace lobot { 00077 00078 //------------------------- CLASS DEFINITION ---------------------------- 00079 00080 /** 00081 \class lobot::OpenPath 00082 \brief A behaviour for steering the robot toward the most open path 00083 that can accommodate it. 00084 00085 This class implements the open path algorithm for steering the robot 00086 toward the most open path that can accommodate the robot's width. 00087 00088 The algorithm uses the current set of distance readings from the laser 00089 range finder and some trigonometry and vector math to build a list of 00090 candidate paths of some user-specified minimum length. It then picks 00091 the path with the maximum traversable area and issues a steering vote 00092 to turn the robot towards that path. 00093 */ 00094 class OpenPath : public Behavior { 00095 // Prevent copy and assignment 00096 OpenPath(const OpenPath&) ; 00097 OpenPath& operator=(const OpenPath&) ; 00098 00099 // Handy type to have around in a derived class 00100 typedef Behavior base ; 00101 00102 // Boilerplate code to make the generic factory design pattern work 00103 friend class subfactory<OpenPath, base> ; 00104 typedef register_factory<OpenPath, base> my_factory ; 00105 static my_factory register_me ; 00106 00107 /// Each potential open path is characterized by a length, a width and 00108 /// an area. This inner class serves to keep these characteristics 00109 /// together in one place. 00110 class PathInfo { 00111 triple<float, float, float> m_info ; 00112 public: 00113 PathInfo(float length, float width) ; 00114 00115 float length() const {return m_info.first ;} 00116 float width() const {return m_info.second ;} 00117 float area() const {return m_info.third ;} 00118 00119 bool operator<(const PathInfo& p) const {return area() < p.area() ;} 00120 } ; 00121 00122 /// In order to find the most open path, the behaviour will have to 00123 /// first build a list of several potential candidates that meet at 00124 /// least the basic criteria for minimum path width and path length. 00125 /// Only then will it be in a position to determine which of these 00126 /// candidates is the best. 00127 /// 00128 /// This data structure is used to store all the candidate paths. 00129 /// Rather than a plain list, we use a map that stores paths 00130 /// corresponding to the particular directions in which they lie. 00131 /// 00132 /// This map is also used for visualization. 00133 //@{ 00134 typedef std::map<int, PathInfo> Paths ; 00135 Paths m_paths ; 00136 //@} 00137 00138 /// In addition to visualizing the candidate paths, this behaviour 00139 /// also draws its most recently issued turn vote. 00140 TurnArbiter::Vote m_vote ; 00141 00142 /// A private constructor because behaviours are instantiated with an 00143 /// object factory and not directly by clients. 00144 OpenPath() ; 00145 00146 /// Some things to do before commencing regular action processing. 00147 void pre_run() ; 00148 00149 /// This method provides the body of the behaviour's main loop. 00150 void action() ; 00151 00152 /// This is a helper function that implements all the necessary math 00153 /// required to find an open path in the specified direction. The path 00154 /// must have the configured minimum width (to allow the robot to fit) 00155 /// and minimum length (to ensure a decent amount of forward motion). 00156 PathInfo open_path(int angle, const LRFData&) const ; 00157 00158 /// Visualization routines to aid with development and debugging. 00159 //@{ 00160 void render_me() ; 00161 static void render_paths(unsigned long client_data) ; 00162 void render_paths() ; 00163 //@} 00164 00165 /// Clean-up. 00166 ~OpenPath() ; 00167 } ; 00168 00169 //----------------------------------------------------------------------- 00170 00171 } // end of namespace encapsulating this file's definitions 00172 00173 #endif 00174 00175 /* So things look consistent in everyone's emacs... */ 00176 /* Local Variables: */ 00177 /* indent-tabs-mode: nil */ 00178 /* End: */