00001 /*!@file SeaBee/seaBeeMain.C Main dispatcher */ 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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/seaBeeMainOld.C $ 00035 // $Id: seaBeeMainOld.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 // 00039 #include "Component/ModelManager.H" 00040 #include "Devices/DeviceOpts.H" 00041 #include "Media/FrameSeries.H" 00042 #include "Media/MediaOpts.H" 00043 #include "Image/ShapeOps.H" 00044 #include "SeaBee/SubController.H" 00045 #include "SeaBee/SubGUI.H" 00046 00047 00048 #include <fcntl.h> 00049 #include <sys/types.h> 00050 #include <sys/stat.h> 00051 #include <signal.h> 00052 00053 #include "Devices/DeviceOpts.H" 00054 #include "GUI/XWinManaged.H" 00055 #include "Raster/GenericFrame.H" 00056 #include "Raster/Raster.H" 00057 #include "Component/ModelManager.H" 00058 #include "Devices/DeviceOpts.H" 00059 #include "GUI/XWindow.H" 00060 #include "Image/DrawOps.H" 00061 #include "Image/CutPaste.H" 00062 #include "Image/Image.H" 00063 #include "Image/Pixels.H" 00064 #include "Image/MathOps.H" 00065 #include "Neuro/EnvVisualCortex.H" 00066 #include "Media/FrameSeries.H" 00067 #include "Media/MediaOpts.H" 00068 #include "Transport/FrameInfo.H" 00069 #include "Raster/GenericFrame.H" 00070 #include "Raster/Raster.H" 00071 #include "Util/Timer.H" 00072 #include "Util/log.H" 00073 #include "Util/MathFunctions.H" 00074 00075 #include "Util/Angle.H" 00076 00077 //! Signal handler (e.g., for control-C) 00078 void terminate(int s) 00079 { 00080 LERROR("*** INTERRUPT ***"); 00081 exit(0); 00082 } 00083 00084 00085 int main(int argc, const char **argv) 00086 { 00087 // Instantiate a ModelManager: 00088 ModelManager *mgr = new ModelManager("USC BeoSub"); 00089 00090 00091 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr)); 00092 mgr->addSubComponent(ofs); 00093 00094 // Parse command-line: 00095 if (mgr->parseCommandLine(argc, argv, "<simulator>", 0, 1) == false) return(1); 00096 00097 bool deamonMode = false; 00098 bool simulator = false; 00099 00100 LINFO("%i %s", mgr->numExtraArgs(), mgr->getExtraArg(0).c_str()); 00101 if (mgr->numExtraArgs() > 0 && 00102 mgr->getExtraArg(0) == "simulator") 00103 simulator = false; 00104 00105 // nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr)); 00106 // mgr->addSubComponent(ifs); 00107 00108 00109 nub::soft_ref<SubController> subController(new SubController(*mgr, "SubController", "SubController", false)); 00110 mgr->addSubComponent(subController); 00111 00112 nub::soft_ref<SubGUI> subGUI(new SubGUI(*mgr)); 00113 mgr->addSubComponent(subGUI); 00114 00115 mgr->exportOptions(MC_RECURSE); 00116 00117 mgr->setOptionValString(&OPT_InputFrameSource, "V4L2"); 00118 mgr->setOptionValString(&OPT_FrameGrabberMode, "YUYV"); 00119 mgr->setOptionValString(&OPT_FrameGrabberDims, "1024x576"); 00120 mgr->setOptionValString(&OPT_FrameGrabberByteSwap, "no"); 00121 mgr->setOptionValString(&OPT_FrameGrabberFPS, "30"); 00122 00123 00124 if (deamonMode) 00125 { 00126 LINFO("Running as a daemon. Set --debug to see any errors."); 00127 //Become a daemon 00128 // fork off the parent process 00129 pid_t pid = fork(); 00130 if (pid < 0) 00131 LFATAL("Can not fork"); 00132 00133 if (pid > 0) 00134 exit(0); //exit the parent process 00135 00136 // Change the file mask 00137 umask(0); 00138 00139 //Create a new system id so that the kernel wont think we are an orphan. 00140 pid_t sid = setsid(); 00141 if (sid < 0) 00142 LFATAL("Can not become independent"); 00143 00144 fclose(stdin); 00145 fclose(stdout); 00146 fclose(stderr); 00147 00148 } 00149 // catch signals and redirect them to terminate for clean exit: 00150 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00151 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00152 signal(SIGALRM, terminate); 00153 00154 00155 00156 // do post-command-line configs: 00157 //Dims imageDims = ifs->peekDims(); 00158 00159 // let's get all our ModelComponent instances started: 00160 mgr->start(); 00161 00162 //start streaming 00163 // ifs->startStream(); 00164 00165 00166 00167 if (!deamonMode) 00168 { 00169 //start the gui thread 00170 subGUI->startThread(ofs); 00171 sleep(1); 00172 //setup gui for various objects 00173 subGUI->setupGUI(subController.get(), true); 00174 00175 //Main GUI Window 00176 subGUI->addMeter(subController->getIntPressurePtr(), 00177 "Int Pressure", 1024, PixRGB<byte>(255, 0, 0)); 00178 subGUI->addMeter(subController->getHeadingPtr(), 00179 "Heading", 360, PixRGB<byte>(192, 255, 0)); 00180 subGUI->addMeter(subController->getPitchPtr(), 00181 "Pitch", 256, PixRGB<byte>(192, 255, 0)); 00182 subGUI->addMeter(subController->getRollPtr(), 00183 "Roll", 256, PixRGB<byte>(192, 255, 0)); 00184 subGUI->addMeter(subController->getDepthPtr(), 00185 "Depth", 1024, PixRGB<byte>(192, 255, 0)); 00186 00187 subGUI->addMeter(subController->getThruster_Up_Left_Ptr(), 00188 "Motor_Up_Left", -100, PixRGB<byte>(0, 255, 0)); 00189 subGUI->addMeter(subController->getThruster_Up_Right_Ptr(), 00190 "Motor_Up_Right", -100, PixRGB<byte>(0, 255, 0)); 00191 subGUI->addMeter(subController->getThruster_Up_Back_Ptr(), 00192 "Motor_Up_Back", -100, PixRGB<byte>(0, 255, 0)); 00193 subGUI->addMeter(subController->getThruster_Fwd_Left_Ptr(), 00194 "Motor_Fwd_Left", -100, PixRGB<byte>(0, 255, 0)); 00195 subGUI->addMeter(subController->getThruster_Fwd_Right_Ptr(), 00196 "Motor_Fwd_Right", -100, PixRGB<byte>(0, 255, 0)); 00197 00198 00199 subGUI->addImage(subController->getPIDImagePtr()); 00200 subGUI->addImage(subController->getSubImagePtr()); 00201 00202 } 00203 00204 00205 while(1) { 00206 usleep(1000); 00207 } 00208 00209 00210 // stop all our ModelComponents 00211 mgr->stop(); 00212 00213 // all done! 00214 return 0; 00215 } 00216