test-BeeSTEM.C

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-BeeSTEM.C $
00035 // $Id: test-BeeSTEM.C 8623 2007-07-25 17:57:51Z rjpeters $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Devices/BeeSTEM.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Util/MathFunctions.H"
00042 
00043 #include <cstdlib>
00044 #include <iostream>
00045 
00046 //! Our own little BeeSTEMListener
00047 class MyBeeSTEMListener : public BeeSTEMListener
00048 {
00049 public:
00050   MyBeeSTEMListener()
00051   {  }
00052 
00053   virtual ~MyBeeSTEMListener()
00054   { }
00055 
00056   virtual void event(const BeeSTEMEventType t, const unsigned char dat1,
00057                      const unsigned char dat2)
00058   {
00059     LDEBUG("Event: %d dat1 = %d, dat2 = %d", int(t), dat1, dat2);
00060 
00061     switch(t) {
00062 
00063     case COMPASS_HEADING_EVENT:   LINFO("Heading: %d", (unsigned int)dat1*2); break;  //Careful here! The heading is sent /2 because of byte limits
00064     case COMPASS_PITCH_EVENT:     LINFO("Pitch: %d", (signed char)dat1); break;
00065     case COMPASS_ROLL_EVENT:      LINFO("Roll: %d", (signed char)dat1); break;
00066     case ACCEL_X_EVENT:           break;
00067     case ACCEL_Y_EVENT:           break;
00068     case INT_PRESS_EVENT:         LINFO("Int pressure: %d", (unsigned int)dat1);break;
00069     case EXT_PRESS_EVENT:         LINFO("External Pressure: %d", (unsigned int)dat1); break;
00070     case TEMP1_EVENT:             break;
00071     case TEMP2_EVENT:             break;
00072     case TEMP3_EVENT:             break;
00073     case DIG_IN_EVENT:            break;
00074     case ADC_IN_EVENT:            break;
00075     case MOTOR_A_CURR_EVENT:      LINFO("Motor A Current: %d", (unsigned int)dat1);break;
00076     case MOTOR_B_CURR_EVENT:      LINFO("Motor B Current: %d", (unsigned int)dat1);break;
00077     case MOTOR_C_CURR_EVENT:      LINFO("Motor C Current: %d", (unsigned int)dat1);break;
00078     case MOTOR_D_CURR_EVENT:      LINFO("Motor D Current: %d", (unsigned int)dat1);break;
00079     case MOTOR_E_CURR_EVENT:      LINFO("Motor E Current: %d", (unsigned int)dat1);break;
00080     case ECHO_REPLY_EVENT:        LINFO("BeeSTEM Echo Reply Recieved."); break;
00081     case RESET_EVENT:             LERROR("BeeSTEM RESET occurred!"); break;
00082     case SW_OVERFLOW_EVENT:       LERROR("BeeSTEM Software Overflow!"); break;
00083     case FRAMING_ERR_EVENT:       LERROR("BeeSTEM Framing Error!"); break;
00084     case OVR_ERR_EVENT:           LERROR("BeeSTEM Hardware Overflow!"); break;
00085     case HMR3300_LOST_EVENT:      break;
00086     case ACCEL_LOST_EVENT:        break;
00087     case TEMP1_LOST_EVENT:        break;
00088     case TEMP2_LOST_EVENT:        break;
00089     case HMR_LEVELED_EVENT:       LINFO("HMR3300 Leveling Complete"); break;
00090     case ESTOP_EVENT:             break;
00091     case UNRECOGNIZED_EVENT:      break;
00092     case BAD_OUT_CMD_SEQ_EVENT:   LERROR("BeeSTEM Reports a Bad Command Sequence!"); break;
00093     case BAD_IN_CMD_SEQ_EVENT:    break;
00094     case RESET_ACK_EVENT:         LINFO("BeeSTEM Acknowledges Reset Request"); break;
00095     case HMR3300_CAL_EVENT:       LINFO("HMR3300 is Calibrating!"); break;
00096     case  NO_EVENT:               break;
00097     default:                      LERROR("Unknown event %d received!", int(t)); break;
00098 
00099     }
00100   }
00101 };
00102 
00103 //! This program provides basic interfacing to the BeeSTEM
00104 /*! See the BeeSTEM class for details.*/
00105 int main(const int argc, const char* argv[])
00106 {
00107   char c = 0;
00108   int num = 0;
00109   int motor = 0;
00110   int speed = 0;
00111 
00112   MYLOGVERB = LOG_INFO;
00113 
00114   // instantiate a model manager:
00115   ModelManager manager("BeeSTEM test program");
00116 
00117   // Instantiate our various ModelComponents:
00118   nub::soft_ref<BeeSTEM> b(new BeeSTEM(manager,"BeeSTEM", "BeeSTEM", "/dev/ttyS1"));
00119   manager.addSubComponent(b);
00120 
00121   if (manager.parseCommandLine(argc, argv, "No Options Yet", 0,0) == false)
00122                                    return(1);
00123 
00124   rutz::shared_ptr<MyBeeSTEMListener> lis(new MyBeeSTEMListener);
00125   rutz::shared_ptr<BeeSTEMListener> lis2; lis2.dynCastFrom(lis); // cast down
00126   b->setListener(lis2);
00127 
00128   // let's get all our ModelComponent instances started:
00129   manager.start();
00130 
00131   LINFO("Echo request (should bring an echo reply back)...");
00132   b->echoRequest(); sleep(2);
00133   while(c != 'q') {
00134     std::cin >> c;
00135     switch(c) {
00136     case 'h':
00137       std::cout << "Commands:" << std::endl;
00138       std::cout << "E: Echo Request" << std::endl;
00139       std::cout << "R: Reset the chip" << std::endl;
00140       std::cout << "F: Flood the chip with echo requests" << std::endl;
00141       std::cout << "C=on c=off: Toggle Compass Reporting" << std::endl;
00142       std::cout << "M: Set a thruster speed" << std::endl;
00143       std::cout << "I=on i=off: Toggle Internal Pressure Reporting" << std::endl;
00144       std::cout << "P=on p=off: Toggle External Pressure Reporting" << std::endl;
00145       std::cout << "D=on d=off:  Toggle Debugging Mode" << std::endl;
00146       std::cout << "A=on a=off: Toggle Motor Reporting" << std::endl;
00147       std::cout << "S: Toggle HMR3300 Calibration Mode" << std::endl;
00148       std::cout << "L: Level the HMR3300" << std::endl;
00149       break;
00150     case 'e':
00151       LINFO("Echo request (should bring an echo reply back)...");
00152       b->echoRequest();
00153       break;
00154     case 'r':
00155       LINFO("Reseting the BeeSTEM...");
00156       b->resetChip();
00157       break;
00158     case 'f':
00159       LINFO("Enter the number of echo requests to flood");
00160       std::cin >> num;
00161       LINFO("Flooding the BeeSTEM with %d echo requests...", num);
00162       for(int i=0; i<num;i++)
00163         b->echoRequest();
00164       break;
00165     case 'C':
00166       b->setReporting(HMR3300, true);
00167       break;
00168     case 'c':
00169       b->setReporting(HMR3300, false);
00170       break;
00171     case 'I':
00172       b->setReporting(INT_PRESS, true);
00173       break;
00174     case 'i':
00175       b->setReporting(INT_PRESS, false);
00176       break;
00177     case 'D':
00178       b->debugMode(true);
00179     case 'd':
00180       b->debugMode(false);
00181     case 'm':
00182     case 'M':
00183       LINFO("Motor:");
00184       std::cin >> motor;
00185       LINFO("Speed:");
00186       std::cin >> speed;
00187       b->setMotor(motor, speed);
00188       break;
00189     case 'P':
00190       b->setReporting(EXT_PRESS, true);
00191       break;
00192     case 'p':
00193       b->setReporting(EXT_PRESS, false);
00194       break;
00195     case 'S':
00196     case 's':
00197       b->toggleCalibrateHMR3300();
00198       break;
00199     case 'L':
00200     case 'l':
00201       b->levelHMR3300();
00202       break;
00203     case 'A':
00204       b->setReporting(MOTOR_CURR, true);
00205       break;
00206     case 'a':
00207       b->setReporting(MOTOR_CURR, false);
00208       break;
00209     }
00210   }
00211 
00212 
00213   manager.stop();
00214   return 0;
00215 }
00216 
00217 // ######################################################################
00218 /* So things look consistent in everyone's emacs... */
00219 /* Local Variables: */
00220 /* indent-tabs-mode: nil */
00221 /* End: */
Generated on Sun May 8 08:40:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3