00001 /*!@file Robots2/Beobot2/app-Beobot2GistSalMaster.C 00002 Robot navigation using a combination saliency and gist. 00003 Run app-Beobot2GistSalMaster at X1 to run Gist-Saliency model 00004 Run app-LandmarkDBWorker at X[2 ... 8] to run SIFT recognition */ 00005 // //////////////////////////////////////////////////////////////////// // 00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00007 // University of Southern California (USC) and the iLab at USC. // 00008 // See http://iLab.usc.edu for information about this project. // 00009 // //////////////////////////////////////////////////////////////////// // 00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00012 // in Visual Environments, and Applications'' by Christof Koch and // 00013 // Laurent Itti, California Institute of Technology, 2001 (patent // 00014 // pending; application number 09/912,225 filed July 23, 2001; see // 00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00016 // //////////////////////////////////////////////////////////////////// // 00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00018 // // 00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00020 // redistribute it and/or modify it under the terms of the GNU General // 00021 // Public License as published by the Free Software Foundation; either // 00022 // version 2 of the License, or (at your option) any later version. // 00023 // // 00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00027 // PURPOSE. See the GNU General Public License for more details. // 00028 // // 00029 // You should have received a copy of the GNU General Public License // 00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00032 // Boston, MA 02111-1307 USA. // 00033 // //////////////////////////////////////////////////////////////////// // 00034 // 00035 // Primary maintainer for this file: Christian Siagian 00036 // <siagian@usc.edu> $HeadURL: 00037 // svn://ilab.usc.edu/trunk/saliency/src/Robots/Beobot2/app-BeobotGistSalMaster.C 00038 // $ $Id: app-Beobot2GistSalMaster.C 12962 2010-03-06 02:13:53Z irock $ 00039 // 00040 ////////////////////////////////////////////////////////////////////////// 00041 00042 #include "Component/ModelManager.H" 00043 #include "Component/ModelComponent.H" 00044 #include "Component/ModelOptionDef.H" 00045 #include "Robots/Beobot2/Localization/Beobot2GistSalMaster.H" 00046 00047 #include <Ice/Ice.h> 00048 #include <Ice/Service.h> 00049 #include "Ice/RobotSimEvents.ice.H" 00050 #include "Ice/RobotBrainObjects.ice.H" 00051 #include "Ice/SimEventsUtils.H" 00052 #include "Ice/IceImageUtils.H" 00053 00054 #include "Beobot/beobot-GSnav-def.H" 00055 #include "Beobot/GSnavResult.H" 00056 00057 // ###################################################################### 00058 // ###################################################################### 00059 class RobotBrainServiceService : public Ice::Service { 00060 protected: 00061 virtual bool start(int, char* argv[]); 00062 virtual bool stop() { 00063 if (itsMgr) 00064 delete itsMgr; 00065 return true; 00066 } 00067 00068 private: 00069 Ice::ObjectAdapterPtr itsAdapter; 00070 ModelManager *itsMgr; 00071 }; 00072 00073 // ###################################################################### 00074 bool RobotBrainServiceService::start(int argc, char* argv[]) 00075 { 00076 MYLOGVERB = LOG_INFO; 00077 00078 char adapterStr[255]; 00079 00080 LINFO("Creating Topic!"); 00081 00082 // Create the topics 00083 // SimEventsUtils::createTopic 00084 // (communicator(), "Beobot2GistSalMasterMessageTopic"); 00085 00086 // Create the adapter 00087 int port = RobotBrainObjects::RobotBrainPort; 00088 bool connected = false; 00089 00090 // try to connect to ports until successful 00091 LDEBUG("Opening Connection"); 00092 while(!connected) 00093 { 00094 try 00095 { 00096 LINFO("Trying Port:%d", port); 00097 sprintf(adapterStr, "default -p %i", port); 00098 itsAdapter = communicator()->createObjectAdapterWithEndpoints 00099 ("Beobot2GistSalMaster", adapterStr); 00100 connected = true; 00101 } 00102 catch(Ice::SocketException) 00103 { 00104 port++; 00105 } 00106 } 00107 00108 //Create the manager and its objects 00109 itsMgr = new ModelManager("Beobot2GistSalMasterService"); 00110 00111 // Note the string was Beobot2GistSalMaster1 & 2 00112 LINFO("Starting Beobot2GistSalMaster"); 00113 nub::ref<Beobot2GistSalMasterI> GSMaster 00114 (new Beobot2GistSalMasterI(*itsMgr, "Beobot2GistSalMaster", 00115 "Beobot2GistSalMaster")); 00116 LINFO("Beobot2GistSalMaster Created"); 00117 itsMgr->addSubComponent(GSMaster); 00118 LINFO("Beobot2GistSalMaster Added As Sub Component"); 00119 GSMaster->init(communicator(), itsAdapter); 00120 LINFO("Beobot2GistSalMaster Initiated"); 00121 00122 // check command line inputs/options 00123 if (itsMgr->parseCommandLine((const int)argc, (const char**)argv, 00124 "[input frame rate]", 0, 1) 00125 == false) return(1); 00126 00127 int w = GSMaster->getIfs()->getWidth(), h = GSMaster->getIfs()->getHeight(); 00128 std::string dims = convertToString(Dims(w, h)); 00129 LINFO("image size: [%dx%d]", w, h); 00130 itsMgr->setOptionValString(&OPT_InputFrameDims, dims); 00131 itsMgr->setModelParamVal("InputFrameDims", Dims(w, h), 00132 MC_RECURSE | MC_IGNORE_MISSING); 00133 00134 // input frame rate 00135 uint64 inputFrameRate = 0; 00136 if(itsMgr->numExtraArgs() > 0) 00137 inputFrameRate = itsMgr->getExtraArgAs<uint>(0); 00138 LINFO("frame frequency: %f ms/frame", inputFrameRate/1000.0F); 00139 GSMaster->setInputFrameRate(inputFrameRate); 00140 00141 // activate manager and adapter 00142 itsAdapter->activate(); 00143 itsMgr->start(); 00144 00145 return true; 00146 } 00147 00148 00149 // ###################################################################### 00150 int main(int argc, char** argv) { 00151 00152 LINFO("Creating Service..."); 00153 RobotBrainServiceService svc; 00154 LINFO("Service Created..."); 00155 return svc.main(argc, argv); 00156 } 00157 00158 // ###################################################################### 00159 /* So things look consistent in everyone's emacs... */ 00160 /* Local Variables: */ 00161 /* indent-tabs-mode: nil */ 00162 /* End: */