00001 /*!@file AppDevices/test-armSim.C Test the sub simulator */ 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/BeoSub/test-subSim.C $ 00035 // $Id: test-subSim.C 11564 2009-08-09 01:10:32Z rand $ 00036 // 00037 00038 00039 00040 #include "Component/ModelManager.H" 00041 #include "Raster/GenericFrame.H" 00042 #include "Image/Layout.H" 00043 #include "Media/FrameSeries.H" 00044 #include "Transport/FrameInfo.H" 00045 #include "Image/MatrixOps.H" 00046 #include "GUI/ImageDisplayStream.H" 00047 #include "GUI/XWinManaged.H" 00048 #include "BeoSub/SubSim.H" 00049 #include <stdio.h> 00050 #include <stdlib.h> 00051 00052 void handle_keys(nub::soft_ref<OutputFrameSeries> ofs, nub::soft_ref<SubSim> subSim) 00053 { 00054 //handle keyboard input 00055 const nub::soft_ref<ImageDisplayStream> ids = 00056 ofs->findFrameDestType<ImageDisplayStream>(); 00057 00058 const rutz::shared_ptr<XWinManaged> uiwin = 00059 ids.is_valid() 00060 ? ids->getWindow("subSim") 00061 : rutz::shared_ptr<XWinManaged>(); 00062 00063 int key = uiwin->getLastKeyPress(); 00064 if (key != -1) 00065 { 00066 float panTruster = 0; 00067 float tiltTruster = 0; 00068 float forwardTruster = 0; 00069 float upTruster = 0; 00070 switch(key) 00071 { 00072 case 38: upTruster = -3.0; break; //a 00073 case 52: upTruster = 3.0; break; //z 00074 case 33: panTruster = 1.0; break; //p 00075 case 32: panTruster = -1.0; break; //o 00076 case 40: forwardTruster = 1.0; break; //d 00077 case 54: forwardTruster = -1.0; break; //c 00078 case 39: tiltTruster = 1.0; break; //s 00079 case 53: tiltTruster = -1.0; break; //x 00080 case 65: //stop 00081 panTruster = 0; 00082 tiltTruster = 0; 00083 forwardTruster = 0; 00084 upTruster = 0; 00085 break; // space 00086 00087 } 00088 subSim->setTrusters(panTruster, tiltTruster, forwardTruster, upTruster); 00089 00090 LINFO("Key is %i\n", key); 00091 } 00092 } 00093 00094 00095 int main(int argc, char *argv[]) 00096 { 00097 // Instantiate a ModelManager: 00098 ModelManager manager("Sub Simulator"); 00099 00100 //nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00101 //manager.addSubComponent(ifs); 00102 00103 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00104 manager.addSubComponent(ofs); 00105 00106 // Instantiate our various ModelComponents: 00107 nub::soft_ref<SubSim> subSim(new SubSim(manager)); 00108 manager.addSubComponent(subSim); 00109 00110 // Parse command-line: 00111 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00112 00113 00114 // let's get all our ModelComponent instances started: 00115 manager.start(); 00116 00117 00118 00119 while(1){ 00120 Layout<PixRGB<byte> > outDisp; 00121 00122 subSim->simLoop(); 00123 Image<PixRGB<byte> > forwardCam = flipVertic(subSim->getFrame(1)); 00124 Image<PixRGB<byte> > downwardCam = flipVertic(subSim->getFrame(2)); 00125 00126 outDisp = vcat(outDisp, hcat(forwardCam, downwardCam)); 00127 00128 ofs->writeRgbLayout(outDisp, "subSim", FrameInfo("subSim", SRC_POS)); 00129 00130 handle_keys(ofs, subSim); 00131 00132 } 00133 return 0; 00134 00135 }