LoVFH.C

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/control/LoVFH.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::VFH class.
00005 */
00006 
00007 // //////////////////////////////////////////////////////////////////// //
00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00009 // by the University of Southern California (USC) and the iLab at USC.  //
00010 // See http://iLab.usc.edu for information about this project.          //
00011 // //////////////////////////////////////////////////////////////////// //
00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00014 // in Visual Environments, and Applications'' by Christof Koch and      //
00015 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00016 // pending; application number 09/912,225 filed July 23, 2001; see      //
00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00022 // redistribute it and/or modify it under the terms of the GNU General  //
00023 // Public License as published by the Free Software Foundation; either  //
00024 // version 2 of the License, or (at your option) any later version.     //
00025 //                                                                      //
00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00029 // PURPOSE.  See the GNU General Public License for more details.       //
00030 //                                                                      //
00031 // You should have received a copy of the GNU General Public License    //
00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00034 // Boston, MA 02111-1307 USA.                                           //
00035 // //////////////////////////////////////////////////////////////////// //
00036 //
00037 // Primary maintainer for this file: mviswana usc edu
00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/control/LoVFH.C $
00039 // $Id: LoVFH.C 13037 2010-03-23 01:00:53Z mviswana $
00040 //
00041 
00042 //------------------------------ HEADERS --------------------------------
00043 
00044 // lobot headers
00045 #include "Robots/LoBot/control/LoVFH.H"
00046 //#include "Robots/LoBot/control/LoSpeedArbiter.H"
00047 
00048 //#include "Robots/LoBot/LoApp.H"
00049 #include "Robots/LoBot/config/LoConfigHelpers.H"
00050 
00051 //#include "Robots/LoBot/misc/LoUpdateLock.H"
00052 //#include "Robots/LoBot/misc/LoExcept.H"
00053 #include "Robots/LoBot/misc/LoRegistry.H"
00054 #include "Robots/LoBot/util/LoGL.H"
00055 
00056 // OpenGL headers
00057 #ifdef INVT_HAVE_LIBGL
00058 #include <GL/gl.h>
00059 #endif
00060 
00061 // Standard C++ headers
00062 #include <algorithm>
00063 
00064 //----------------------------- NAMESPACE -------------------------------
00065 
00066 namespace lobot {
00067 
00068 //--------------------------- LOCAL HELPERS -----------------------------
00069 
00070 // Retrieve settings from vfh section of config file
00071 template<typename T>
00072 static inline T conf(const std::string& key, const T& default_value)
00073 {
00074    return get_conf<T>(LOBE_VFH, key, default_value) ;
00075 }
00076 
00077 //-------------------------- INITIALIZATION -----------------------------
00078 
00079 VFH::VFH()
00080    : base(clamp(conf("update_delay", 150), 1, 1500))
00081 {
00082    start(LOBE_VFH) ;
00083 }
00084 
00085 void VFH::pre_run()
00086 {
00087 }
00088 
00089 //---------------------- THE BEHAVIOUR'S ACTION -------------------------
00090 
00091 void VFH::action()
00092 {
00093    // Vote to drive straight ahead
00094    //TurnArbiter::Vote* V = new TurnArbiter::Vote() ;
00095    //V->dump("VFH::action") ;
00096    //TurnArbiter::instance().vote(base::name, V) ;
00097 
00098    // Vote to drive at user-specified cruising speed (or PWM)
00099    //SpeedArbiter::instance().vote(base::name,
00100       //new SpeedArbiter::Vote(Params::cruising_speed(),
00101                              //Params::cruising_pwm())) ;
00102 
00103    //viz_lock() ;
00104       //m_vote = *V ; // record most recent vote for visualization
00105       //m_vote.dump("VFH::action") ;
00106    //viz_unlock() ;
00107 }
00108 
00109 //--------------------------- VISUALIZATION -----------------------------
00110 
00111 #ifdef INVT_HAVE_LIBGL
00112 
00113 void VFH::render()
00114 {
00115    // Render the votes visualization
00116    //glBegin(GL_LINES) ;
00117    //viz_lock() ;
00118       /*
00119       for (TurnArbiter::Vote::iterator it = m_vote.begin(); it; ++it)
00120       {
00121          float vote = it.value() ;
00122          float direction = it.direction() ;
00123          if (vote < 0) // voted against this direction
00124          {
00125             glColor3f(1, 0, 0) ;
00126             glVertex2i(0, 0) ;
00127             glVertex2f(-vote * cos(direction), -vote * sin(direction)) ;
00128          }
00129          else if (vote > 0) // voted for this direction
00130          {
00131             glColor3f(0, 1, 0) ;
00132             glVertex2i(0, 0) ;
00133             glVertex2f(vote * cos(direction), vote * sin(direction)) ;
00134          }
00135       }
00136       */
00137    //viz_unlock() ;
00138    //glEnd() ;
00139 
00140    // Label the visualization so that it is easy to tell which behaviour
00141    // is being visualized.
00142    glColor3f(0, 1, 1) ;
00143    glPushMatrix() ;
00144       glLoadIdentity() ;
00145       draw_label(-0.9f, -0.9f, "VFH") ;
00146    glPopMatrix() ;
00147 }
00148 
00149 #endif
00150 
00151 //----------------------------- CLEAN-UP --------------------------------
00152 
00153 VFH::~VFH(){}
00154 
00155 //-------------------------- KNOB TWIDDLING -----------------------------
00156 
00157 // Parameters initialization
00158 VFH::Params::Params()
00159 {}
00160 
00161 // Parameters clean-up
00162 VFH::Params::~Params(){}
00163 
00164 //-----------------------------------------------------------------------
00165 
00166 } // end of namespace encapsulating this file's definitions
00167 
00168 /* So things look consistent in everyone's emacs... */
00169 /* Local Variables: */
00170 /* indent-tabs-mode: nil */
00171 /* End: */
Generated on Sun May 8 08:05:54 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3