00001 /** 00002 \file Robots/LoBot/control/LoSpinArbiter.C 00003 \brief This file defines the non-inline member functions of the 00004 lobot::SpinArbiter 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/LoSpinArbiter.C $ 00039 // $Id: LoSpinArbiter.C 13770 2010-08-08 06:49:50Z mviswana $ 00040 // 00041 00042 //------------------------------ HEADERS -------------------------------- 00043 00044 // lobot headers 00045 #include "Robots/LoBot/control/LoSpinArbiter.H" 00046 #include "Robots/LoBot/config/LoConfigHelpers.H" 00047 #include "Robots/LoBot/thread/LoUpdateLock.H" 00048 #include "Robots/LoBot/util/LoMath.H" 00049 00050 //----------------------------- NAMESPACE ------------------------------- 00051 00052 namespace lobot { 00053 00054 //-------------------------- INITIALIZATION ----------------------------- 00055 00056 SpinArbiter::SpinArbiter() 00057 : Arbiter(clamp(get_conf("spin_arbiter", "update_delay", 500), 1, 1000)) 00058 { 00059 start("spin_arbiter") ; 00060 } 00061 00062 SpinArbiter::Vote::Vote(float spin) 00063 : m_spin(spin) 00064 {} 00065 00066 float SpinArbiter::get_configured_priority(const std::string& behaviour) const 00067 { 00068 return abs(get_conf(behaviour, "spin_priority", 0.0f)) ; 00069 } 00070 00071 //-------------------------- MOTOR COMMANDS ----------------------------- 00072 00073 void SpinArbiter::motor_cmd(const Arbiter::Votes& votes, Robot* robot) 00074 { 00075 // Compute final spin amount as weighted sum of all votes 00076 float result = 0 ; 00077 Arbiter::Votes::const_iterator it = votes.begin() ; 00078 for (; it != votes.end(); ++it) 00079 result += (dynamic_cast<Vote*>((*it)->vote))->spin() 00080 * priority((*it)->behavior_name) ; 00081 00082 UpdateLock::begin_write() ; 00083 robot->spin(result) ; 00084 UpdateLock::end_write() ; 00085 } 00086 00087 //----------------------- SPIN ARBITER CLEAN-UP ------------------------- 00088 00089 SpinArbiter::~SpinArbiter(){} 00090 00091 //----------------------------------------------------------------------- 00092 00093 } // end of namespace encapsulating this file's definitions 00094 00095 /* So things look consistent in everyone's emacs... */ 00096 /* Local Variables: */ 00097 /* indent-tabs-mode: nil */ 00098 /* End: */