00001 /*!@file Beobot/BeobotMemory.C sensory/motor memory for the Beobots */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/BeobotMemory.C $ 00035 // $Id: BeobotMemory.C 4663 2005-06-23 17:47:28Z rjpeters $ 00036 // 00037 00038 #include "Beobot/BeobotMemory.H" 00039 00040 #include "Util/Assert.H" 00041 00042 // ######################################################################### 00043 BeobotMemory::BeobotMemory( void ) 00044 { 00045 idx = 0; 00046 state = HAVE_ACTION; 00047 // just to initialize, this way we can only call presentSensation(...) 00048 00049 for(int t=0;t<memoryLength;t++) 00050 valid[t]=false; 00051 } 00052 00053 // ######################################################################### 00054 void BeobotMemory::presentSensation( BeobotSensation &sensa ) 00055 { 00056 // check that we are begining a new cycle 00057 ASSERT( state == HAVE_ACTION ); 00058 00059 sensation[idx] = sensa; 00060 valid[idx] = true; 00061 00062 state = HAVE_SENSATION; 00063 00064 // we will idx++ at the end ! 00065 } 00066 00067 // ######################################################################### 00068 void BeobotMemory::presentActionRecommendation( BeobotAction &act ) 00069 { 00070 // the actionRecommendation is based on previous sensations 00071 ASSERT( state == HAVE_SENSATION ); 00072 00073 actionRecommendation[ idx ] = act; 00074 00075 state = HAVE_RECOM_ACTION; 00076 } 00077 00078 // ######################################################################### 00079 bool BeobotMemory::passedSensation( int howOld, BeobotSensation & sensa ) 00080 { 00081 ASSERT( howOld < memoryLength ); 00082 int i = idx - howOld; if (i < 0) i += memoryLength; 00083 // note: no -1 because we have not incremented idx 00084 00085 if(!valid[i]) 00086 return false; 00087 00088 sensa = sensation[i]; 00089 return true; 00090 } 00091 00092 // ######################################################################### 00093 void BeobotMemory::generatePresentAction( BeobotAction & currentAction ) 00094 { 00095 ASSERT( state == HAVE_RECOM_ACTION ); 00096 00097 float turn; 00098 float speed; 00099 int gear; 00100 00101 gear=1; // why not ? 00102 00103 // computes the new action as 00104 turn=0; 00105 speed=0; 00106 int nbValidMemories=0; 00107 for(int t=0;t<memoryLength;t++) 00108 { 00109 if( valid[t] ) 00110 // if( ! confused ) 00111 /* 00112 try to think of something clever here 00113 if sensations are very different then maybe we need more 00114 time. 00115 */ 00116 { 00117 turn+=actionRecommendation[t].getTurn(); 00118 speed+=actionRecommendation[t].getSpeed(); 00119 nbValidMemories++; 00120 } 00121 } 00122 currentAction.setTurn( turn/nbValidMemories ); 00123 currentAction.setSpeed( speed/nbValidMemories ); 00124 currentAction.setGear( gear ); 00125 00126 // keep track of our decision 00127 action[idx]=currentAction; 00128 00129 // consider oldest cell as next free cell 00130 idx++; 00131 if (idx >= memoryLength) idx = 0; 00132 00133 state = HAVE_ACTION; 00134 } 00135 00136 // ###################################################################### 00137 /* So things look consistent in everyone's emacs... */ 00138 /* Local Variables: */ 00139 /* indent-tabs-mode: nil */ 00140 /* End: */