IMU_MicroStrain_3DM_GX2.H

Go to the documentation of this file.
00001 /*!@file Devices/IMU_MicroStrain_3DM_GX2.H class
00002  for interfacing with the MicroStrain 3DM_GX2 IMU */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00006 // by the University of Southern California (USC) and the iLab at USC.  //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/IMU_MicroStrain_3DM_GX2.H $
00035 // $Id: IMU_MicroStrain_3DM_GX2.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef IMU_MICROSTRAIN_3DM_GX2_H_DEFINED
00039 #define IMU_MICROSTRAIN_3DM_GX2_H_DEFINED
00040 
00041 #include "Component/OptionManager.H"
00042 #include "Devices/Serial.H"
00043 #include "Util/Angle.H"
00044 
00045 enum DataRequested { ACCEL_AND_ANG_RATE,
00046                      DELTA_ANG_AND_VEL,
00047                      MAGNETOMETER,
00048                      ORIENTATION_MATRIX,
00049                      ROLL_PITCH_YAW,
00050                      TEMPERATURE };
00051 
00052 typedef struct _AccelAndAngRateRecord
00053 {
00054   float accelX;
00055   float accelY;
00056   float accelZ;
00057   float angRateX;
00058   float angRateY;
00059   float angRateZ;
00060 }
00061 AccelAndAngRateRecord;
00062 
00063 typedef struct _MagnetometerRecord
00064 {
00065   float magX;
00066   float magY;
00067   float magZ;
00068 }
00069 MagnetometerRecord;
00070 
00071 typedef struct _RollPitchYawRecord
00072 {
00073   float roll;
00074   float pitch;
00075   float yaw;
00076 }
00077 RollPitchYawRecord;
00078 
00079 //! Class for interfacing with the IMU
00080 //! It sends X,Y,Z acceleration and X,Y,Z angular velocity
00081 class IMU_MicroStrain_3DM_GX2: public ModelComponent
00082 {
00083 public:
00084   //! Initialize
00085   IMU_MicroStrain_3DM_GX2
00086   (OptionManager& mgr,
00087    const std::string& descrName = "IMU_MicroStrain_3DM_GX2",
00088    const std::string& tagName   = "IMU_MicroStrain_3DM_GX2",
00089    const std::string& dev       = "/dev/ttyUSB0");
00090 
00091   //! Destructor
00092   ~IMU_MicroStrain_3DM_GX2();
00093 
00094   //! to select which serial port to use
00095   void configureSerial(std::string dev);
00096 
00097   //! get acceleration and angular rate
00098   void getAccelerationAndAngularRate
00099   (AccelAndAngRateRecord &record);
00100 
00101   //! get magnetometer dircetion and magnitude
00102   void getMagnetometer(MagnetometerRecord &record);
00103 
00104   //! get roll, pitch, and yaw
00105   void getRollPitchYaw(RollPitchYawRecord &record);
00106 
00107   //! set the data requested from the IMU
00108   bool setDataRequested(DataRequested dataRequested);
00109 
00110   DataRequested getDataRequested();
00111 
00112   //! a thread that keeps updating the requested data
00113   void run();
00114 
00115   //! is there a new data since it is last accessed
00116   bool newData();
00117 
00118 protected:
00119   void start1(); //!< get started
00120   void stop1();  //!< get stopped
00121 
00122 private:
00123 
00124   //! actual get acceleration and angular rate to IMU
00125   void getAccelerationAndAngularRate();
00126 
00127   //! actual get magnetometer dircetion and magnitude to IMU
00128   void getMagnetometer();
00129 
00130   //! actual get roll, pitch, and yaw to IMU
00131   void getRollPitchYaw();
00132 
00133   std::string itsSerialDev;
00134   nub::soft_ref<Serial> itsSerial;
00135 
00136   DataRequested itsDataRequested;
00137   pthread_mutex_t itsDataRequestedLock;
00138 
00139   //! results
00140   AccelAndAngRateRecord itsAccelAndAngRateRecord;
00141   MagnetometerRecord itsMagnetometerRecord;
00142   RollPitchYawRecord itsRollPitchYawRecord;
00143   bool itsNewData;
00144 
00145   bool itsRunDataUpdateThread;
00146   pthread_t itsDataUpdateThread;
00147   pthread_t itsDataDisplayThread;
00148   pthread_mutex_t itsResLock;
00149 };
00150 
00151 #endif
00152 
00153 // ######################################################################
00154 /* So things look consistent in everyone's emacs... */
00155 /* Local Variables: */
00156 /* indent-tabs-mode: nil */
00157 /* End: */
Generated on Sun May 8 08:40:37 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3