test-Gumbot.C

Go to the documentation of this file.
00001 /*!@file test-Gumbot.C a test the Gumbot 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/Gumbot/test-Gumbot.C $
00035 // $Id: test-Gumbot.C 12281 2009-12-17 09:00:36Z itti $
00036 //
00037 
00038 #include <Ice/Ice.h>
00039 #include "Ice/Gumbot.ice.H"
00040 #include "Ice/ImageIce.ice.H"
00041 #include "Ice/IceImageUtils.H"
00042 
00043 #include "Component/ModelManager.H"
00044 #include "Media/FrameSeries.H"
00045 #include "Transport/FrameInfo.H"
00046 #include "Raster/GenericFrame.H"
00047 #include "Image/Image.H"
00048 #include "GUI/XWinManaged.H"
00049 #include "GUI/ImageDisplayStream.H"
00050 
00051 using namespace std;
00052 using namespace Robots;
00053 
00054 #define KEY_UP 98
00055 #define KEY_DOWN 104
00056 #define KEY_LEFT 100
00057 #define KEY_RIGHT 102
00058 
00059 int getKey(nub::ref<OutputFrameSeries> &ofs)
00060 {
00061   const nub::soft_ref<ImageDisplayStream> ids =
00062     ofs->findFrameDestType<ImageDisplayStream>();
00063 
00064   const rutz::shared_ptr<XWinManaged> uiwin =
00065     ids.is_valid()
00066     ? ids->getWindow("Output")
00067     : rutz::shared_ptr<XWinManaged>();
00068   return uiwin->getLastKeyPress();
00069 }
00070 
00071 //////////////////////////////////////////////////////////////////////
00072 int main(int argc, char** argv)
00073 {
00074 
00075   MYLOGVERB = LOG_INFO;
00076   ModelManager manager("test-Gumbot");
00077 
00078   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00079   manager.addSubComponent(ofs);
00080 
00081 
00082   int status = 0;
00083   Ice::CommunicatorPtr ic;
00084   try {
00085     ic = Ice::initialize(argc, argv);
00086     Ice::ObjectPrx base = ic->stringToProxy(
00087         "GumbotService:default -p 10000 -h 192.168.1.15");
00088     GumbotPrx gumbot = GumbotPrx::checkedCast(base);
00089     if(!gumbot)
00090       throw "Invalid proxy";
00091 
00092     manager.exportOptions(MC_RECURSE);
00093 
00094     if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00095       return 1;
00096     manager.start();
00097 
00098     Image<PixRGB<byte> > gumbotImg = Ice2Image<PixRGB<byte> >(gumbot->getImageSensor(0));
00099     ofs->writeRGB(gumbotImg, "Output", FrameInfo("Output", SRC_POS));
00100 
00101     gumbot->sendStart();
00102     gumbot->setMode(Robots::SafeMode);
00103     while(true)
00104     {
00105 
00106       //Show the image from the robot camera
00107 
00108       int key = getKey(ofs);
00109 
00110 
00111       if (key != -1)
00112       {
00113         switch(key)
00114         {
00115           case KEY_UP:
00116             gumbot->setSteering(0);
00117             gumbot->setSpeed(200);
00118             break;
00119           case KEY_DOWN:
00120             gumbot->setSteering(0);
00121             gumbot->setSpeed(-200);
00122             break;
00123           case KEY_LEFT:
00124             gumbot->setSteering(10);
00125             gumbot->setSpeed(100);
00126             break;
00127           case KEY_RIGHT:
00128             gumbot->setSteering(-10);
00129             gumbot->setSpeed(100);
00130             break;
00131           case 65: //space
00132             gumbot->setMode(Robots::SafeMode);
00133             gumbot->setSteering(0);
00134             gumbot->setSpeed(0);
00135             break;
00136           case 33: //p for playing the song
00137             LINFO("Play song");
00138             gumbot->playSong(0);
00139             break;
00140           case 40: //d for dock with base station
00141             LINFO("Docking");
00142             gumbot->setMode(Robots::CoverAndDockMode);
00143             break;
00144           default:
00145             LINFO("Unknown key %i\n", key);
00146             break;
00147         }
00148       }
00149     }
00150 
00151   }
00152   catch (const Ice::Exception& ex) {
00153     cerr << ex << endl;
00154     status = 1;
00155   }
00156   catch(const char* msg) {
00157     cerr << msg << endl;
00158     status = 1;
00159   }
00160   if (ic)
00161     ic->destroy();
00162   return status;
00163 }
Generated on Sun May 8 08:41:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3