HippocampusI.H

Go to the documentation of this file.
00001 /*!@file HippocampusI.H maintains the current thought location of the robot */
00002 
00003 
00004 //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Lior Elazary <lelazary@yahoo.com>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/RobotBrain/HippocampusI.H $
00036 // $Id: HippocampusI.H 12281 2009-12-17 09:00:36Z itti $
00037 //
00038 
00039 #ifndef HIPPOCAMPUSI_H_DEFINED
00040 #define HIPPOCAMPUSI_H_DEFINED
00041 
00042 #include "Component/ModelComponent.H"
00043 #include "Component/ModelParam.H"
00044 #include "Media/FrameSeries.H"
00045 #include "Transport/FrameInfo.H"
00046 #include "Raster/GenericFrame.H"
00047 #include "Image/Image.H"
00048 #include "GUI/XWinManaged.H"
00049 #include "GUI/ImageDisplayStream.H"
00050 #include "Image/Image.H"
00051 #include "Image/Pixels.H"
00052 #include "Ice/RobotBrainObjects.ice.H"
00053 #include "Ice/RobotSimEvents.ice.H"
00054 #include "Ice/IceImageUtils.H"
00055 #include "Ice/SimEventsUtils.H"
00056 #include <IceUtil/Thread.h>
00057 
00058 class HippocampusI : public ModelComponent, public RobotBrainObjects::Hippocampus, public IceUtil::Thread
00059 {
00060 
00061 public:
00062 
00063 
00064   struct Landmark
00065   {
00066     std::string name;
00067     double posX;
00068     double posY;
00069     Image<double> cov;
00070 
00071     Landmark(std::string n, double x, double y,
00072         Image<double>& c) : name(n), posX(x), posY(y), cov(c) {};
00073 
00074     Landmark() : name(""), posX(-1.0), posY(-1.0), cov(Image<double>(2,2,ZEROS)) {};
00075   };
00076 
00077   struct Particle
00078   {
00079     float x;
00080     float y;
00081     float theta;
00082     std::map<std::string, Landmark> landmarksDB;
00083     float w;
00084   };
00085 
00086 
00087   HippocampusI(OptionManager& mgr,
00088           const std::string& descrName = "Hippocampus",
00089           const std::string& tagName = "Hippocampus");
00090   ~HippocampusI();
00091 
00092   virtual void run();
00093 
00094 
00095   ////!Get the current state
00096   //PosState getCurrentState();
00097 
00098 
00099   ////!Update the state from the motion model
00100   //void updateState(const float xPos, const float yPos, const float ori);
00101 
00102 
00103   //Image<PixRGB<byte> > getCurrentMap();
00104 
00105   //!Update the current map
00106   //void updateMap();
00107 
00108   void evolve(); //Our evolve function
00109 
00110   //!Get a message from another part of the brain
00111   virtual void updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00112       const Ice::Current&);
00113 
00114   //!Initalize the object
00115   void init(Ice::CommunicatorPtr ic, Ice::ObjectAdapterPtr adapter);
00116 
00117 
00118   //! Display an image representation of our current belief state
00119   //! ie. Draw all of our particles, landmarks, etc onto an image and display it
00120   void displayMap();
00121 
00122   //! Use a roulette wheel to probabilistically duplicate particles with high weights,
00123   //! and discard those with low weights
00124   void resampleParticles();
00125 
00126   //! Assign weights to each particle to judge how likely a particle is to
00127   //! observe the currently observed set of landmarks
00128   void updateParticleObservation(RobotSimEvents::LandmarksMessagePtr landmarksMsg);
00129 
00130   //! Assign weights to each particle to judge how likely a particle is to
00131   //! observe the currently observed set of landmarks. use EKF to track the landmarks
00132   void updateParticleSlamObservation(RobotSimEvents::LandmarksMessagePtr landmarksMsg);
00133 
00134 
00135   //! Add a new landmark to the landmark database
00136   void addLandmark(Landmark lm);
00137 
00138   //! Move each particle according to the motion model, plus some uniform noise
00139   void updateParticleMotion(RobotSimEvents::MotionMessagePtr newMotion);
00140 
00141 
00142 
00143 private:
00144   nub::soft_ref<OutputFrameSeries> itsOfs;
00145   Image<PixRGB<byte> > itsMap;
00146   RobotSimEvents::EventsPrx itsEventsPub;
00147   std::vector<SimEventsUtils::TopicInfo> itsTopicsSubscriptions;
00148   Ice::ObjectPrx itsObjectPrx; //Our Proxy
00149   RobotSimEvents::StateMessagePtr itsCurrentState;
00150   RobotSimEvents::GPSMessagePtr itsCurrentGPSPos;
00151   RobotSimEvents::MotionMessagePtr itsCurrentMotion;
00152   RobotSimEvents::LandmarksMessagePtr itsCurrentLandmarks;
00153   RobotSimEvents::StateMessagePtr itsLastLandmarkState;
00154 //  std::vector<Landmark> itsLandmarks;
00155   std::vector<Particle> itsParticles;
00156 
00157   std::map<std::string, Landmark> itsLandmarkDB;
00158   std::map<std::string, Landmark> itsGTLandmarkDB;
00159 
00160   //A record of the sum of the euclidean distances between landmarks and
00161   //their groundtruths at every timestep of the algorithm.
00162   //-Used in display map
00163   std::vector<float> itsLmDistanceHistory;
00164   float itsLmDistanceMax;
00165 
00166   int     itsNumParticles;
00167   float   itsRangeVariance;
00168   float   itsBearingVariance;
00169   int     itsFrame;
00170 
00171   IceUtil::Mutex itsParticlesMutex;
00172 
00173 
00174 };
00175 
00176 #endif
Generated on Sun May 8 08:41:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3