test-BeoSubBallast.C

Go to the documentation of this file.
00001 /*!@file BeoSub/test-BeoSubBallast.C test submarine ballasts */
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/BeoSub/test-BeoSubBallast.C $
00035 // $Id: test-BeoSubBallast.C 6990 2006-08-11 18:13:51Z rjpeters $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Devices/BeoChip.H"
00040 #include "BeoSub/BeoSubBallast.H"
00041 
00042 #include <cstdlib>
00043 #include <pthread.h>
00044 
00045 //! Our own little BeoChipListener
00046 class MyBeoChipListener : public BeoChipListener
00047 {
00048 public:
00049   MyBeoChipListener(nub::soft_ref<BeoSubBallast>& ballast,
00050                     nub::soft_ref<BeoChip>& beochip) :
00051     itsBallast(ballast), itsBeoChip(beochip)
00052   { }
00053 
00054   virtual ~MyBeoChipListener()
00055   { }
00056 
00057   virtual void event(const BeoChipEventType t, const int valint,
00058                      const float valfloat)
00059   {
00060     LINFO("Event: %d val = %d, fval = %f", int(t), valint, valfloat);
00061 
00062     switch(t)
00063       {
00064       case NONE: break;
00065       case KBD:
00066         // in this test program, we only care about keyboard events:
00067         itsBallast->input(valint);
00068 
00069         // let the user know what is going on:
00070         itsBeoChip->lcdPrintf(0, 3, "Current=%04d / %1.3f",
00071                               itsBallast->getPulses(), itsBallast->get());
00072         break;
00073       case RESET: LERROR("BeoChip RESET occurred!"); break;
00074       case ECHOREP: LINFO("BeoChip Echo reply received."); break;
00075       case INOVERFLOW: LERROR("BeoChip input overflow!"); break;
00076       case SERIALERROR: LERROR("BeoChip serial error!"); break;
00077       case OUTOVERFLOW: LERROR("BeoChip output overflow!"); break;
00078       default: LERROR("Unexpected event %d received!", int(t)); break;
00079       }
00080   }
00081 
00082 private:
00083   nub::soft_ref<BeoSubBallast> itsBallast;
00084   nub::soft_ref<BeoChip> itsBeoChip;
00085 };
00086 
00087 //! This program provides basic testing of a BeoSubBallast
00088 int main(const int argc, const char* argv[])
00089 {
00090   MYLOGVERB = LOG_INFO;
00091 
00092   // instantiate a model manager:
00093   ModelManager manager("BeoSubBallast test program");
00094 
00095   // Instantiate our various ModelComponents:
00096   nub::soft_ref<BeoChip> bc(new BeoChip(manager));
00097   manager.addSubComponent(bc);
00098 
00099   nub::soft_ref<BeoSubBallast> bal(new BeoSubBallast(manager));
00100   manager.addSubComponent(bal);
00101 
00102   bal->setBeoChip(bc);  // hook BeoChip to Ballast
00103 
00104   // Parse command-line:
00105   if (manager.parseCommandLine(argc, argv,
00106                                "<serdev> <front|rear>", 2, 2) == false)
00107     return(1);
00108 
00109   // let's configure our serial device:
00110   bc->setModelParamVal("BeoChipDeviceName", manager.getExtraArg(0));
00111   bc->setModelParamVal("BeoChipUseRTSCTS", false);
00112 
00113   // let's register our listener:
00114   rutz::shared_ptr<BeoChipListener> lis2(new MyBeoChipListener(bal, bc));
00115   bc->setListener(lis2);
00116 
00117   // setup for the particular ballast we are testing:
00118   if (manager.getExtraArg(1).compare("rear") == 0)
00119     {
00120       // defaults for ballast that is directly attached to the BeoChip:
00121       bal->setModelParamVal("BeoSubBallastOutRed", 1);
00122       bal->setModelParamVal("BeoSubBallastOutWhite", 0);
00123       bal->setModelParamVal("BeoSubBallastInYellow", 1);
00124       bal->setModelParamVal("BeoSubBallastInWhite", 0);
00125       LINFO("Testing REAR ballast (holding BeoChip assembly)");
00126     }
00127   else
00128     {
00129       // defaults for ballast that is NOT directly attached to the BeoChip:
00130       bal->setModelParamVal("BeoSubBallastOutRed", 3);
00131       bal->setModelParamVal("BeoSubBallastOutWhite", 2);
00132       bal->setModelParamVal("BeoSubBallastInYellow", 3);
00133       bal->setModelParamVal("BeoSubBallastInWhite", 2);
00134       LINFO("Testing FRONT ballast (NOT holding BeoChip assembly)");
00135     }
00136 
00137   // let's get all our ModelComponent instances started:
00138   manager.start();
00139 
00140   LINFO("Reseting the BeoChip...");
00141   bc->reset(MC_RECURSE);
00142   sleep(1);
00143 
00144   LINFO("Waiting for a bit. Turn BeoChip on if not already on."); sleep(2);
00145   LINFO("Echo request (should bring an echo reply back)...");
00146   bc->echoRequest(); sleep(1);
00147 
00148   // load a cool custom font:
00149   bc->lcdLoadFont(1);
00150 
00151   // let's turn everything on:
00152   bc->capturePulse(0, false);
00153   bc->capturePulse(1, false);
00154   bc->captureAnalog(0, false);
00155   bc->captureAnalog(1, false);
00156   bc->debounceKeyboard(false);
00157   bc->captureKeyboard(true);
00158 
00159   // let's play with the LCD:
00160   LINFO("Start...");
00161   bc->lcdClear();   // 01234567890123456789
00162   bc->lcdPrintf(0, 0, "test-BeoSubBallast  ");
00163   bc->lcdPrintf(0, 1, "                    ");
00164   bc->lcdPrintf(0, 2, "Desired=0.000       ");
00165   bc->lcdPrintf(0, 3, "Current=0000 / 0.000");
00166 
00167   // initialize the ballast:
00168   bc->lcdPrintf(0, 1, "---- Initialize ----");
00169   bal->mechanicalInitialize();
00170 
00171   // let's play with the ballast:
00172   while(true)
00173     {
00174       bc->lcdPrintf(0, 1, "------ Actuate -----");
00175       bc->lcdPrintf(0, 2, "Desired=1.000");
00176       bal->set(1.0F, true);
00177       bc->lcdPrintf(0, 1, "------- Idle -------");
00178       sleep(10);
00179 
00180       bc->lcdPrintf(0, 1, "------ Actuate -----");
00181       bc->lcdPrintf(0, 2, "Desired=0.000");
00182       bal->set(0.0F, true);
00183       bc->lcdPrintf(0, 1, "------- Idle -------");
00184       sleep(10);
00185 
00186       bc->lcdPrintf(0, 1, "------ Actuate -----");
00187       bc->lcdPrintf(0, 2, "Desired=0.500");
00188       bal->set(0.5F, true);
00189       bc->lcdPrintf(0, 1, "------- Idle -------");
00190       sleep(10);
00191 
00192       bc->lcdPrintf(0, 1, "------ Actuate -----");
00193       bc->lcdPrintf(0, 2, "Desired=0.600");
00194       bal->set(0.6F, true);
00195       bc->lcdPrintf(0, 1, "------- Idle -------");
00196       sleep(10);
00197 
00198       bc->lcdPrintf(0, 1, "------ Actuate -----");
00199       bc->lcdPrintf(0, 2, "Desired=0.550");
00200       bal->set(0.55F, true);
00201       bc->lcdPrintf(0, 1, "------- Idle -------");
00202       sleep(10);
00203 
00204       bc->lcdPrintf(0, 1, "------ Actuate -----");
00205       bc->lcdPrintf(0, 2, "Desired=0.560");
00206       bal->set(0.56F, true);
00207       bc->lcdPrintf(0, 1, "------- Idle -------");
00208       sleep(10);
00209 
00210       bc->lcdPrintf(0, 1, "------ Actuate -----");
00211       bc->lcdPrintf(0, 2, "Desired=0.555");
00212       bal->set(0.555F, true);
00213       bc->lcdPrintf(0, 1, "------- Idle -------");
00214       sleep(10);
00215 
00216       bc->lcdPrintf(0, 1, "------ Actuate -----");
00217       bc->lcdPrintf(0, 2, "Desired=0.556");
00218       bal->set(0.556F, true);
00219       bc->lcdPrintf(0, 1, "------- Idle -------");
00220       sleep(10);
00221     }
00222 
00223   manager.stop();
00224   return 0;
00225 }
00226 
00227 // ######################################################################
00228 /* So things look consistent in everyone's emacs... */
00229 /* Local Variables: */
00230 /* indent-tabs-mode: nil */
00231 /* End: */
Generated on Sun May 8 08:40:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3