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 <stack>
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                 kStateAddingUserData,
00070                 kStateSettingGoal,
00071                 kStateCancellingGoal,
00072                 kStateLabelling
00073         };
00074 
00075 public:
00076         // take ownership
00077         RtabmapThread(Rtabmap * rtabmap);
00078         virtual ~RtabmapThread();
00079 
00080         void clearBufferedData();
00081         void setDetectorRate(float rate);
00082         void setDataBufferSize(unsigned int bufferSize);
00083         void createIntermediateNodes(bool enabled);
00084 
00085         // this will delete rtabmap object if set
00086         void close(bool databaseSaved);
00087 
00088 protected:
00089         virtual void handleEvent(UEvent * anEvent);
00090 
00091 private:
00092         virtual void mainLoopBegin();
00093         virtual void mainLoop();
00094         virtual void mainLoopKill();
00095         void process();
00096         void addData(const OdometryEvent & odomEvent);
00097         bool getData(OdometryEvent & data);
00098         void pushNewState(State newState, const ParametersMap & parameters = ParametersMap());
00099         void publishMap(bool optimized, bool full, bool graphOnly) const;
00100 
00101 private:
00102         UMutex _stateMutex;
00103         std::stack<State> _state;
00104         std::stack<ParametersMap> _stateParam;
00105 
00106         std::list<OdometryEvent> _dataBuffer;
00107         UMutex _dataMutex;
00108         USemaphore _dataAdded;
00109         unsigned int _dataBufferMaxSize;
00110         float _rate;
00111         bool _createIntermediateNodes;
00112         UTimer * _frameRateTimer;
00113         double _previousStamp;
00114 
00115         Rtabmap * _rtabmap;
00116         bool _paused;
00117         Transform lastPose_;
00118         double _rotVariance;
00119         double _transVariance;
00120 
00121         cv::Mat _userData;
00122         UMutex _userDataMutex;
00123 };
00124 
00125 } /* namespace rtabmap */
00126 #endif /* RTABMAPTHREAD_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:17