beobot-followColor.C

Go to the documentation of this file.
00001 /*!@file Beobot/beobot-followColor.C Test color segment following - slave */
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:  T. Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/beobot-followColor.C $
00035 // $Id: beobot-followColor.C 7063 2006-08-29 18:26:55Z rjpeters $
00036 //
00037 
00038 #include "Devices/BeoChip.H"
00039 #include "Beobot/BeobotConfig.H"
00040 #include "Beowulf/Beowulf.H"
00041 #include "Component/ModelManager.H"
00042 #include "Util/log.H"
00043 #include "rutz/shared_ptr.h"
00044 #include <signal.h>
00045 
00046 static bool goforever = true;
00047 // ######################################################################
00048 void terminate(int s) { LERROR("*** INTERRUPT ***"); goforever = false; exit(1);}
00049 
00050 // ######################################################################
00051 //! Receive signals from master node and performs requested actions
00052 int main(const int argc, const char **argv)
00053 {
00054   MYLOGVERB = LOG_INFO;
00055 
00056   // instantiate a model manager
00057   ModelManager manager( "Following Color Segments - Slave" );
00058 
00059   // instantiate our various ModelComponents
00060   BeobotConfig bbc;
00061   nub::soft_ref<BeoChip> b(new BeoChip(manager));
00062   manager.addSubComponent(b);
00063   nub::soft_ref<Beowulf>
00064     beo(new Beowulf(manager, "Beowulf Slave", "BeowulfSlave", false));
00065   manager.addSubComponent(beo);
00066 
00067   // parse command-line
00068   if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false)
00069     return(1);
00070 
00071   // let's configure our serial device:
00072   b->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00073   // NOTE: may want to add a BeoChip listener
00074 
00075   // setup signal handling:
00076   signal(SIGHUP, terminate); signal(SIGINT, terminate);
00077   signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00078 
00079   TCPmessage rmsg;       // received messages
00080 
00081   manager.start();
00082 
00083   // reset the beochip:
00084   LINFO("Resetting BeoChip...");
00085   b->resetChip(); sleep(1);
00086 
00087   // keep the gear at the lowest speed/highest torque
00088   b->setServoRaw(bbc.gearServoNum, bbc.gearMinVal);
00089 
00090   int32 rframe, raction, rnode = -1; // receive from any node
00091   while( goforever )
00092   {
00093     // wait up to 5ms
00094     if( beo->receive( rnode, rmsg, rframe, raction, 5 ) )
00095     {
00096       float steerVal = rmsg.getElementFloat();
00097       float speedVal = rmsg.getElementFloat();
00098       float  gearVal = rmsg.getElementFloat();
00099       LINFO( "Received steer: %f speed: %f gear: %f",
00100              steerVal, speedVal, gearVal);
00101       b->setServo(bbc.steerServoNum, steerVal);
00102       b->setServo(bbc.speedServoNum, speedVal);
00103       rmsg.reset(rframe, raction);
00104     }
00105   }
00106 
00107   manager.stop();
00108   return 0;
00109 }
00110 
00111 // ######################################################################
00112 /* So things look consistent in everyone's emacs... */
00113 /* Local Variables: */
00114 /* indent-tabs-mode: nil */
00115 /* End: */
Generated on Sun May 8 08:40:11 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3