00001 #include "ThreadMapping.h" 00002 #include "SlamNode.h" 00003 00004 #include "obcore/base/Logger.h" 00005 #include "obcore/math/mathbase.h" 00006 00007 #include <cmath> 00008 00009 namespace ohm_tsd_slam 00010 { 00011 00012 ThreadMapping::ThreadMapping(obvious::TsdGrid* grid): 00013 ThreadSLAM(*grid), 00014 _initialized(false) 00015 { 00016 } 00017 00018 ThreadMapping::~ThreadMapping() 00019 { 00020 _thread->join(); 00021 } 00022 00023 bool ThreadMapping::initialized(void) 00024 { 00025 bool var = false; 00026 _pushMutex.lock(); 00027 var = _initialized; 00028 _pushMutex.unlock(); 00029 return var; 00030 } 00031 00032 void ThreadMapping::initPush(obvious::SensorPolar2D* sensor) 00033 { 00034 if(this->initialized()) 00035 return; 00036 _pushMutex.lock(); 00037 for(unsigned int i = 0; i < INIT_PSHS; i++) 00038 _grid.push(sensor); 00039 _initialized = true; 00040 _pushMutex.unlock(); 00041 } 00042 00043 void ThreadMapping::eventLoop(void) 00044 { 00045 while(_stayActive) 00046 { 00047 _sleepCond.wait(_sleepMutex); 00048 while(_stayActive && !_sensors.empty()) 00049 { 00050 obvious::SensorPolar2D* sensor = _sensors.front(); 00051 _grid.push(sensor); 00052 _pushMutex.lock(); 00053 delete _sensors.front(); 00054 _sensors.pop(); 00055 _initialized = true; 00056 _pushMutex.unlock(); 00057 } 00058 } 00059 } 00060 00061 void ThreadMapping::queuePush(obvious::SensorPolar2D* sensor) 00062 { 00063 _pushMutex.lock(); 00064 obvious::SensorPolar2D* sensorLocal = new obvious::SensorPolar2D(sensor->getRealMeasurementSize(), sensor->getAngularResolution(), sensor->getPhiMin(), 00065 sensor->getMaximumRange(), sensor->getMinimumRange(), sensor->getLowReflectivityRange()); 00066 sensorLocal->setTransformation(sensor->getTransformation()); 00067 sensorLocal->setRealMeasurementData(sensor->getRealMeasurementData()); 00068 sensorLocal->setStandardMask(); 00069 _sensors.push(sensorLocal); 00070 _pushMutex.unlock(); 00071 this->unblock(); 00072 } 00073 00074 } /* namespace */