test-followColor.C

Go to the documentation of this file.
00001 /*!@file Beobot/test-followColor.C Test color segment following - slave */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file:  T. Nathan Mundhenk <mundhenk@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-followColor.C $
00034 // $Id: test-followColor.C 6988 2006-08-11 17:15:38Z rjpeters $
00035 //
00036 
00037 #include "Devices/BeoChip.H"
00038 #include "Beobot/BeobotConfig.H"
00039 #include "Beowulf/Beowulf.H"
00040 #include "Component/ModelManager.H"
00041 #include "Util/log.H"
00042 #include "rutz/shared_ptr.h"
00043 #include <signal.h>
00044 
00045 static bool goforever = true;
00046 // ######################################################################
00047 void terminate(int s) { LERROR("*** INTERRUPT ***"); goforever = false; exit(1);}
00048 
00049 // ######################################################################
00050 //! Receive signals from master node and performs requested actions
00051 int main(const int argc, const char **argv)
00052 {
00053   MYLOGVERB = LOG_INFO;
00054 
00055   // instantiate a model manager
00056   ModelManager manager( "Following Color Segments - Slave" );
00057 
00058   // instantiate our various ModelComponents
00059   BeobotConfig bbc;
00060   nub::soft_ref<BeoChip> b(new BeoChip(manager));
00061   manager.addSubComponent(b);
00062   nub::soft_ref<Beowulf>
00063     beo(new Beowulf(manager, "Beowulf Slave", "BeowulfSlave", false));
00064   manager.addSubComponent(beo);
00065 
00066   // parse command-line
00067   if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false)
00068     return(1);
00069 
00070   // let's configure our serial device:
00071   b->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00072   // NOTE: may want to add a BeoChip listener
00073 
00074   // setup signal handling:
00075   signal(SIGHUP, terminate); signal(SIGINT, terminate);
00076   signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00077 
00078   TCPmessage rmsg;       // received messages
00079 
00080   manager.start();
00081 
00082   // reset the beochip:
00083   LINFO("Resetting BeoChip...");
00084   b->resetChip(); sleep(1);
00085 
00086   // keep the gear at the lowest speed/highest torque
00087   b->setServoRaw(bbc.gearServoNum, bbc.gearMinVal);
00088 
00089   int32 rframe, raction, rnode = -1; // receive from any node
00090   while( goforever )
00091   {
00092     if( beo->receive( rnode, rmsg, rframe, raction, 10 ) ) // wait up to 10ms
00093     {
00094       double speedVal = rmsg.getElementDouble();
00095       double steerVal = rmsg.getElementDouble();
00096       LINFO( "Received speed=%f steer=%f", speedVal, steerVal );
00097       b->setServo(bbc.speedServoNum, (float)speedVal);
00098       b->setServo(bbc.steerServoNum, (float)steerVal);
00099     }
00100   }
00101 }
00102 
00103 // ######################################################################
00104 /* So things look consistent in everyone's emacs... */
00105 /* Local Variables: */
00106 /* indent-tabs-mode: nil */
00107 /* End: */
Generated on Sun May 8 08:40:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3