00001 /*!@file test-Rovio.C a test the Rovio service */ 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 <lelazary@yahoo.com> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/Rovio/test-Rovio.C $ 00035 // $Id: test-Rovio.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Media/FrameSeries.H" 00040 #include "Transport/FrameInfo.H" 00041 #include "Raster/GenericFrame.H" 00042 #include "Image/Image.H" 00043 #include "Image/DrawOps.H" 00044 #include "Image/ColorOps.H" 00045 #include "GUI/XWinManaged.H" 00046 #include "GUI/ImageDisplayStream.H" 00047 #include "Util/Timer.H" 00048 #include "Robots/Rovio/Rovio.H" 00049 00050 using namespace std; 00051 00052 #define KEY_UP 98 00053 #define KEY_DOWN 104 00054 #define KEY_LEFT 100 00055 #define KEY_RIGHT 102 00056 00057 int getKey(nub::ref<OutputFrameSeries> &ofs) 00058 { 00059 const nub::soft_ref<ImageDisplayStream> ids = 00060 ofs->findFrameDestType<ImageDisplayStream>(); 00061 00062 const rutz::shared_ptr<XWinManaged> uiwin = 00063 ids.is_valid() 00064 ? ids->getWindow("Output") 00065 : rutz::shared_ptr<XWinManaged>(); 00066 if (uiwin.is_valid()) 00067 return uiwin->getLastKeyPress(); 00068 00069 return -1; 00070 } 00071 00072 ////////////////////////////////////////////////////////////////////// 00073 int main(int argc, char** argv) 00074 { 00075 00076 MYLOGVERB = LOG_INFO; 00077 ModelManager manager("test-Rovio"); 00078 00079 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00080 manager.addSubComponent(ifs); 00081 00082 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00083 manager.addSubComponent(ofs); 00084 00085 nub::ref<Rovio> rovio(new Rovio(manager)); 00086 manager.addSubComponent(rovio); 00087 00088 Timer localTimer; 00089 00090 manager.exportOptions(MC_RECURSE); 00091 00092 if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false) 00093 return 1; 00094 manager.start(); 00095 00096 00097 localTimer.reset(); 00098 00099 00100 00101 while(true) 00102 { 00103 localTimer.reset(); 00104 const FrameState is = ifs->updateNext(); 00105 if (is == FRAME_COMPLETE) return 0; 00106 GenericFrame input = ifs->readFrame(); 00107 Image<PixRGB<byte> > RovioImg = input.asRgb(); 00108 00109 ofs->writeRGB(RovioImg, "Output", FrameInfo("Output", SRC_POS)); 00110 ofs->updateNext(); 00111 00112 int key = getKey(ofs); 00113 if (key != -1) 00114 { 00115 switch(key) 00116 { 00117 case KEY_UP: 00118 rovio->moveForward(0.5); 00119 break; 00120 case KEY_DOWN: 00121 rovio->moveBackward(0.5); 00122 break; 00123 case KEY_LEFT: 00124 rovio->rotateLeft(0.4); 00125 break; 00126 case KEY_RIGHT: 00127 rovio->rotateRight(0.4); 00128 break; 00129 case 65: //space 00130 rovio->stop(); 00131 break; 00132 case 39: //s for status 00133 rovio->getStatus(); 00134 break; 00135 case 24: //q camera up 00136 rovio->setCameraPos(2); 00137 break; 00138 case 38: //a camera mid 00139 rovio->setCameraPos(1); 00140 break; 00141 case 52: //z camera down 00142 rovio->setCameraPos(0); 00143 break; 00144 case 40: //d for play sound 00145 rovio->playSound(); 00146 break; 00147 00148 default: 00149 LINFO("Unknown key %i\n", key); 00150 break; 00151 } 00152 localTimer.reset(); 00153 } 00154 } 00155 00156 manager.stop(); 00157 return 0; 00158 }