00001 /*!@file SeaBee/SeaBeeMainA.C main 2008 competition code 00002 Run SeaBeeMainA at CPU_A 00003 Run SeaBeeMainB at CPU_B */ 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: Michael Montalbo <montalbo@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/SeaBeeMainA.C $ 00036 // $Id: SeaBeeMainA.C 10794 2009-02-08 06:21:09Z itti $ 00037 // 00038 ////////////////////////////////////////////////////////////////////////// 00039 00040 #include "Beowulf/Beowulf.H" 00041 #include "Component/ModelManager.H" 00042 #include "Raster/Raster.H" 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 #include "GUI/XWinManaged.H" 00046 #include "Neuro/EnvVisualCortex.H" 00047 #include "Image/ShapeOps.H" 00048 00049 #include "Media/MediaOpts.H" 00050 #include "Devices/DeviceOpts.H" 00051 #include "Devices/FrameGrabberConfigurator.H" 00052 #include "Devices/FrameGrabberFactory.H" 00053 #include "Raster/GenericFrame.H" 00054 00055 #include "Image/CutPaste.H" 00056 #include "Image/ShapeOps.H" 00057 00058 #include "AgentManagerA.H" 00059 #include "SubGUI.H" 00060 #include "Globals.H" 00061 #include "SubController.H" 00062 00063 #include <signal.h> 00064 00065 #define SIM_MODE false 00066 00067 volatile bool goforever = false; 00068 00069 00070 // package an agent manager command to a TCP message to send 00071 void packageAgentManagerCommand 00072 (nub::ref<AgentManagerA> agentManager, 00073 rutz::shared_ptr<AgentManagerCommand> agentManagerCommand, 00074 TCPmessage &smsg); 00075 00076 00077 // ###################################################################### 00078 //! Signal handler (e.g., for control-C) 00079 void terminate(int s) 00080 { 00081 LERROR("*** INTERRUPT ***"); 00082 goforever = false; 00083 exit(1); 00084 } 00085 00086 const ModelOptionDef OPT_ALIASseabeeCamOnly = 00087 { MODOPT_ALIAS, "ALIASseabeeCamOnly", &MOC_ALIAS, OPTEXP_CORE, 00088 "Set parameters for the seabee", 00089 "seabee-camonly", '\0', "", 00090 "--in=v4l2 " 00091 "--framegrabber-dims=320x240 " 00092 "--framegrabber-mode=YUYV " 00093 "--framegrabber-bswap=false " 00094 "--out=display " 00095 }; 00096 00097 00098 static const ModelOptionDef OPT_RunAgents = 00099 { MODOPT_FLAG, "SeaBeeRunAgents", &MOC_OUTPUT, OPTEXP_CORE, 00100 "Whether to run seabee submarine agents ", 00101 "run-seabee-agents", '\0', "", "false" }; 00102 // ###################################################################### 00103 int main( int argc, const char* argv[] ) 00104 { 00105 MYLOGVERB = LOG_INFO; 00106 00107 // instantiate a model manager: 00108 ModelManager manager("SeaBee 2008 Competition Master"); 00109 00110 OModelParam<bool> runSubAgents(&OPT_RunAgents, &manager); 00111 00112 // Instantiate our various ModelComponents: 00113 00114 00115 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00116 manager.addSubComponent(ofs); 00117 00118 nub::soft_ref<SubGUI> subGUI(new SubGUI(manager)); 00119 manager.addSubComponent(subGUI); 00120 00121 nub::soft_ref<SubController> subController(new SubController(manager, "SubController", "SubController")); 00122 manager.addSubComponent(subController); 00123 00124 nub::soft_ref<EnvVisualCortex> evc(new EnvVisualCortex(manager)); 00125 manager.addSubComponent(evc); 00126 00127 // create an Agent Manager 00128 nub::ref<AgentManagerA> agentManager(new AgentManagerA(subController,evc,manager)); 00129 manager.addSubComponent(agentManager); 00130 00131 // manager.setOptionValString(&OPT_InputFrameSource, "V4L2"); 00132 // manager.setOptionValString(&OPT_FrameGrabberMode, "YUYV"); 00133 // manager.setOptionValString(&OPT_FrameGrabberDims, "1024x576"); 00134 // manager.setOptionValString(&OPT_FrameGrabberByteSwap, "no"); 00135 // manager.setOptionValString(&OPT_FrameGrabberFPS, "30"); 00136 00137 manager.requestOptionAlias(&OPT_ALIASseabeeCamOnly); 00138 00139 manager.exportOptions(MC_RECURSE); 00140 00141 // Parse command-line: 00142 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00143 00144 Dims cameraDims = subController->peekDims(); 00145 00146 // catch signals and redirect them to terminate for clean exit: 00147 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00148 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00149 signal(SIGALRM, terminate); 00150 00151 // let's do it! 00152 manager.start(); 00153 00154 //eventually make this a command-line param 00155 bool competitionMode = false; 00156 00157 // Setup GUI if not in competition mode 00158 if(!competitionMode) 00159 { 00160 subGUI->startThread(ofs); 00161 subGUI->setupGUI(subController.get(), true); 00162 subGUI->addMeter(subController->getIntPressurePtr(), 00163 "Int Pressure", 500, PixRGB<byte>(255, 0, 0)); 00164 subGUI->addMeter(subController->getHeadingPtr(), 00165 "Heading", 360, PixRGB<byte>(192, 255, 0)); 00166 subGUI->addMeter(subController->getPitchPtr(), 00167 "Pitch", 256, PixRGB<byte>(192, 255, 0)); 00168 subGUI->addMeter(subController->getRollPtr(), 00169 "Roll", 256, PixRGB<byte>(192, 255, 0)); 00170 subGUI->addMeter(subController->getDepthPtr(), 00171 "Depth", 300, PixRGB<byte>(192, 255, 0)); 00172 subGUI->addMeter(subController->getThruster_Up_Left_Ptr(), 00173 "Motor_Up_Left", -100, PixRGB<byte>(0, 255, 0)); 00174 subGUI->addMeter(subController->getThruster_Up_Right_Ptr(), 00175 "Motor_Up_Right", -100, PixRGB<byte>(0, 255, 0)); 00176 subGUI->addMeter(subController->getThruster_Up_Back_Ptr(), 00177 "Motor_Up_Back", -100, PixRGB<byte>(0, 255, 0)); 00178 subGUI->addMeter(subController->getThruster_Fwd_Left_Ptr(), 00179 "Motor_Fwd_Left", -100, PixRGB<byte>(0, 255, 0)); 00180 subGUI->addMeter(subController->getThruster_Fwd_Right_Ptr(), 00181 "Motor_Fwd_Right", -100, PixRGB<byte>(0, 255, 0)); 00182 00183 subGUI->addImage(subController->getSubImagePtr()); 00184 subGUI->addImage(subController->getPIDImagePtr()); 00185 } 00186 00187 00188 if(runSubAgents.getVal()) 00189 { 00190 rutz::shared_ptr<XWinManaged> cwin 00191 (new XWinManaged(Dims(320,240), 0, 0, "SeaBeeMainA Window")); 00192 00193 agentManager->setWindow(cwin); 00194 00195 agentManager->startRun(); 00196 } 00197 00198 goforever = true; uint fnum = 0; 00199 00200 00201 while(goforever) 00202 { 00203 if(runSubAgents.getVal()) 00204 { 00205 Image< PixRGB<byte> > img = subController->getImage(1); 00206 00207 agentManager->setCurrentImage(img, fnum); 00208 00209 if(subController->isSimMode()) 00210 { 00211 } 00212 00213 fnum++; 00214 00215 } 00216 else 00217 { 00218 Image< PixRGB<byte> > img = subController->getImage(1); 00219 ofs->writeRGB(img, "ForwardCam", FrameInfo("Frame",SRC_POS)); 00220 ofs->updateNext(); 00221 } 00222 } 00223 00224 00225 // we are done 00226 manager.stop(); 00227 return 0; 00228 } 00229 00230 00231 // ###################################################################### 00232 /* So things look consistent in everyone's emacs... */ 00233 /* Local Variables: */ 00234 /* indent-tabs-mode: nil */ 00235 /* End: */