00001 /*!@file SeaBee/seaBeeLongShot.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/seaBeeLongShot.C $ 00035 // $Id: seaBeeLongShot.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 #include "Devices/DeviceOpts.H" 00048 #include "GUI/XWinManaged.H" 00049 #include "Raster/GenericFrame.H" 00050 #include "Raster/Raster.H" 00051 #include "Component/ModelManager.H" 00052 #include "Devices/DeviceOpts.H" 00053 #include "GUI/XWindow.H" 00054 #include "Image/DrawOps.H" 00055 #include "Image/CutPaste.H" 00056 #include "Image/Image.H" 00057 #include "Image/Pixels.H" 00058 #include "Image/MathOps.H" 00059 #include "Neuro/EnvVisualCortex.H" 00060 #include "Media/FrameSeries.H" 00061 #include "Media/MediaOpts.H" 00062 #include "Transport/FrameInfo.H" 00063 #include "Raster/GenericFrame.H" 00064 #include "Raster/Raster.H" 00065 #include "Util/Timer.H" 00066 #include "Util/log.H" 00067 #include "Util/MathFunctions.H" 00068 #include "Neuro/EnvVisualCortex.H" 00069 00070 #include "Util/Angle.H" 00071 00072 int main(int argc, const char **argv) 00073 { 00074 int compMode = false; 00075 bool simMode = true; 00076 00077 // Instantiate a ModelManager: 00078 ModelManager *mgr = new ModelManager("USC BeoSub"); 00079 00080 // Instantiate our various ModelComponents: 00081 //nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr)); 00082 //mgr->addSubComponent(ifs); 00083 00084 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr)); 00085 mgr->addSubComponent(ofs); 00086 00087 nub::soft_ref<SubController> subController(new SubController(*mgr, "SubController", "SubController", simMode)); 00088 mgr->addSubComponent(subController); 00089 00090 nub::soft_ref<SubGUI> subGUI(new SubGUI(*mgr)); 00091 mgr->addSubComponent(subGUI); 00092 00093 nub::ref<EnvVisualCortex> evc(new EnvVisualCortex(*mgr)); 00094 mgr->addSubComponent(evc); 00095 00096 mgr->exportOptions(MC_RECURSE); 00097 00098 mgr->setOptionValString(&OPT_InputFrameSource, "V4L2"); 00099 mgr->setOptionValString(&OPT_FrameGrabberMode, "YUYV"); 00100 mgr->setOptionValString(&OPT_FrameGrabberDims, "1024x576"); 00101 mgr->setOptionValString(&OPT_FrameGrabberByteSwap, "no"); 00102 mgr->setOptionValString(&OPT_FrameGrabberFPS, "30"); 00103 00104 00105 // Parse command-line: 00106 if (mgr->parseCommandLine(argc, argv, "<initialForward> <diveDown> <diveTime> <timeToGate> <xPropSalTrack> <leftTurn> <compmode>", 6, 7) == false) return(1); 00107 00108 if (mgr->numExtraArgs() && 00109 mgr->getExtraArg(6) == "compMode") 00110 compMode = true; 00111 00112 //parameters 00113 int initialForward = atoi(mgr->getExtraArg(0).c_str()); //the first forward to clear the bottom 00114 00115 //the values required to bring the sub down 00116 int diveDown = atoi(mgr->getExtraArg(1).c_str()); 00117 //the time required to reach depth 00118 int diveTime = atoi(mgr->getExtraArg(2).c_str()); 00119 00120 //the time required to reach gate 00121 int timeToGate = atoi(mgr->getExtraArg(3).c_str()); 00122 00123 //the proprotinal x and y track 00124 float xPropSalTrack = atof(mgr->getExtraArg(4).c_str()); 00125 00126 //int turnLeftAmount = atoi(mgr->getExtraArg(5).c_str()); 00127 00128 LINFO("Setting params to: %i %i %i %i %f", 00129 initialForward, diveDown, diveTime, 00130 timeToGate, xPropSalTrack); 00131 00132 00133 00134 // do post-command-line configs: 00135 //Dims imageDims = ifs->peekDims(); 00136 00137 // let's get all our ModelComponent instances started: 00138 mgr->start(); 00139 00140 //start streaming 00141 //ifs->startStream(); 00142 00143 int smap_level = evc->getMapLevel(); 00144 00145 //setup gui for subController 00146 00147 subController->setMotorsOn(false); 00148 subController->setDepth(-1); //kill depth motors 00149 if (!compMode) 00150 { 00151 subGUI->startThread(ofs); 00152 subGUI->setupGUI(subController.get(), true); 00153 subGUI->addMeter(subController->getIntPressurePtr(), 00154 "Int Pressure", 500, PixRGB<byte>(255, 0, 0)); 00155 subGUI->addMeter(subController->getHeadingPtr(), 00156 "Heading", 360, PixRGB<byte>(192, 255, 0)); 00157 subGUI->addMeter(subController->getPitchPtr(), 00158 "Pitch", 256, PixRGB<byte>(192, 255, 0)); 00159 subGUI->addMeter(subController->getRollPtr(), 00160 "Roll", 256, PixRGB<byte>(192, 255, 0)); 00161 subGUI->addMeter(subController->getDepthPtr(), 00162 "Depth", 300, PixRGB<byte>(192, 255, 0)); 00163 00164 subGUI->addMeter(subController->getThruster_Up_Left_Ptr(), 00165 "Motor_Up_Left", -100, PixRGB<byte>(0, 255, 0)); 00166 subGUI->addMeter(subController->getThruster_Up_Right_Ptr(), 00167 "Motor_Up_Right", -100, PixRGB<byte>(0, 255, 0)); 00168 subGUI->addMeter(subController->getThruster_Up_Back_Ptr(), 00169 "Motor_Up_Back", -100, PixRGB<byte>(0, 255, 0)); 00170 subGUI->addMeter(subController->getThruster_Fwd_Left_Ptr(), 00171 "Motor_Fwd_Left", -100, PixRGB<byte>(0, 255, 0)); 00172 subGUI->addMeter(subController->getThruster_Fwd_Right_Ptr(), 00173 "Motor_Fwd_Right", -100, PixRGB<byte>(0, 255, 0)); 00174 00175 00176 subGUI->addImage(subController->getSubImagePtr()); 00177 subGUI->addImage(subController->getPIDImagePtr()); 00178 00179 } else { 00180 //running in comp mode, wait for kill switch 00181 LINFO("Running in comp mode"); 00182 while(!subController->getKillSwitch()) 00183 { 00184 sleep(1); 00185 LINFO("Waiting for kill switch"); 00186 } 00187 00188 //start the RUN 00189 sleep(7); //Wait for the sub to be pointed to gate 00190 } 00191 00192 //get heading by avraging the current direction 00193 subController->setSpeed(10); 00194 00195 while(1) 00196 { 00197 //ifs->updateNext(); 00198 00199 //grab the images 00200 //GenericFrame input = ifs->readFrame(); 00201 Point2D<int> maxPos(-1,-1); float maxVal = -1; 00202 Image<PixRGB<byte> > input = subController->getImage(2); 00203 00204 if (input.initialized()) 00205 { 00206 //look for the most salient point and go towerd it 00207 Image<PixRGB<byte> > frontImg = rescale(input, 320, 280); 00208 evc->input(frontImg); 00209 Image<float> vcxmap = evc->getVCXmap(); 00210 findMax(vcxmap, maxPos, maxVal); 00211 00212 if (maxVal > 50) 00213 { 00214 if (!compMode) 00215 drawCircle(frontImg, 00216 Point2D<int>(maxPos.i<<smap_level, 00217 maxPos.j<<smap_level), 00218 10, PixRGB<byte>(255,0,0)); 00219 int xerr = (maxPos.i-(vcxmap.getWidth()/2)); 00220 int desiredHeading = (int)((float)xerr*-1*xPropSalTrack); 00221 00222 subController->setHeading(subController->getHeading() 00223 + desiredHeading); 00224 } 00225 00226 ofs->writeRGB(frontImg, "input", FrameInfo("Copy of input", SRC_POS)); 00227 00228 } 00229 00230 } 00231 00232 // stop all our ModelComponents 00233 mgr->stop(); 00234 00235 // all done! 00236 return 0; 00237 } 00238