tcm3_compass_driver.cpp
Go to the documentation of this file.
00001 #include "tcm3_compass_driver.h"
00002 
00003 
00004 Tcm3CompassDriver::Tcm3CompassDriver()
00005 {
00006   //setDriverId(driver string id);
00007   tcm3_ = new CTCM3();
00008   base_heading_ = 0;
00009   last_heading_ = 0;
00010 }
00011 
00012 bool Tcm3CompassDriver::openDriver(void)
00013 {
00014   //setDriverId(driver string id);
00015   tcm3_->init();
00016   ROS_INFO("TCM3 Initiated");
00017 
00018   return true;
00019 }
00020 
00021 bool Tcm3CompassDriver::closeDriver(void)
00022 {
00023   tcm3_->close();
00024   return true;
00025 }
00026 
00027 bool Tcm3CompassDriver::startDriver(void)
00028 {
00029   tcm3_->addDataComponentId(kHEADING);
00030   tcm3_->addDataComponentId(kPANGLE);
00031   tcm3_->addDataComponentId(kRANGLE);
00032   tcm3_->addDataComponentId(kDISTORTION);
00033   tcm3_->setAcquisitionParameters(PUSHMODE);//1/config_.frequency);
00034   tcm3_->setMountingRef(config_.mounting_position);
00035   ROS_INFO("TCM3 Configured | mounting: %d",config_.mounting_position);
00036   ROS_INFO("TCM3 Starting Continuous Acquisition");
00037   tcm3_->startContinuousAcquisition();
00038   if(config_.relative)
00039   {
00040     tcm3_->getData();
00041     base_heading_ = (double)tcm3_->getHeading();
00042     ROS_DEBUG("TCM3 new base heading: %f",base_heading_);
00043   }
00044   return true;
00045 }
00046 
00047 bool Tcm3CompassDriver::stopDriver(void)
00048 {
00049   ROS_INFO("TCM3 Stopping Continuous Acquisition");
00050   tcm3_->stopContinuousAcquisition();
00051   return true;
00052 }
00053 
00054 void Tcm3CompassDriver::config_update(const Config& new_cfg, uint32_t level)
00055 {
00056   this->lock();
00057 
00058   // depending on current state
00059   // update driver with new_cfg data
00060   switch(this->getState())
00061   {
00062     case Tcm3CompassDriver::CLOSED:
00063       break;
00064 
00065     case Tcm3CompassDriver::OPENED:
00066       break;
00067 
00068     case Tcm3CompassDriver::RUNNING:
00069       if(new_cfg.relative != config_.relative)
00070       {
00071         if(new_cfg.relative)
00072           base_heading_ = last_heading_;
00073         else
00074           base_heading_ = 0;
00075         ROS_DEBUG("TCM3 new base heading: %f",base_heading_);
00076       }
00077       break;
00078   }
00079 
00080   // save the current configuration
00081   config_=new_cfg;
00082 
00083   this->unlock();
00084 }
00085 
00086 Tcm3CompassDriver::~Tcm3CompassDriver()
00087 {
00088   delete tcm3_;
00089 }
00090 
00091 // -------------------------------------------------------------------------- //
00092 
00093 void Tcm3CompassDriver::getData(double & heading, double & pitch, double & roll, bool & distortion)
00094 {
00095   tcm3_->getData();
00096 
00097   last_heading_ = (double)tcm3_->getHeading();
00098   heading       = last_heading_ - base_heading_;
00099   pitch         = (double)tcm3_->getPitch();
00100   roll          = (double)tcm3_->getRoll();
00101   distortion    = (bool)tcm3_->getDistortion();
00102 
00103   ROS_DEBUG("heading: %f (%f) pitch: %f roll: %f",heading,last_heading_,pitch,roll);
00104 }
00105 
00106 


iri_tcm3_compass
Author(s): Marti Morta, mmorta at iri.upc.edu
autogenerated on Fri Dec 6 2013 23:04:29