BeoSubIMU.H

Go to the documentation of this file.
00001 /*!@file BeoSub/BeoSubIMU.H class for interfacing with the IMU */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
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 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeoSubIMU.H $
00034 // $Id: BeoSubIMU.H 11659 2009-09-05 01:27:31Z siagian $
00035 //
00036 
00037 #ifndef BEOSUBIMU_H_DEFINED
00038 #define BEOSUBIMU_H_DEFINED
00039 
00040 #include "Component/OptionManager.H"
00041 #include "Devices/Serial.H"
00042 #include "Util/Angle.H"
00043 #include <pthread.h>
00044 
00045 //! A hook which will be called when a new IMU reading is received
00046 class BeoSubIMUListener {
00047 public:
00048   //! Destructor
00049   virtual ~BeoSubIMUListener();
00050 
00051   //! New data was received
00052   virtual void newData(const float xa, const float ya, const float za,
00053                        const Angle xv, const Angle yv, const Angle zv) = 0;
00054 };
00055 
00056 //! Class for interfacing with the IMU
00057 /*! This is an IMU. It sends X,Y,Z acceleration and X,Y,Z angular velocity*/
00058 class BeoSubIMU: public ModelComponent
00059 {
00060 public:
00061   //! Initialize
00062   BeoSubIMU(OptionManager& mgr,
00063             const std::string& descrName = "IMU",
00064             const std::string& tagName = "IMU",
00065             const char *dev = "/dev/ttyS0");
00066 
00067   //! Destructor
00068   ~BeoSubIMU();
00069 
00070   //! Setup a listener that will be called each time new data is received
00071   void setListener(rutz::shared_ptr<BeoSubIMUListener> listener);
00072 
00073   //! Get the current X acceleration
00074   float getXaccel();
00075 
00076   //! Get the current Y acceleration
00077   float getYaccel();
00078 
00079   //! Get the current Z acceleration
00080   float getZaccel();
00081 
00082   //! Get the current X velocity
00083   Angle getXvel();
00084 
00085   //! Get the current Y velocity
00086   Angle getYvel();
00087 
00088   //! Get the current Z velocity
00089   Angle getZvel();
00090 
00091   void run();
00092 
00093 protected:
00094   void start2(); //!< get started
00095   void stop1(); //!< get stopped
00096   float accelConvert(int data);
00097   float rateConvert(int data);
00098 
00099 private:
00100   nub::soft_ref<Serial> itsSerial;
00101   rutz::shared_ptr<BeoSubIMUListener> itsListener;
00102   Angle itsXvel, itsYvel, itsZvel;
00103   float itsXaccel, itsYaccel, itsZaccel;
00104   bool itsKeepgoing;
00105   pthread_t itsRunner;
00106   pthread_mutex_t itsLock;
00107 };
00108 
00109 #endif
00110 
00111 // ######################################################################
00112 /* So things look consistent in everyone's emacs... */
00113 /* Local Variables: */
00114 /* indent-tabs-mode: nil */
00115 /* End: */
Generated on Sun May 8 08:04:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3