00001 /*!@file Robots2/Beobot2/Navigation/GistSal_Navigation/CornerNavigation.H Ice Module to Log data */ 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: Christian Siagian <siagian@usc.edu> 00033 // $HeadURL: svn://ilab.usc.edu/trunk/saliency/src/Robots/Beobot2/Navigation/GistSal_Navigation/CornerNavigation.H 00034 // $Id: CornerNavigation.H 12962 2010-03-06 02:13:53Z irock $ 00035 // 00036 00037 #include "Component/ModelComponent.H" 00038 #include "Component/ModelParam.H" 00039 00040 #include "Robots/RobotBrain/RobotBrainComponent.H" 00041 #include "Util/Timer.H" 00042 00043 #include "Ice/RobotBrainObjects.ice.H" 00044 #include "Ice/RobotSimEvents.ice.H" 00045 #include <IceUtil/Thread.h> 00046 00047 #include "Robots/Beobot2/BeoCommon.H" 00048 00049 #include "Media/FrameSeries.H" 00050 00051 #include "Image/Image.H" 00052 #include "Image/Point3D.H" 00053 #include "GUI/SimpleMeter.H" 00054 00055 #include "Neuro/GistEstimatorFFT.H" 00056 #include "Gist/FFN.H" 00057 00058 #include <vector> 00059 #include "SIFT/Keypoint.H" 00060 #include "SIFT/VisualObject.H" 00061 #include "SIFT/VisualObjectDB.H" 00062 #include "SIFT/VisualObjectMatch.H" 00063 #include "Transport/FrameInfo.H" 00064 00065 #ifndef CORNER_NAVIGATIONI_H 00066 #define CORNER_NAVIGATIONI_H 00067 00068 typedef struct _RegionInformation 00069 { 00070 uint start; 00071 uint end; 00072 00073 float minDistance; 00074 uint minIndex; 00075 } 00076 RegionInformation; 00077 00078 typedef struct cornerDB 00079 { 00080 std::string path;//Full path such as "../data/corner/HNB/2010_12_34/image00000" 00081 int start; 00082 int end; 00083 char type; 00084 rutz::shared_ptr<VisualObjectDB> vdb; 00085 00086 }cornerDB; 00087 class CornerNavigation : public RobotBrainComponent 00088 { 00089 public: 00090 00091 CornerNavigation(OptionManager& mgr, 00092 const std::string& descrName = "CornerNavigation", 00093 const std::string& tagName = "CornerNavigation"); 00094 00095 ~CornerNavigation(); 00096 00097 virtual void evolve(); 00098 00099 //! Get a message 00100 virtual void updateMessage 00101 (const RobotSimEvents::EventMessagePtr& eMsg, 00102 const Ice::Current&); 00103 00104 virtual void registerTopics(); 00105 00106 void start1(); 00107 00108 private: 00109 Beobot2::MotorCommand computeCornerNavigation(); 00110 00111 void navigation(); 00112 void loadFrame(); 00113 bool computeSIFT();//return true when match is valid 00114 double computeDirection();//return error rate of direction 00115 double computeDirection2(int teachID);//return error rate of direction 00116 void recovery(); 00117 int computeEntropy(); 00118 void updateKeyframe(double error); 00119 00120 void updateMotorPID(double tran, double rot,double error); 00121 void updateMotor(double tran,double rot, int status); 00122 00123 void openDB(const std::string& path); 00124 void loadDB(cornerDB db); 00125 void saveDB(int start,int end,const std::string& path); 00126 void drawState(); 00127 00128 void initFFN(); 00129 void updatePosition(double turn); 00130 Image<PixRGB<byte> > drawInfoImg(); 00131 00132 Image<PixRGB<byte> > itsCurrImg; 00133 Image<PixRGB<byte> > itsProcImg; 00134 Image<float> itsNormalizedProcImg; 00135 00136 Image<double> itsFftFeatures; 00137 00138 IceUtil::Mutex its_Curr_Img_mutex; //!< locking log filename 00139 IceUtil::Mutex its_Curr_Mtr_mutex; //!< locking motor command 00140 IceUtil::Mutex its_Corner_Loc_mutex; //!< locking corner location 00141 00142 nub::soft_ref<GistEstimatorFFT> itsFftComputer; 00143 00144 nub::soft_ref<OutputFrameSeries> itsOfs; 00145 00146 //! Overall Display Image 00147 Image<PixRGB<byte> > itsDispImg; 00148 00149 //! Location Map which maintain the track of data 00150 Image<PixRGB<byte> > itsMapImg; 00151 00152 //! Teach and Replay Images for Display 00153 Image<PixRGB<byte> > itsTeachImg; 00154 Image<PixRGB<byte> > itsReplayImg; 00155 00156 //! Two objects for SIFT key points 00157 rutz::shared_ptr<VisualObject> itsTeachVo; 00158 rutz::shared_ptr<VisualObject> itsReplayVo; 00159 00160 //! list of match point from two objects 00161 rutz::shared_ptr<VisualObjectMatch> itsMatchList; 00162 00163 //! list of objects as evidence of its exitance 00164 00165 //! The current index of the database is using 00166 int itsDBnum; 00167 //! The current index of the replay database 00168 int itsReplayDBnum; 00169 00170 std::vector<cornerDB> itsVisualObjectDBs; 00171 rutz::shared_ptr<FeedForwardNetwork> itsFfn; 00172 Image<double> itsPcaIcaVector; 00173 Image<double> itsFfnResults; 00174 00175 Timer itsTimer; 00176 int itsCurrImgID; 00177 int itsPrevProcImgID; 00178 int itsTeachImgID; 00179 int itsReplayImgID; 00180 double itsRcTransSpeed; 00181 double itsRcRotSpeed; 00182 double itsTransSpeed; 00183 double itsRotSpeed; 00184 int itsRemoteMode; 00185 00186 bool itsTrainMode; 00187 Image<double> itsNNrotCommand; 00188 Image<double> itsRCrotCommand; 00189 00190 double itsDirVector; // the angle of current turning 00191 int itsDir; // current direction 00192 double itsMilestoneErr; // current error 00193 double itsFalseErrRate; // mean error / std error 00194 int itsDirCount; // current direction count since last turning 00195 Point3D<double>itsPosition; 00196 Point3D<double>itsError; 00197 OModelParam<bool> itsRealCamera; 00198 bool itsEstop; 00199 00200 double itsIState; 00201 double itsDState; 00202 00203 double itsPGain; 00204 double itsIGain; 00205 double itsDGain; 00206 00207 int itsCornerLocation; 00208 int itsStatus; 00209 }; 00210 #endif 00211 00212 // ###################################################################### 00213 /* So things look consistent in everyone's emacs... */ 00214 /* Local Variables: */ 00215 /* indent-tabs-mode: nil */ 00216 /* End: */