leuze_laser_driver.cpp
Go to the documentation of this file.
00001 #include "leuze_laser_driver.h"
00002 #include "leuze_laser_exceptions.h"
00003 
00004 LeuzeLaserDriver::LeuzeLaserDriver() :
00005   leuze_("leuze")
00006 {
00007   setDriverId("leuze");
00008 }
00009 
00010 bool LeuzeLaserDriver::openDriver(void)
00011 {
00012   try
00013   {
00014     this->lock();
00015     std::string port(config_.serial_port);
00016     this->unlock();  
00017 
00018     leuze_.open(port);
00019   }
00020   catch (CException & e)
00021   {
00022     leuze_.close();
00023     ROS_ERROR("'%s'", e.what().c_str());
00024     return false;
00025   }
00026   return true;
00027 }
00028 
00029 bool LeuzeLaserDriver::closeDriver(void)
00030 {
00031   try
00032   {
00033     leuze_.close();
00034   }
00035   catch (CException & e)
00036   {
00037     ROS_ERROR("'%s'", e.what().c_str());
00038     return false;
00039   }
00040   return true;
00041 }
00042 
00043 bool LeuzeLaserDriver::startDriver(void)
00044 {
00045   try
00046   {
00047     leuze_.start();
00048   }
00049   catch (CException & e)
00050   {
00051     ROS_ERROR("'%s'", e.what().c_str());
00052     return false;
00053   }
00054   return true;
00055 }
00056 
00057 bool LeuzeLaserDriver::stopDriver(void)
00058 {
00059   try
00060   {
00061     leuze_.stop();
00062   }
00063   catch (CException & e)
00064   {
00065     ROS_ERROR("'%s'", e.what().c_str());
00066     return false;
00067   }
00068   return true;
00069 }
00070 
00071 void LeuzeLaserDriver::config_update(const Config& new_cfg, uint32_t level)
00072 {
00073   this->lock();
00074   
00075   // depending on current state
00076   // update driver with new_cfg data
00077   switch(this->getState())
00078   {
00079     case LeuzeLaserDriver::CLOSED:
00080        config_.serial_port = new_cfg.serial_port;
00081       break;
00082 
00083     case LeuzeLaserDriver::OPENED:
00084       break;
00085 
00086     case LeuzeLaserDriver::RUNNING:
00087       break;
00088   }
00089 
00090   // save the current configuration
00091   this->config_=new_cfg;
00092 
00093   this->unlock();
00094 }
00095 
00096 std::string LeuzeLaserDriver::getNewScanEventId(void) const
00097 {
00098   return leuze_.get_new_scan_event_id();
00099 }
00100 
00101 std::string LeuzeLaserDriver::getNoLaserEventId(void) const
00102 {
00103   return leuze_.get_laser_not_present_event_id();
00104 }
00105 
00106 sensor_msgs::LaserScan LeuzeLaserDriver::getScan(void)
00107 {
00108   TLeuzeScan scan;
00109   leuze_.get_scan(&scan);
00110   return leuzeScantoLaserScan(scan);
00111 }
00112 
00113 iri_common_drivers_msgs::leuze_status LeuzeLaserDriver::getStatus(void)
00114 {
00115   iri_common_drivers_msgs::leuze_status ros_status;
00116   TLeuzeStatus status;
00117   
00118   leuze_.get_status(&status);
00119   ros_status.header.stamp    = ros::Time::now();
00120   ros_status.header.frame_id = config_.frame_id;
00121   ros_status.alarm1=status.alarm1;
00122   ros_status.alarm2=status.alarm2;
00123   ros_status.ossd1=status.ossd1;
00124   ros_status.ossd2=status.ossd2;
00125   ros_status.current_pair=status.current_pair;
00126 
00127   return ros_status;
00128 }
00129 
00130 sensor_msgs::LaserScan LeuzeLaserDriver::leuzeScantoLaserScan(const TLeuzeScan & leuze_scan)
00131 {
00132   sensor_msgs::LaserScan scan;
00133   static ros::Time start=ros::Time::now();
00134   ros::Time end=ros::Time::now();
00135 
00136   scan.header.stamp    = ros::Time::now();
00137   scan.header.frame_id = config_.frame_id;
00138 
00139   unsigned int num_ranges = ((leuze_scan.stop-leuze_scan.start)/leuze_scan.res)+1;
00140 
00141   scan.angle_max       = (0.006268668*(leuze_scan.start-1))-(95.04*M_PI/180.0); //start angle of the scan [rad]
00142   scan.angle_min       = (0.006268668*(leuze_scan.stop-1))-(95.04*M_PI/180.0);//end angle of the scan [rad]
00143   scan.angle_increment = leuze_scan.res*(-0.006268668);//-(scan.angle_min - scan.angle_max) / (double)(num_ranges-1);
00144   scan.time_increment  = 0.f;//time between measurements [seconds]
00145   scan.scan_time       = (end-start).toSec();//time between scans [seconds]
00146   scan.range_min       = 0.f;//minimum range value [m]
00147   scan.range_max       = 50.f;//maximum range value [m]
00148 
00149   for(unsigned int ii=0; ii<num_ranges; ii++)
00150     scan.ranges.push_back((float)leuze_scan.data[ii]/1000.f);
00151 
00152   start=end;
00153 
00154   return scan;
00155 }
00156 
00157 bool LeuzeLaserDriver::changePair(unsigned char new_pair)
00158 {
00159   if(new_pair>LEUZE_FP4)
00160     return false;
00161   else
00162   {
00163     try{
00164       leuze_.change_pair((pairs_t)new_pair);
00165       return true;
00166     }catch(CLeuzeLaserException &e){
00167       return false;
00168     }
00169   }
00170 }
00171   
00172 LeuzeLaserDriver::~LeuzeLaserDriver()
00173 {
00174 }


iri_leuze_laser
Author(s): Joan Perez, jnperez at iri.upc.edu
autogenerated on Fri Dec 6 2013 20:26:32