RtabmapThread.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef RTABMAPTHREAD_H_
00029 #define RTABMAPTHREAD_H_
00030 
00031 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
00032 
00033 #include <rtabmap/utilite/UThreadNode.h>
00034 #include <rtabmap/utilite/UEventsHandler.h>
00035 #include <rtabmap/utilite/USemaphore.h>
00036 #include <rtabmap/utilite/UMutex.h>
00037 
00038 #include "rtabmap/core/RtabmapEvent.h"
00039 #include "rtabmap/core/SensorData.h"
00040 #include "rtabmap/core/Parameters.h"
00041 #include "rtabmap/core/OdometryEvent.h"
00042 
00043 #include <queue>
00044 
00045 class UTimer;
00046 
00047 namespace rtabmap {
00048 
00049 class Rtabmap;
00050 
00051 class RTABMAP_EXP RtabmapThread :
00052         public UThreadNode,
00053         public UEventsHandler
00054 {
00055 public:
00056         enum State {
00057                 kStateInit,
00058                 kStateDetecting,
00059                 kStateReseting,
00060                 kStateClose,
00061                 kStateChangingParameters,
00062                 kStateDumpingMemory,
00063                 kStateDumpingPrediction,
00064                 kStateExportingDOTGraph,
00065                 kStateExportingPoses,
00066                 kStateCleanDataBuffer,
00067                 kStatePublishingMap,
00068                 kStateTriggeringMap,
00069                 kStateSettingGoal,
00070                 kStateCancellingGoal,
00071                 kStateLabelling
00072         };
00073 
00074 public:
00075         // take ownership
00076         RtabmapThread(Rtabmap * rtabmap);
00077         virtual ~RtabmapThread();
00078 
00079         void clearBufferedData();
00080         void setDetectorRate(float rate);
00081         void setDataBufferSize(unsigned int bufferSize);
00082         void createIntermediateNodes(bool enabled);
00083 
00084         float getDetectorRate() const {return _rate;}
00085         unsigned int getDataBufferSize() const {return _dataBufferMaxSize;}
00086         bool getCreateIntermediateNodes() const {return _createIntermediateNodes;}
00087 
00095         void close(bool databaseSaved, const std::string & databasePath = "");
00096 
00097 protected:
00098         virtual bool handleEvent(UEvent * anEvent);
00099 
00100 private:
00101         virtual void mainLoopBegin();
00102         virtual void mainLoop();
00103         virtual void mainLoopKill();
00104         void process();
00105         void addData(const OdometryEvent & odomEvent);
00106         bool getData(OdometryEvent & data);
00107         void pushNewState(State newState, const ParametersMap & parameters = ParametersMap());
00108         void publishMap(bool optimized, bool full, bool graphOnly) const;
00109 
00110 private:
00111         UMutex _stateMutex;
00112         std::queue<State> _state;
00113         std::queue<ParametersMap> _stateParam;
00114 
00115         std::list<OdometryEvent> _dataBuffer;
00116         std::list<double> _newMapEvents;
00117         UMutex _dataMutex;
00118         USemaphore _dataAdded;
00119         unsigned int _dataBufferMaxSize;
00120         float _rate;
00121         bool _createIntermediateNodes;
00122         UTimer * _frameRateTimer;
00123         double _previousStamp;
00124 
00125         Rtabmap * _rtabmap;
00126         bool _paused;
00127         Transform lastPose_;
00128         cv::Mat covariance_;
00129 
00130         cv::Mat _userData;
00131         UMutex _userDataMutex;
00132 };
00133 
00134 } /* namespace rtabmap */
00135 #endif /* RTABMAPTHREAD_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:22