Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef RTABMAPTHREAD_H_
00029 #define RTABMAPTHREAD_H_
00030
00031 #include "rtabmap/core/RtabmapExp.h"
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
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 }
00135 #endif