00001 /*!@file AppDevices/test-BeoChip.C test suite for Rand Voorhies' BeeSTEM */ 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppDevices/test-BeeStem3.C $ 00035 // $Id: test-BeeStem3.C 12977 2010-03-07 10:58:57Z beobot $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Devices/BeeStem3.H" 00040 #include "Devices/DeviceOpts.H" 00041 #include "Util/MathFunctions.H" 00042 00043 #include <cstdlib> 00044 #include <iostream> 00045 00046 int main(const int argc, const char* argv[]) 00047 { 00048 MYLOGVERB = LOG_INFO; 00049 00050 // instantiate a model manager: 00051 ModelManager manager("BeeStem3 Test Program"); 00052 00053 // Instantiate our various ModelComponents: 00054 nub::soft_ref<BeeStem3> b(new BeeStem3(manager,"BeeStem3", "BeeStem3", "/dev/ttyUSB0")); 00055 manager.addSubComponent(b); 00056 00057 if (manager.parseCommandLine(argc, argv, "No Options Yet", 0,0) == false) 00058 return(1); 00059 00060 00061 // let's get all our ModelComponent instances started: 00062 manager.start(); 00063 00064 int accelX,accelY,accelZ; 00065 int compassHeading, compassPitch, compassRoll; 00066 int internalPressure, externalPressure; 00067 int desiredHeading, desiredDepth, desiredSpeed; 00068 int headingK, headingP, headingD, headingI, headingOutput; 00069 int depthK, depthP, depthD, depthI, depthOutput; 00070 char killSwitch; 00071 00072 char c = 0; 00073 00074 /* int dheading = 0; 00075 int ddepth = 0; 00076 int dspeed = 0; 00077 // int dmarker = 0; 00078 00079 int pidMode = 0; 00080 int dk = 0; 00081 int dp = 0; 00082 int di = 0; 00083 int dd = 0;*/ 00084 00085 while(c != 'q') 00086 { 00087 std::cout << "Command (r = read, s = start compass calibration, e = end compass calibration, q = quit): "; 00088 std::cin >> c; 00089 std:: cout << "\n"; 00090 00091 if(c == 'r') 00092 { 00093 while(b->getSensors(accelX,accelY,accelZ, 00094 compassHeading, compassPitch, compassRoll, 00095 internalPressure, externalPressure, 00096 desiredHeading, desiredDepth, desiredSpeed, 00097 headingK, headingP, headingD, headingI, headingOutput, 00098 depthK, depthP, depthD, depthI, depthOutput, killSwitch)) 00099 { 00100 LINFO("==================================="); 00101 LINFO("Accel X: %d, AccelY: %d, AccelZ: %d",accelX,accelY,accelZ); 00102 LINFO("Heading: %d, Pitch: %d, Roll: %d",compassHeading, compassPitch, compassRoll); 00103 LINFO("Int Pressure: %d, Ext Pressure: %d",internalPressure,externalPressure); 00104 LINFO("Desired Heading: %d, Desired Depth: %d, Desired Speed: %d",desiredHeading, desiredDepth, desiredSpeed); 00105 LINFO("Heading K=%d, P=%d, I=%d, D=%d, Output=%d",headingK, headingP, headingI, headingD, headingOutput); 00106 LINFO("Depth K=%d, P=%d, I=%d, D=%d, Output=%d",depthK, depthP, depthI, depthD, depthOutput); 00107 LINFO("Kill Switch: %d",killSwitch); 00108 LINFO("==================================="); 00109 sleep(0.5); 00110 } 00111 00112 } 00113 else if(c == 's') 00114 { 00115 LINFO("Starting compass calibration"); 00116 b->startCompassCalibration(); 00117 } 00118 else if(c == 'e') 00119 { 00120 LINFO("Ending compass calibration"); 00121 b->endCompassCalibration(); 00122 } 00123 /*else if(c == 's') 00124 { 00125 std::cout << "Desired Heading: "; 00126 std::cin >> dheading; 00127 std::cout << "\n"; 00128 std::cout << "Desired Depth: "; 00129 std::cin >> ddepth; 00130 std::cout << "\n"; 00131 std::cout << "Desired Speed: "; 00132 std::cin >> dspeed; 00133 std::cout << "\n"; 00134 00135 // NOTE: dmarker is ignored for now 00136 00137 bool succ = b->setDesiredValues(dheading,ddepth,dspeed,dmarker); 00138 00139 if(succ) 00140 LINFO("Desired values updated successfully!"); 00141 else 00142 LINFO("Error setting desired values"); 00143 00144 } 00145 else if(c == 'i') 00146 { 00147 std::cout << "PID Mode (0 = Depth, 1 = Heading): "; 00148 std::cin >> pidMode; 00149 std::cout <<"\n"; 00150 00151 std::cout << "K = "; 00152 std::cin >> dk; 00153 std::cout <<"\n"; 00154 00155 std::cout << "P = "; 00156 std::cin >> dp; 00157 std::cout <<"\n"; 00158 00159 std::cout << "I = "; 00160 std::cin >> di; 00161 std::cout <<"\n"; 00162 00163 std::cout << "D = "; 00164 std::cin >> dd; 00165 std::cout <<"\n"; 00166 00167 bool succ = b->setPID(pidMode,dk,dp,di,dd); 00168 00169 if(succ) 00170 LINFO("PID values updated successfully!"); 00171 else 00172 LINFO("Error setting PID values"); 00173 }*/ 00174 } 00175 00176 manager.stop(); 00177 return 0; 00178 } 00179 00180 // ###################################################################### 00181 /* So things look consistent in everyone's emacs... */ 00182 /* Local Variables: */ 00183 /* indent-tabs-mode: nil */ 00184 /* End: */