test-BotControl.C

Go to the documentation of this file.
00001 /*!@file RCBot/test-BotControl.C test the Robot Controller
00002  */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Zack Gossman <gossman@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/RCBot/test-BotControl.C $
00036 // $Id: test-BotControl.C 9412 2008-03-10 23:10:15Z farhan $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "GUI/XWinManaged.H"
00043 #include "Image/CutPaste.H"     // for inplacePaste()
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "RCBot/BotControl.H"
00047 #include "Raster/Raster.H"
00048 #include "Transport/FrameIstream.H"
00049 #include "Util/Timer.H"
00050 
00051 #include <arpa/inet.h>
00052 #include <fcntl.h>
00053 #include <netdb.h>
00054 #include <signal.h>
00055 #include <stdlib.h>
00056 #include <unistd.h>
00057 
00058 static bool goforever = true;  //!< Will turn false on interrupt signal
00059 
00060 //! Signal handler (e.g., for control-C)
00061 void terminate(int s)
00062 { LERROR("*** INTERRUPT ***"); goforever = false; exit(1); }
00063 
00064 // ######################################################################
00065 int main(const int argc, const char **argv)
00066 {
00067   MYLOGVERB = LOG_INFO;
00068 
00069   // instantiate a model manager (for camera input):
00070   ModelManager manager("BotControl Tester");
00071 
00072   nub::ref<BotControl>
00073     botControl(new BotControl(manager, "Robot control",
00074                               "BotControl", BotControl::SIMULATION));
00075   manager.addSubComponent(botControl);
00076 
00077   // Parse command-line:
00078   if (manager.parseCommandLine(argc, argv, "", 0, 1) == false)
00079     return(1);
00080 
00081   manager.start();
00082 
00083   //init the robot controller
00084   botControl->init();
00085 
00086   short w, h;
00087   botControl->getImageSensorDims(w,h,0);
00088 
00089   // catch signals and redirect them to terminate for clean exit:
00090   signal(SIGHUP, terminate); signal(SIGINT, terminate);
00091   signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00092   signal(SIGALRM, terminate);
00093 
00094   botControl->setSpeed(0);
00095   botControl->setSteering(0);
00096 
00097   // main loop
00098   while(goforever)
00099     {
00100       Point2D<int> loc;
00101       int key = botControl->getUserInput(loc);
00102 
00103       Image<PixRGB<byte> > ima = botControl->getImageSensor();
00104       if(!ima.initialized()) break;
00105       switch (key) {
00106       case 98: //up
00107         botControl->setSpeed(0.1);
00108         break;
00109       case 104: //down
00110         botControl->setSpeed(-0.1);
00111         break;
00112       case 102: //right
00113         botControl->setSteering(0.4);
00114         break;
00115       case 100: //left
00116         botControl->setSteering(-0.4);
00117         break;
00118       case 65: //space
00119         LINFO("stop");
00120         botControl->setSpeed(0);
00121         botControl->setSteering(0);
00122         break;
00123       default:
00124         if (key != -1)
00125           LINFO("Unknown Key %i", key);
00126         botControl->setSpeed(0);
00127         botControl->setSteering(0);
00128         break;
00129       }
00130     }
00131 
00132   // get ready to terminate:
00133   manager.stop();
00134 
00135   return 0;
00136 }
00137 
00138 // ######################################################################
00139 /* So things look consistent in everyone's emacs... */
00140 /* Local Variables: */
00141 /* indent-tabs-mode: nil */
00142 /* End: */
Generated on Sun May 8 08:05:35 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3