RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
rtabmap::RtabmapThread Class Reference

Runs a Rtabmap instance in its own thread, driven by events. More...

#include <RtabmapThread.h>

Inheritance diagram for rtabmap::RtabmapThread:
Collaboration diagram for rtabmap::RtabmapThread:

Public Types

enum  State { kStateDetecting , kStateProcessCommand }
 What the main loop does on its next wake-up. More...
 
- Public Types inherited from UThread
enum  Priority {
  kPLow , kPBelowNormal , kPNormal , kPAboveNormal ,
  kPRealTime
}
 
- Public Types inherited from UThreadC< void >
typedef THREAD_HANDLE Handle
 
typedef void(* Handler) ()
 
typedef THREAD_HANDLE Handle
 
typedef void(* Handler) ()
 

Public Member Functions

 RtabmapThread (Rtabmap *rtabmap)
 Constructor.
 
void clearBufferedData ()
 Drops the buffered frames, the pending user data and the odometry state.
 
void setDetectorRate (float rate)
 Sets the maximum rate at which frames are processed (Hz, 0 = unlimited).
 
void setDataBufferSize (unsigned int bufferSize)
 Sets how many frames may wait in the buffer (0 = unlimited).
 
void createIntermediateNodes (bool enabled)
 Keeps the frames skipped by setDetectorRate() as intermediate nodes.
 
float getDetectorRate () const
 
unsigned int getDataBufferSize () const
 
bool getCreateIntermediateNodes () const
 
void close (bool databaseSaved, const std::string &databasePath="")
 Joins the thread and closes rtabmap. This will delete rtabmap object if set.
 
- Public Member Functions inherited from UThread
 UThread (Priority priority=kPNormal)
 
virtual ~UThread ()
 
void start ()
 
void kill ()
 
void join (bool killFirst=false)
 
void setPriority (Priority priority)
 
void setAffinity (int cpu=0)
 
bool isCreating () const
 
bool isRunning () const
 
bool isIdle () const
 
bool isKilled () const
 
Handle getThreadHandle () const
 
unsigned long getThreadId () const
 
- Public Member Functions inherited from UThreadC< void >
int Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const
 
int Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const
 
int Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const
 
int Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const
 
- Public Member Functions inherited from UEventsHandler
void registerToEventsManager ()
 
void unregisterFromEventsManager ()
 

Protected Member Functions

virtual bool handleEvent (UEvent *anEvent)
 Receives the events listed in the class description.
 
- Protected Member Functions inherited from UEventsHandler
 UEventsHandler ()
 
virtual ~UEventsHandler ()
 
- Protected Member Functions inherited from UEventsSender
void post (UEvent *event, bool async=true) const
 

Additional Inherited Members

- Static Public Member Functions inherited from UThread
static unsigned long currentThreadId ()
 
- Static Public Member Functions inherited from UThreadC< void >
static int Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false)
 
static int Join (Handle H)
 
static int Kill (Handle H)
 
static int Detach (Handle H)
 
static int Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false)
 
static int Join (const Handle &H)
 
static int Kill (const Handle &H)
 
static int Detach (const Handle &H)
 
- Static Protected Member Functions inherited from UThreadC< void >
static void Exit ()
 
static void TestCancel ()
 
static Handle Self ()
 
static void Exit ()
 
static void TestCancel ()
 
static int Self ()
 

Detailed Description

Runs a Rtabmap instance in its own thread, driven by events.

The thread owns the Rtabmap object and calls Rtabmap::process() on the data it receives, so that mapping never blocks the sensor or odometry threads. It is the last stage of the event-based pipeline: SensorCaptureThreadOdometryThreadRtabmapThread.

