00001 /*!@file Robots/NavBot/test-navBot.C Test the navbot robot*/ 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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/NavBot/test-NavBot.C $ 00035 // $Id: test-NavBot.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Robots/NavBot/NavBot.H" 00040 #include "Util/log.H" 00041 #include <unistd.h> 00042 #include <stdio.h> 00043 #include <signal.h> 00044 #include <curses.h> 00045 00046 #define DOWN_KEY 258 00047 #define UP_KEY 259 00048 #define LEFT_KEY 260 00049 #define RIGHT_KEY 261 00050 00051 nub::soft_ref<NavBot> navBot; 00052 00053 void terminate(int s) 00054 { 00055 LINFO("*** INTERRUPT ***"); 00056 navBot->stopAllMotors(); 00057 exit(0); 00058 } 00059 00060 00061 void initScreen() 00062 { 00063 //init the ncurses 00064 (void) initscr(); /* initialize the curses library */ 00065 keypad(stdscr, TRUE); /* enable keyboard mapping */ 00066 (void) nonl(); /* tell curses not to do NL->CR/NL on output */ 00067 intrflush(stdscr, FALSE); 00068 (void) noecho; /* don't echo characters */ 00069 (void) cbreak; /* don't wait for enter before accepting input */ 00070 intrflush(stdscr, FALSE); 00071 } 00072 00073 int getKey() 00074 { 00075 return getch(); 00076 } 00077 00078 00079 00080 int main(int argc, const char **argv) 00081 { 00082 // Instantiate a ModelManager: 00083 ModelManager manager("Navbot Controller"); 00084 00085 navBot = nub::soft_ref<NavBot>(new NavBot(manager)); 00086 manager.addSubComponent(navBot); 00087 00088 // catch signals and redirect them to terminate for clean exit: 00089 signal(SIGHUP, terminate); signal(SIGINT, terminate); 00090 signal(SIGQUIT, terminate); signal(SIGTERM, terminate); 00091 signal(SIGALRM, terminate); 00092 00093 initScreen(); 00094 00095 // Parse command-line: 00096 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00097 00098 // let's get all our ModelComponent instances started: 00099 manager.start(); 00100 00101 LINFO("Starting NavBot"); 00102 int key = getKey(); 00103 int speed = 30; 00104 while(key != 'Q') 00105 { 00106 switch (key) 00107 { 00108 case KEY_UP: 00109 mvprintw(0,0,"Moving forward speed %i R:(%i:%i)\n", speed, 00110 navBot->setMotor(NavBot::LEFT_WHEEL, speed), 00111 navBot->setMotor(NavBot::RIGHT_WHEEL, speed)); 00112 break; 00113 case KEY_DOWN: 00114 mvprintw(0,0,"Moving Back speed %i R:(%i,%i)\n", speed, 00115 navBot->setMotor(NavBot::LEFT_WHEEL, -1*speed), 00116 navBot->setMotor(NavBot::RIGHT_WHEEL, -1*speed)); 00117 break; 00118 case KEY_LEFT: 00119 mvprintw(0,0,"Moving Left speed %i R:(%i,%i)\n", speed, 00120 navBot->setMotor(NavBot::LEFT_WHEEL, speed), 00121 navBot->setMotor(NavBot::RIGHT_WHEEL, -1*speed)); 00122 break; 00123 case KEY_RIGHT: 00124 mvprintw(0,0,"Moving Right speed %i R:(%i,%i)\n", speed, 00125 navBot->setMotor(NavBot::LEFT_WHEEL, -1*speed), 00126 navBot->setMotor(NavBot::RIGHT_WHEEL, speed)); 00127 break; 00128 case ' ': 00129 mvprintw(0,0,"Stop!! %i\n", 00130 navBot->stopAllMotors()); 00131 break; 00132 00133 case 'b': 00134 mvprintw(1,0,"Battery voltage %0.2f\n", 00135 navBot->getBatteryVoltage()); 00136 break; 00137 00138 case '+': 00139 speed += 5; 00140 mvprintw(0,0,"Speed %i\n", speed); 00141 break; 00142 case '-': 00143 speed -= 5; 00144 mvprintw(0,0,"Speed %i\n", speed); 00145 break; 00146 00147 00148 } 00149 key = getKey(); 00150 } 00151 00152 // stop all our ModelComponents 00153 manager.stop(); 00154 00155 // all done! 00156 return 0; 00157 } 00158 00159 00160 // ###################################################################### 00161 /* So things look consistent in everyone's emacs... */ 00162 /* Local Variables: */ 00163 /* indent-tabs-mode: nil */ 00164 /* End: */