BeoIMU.C

00001 /*!@file Robots2/Beobot2/Hardware/BeoIMU.C Ice Module for IMU           */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Christian Siagian <siagian@usc.edu>
00033 // $HeadURL: svn://ilab.usc.edu/trunk/saliency/src/Robots/Beobot2/Hardware/BeoIMU.C
00034 // $ $Id: BeoIMU.C 12962 2010-03-06 02:13:53Z irock $
00035 //
00036 //////////////////////////////////////////////////////////////////////////
00037 
00038 #include "Robots/Beobot2/Hardware/BeoIMU.H"
00039 #include "Ice/BeobotEvents.ice.H"
00040 
00041 // ######################################################################
00042 BeoIMU::BeoIMU(OptionManager& mgr,
00043                const std::string& descrName, const std::string& tagName) :
00044   RobotBrainComponent(mgr, descrName, tagName),
00045   itsIMU(new IMU_MicroStrain_3DM_GX2(mgr)),
00046   //  itsOfs(new OutputFrameSeries(mgr))
00047   itsTimer(1000000),
00048   itsCurrMessageID(0)
00049 {
00050   addSubComponent(itsIMU);
00051   //  addSubComponent(itsOfs);
00052   itsTimer.reset();
00053 }
00054 
00055 // ######################################################################
00056 void BeoIMU::configureSerial(std::string dev)
00057 {
00058   itsIMU->configureSerial(dev);
00059 }
00060 
00061 // ######################################################################
00062 bool BeoIMU::setDataRequested(DataRequested dataRequested)
00063 {
00064   return itsIMU->setDataRequested(dataRequested);
00065 }
00066 
00067 // ######################################################################
00068 BeoIMU::~BeoIMU()
00069 { }
00070 
00071 // ######################################################################
00072 void BeoIMU::registerTopics()
00073 {
00074   this->registerPublisher("IMUMessageTopic");
00075 }
00076 
00077 // ######################################################################
00078 void BeoIMU::evolve()
00079 {
00080   // get data from IMU
00081   if(itsIMU->newData())
00082     {
00083       DataRequested dr = itsIMU->getDataRequested();
00084 
00085       // IMUMessage to be sent out
00086       BeobotEvents::IMUMessagePtr msg =
00087         new BeobotEvents::IMUMessage;
00088       msg->RequestID = itsCurrMessageID;
00089 
00090       // data requested for polling mode
00091       switch(dr)
00092         {
00093         case ACCEL_AND_ANG_RATE:
00094           {
00095             // get acceleration and angular rate
00096             AccelAndAngRateRecord record;
00097             itsIMU->getAccelerationAndAngularRate(record);
00098             LINFO("Acceleration x:%15.6f y:%15.6f z:%15.6f",
00099                   record.accelX, record.accelY, record.accelZ);
00100             LINFO("Angular Rate x:%15.6f y:%15.6f z:%15.6f",
00101                   record.angRateX , record.angRateY, record.angRateZ);
00102 
00103             msg->validAccAndAng = true;
00104             msg->accelX = record.accelX;
00105             msg->accelY = record.accelY;
00106             msg->accelZ = record.accelZ;
00107 
00108             msg->angRateX = record.angRateX;
00109             msg->angRateY = record.angRateY;
00110             msg->angRateZ = record.angRateZ;
00111 
00112             msg->validMagnetometer = false;
00113             msg->validRollPitchYaw = false;
00114           }
00115           break;
00116 
00117         case DELTA_ANG_AND_VEL:
00118           // FIX: itsIMU->getDeltaAngleAndVelocity();
00119           break;
00120 
00121         case MAGNETOMETER:
00122           {
00123             // get instantaneous magnetometer direction and magnitude
00124             MagnetometerRecord record;
00125             itsIMU->getMagnetometer(record);
00126             LINFO("Magnetometer x:%15.6f y:%15.6f z:%15.6f",
00127                   record.magX, record.magY, record.magZ);
00128 
00129             msg->validMagnetometer = true;
00130             msg->magX = record.magX;
00131             msg->magY = record.magY;
00132             msg->magZ = record.magZ;
00133 
00134             msg->validAccAndAng    = false;
00135             msg->validRollPitchYaw = false;
00136           }
00137           break;
00138 
00139         case ORIENTATION_MATRIX:
00140           // FIX: itsIMU->getOrientationMatrix();
00141           break;
00142 
00143         case ROLL_PITCH_YAW:
00144           {
00145             // get roll, pitch, and yaw
00146             RollPitchYawRecord rpyRecord;
00147             itsIMU->getRollPitchYaw(rpyRecord);
00148 
00149             msg->validRollPitchYaw = true;
00150 
00151             // YAW has to be reversed
00152             // because of the IMU configuration in Beobot2.0
00153             msg->roll  = rpyRecord.roll;
00154             msg->pitch = rpyRecord.pitch;
00155             if(rpyRecord.yaw < 0)
00156               msg->yaw   =  rpyRecord.yaw + M_PI;
00157             else
00158               msg->yaw   =  rpyRecord.yaw - M_PI;
00159 
00160             msg->validAccAndAng    = false;
00161             msg->validMagnetometer = false;
00162 
00163             LINFO("Euler Angle  r:%15.6f p:%15.6f y:%15.6f",
00164                   msg->roll, msg->pitch, msg->yaw);
00165           }
00166           break;
00167 
00168         case TEMPERATURE:
00169           // FIX: itsIMU->getTemperature();
00170           break;
00171 
00172         default: LERROR("Unknown data requested: %d", dr);
00173         }
00174 
00175       LINFO("[%6d] Publishing IMUMessage", itsCurrMessageID);
00176       publish("IMUMessageTopic", msg);
00177 
00178       //LINFO("IMU Time: %f", itsTimer.get()/1000.0F);
00179       itsTimer.reset();
00180       itsCurrMessageID++;
00181     }
00182 }
00183 
00184 // ######################################################################
00185 void BeoIMU::updateMessage(const RobotSimEvents::EventMessagePtr& eMsg,
00186     const Ice::Current&)
00187 { }
00188 
00189 // ######################################################################
00190 /* So things look consistent in everyone's emacs... */
00191 /* Local Variables: */
00192 /* indent-tabs-mode: nil */
00193 /* End: */
Generated on Sun May 8 08:41:17 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3