LoSpeedArbiter.H

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/control/LoSpeedArbiter.H
00003    \brief An arbiter for issuing speed commands to the robot.
00004 
00005    This file defines a class that implements a DAMN speed arbiter for
00006    Robolocust.
00007 */
00008 
00009 // //////////////////////////////////////////////////////////////////// //
00010 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00011 // by the University of Southern California (USC) and the iLab at USC.  //
00012 // See http://iLab.usc.edu for information about this project.          //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00015 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00016 // in Visual Environments, and Applications'' by Christof Koch and      //
00017 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00018 // pending; application number 09/912,225 filed July 23, 2001; see      //
00019 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00020 // //////////////////////////////////////////////////////////////////// //
00021 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00024 // redistribute it and/or modify it under the terms of the GNU General  //
00025 // Public License as published by the Free Software Foundation; either  //
00026 // version 2 of the License, or (at your option) any later version.     //
00027 //                                                                      //
00028 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00029 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00030 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00031 // PURPOSE.  See the GNU General Public License for more details.       //
00032 //                                                                      //
00033 // You should have received a copy of the GNU General Public License    //
00034 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00035 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00036 // Boston, MA 02111-1307 USA.                                           //
00037 // //////////////////////////////////////////////////////////////////// //
00038 //
00039 // Primary maintainer for this file: Manu Viswanathan mviswana usc edu
00040 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/control/LoSpeedArbiter.H $
00041 // $Id: LoSpeedArbiter.H 12827 2010-02-12 00:17:25Z mviswana $
00042 //
00043 
00044 #ifndef LOBOT_SPEED_ARBITER_DOT_H
00045 #define LOBOT_SPEED_ARBITER_DOT_H
00046 
00047 //------------------------------ HEADERS --------------------------------
00048 
00049 // lobot headers
00050 #include "Robots/LoBot/control/LoArbiter.H"
00051 #include "Robots/LoBot/misc/singleton.hh"
00052 
00053 // Standard C++ headers
00054 #include <string>
00055 
00056 //----------------------------- NAMESPACE -------------------------------
00057 
00058 namespace lobot {
00059 
00060 //------------------------- CLASS DEFINITION ----------------------------
00061 
00062 /**
00063    \class lobot::SpeedArbiter
00064    \brief A DAMN speed arbiter for controlling Robolocust's speed.
00065 
00066    This class implements a DAMN speed arbiter that acts as the interface
00067    between the Robolocust behaviours and the robot's speed controls. Each
00068    behaviour that wants to influence the robot's driving speed will have
00069    to vote by specifying an acceptable maximum speed value. The arbiter
00070    will issue the motor control command for the highest priority
00071    behaviour.
00072 */
00073 class SpeedArbiter : public Arbiter, public singleton<SpeedArbiter> {
00074    // Prevent copy and assignment
00075    SpeedArbiter(const SpeedArbiter&) ;
00076    SpeedArbiter& operator=(const SpeedArbiter&) ;
00077 
00078    // Boilerplate code to make the generic singleton design pattern work
00079    friend class singleton<SpeedArbiter> ;
00080 
00081    /// A private constructor because this class is a singleton.
00082    SpeedArbiter() ;
00083 
00084    /// Retrieve the user-assigned priority for the given behaviour.
00085    float get_configured_priority(const std::string& behaviour) const ;
00086 
00087    /// Tally votes and issue appropriate motor command.
00088    void motor_cmd(const Votes&, Robot*) ;
00089 
00090 public:
00091    /// To control the robot's speed, each speed related behaviour must
00092    /// vote for the maximum acceptable speed. These votes are represented
00093    /// by this inner class. In order to vote, a behaviour must
00094    /// instantiate this class with the new operator, fill out the voting
00095    /// structure properly and then pass it to the arbiter's vote()
00096    /// method.
00097    class Vote : public VoteBase {
00098       /// A vote is simply a number indicating the maximum acceptable
00099       /// speed (in m/s).
00100       float m_speed ;
00101 
00102       /// Depending on how lobot is configured, its drive commands may
00103       /// require behaviours to specify motor PWM values directly rather
00104       /// than have the motor system compute PWM values corresponding to
00105       /// commanded velocities on the basis of the RPM sensor. Therefore,
00106       /// all speed related behaviours must also supply appropriate PWM
00107       /// values in addition to a m/s speed value.
00108       int m_pwm ;
00109 
00110    public:
00111       /// Filling out a speed arbiter vote object simply involves passing
00112       /// the desired speed to the constructor.
00113       Vote(float speed = 0, int pwm = 0) ;
00114 
00115       /// Retrieving the specified speed.
00116       float speed() const {return m_speed ;}
00117 
00118       /// Retrieving the specified PWM.
00119       int pwm() const {return m_pwm ;}
00120    } ;
00121 
00122 private:
00123    /// The Arbiter class maintains the votes in a list of vote_data*. To
00124    /// find the vote corresponding to the behaviour with the maximum
00125    /// priority, we need a custom function object for use with the
00126    /// std::max_element() algorithm.
00127    ///
00128    /// DEVNOTE: Since vote_data is protected in the lobot::Arbiter base
00129    /// class, this comparator need to be a member function object rather
00130    /// than a local helper in LoSpeedArbiter.C.
00131    class compare_priorities {
00132       const SpeedArbiter* arbiter ;
00133    public:
00134       compare_priorities(const SpeedArbiter*) ;
00135       bool operator()(const vote_data* a, const vote_data* b) const ;
00136    } ;
00137 
00138    /// Speed arbiter clean-up.
00139    ~SpeedArbiter() ;
00140 } ;
00141 
00142 //-----------------------------------------------------------------------
00143 
00144 } // end of namespace encapsulating this file's definitions
00145 
00146 #endif
00147 
00148 /* So things look consistent in everyone's emacs... */
00149 /* Local Variables: */
00150 /* indent-tabs-mode: nil */
00151 /* End: */
Generated on Sun May 8 08:41:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3