00001 /*!@file Beobot/test-BeobotControl.C Test the BeobotControl class */ 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: Laurent Itti <itti@usc.edu> 00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-BeobotControl.C $ 00034 // $Id: test-BeobotControl.C 6814 2006-07-08 05:22:35Z beobot $ 00035 // 00036 00037 #include "Beobot/BeobotControl.H" 00038 #include "Devices/BeoChip.H" 00039 #include "Component/ModelManager.H" 00040 #include "Util/Timer.H" 00041 #include "Util/Types.H" 00042 #include <iostream> 00043 #include <math.h> 00044 #include <signal.h> 00045 #include <unistd.h> 00046 00047 static bool goforever = true; //!< Will turn false on interrupt signal 00048 00049 // ###################################################################### 00050 //! Signal handler (e.g., for control-C) 00051 void terminate(int s){ LERROR("*** INTERRUPT ***"); goforever = false; } 00052 00053 // ###################################################################### 00054 //! The main method - run on Beobot 00055 int main(const int argc, const char **argv) 00056 { 00057 // setup signal handling: 00058 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00059 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00060 00061 // Instantiate a ModelManager: 00062 ModelManager manager("Test BeobotControl"); 00063 00064 // Instantiate our various ModelComponents: 00065 nub::soft_ref<BeoChip> b(new BeoChip(manager)); 00066 manager.addSubComponent(b); 00067 nub::soft_ref<BeobotControl> bc(new BeobotControl(b, manager)); 00068 manager.addSubComponent(bc); 00069 00070 // Parse command-line: 00071 if (manager.parseCommandLine(argc, argv, "<serdev>", 1, 1) == false) 00072 return(1); 00073 00074 // let's configure our serial device: 00075 b->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0)); 00076 00077 // let's get all our ModelComponent instances started: 00078 manager.start(); 00079 00080 float steer = 0.0F, speed = 0.0F; float sti = 0.1F, ssi = 0.02F; 00081 00082 // reset the beochip: 00083 LINFO("Resetting BeoChip..."); 00084 b->resetChip(); sleep(1); 00085 00086 // let's play with the LCD: 00087 b->lcdClear(); // 01234567890123456789 00088 b->lcdPrintf(0, 0, "Test Beobot Control "); 00089 b->lcdPrintf(0, 1, "STEER=XXX SPEED=XXX"); 00090 b->lcdPrintf(0, 2, " "); 00091 b->lcdPrintf(0, 3, " "); 00092 00093 // test ramping functions 00094 bc->setSpeed(0.0F); 00095 LINFO("Linear ramp to 0.4 speed, expected time 5000ms"); 00096 Timer msecs( 1000 ); 00097 msecs.reset(); 00098 bc->toSpeedLinear( 0.4F, 5000 ); 00099 LINFO("Linear ramp took %llums, ending speed = %f", 00100 msecs.get(), bc->getSpeed() ); 00101 LINFO("Sigmoid ramp to 0.0 speed, expected time 5000ms"); 00102 msecs.reset(); 00103 bc->toSpeedSigmoid( 0.0F, 5000 ); 00104 LINFO("Sigmoid ramp took %llums, ending speed = %f", 00105 msecs.get(), bc->getSpeed() ); 00106 00107 bc->rampSpeed( 0.4F, 5000, SPEED_RAMP_SIGMOID ); 00108 LINFO( "Sigmoid ramp to 0.4 speed, expected time 5000ms" ); 00109 msecs.reset(); 00110 while( msecs.get() <= 5000 ) 00111 { 00112 LINFO( "1. Ramping, current speed = %f", bc->getSpeed() ); 00113 usleep( 100000 ); 00114 } 00115 00116 LINFO( "Sigmoid ramp complete, ending speed = %f", bc->getSpeed() ); 00117 bc->rampSpeed( -0.25F, 5000, SPEED_RAMP_LINEAR ); 00118 LINFO("Linear ramp to 0.0 speed, expected time 5000ms" ); 00119 msecs.reset(); 00120 while( msecs.get() <= 2500 ) 00121 { 00122 LINFO( "2. Ramping, current speed = %f", bc->getSpeed() ); 00123 usleep( 100000 ); 00124 } 00125 bc->rampSpeed( 0.4F, 10000, SPEED_RAMP_LINEAR ); 00126 LINFO( "Adjusting linear ramp before completion" ); 00127 msecs.reset(); 00128 while( msecs.get() <= 5000 ) 00129 { 00130 LINFO( "3. Ramping, current speed = %f", bc->getSpeed() ); 00131 usleep( 100000 ); 00132 } 00133 bc->abortRamp(); 00134 bc->setSpeed( 0.0F ); 00135 LINFO( "Prematurely stopping..." ); 00136 LINFO( "Final speed = %f", bc->getSpeed() ); 00137 00138 while(goforever) { 00139 steer += sti; speed += ssi; 00140 if (steer < -1.0F) { steer = -1.0F; sti = fabs(sti); } 00141 if (steer > 1.0F) { steer = 1.0F; sti = -fabs(sti); } 00142 if (speed < -0.2F) { speed = -0.2F; ssi = fabs(ssi); } 00143 if (speed > 0.2F) { speed = 0.2F; ssi = -fabs(ssi); } 00144 00145 LINFO("FORCING SPEED TO ZERO"); speed=0; 00146 00147 LINFO("Steer = %.2f, Speed = %.2f", bc->getSteer(), bc->getSpeed()); 00148 bc->setSteer(steer); bc->setSpeed(speed); 00149 usleep(300000); 00150 } 00151 00152 manager.stop(); 00153 return 0; 00154 } 00155 00156 // ###################################################################### 00157 /* So things look consistent in everyone's emacs... */ 00158 /* Local Variables: */ 00159 /* indent-tabs-mode: nil */ 00160 /* End: */