00001 /*! @file Beobot/test-gistNav.C -- run on board B (has BeoChip). 00002 Executes motor commands from board A (master) 00003 -- Christopher Ackerman 7/30/2003 */ 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 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-gistNav.C $ 00035 // $Id: test-gistNav.C 6795 2006-06-29 20:45:32Z rjpeters $ 00036 00037 #include "Devices/BeoChip.H" 00038 #include "Beobot/BeobotConfig.H" 00039 #include "Beowulf/Beowulf.H" 00040 #include "Component/ModelManager.H" 00041 #include <signal.h> 00042 #include <stdio.h> 00043 00044 static bool goforever = true; //!< Will turn false on interrupt signal 00045 00046 // ###################################################################### 00047 //! Signal handler (e.g., for control-C) 00048 void terminate(int s) 00049 { 00050 LERROR("*** INTERRUPT ***"); 00051 goforever = false; 00052 exit(1); 00053 } 00054 00055 // ###################################################################### 00056 int main(const int argc, const char **argv) 00057 { 00058 // instantiate a model manager: 00059 ModelManager manager("GistNavigator - Slave"); 00060 00061 // Instantiate our various ModelComponents: 00062 nub::soft_ref<BeoChip> b(new BeoChip(manager)); 00063 manager.addSubComponent(b); 00064 00065 nub::soft_ref<Beowulf> beo(new Beowulf(manager, "Beowulf Slave", 00066 "BeowulfSlave", false)); 00067 manager.addSubComponent(beo); 00068 00069 // Parse command-line: 00070 if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false) 00071 return(1); 00072 00073 // let's configure our serial device: 00074 b->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0)); 00075 00076 // setup signal handling: 00077 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00078 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00079 00080 // message being received and to process 00081 TCPmessage rmsg; 00082 00083 manager.start(); 00084 00085 // reset the beochip: 00086 LINFO("Resetting BeoChip..."); 00087 b->resetChip(); sleep(1); 00088 BeobotConfig bbc; 00089 00090 // keep the gear at the lowest speed/highest torque 00091 b->setServoRaw(2, 0); 00092 00093 while(goforever) 00094 { 00095 int32 rframe, raction, rnode = -1; // receive from any node 00096 if (beo->receive(rnode, rmsg, rframe, raction, 3)){ // wait up to 3ms 00097 00098 const double steer = rmsg.getElementDouble(); 00099 const double speed = rmsg.getElementDouble(); 00100 LINFO("Received speed=%f, steer=%f\n",speed,steer); 00101 00102 bool b1 = b->setServo(bbc.speedServoNum, (float)(steer)); 00103 bool b2 = b->setServo(bbc.steerServoNum, (float)(speed)); 00104 LINFO("setSteering returned %d; setSpeed returned %d\n",b1,b2); 00105 LINFO("actual speed=%f, steer=%f\n", 00106 b->getServo(bbc.speedServoNum), 00107 b->getServo(bbc.steerServoNum)); 00108 } 00109 } 00110 00111 manager.stop(); 00112 } 00113 00114 // ###################################################################### 00115 /* So things look consistent in everyone's emacs... */ 00116 /* Local Variables: */ 00117 /* indent-tabs-mode: nil */ 00118 /* End: */