00001 /** 00002 \file Robots/LoBot/control/LoSpinArbiter.H 00003 \brief An arbiter for issuing spin commands to the robot. 00004 00005 This file defines a class that implements a DAMN spin 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: mviswana usc edu 00040 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/control/LoSpinArbiter.H $ 00041 // $Id: LoSpinArbiter.H 13770 2010-08-08 06:49:50Z mviswana $ 00042 // 00043 00044 #ifndef LOBOT_SPIN_ARBITER_DOT_H 00045 #define LOBOT_SPIN_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::SpinArbiter 00064 \brief A DAMN spin arbiter for steering Robolocust using in-place 00065 turns. 00066 00067 This class implements a DAMN arbiter that acts as the interface 00068 between the Robolocust behaviours and the robot's in-place turn 00069 commands. Each behaviour that wants to steer the robot using in-place 00070 turns will have to vote by specifying a desired rotation amount. The 00071 arbiter will issue the appropriate motor control command by combining 00072 the votes of all the different behaviours. 00073 */ 00074 class SpinArbiter : public Arbiter, public singleton<SpinArbiter> { 00075 // Prevent copy and assignment 00076 SpinArbiter(const SpinArbiter&) ; 00077 SpinArbiter& operator=(const SpinArbiter&) ; 00078 00079 // Boilerplate code to make the generic singleton design pattern work 00080 friend class singleton<SpinArbiter> ; 00081 00082 /// A private constructor because this class is a singleton. 00083 SpinArbiter() ; 00084 00085 /// Retrieve the user-assigned priority for the given behaviour. 00086 float get_configured_priority(const std::string& behaviour) const ; 00087 00088 /// Tally votes and issue appropriate motor command. 00089 void motor_cmd(const Votes&, Robot*) ; 00090 00091 /// Spin arbiter clean-up. 00092 ~SpinArbiter() ; 00093 00094 public: 00095 /// To spin the robot, each behaviour must vote for the desired amount 00096 /// of rotation. These votes are represented by this inner class. In 00097 /// order to vote, a behaviour must instantiate this class with the 00098 /// new operator, fill out the voting structure properly and then pass 00099 /// it to the arbiter's vote() method. 00100 class Vote : public VoteBase { 00101 /// A vote is simply a number indicating the desired amount of 00102 /// rotation (in degrees). This value should be a number in the 00103 /// range [-360, 360]. Negative values result in clockwise spins 00104 /// while positive ones are for counterclockwise spins. 00105 float m_spin ; 00106 00107 public: 00108 /// Filling out a speed arbiter vote object simply involves passing 00109 /// the desired spin amount to the constructor. 00110 Vote(float spin = 0) ; 00111 00112 /// Retrieving the specified spin. 00113 float spin() const {return m_spin ;} 00114 } ; 00115 } ; 00116 00117 //----------------------------------------------------------------------- 00118 00119 } // end of namespace encapsulating this file's definitions 00120 00121 #endif 00122 00123 /* So things look consistent in everyone's emacs... */ 00124 /* Local Variables: */ 00125 /* indent-tabs-mode: nil */ 00126 /* End: */