Input events (handled in handleEvent(), i.e. in the caller's thread):

Output events, posted from the thread:

Input regulation, on top of what Rtabmap does:

  • Frames are queued in a buffer of Parameters::kRtabmapImageBufferSize() elements; when it is full the oldest frame is dropped, so a slow map update never delays the live pipeline.
  • Frames arriving faster than Parameters::kRtabmapDetectionRate() are skipped, which is the rate limiting that Rtabmap::process() itself does not do. With Parameters::kRtabmapCreateIntermediateNodes() enabled they are kept instead, and added as intermediate nodes (odometry-only, not used for loop closure detection).
  • An identity odometry pose, or a covariance ≥ 9999, is read as an odometry reset and triggers a new map id on the next processed frame. The largest covariance seen between two processed frames is the one passed on, so the link weight does not depend on the odometry frame rate.

The object registers itself as a UEventsHandler, so posting an event to UEventsManager is enough to feed it:

rtabmap::RtabmapThread rtabmapThread(new rtabmap::Rtabmap()); // takes ownership
rtabmapThread.start();
UEventsManager::createPipe(&odomThread, &rtabmapThread, "OdometryEvent");
static void addHandler(UEventsHandler *handler)
Runs a Rtabmap instance in its own thread, driven by events.
Top-level RTAB-Map SLAM pipeline (mapping, localization and loop closure).
Definition Rtabmap.h:194
See also
Rtabmap
OdometryThread
SensorCaptureThread

Definition at line 104 of file RtabmapThread.h.

Member Enumeration Documentation

◆ State

What the main loop does on its next wake-up.

Enumerator
kStateDetecting 

Process the next buffered frame.

kStateProcessCommand 

Execute the next queued RtabmapEventCmd.

Definition at line 110 of file RtabmapThread.h.

Constructor & Destructor Documentation

◆ RtabmapThread()

rtabmap::RtabmapThread::RtabmapThread ( Rtabmap rtabmap)

Constructor.

Parameters
rtabmapThe map to run; must not be null. The thread takes ownership and deletes it in close(), which the destructor calls.

The buffer size, detection rate and intermediate node settings are taken from the default parameters here, then updated by every RtabmapEventCmd::kCmdInit and RtabmapEventCmd::kCmdUpdateParams command.

Member Function Documentation

◆ setDetectorRate()

void rtabmap::RtabmapThread::setDetectorRate ( float  rate)

Sets the maximum rate at which frames are processed (Hz, 0 = unlimited).

Same setting as Parameters::kRtabmapDetectionRate(). Frames arriving faster are dropped, or added as intermediate nodes if createIntermediateNodes() is enabled.

◆ setDataBufferSize()

void rtabmap::RtabmapThread::setDataBufferSize ( unsigned int  bufferSize)

Sets how many frames may wait in the buffer (0 = unlimited).

Same setting as Parameters::kRtabmapImageBufferSize(). Once full, the oldest frame is dropped to make room for the new one.

◆ createIntermediateNodes()

void rtabmap::RtabmapThread::createIntermediateNodes ( bool  enabled)

Keeps the frames skipped by setDetectorRate() as intermediate nodes.

Same setting as Parameters::kRtabmapCreateIntermediateNodes(). Those nodes carry the odometry link but take no part in loop closure detection.

◆ getDetectorRate()

float rtabmap::RtabmapThread::getDetectorRate ( ) const
inline
Returns
Maximum processing rate in Hz (0 = unlimited).

Definition at line 155 of file RtabmapThread.h.

◆ getDataBufferSize()

unsigned int rtabmap::RtabmapThread::getDataBufferSize ( ) const
inline
Returns
Maximum number of buffered frames (0 = unlimited).

Definition at line 157 of file RtabmapThread.h.

◆ getCreateIntermediateNodes()

bool rtabmap::RtabmapThread::getCreateIntermediateNodes ( ) const
inline
Returns
True if skipped frames are added as intermediate nodes.

Definition at line 159 of file RtabmapThread.h.

◆ close()

void rtabmap::RtabmapThread::close ( bool  databaseSaved,
const std::string &  databasePath = "" 
)

Joins the thread and closes rtabmap. This will delete rtabmap object if set.

Parameters
databaseSavedtrue=database saved, false=database discarded.
databasePathoutput database file name, ignored if Db/Sqlite3InMemory=false (opened database is then overwritten).

Called by the destructor with databaseSaved true. The object cannot be used afterwards: the Rtabmap instance it owned is gone.

◆ handleEvent()

virtual bool rtabmap::RtabmapThread::handleEvent ( UEvent anEvent)
protectedvirtual

Receives the events listed in the class description.

Runs in the posting thread: data events are only queued here, the work happens in the thread's main loop. Events are ignored until the thread is started.

Returns
Always false, so the event keeps being dispatched to other handlers.

Implements UEventsHandler.


The documentation for this class was generated from the following file: