SonarListen.C

Go to the documentation of this file.
00001 /*!@file BeoSub/BeeBrain/SonarListen.C Sonar Listen Agent         */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Michael Montalbo <montalbo@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeeBrain/SonarListen.C $
00034 // $Id: SonarListen.C 8623 2007-07-25 17:57:51Z rjpeters $
00035 //
00036 //////////////////////////////////////////////////////////////////////////
00037 
00038 #include "BeoSub/BeeBrain/SonarListen.H"
00039 
00040 // ######################################################################
00041 SonarListenAgent::SonarListenAgent(std::string name) : SensorAgent(name) { }
00042 
00043 // ######################################################################
00044 SonarListenAgent::SonarListenAgent
00045 ( std::string name,
00046   rutz::shared_ptr<AgentManagerB> amb) : SensorAgent(name)
00047 {
00048   itsAgentManager = amb;
00049 }
00050 
00051 // ######################################################################
00052 // Scheduler
00053 bool SonarListenAgent::pickAndExecuteAnAction()
00054 {
00055   bool listenedForObject = false;
00056 
00057   if(!itsJobs.empty())
00058     {
00059       //first clean out any jobs which are to be ignored
00060       cleanJobs();
00061 
00062       for(itsJobsItr = itsJobs.begin(); itsJobsItr != itsJobs.end(); ++itsJobsItr)
00063         {
00064           rutz::shared_ptr<OceanObject> currentOceanObject = (*itsJobsItr)->oceanObject;
00065           Job* currentJob = *itsJobsItr;
00066 
00067           //find it based on its type
00068           if(currentOceanObject->getType()  == OceanObject::PINGER)
00069             {
00070               listenForPinger(currentJob);
00071             }
00072 
00073           listenedForObject = true;
00074         }
00075 
00076       return listenedForObject;
00077     }
00078   else
00079     {
00080       return false;
00081     }
00082 
00083 }
00084 
00085 // ######################################################################
00086 // Actions
00087 void SonarListenAgent::listenForPinger(Job* j)
00088 {
00089   if(j->status == NOT_STARTED) { j->status = IN_PROGRESS; }
00090 
00091   DataTypes jobDataType = j->dataType;
00092   rutz::shared_ptr<OceanObject> jobOceanObject = j->oceanObject;
00093 
00094   bool isFound = false;
00095 
00096   if(jobDataType == ORIENTATION)
00097     {
00098       Do("Listening for pinger heading");
00099 
00100       isFound = true;
00101     }
00102   else if(jobDataType == DISTANCE)
00103     {
00104       Do("Listening for approximate pinger distance");
00105 
00106       isFound = true;
00107     }
00108 
00109   oceanObjectUpdate(jobOceanObject, jobDataType, isFound);
00110 }
00111 
00112 // ######################################################################
00113 void SonarListenAgent::oceanObjectUpdate
00114 ( rutz::shared_ptr<OceanObject> o,
00115   DataTypes dataType,
00116   bool isFound)
00117 {
00118   if(isFound)
00119     {
00120       if(o->getStatus() == OceanObject::NOT_FOUND)
00121         {
00122           o->setStatus(OceanObject::FOUND);
00123           itsAgentManager->pushResult((CommandType)(OCEAN_OBJECT_STATUS), dataType, o);
00124         }
00125     }
00126   else
00127     {
00128       if(o->getStatus() == OceanObject::FOUND)
00129         {
00130           o->setStatus(OceanObject::LOST);
00131           itsAgentManager->pushResult((CommandType)(OCEAN_OBJECT_STATUS), dataType, o);
00132         }
00133     }
00134 }
00135 
00136 // ######################################################################
00137 /* So things look consistent in everyone's emacs... */
00138 /* Local Variables: */
00139 /* indent-tabs-mode: nil */
00140 /* End: */
Generated on Sun May 8 08:04:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3