RTAB-Map 0.23.10
Loading...
Searching...
No Matches
RtabmapThread.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef RTABMAPTHREAD_H_
29#define RTABMAPTHREAD_H_
30
31#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
32
33#include <rtabmap/utilite/UThreadNode.h>
34#include <rtabmap/utilite/UEventsHandler.h>
35#include <rtabmap/utilite/USemaphore.h>
36#include <rtabmap/utilite/UMutex.h>
37
38#include "rtabmap/core/RtabmapEvent.h"
39#include "rtabmap/core/SensorData.h"
40#include "rtabmap/core/Parameters.h"
41#include "rtabmap/core/OdometryEvent.h"
42
43#include <queue>
44
45class UTimer;
46
47namespace rtabmap {
48
49class Rtabmap;
50
51class RTABMAP_CORE_EXPORT RtabmapThread :
52 public UThreadNode,
53 public UEventsHandler
54{
55public:
56 enum State {
57 kStateDetecting,
58 kStateProcessCommand
59 };
60
61public:
62 // take ownership
64 virtual ~RtabmapThread();
65
66 void clearBufferedData();
67 void setDetectorRate(float rate);
68 void setDataBufferSize(unsigned int bufferSize);
69 void createIntermediateNodes(bool enabled);
70
71 float getDetectorRate() const {return _rate;}
72 unsigned int getDataBufferSize() const {return _dataBufferMaxSize;}
73 bool getCreateIntermediateNodes() const {return _createIntermediateNodes;}
74
82 void close(bool databaseSaved, const std::string & databasePath = "");
83
84protected:
85 virtual bool handleEvent(UEvent * anEvent);
86
87private:
88 virtual void mainLoopBegin();
89 virtual void mainLoop();
90 virtual void mainLoopKill();
91 void process();
92 void addData(const OdometryEvent & odomEvent);
93 bool getData(OdometryEvent & data);
94 void pushNewState(State newState, const RtabmapEventCmd & cmdEvent = RtabmapEventCmd(RtabmapEventCmd::kCmdUndef));
95 void publishMap(bool optimized, bool full, bool graphOnly) const;
96
97private:
98 UMutex _stateMutex;
99 std::queue<State> _state;
100 std::queue<RtabmapEventCmd> _stateParam;
101
102 std::list<OdometryEvent> _dataBuffer;
103 std::list<double> _newMapEvents;
104 UMutex _dataMutex;
105 USemaphore _dataAdded;
106 unsigned int _dataBufferMaxSize;
107 float _rate;
108 bool _createIntermediateNodes;
109 double _previousStamp;
110
111 Rtabmap * _rtabmap;
112 bool _paused;
113 Transform lastPose_;
114 cv::Mat covariance_;
115
116 cv::Mat _userData;
117 UMutex _userDataMutex;
118};
119
120} /* namespace rtabmap */
121#endif /* RTABMAPTHREAD_H_ */
void close(bool databaseSaved, const std::string &databasePath="")
virtual bool handleEvent(UEvent *anEvent)
Top-level RTAB-Map SLAM pipeline (mapping, localization and loop closure).
Definition Rtabmap.h:194
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53