00001 /*!@file BeoSub/test-BeoSubIMUFilter.C test the IMU */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002 // 00005 // by the 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-BeoSubIMUFilter.C $ 00035 // $Id: test-BeoSubIMUFilter.C 7880 2007-02-09 02:34:07Z itti $ 00036 // 00037 00038 #include "BeoSub/BeoSubIMU.H" 00039 #include "Devices/HMR3300.H" 00040 #include "Component/ModelManager.H" 00041 #include <math.h> 00042 00043 //Global vars set by listeners 00044 float xAccel = 0, yAccel = 0, zAccel = 0; 00045 Angle xVel = 0, yVel = 0, zVel = 0, cHeading = 0, cPitch = 0, cRoll = 0; 00046 Angle hError = 0, pError = 0, rError = 0; 00047 Angle realPitch = 0, realRoll = 0; 00048 float realXAccel = 0, realZAccel = 0; 00049 00050 bool firstTime = true; 00051 pthread_mutex_t outLock; 00052 00053 class TestHMR3300Listener : public HMR3300Listener { 00054 public: 00055 //! Destructor 00056 virtual ~TestHMR3300Listener() {}; 00057 00058 //! New data was received 00059 virtual void newData(const Angle heading, const Angle pitch, 00060 const Angle roll) 00061 { 00062 pthread_mutex_lock(&outLock); 00063 printf("CH: %3.4f CP: %3.4f CR: %3.4f\n", heading.getVal(), pitch.getVal(), roll.getVal()); 00064 pthread_mutex_unlock(&outLock); 00065 } 00066 }; 00067 00068 00069 #include <cstdio> 00070 00071 //! A hook which will be called when a new IMU reading is received 00072 class TestBeoSubIMUListener : public BeoSubIMUListener { 00073 public: 00074 //! Destructor 00075 virtual ~TestBeoSubIMUListener() {} 00076 00077 //! New data was received 00078 virtual void newData(const float xa, const float ya, const float za, 00079 const Angle xv, const Angle yv, const Angle zv) 00080 { 00081 pthread_mutex_lock(&outLock); 00082 printf("XA: %3.4f YA:%3.4f ZA:%3.4f XV:%3.4f XY:%3.4f XZ: %3.4f\n", xa, xa, xa, xv.getVal(), yv.getVal(), zv.getVal()); 00083 pthread_mutex_unlock(&outLock); 00084 } 00085 }; 00086 00087 int main(const int argc, const char **argv) 00088 { 00089 // get a manager going: 00090 ModelManager manager("IMU Manager"); 00091 00092 // instantiate our model components: 00093 nub::soft_ref<BeoSubIMU> imu(new BeoSubIMU(manager)); 00094 manager.addSubComponent(imu); 00095 00096 nub::soft_ref<HMR3300> hmr(new HMR3300(manager) ); 00097 manager.addSubComponent(hmr); 00098 00099 00100 // Parse command-line: 00101 if (manager.parseCommandLine(argc, argv, "<serdev>", 2, 2) == false) 00102 return(1); 00103 00104 // let's configure our serial devices: 00105 imu->setModelParamVal("IMUSerialPortDevName", 00106 manager.getExtraArg(0), MC_RECURSE); 00107 00108 hmr->setModelParamVal("HMR3300SerialPortDevName", 00109 manager.getExtraArg(1), MC_RECURSE); 00110 00111 // let's register our listeners: 00112 rutz::shared_ptr<TestBeoSubIMUListener> lis(new TestBeoSubIMUListener); 00113 rutz::shared_ptr<BeoSubIMUListener> lis2; lis2.dynCastFrom(lis); // cast down 00114 imu->setListener(lis2); 00115 00116 rutz::shared_ptr<TestHMR3300Listener> lisn(new TestHMR3300Listener); 00117 rutz::shared_ptr<HMR3300Listener> lisn2; lisn2.dynCastFrom(lisn); // cast down 00118 hmr->setListener(lisn2); 00119 00120 // initialize output lock 00121 pthread_mutex_init(&outLock, NULL); 00122 00123 // get started: 00124 manager.start(); 00125 00126 // this is completely event driven, so here we just sleep. When data 00127 // is received, it will trigger our listener: 00128 while (1) sleep(1000); 00129 00130 // stop everything and exit: 00131 manager.stop(); 00132 return 0; 00133 } 00134 00135 // ###################################################################### 00136 /* So things look consistent in everyone's emacs... */ 00137 /* Local Variables: */ 00138 /* indent-tabs-mode: nil */ 00139 /* End: */