LoCountdown.C

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/control/LoCountdown.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::Countdown 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/LoCountdown.C $
00039 // $Id: LoCountdown.C 14305 2010-12-08 21:17:33Z mviswana $
00040 //
00041 
00042 //------------------------------ HEADERS --------------------------------
00043 
00044 // lobot headers
00045 #include "Robots/LoBot/control/LoCountdown.H"
00046 #include "Robots/LoBot/control/LoMetrics.H"
00047 
00048 #include "Robots/LoBot/LoApp.H"
00049 #include "Robots/LoBot/slam/LoMap.H"
00050 #include "Robots/LoBot/config/LoConfigHelpers.H"
00051 #include "Robots/LoBot/thread/LoShutdown.H"
00052 
00053 #include "Robots/LoBot/misc/LoRegistry.H"
00054 #include "Robots/LoBot/misc/singleton.hh"
00055 #include "Robots/LoBot/util/LoTime.H"
00056 
00057 // Standard C++ headers
00058 #include <iomanip>
00059 
00060 //----------------------------- NAMESPACE -------------------------------
00061 
00062 namespace lobot {
00063 
00064 //-------------------------- KNOB TWIDDLING -----------------------------
00065 
00066 namespace {
00067 
00068 // Retrieve settings from monitor_danger_zone section of config file
00069 template<typename T>
00070 inline T conf(const std::string& key, const T& default_value)
00071 {
00072    return get_conf<T>(LOBE_COUNTDOWN, key, default_value) ;
00073 }
00074 
00075 /// This local class encapsulates various parameters that can be used to
00076 /// tweak different aspects of the monitor_danger_zone behaviour.
00077 class CountdownParams : public singleton<CountdownParams> {
00078    /// This setting specifies the number of seconds for the countdown.
00079    int m_duration ;
00080 
00081    /// The number of milliseconds between successive iterations of this
00082    /// behaviour.
00083    ///
00084    /// WARNING: The ability to change a behaviour's update frequency is a
00085    /// very powerful feature whose misuse or abuse can wreak havoc! Be
00086    /// sure to use reasonable values for this setting.
00087    int m_update_delay ;
00088 
00089    /// Private constructor because this is a singleton.
00090    CountdownParams() ;
00091    friend class singleton<CountdownParams> ;
00092 
00093 public:
00094    /// Accessing the various parameters
00095    //@{
00096    static int duration()     {return instance().m_duration     ;}
00097    static int update_delay() {return instance().m_update_delay ;}
00098    //@}
00099 } ;
00100 
00101 // Parameter initialization
00102 CountdownParams::CountdownParams()
00103    : m_duration(clamp(conf("duration", 10800), 5, 86400) * 1000),
00104      m_update_delay(clamp(conf("update_delay", 1000), 500, 5000))
00105 {}
00106 
00107 // Shortcut
00108 typedef CountdownParams Params ;
00109 
00110 } // end of local anonymous namespace encapsulating above helpers
00111 
00112 //-------------------------- INITIALIZATION -----------------------------
00113 
00114 Countdown::Countdown()
00115    : base(Params::update_delay(), LOBE_COUNTDOWN),
00116      m_time(-1)
00117 {
00118    start(LOBE_COUNTDOWN) ;
00119 }
00120 
00121 void Countdown::pre_run()
00122 {
00123    m_time = current_time() ;
00124 }
00125 
00126 //---------------------- THE BEHAVIOUR'S ACTION -------------------------
00127 
00128 void Countdown::action()
00129 {
00130    if (current_time() - m_time >= Params::duration())
00131    {
00132       using std::setw ; using std::left ;
00133 
00134       Metrics::Log log ;
00135       log << setw(Metrics::opw()) << left << base::name ;
00136       Map* M = App::map() ;
00137       if (M)
00138          log << M->current_pose() ;
00139 
00140       Shutdown::signal() ;
00141    }
00142 }
00143 
00144 //----------------------------- CLEAN-UP --------------------------------
00145 
00146 Countdown::~Countdown(){}
00147 
00148 //-----------------------------------------------------------------------
00149 
00150 } // end of namespace encapsulating this file's definitions
00151 
00152 /* So things look consistent in everyone's emacs... */
00153 /* Local Variables: */
00154 /* indent-tabs-mode: nil */
00155 /* End: */
Generated on Sun May 8 08:41:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3