49 int64_t CHMTSLAM::m_nextAreaLabel = 0;
50 TPoseID CHMTSLAM::m_nextPoseID = 0;
60 m_terminateThreads =
false;
61 m_terminationFlag_LSLAM = m_terminationFlag_TBI =
62 m_terminationFlag_3D_viewer =
false;
66 m_hThread_LSLAM = std::thread(&CHMTSLAM::thread_LSLAM,
this);
67 m_hThread_TBI = std::thread(&CHMTSLAM::thread_TBI,
this);
68 m_hThread_3D_viewer = std::thread(&CHMTSLAM::thread_3D_viewer,
this);
71 m_LSLAM_method =
nullptr;
75 registerLoopClosureDetector(
76 "gridmaps", &CTopLCDetector_GridMatching::createNewInstance);
77 registerLoopClosureDetector(
78 "fabmap", &CTopLCDetector_FabMap::createNewInstance);
91 m_terminateThreads =
true;
95 MRPT_LOG_DEBUG(
"[CHMTSLAM::destructor] Waiting for threads end...\n");
97 m_hThread_3D_viewer.join();
98 m_hThread_LSLAM.join();
105 if (!m_options.LOG_OUTPUT_DIR.empty())
119 catch (std::exception& e)
123 "Ignoring exception at ~CHMTSLAM():\n%s", e.what()));
138 delete m_LSLAM_method;
139 m_LSLAM_method =
nullptr;
144 std::lock_guard<std::mutex> lock(m_topLCdets_cs);
148 it != m_topLCdets.end(); ++it)
157 void CHMTSLAM::clearInputQueue()
161 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
163 while (!m_inputQueue.empty())
176 if (m_terminateThreads)
184 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
185 m_inputQueue.push(acts);
194 if (m_terminateThreads)
202 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
203 m_inputQueue.push(sf);
212 if (m_terminateThreads)
224 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
225 m_inputQueue.push(sf);
234 m_options.loadFromConfigFile(cfg,
"HMT-SLAM");
236 m_options.defaultMapsInitializers.loadFromConfigFile(cfg,
"MetricMaps");
238 m_options.pf_options.loadFromConfigFile(cfg,
"PARTICLE_FILTER");
240 m_options.KLD_params.loadFromConfigFile(cfg,
"KLD");
242 m_options.AA_options.loadFromConfigFile(cfg,
"GRAPH_CUT");
245 m_options.TLC_grid_options.loadFromConfigFile(cfg,
"TLC_GRIDMATCHING");
246 m_options.TLC_fabmap_options.loadFromConfigFile(cfg,
"TLC_FABMAP");
248 m_options.dumpToConsole();
264 CHMTSLAM::TOptions::TOptions()
269 SLAM_METHOD = lsmRBPF_2DLASER;
271 SLAM_MIN_DIST_BETWEEN_OBS = 1.0f;
272 SLAM_MIN_HEADING_BETWEEN_OBS =
DEG2RAD(25.0f);
274 MIN_ODOMETRY_STD_XY = 0;
275 MIN_ODOMETRY_STD_PHI = 0;
277 VIEW3D_AREA_SPHERES_HEIGHT = 10.0f;
278 VIEW3D_AREA_SPHERES_RADIUS = 1.0f;
282 TLC_detectors.clear();
284 stds_Q_no_odo.resize(3);
285 stds_Q_no_odo[0] = stds_Q_no_odo[1] = 0.10f;
286 stds_Q_no_odo[2] =
DEG2RAD(4.0f);
292 void CHMTSLAM::TOptions::loadFromConfigFile(
312 stds_Q_no_odo[2] =
RAD2DEG(stds_Q_no_odo[2]);
313 source.read_vector(section,
"stds_Q_no_odo", stds_Q_no_odo, stds_Q_no_odo);
314 ASSERT_(stds_Q_no_odo.size() == 3);
316 stds_Q_no_odo[2] =
DEG2RAD(stds_Q_no_odo[2]);
319 source.read_string(section,
"TLC_detectors",
"",
true);
323 std::cout <<
"TLC_detectors: " << TLC_detectors.size() << std::endl;
326 AA_options.loadFromConfigFile(
source, section);
332 void CHMTSLAM::TOptions::dumpToTextStream(std::ostream& out)
const 334 out <<
mrpt::format(
"\n----------- [CHMTSLAM::TOptions] ------------ \n\n");
349 AA_options.dumpToTextStream(out);
350 pf_options.dumpToTextStream(out);
351 KLD_params.dumpToTextStream(out);
352 defaultMapsInitializers.dumpToTextStream(out);
353 TLC_grid_options.dumpToTextStream(out);
354 TLC_fabmap_options.dumpToTextStream(out);
360 bool CHMTSLAM::isInputQueueEmpty()
365 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
366 res = m_inputQueue.empty();
374 size_t CHMTSLAM::inputQueueSize()
378 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
379 res = m_inputQueue.size();
392 std::lock_guard<std::mutex> lock(m_inputQueue_cs);
393 if (!m_inputQueue.empty())
395 obj = m_inputQueue.front();
405 void CHMTSLAM::initializeEmptyMap()
411 LMH_hyps.insert(newHypothID);
418 std::lock_guard<std::mutex> lock(m_map_cs);
426 mrpt::make_aligned_shared<CHMHMapNode>(&m_map);
427 firstAreaID = firstArea->getID();
429 firstArea->m_hypotheses = LMH_hyps;
433 firstArea->m_nodeType =
"Area";
434 firstArea->m_label = generateUniqueAreaLabel();
435 firstArea->m_annotations.set(
437 firstArea->m_annotations.setElemental(
445 std::lock_guard<std::mutex> lock(m_LMHs_cs);
455 newLMH.
m_ID = newHypothID;
466 switch (m_options.SLAM_METHOD)
468 case lsmRBPF_2DLASER:
470 if (m_LSLAM_method)
delete m_LSLAM_method;
476 "Invalid selection for LSLAM method: %i",
477 (
int)m_options.SLAM_METHOD);
484 std::lock_guard<std::mutex> lock(m_topLCdets_cs);
488 it != m_topLCdets.end(); ++it)
496 m_options.TLC_detectors.begin();
497 d != m_options.TLC_detectors.end(); ++d)
498 m_topLCdets.push_back(loopClosureDetector_factory(*d));
504 m_LSLAM_queue.clear();
509 if (!m_options.LOG_OUTPUT_DIR.empty())
518 m_options.LOG_OUTPUT_DIR +
"/HMTSLAM_state");
527 return format(
"%li", (
long int)(m_nextAreaLabel++));
533 TPoseID CHMTSLAM::generatePoseID() {
return m_nextPoseID++; }
549 bool CHMTSLAM::abortedDueToErrors()
551 return m_terminationFlag_LSLAM || m_terminationFlag_TBI ||
552 m_terminationFlag_3D_viewer;
558 void CHMTSLAM::registerLoopClosureDetector(
561 m_registeredLCDetectors[
name] = ptrCreateObject;
572 m_registeredLCDetectors.find(
name);
573 if (it == m_registeredLCDetectors.end())
575 "Invalid value for TLC_detectors: %s",
name.c_str());
576 return it->second(
this);
617 std::lock_guard<std::mutex> lock_map(m_map_cs);
620 in >> m_nextAreaLabel >> m_nextPoseID >> m_nextHypID;
633 uint8_t CHMTSLAM::serializeGetVersion()
const {
return 0; }
638 std::lock_guard<std::mutex> lock_map(m_map_cs);
641 out << m_nextAreaLabel << m_nextPoseID << m_nextHypID;
bool createDirectory(const std::string &dirName)
Creates a directory.
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
Implements a 2D local SLAM method based on a RBPF over an occupancy grid map.
THypothesisID m_ID
The unique ID of the hypothesis (Used for accessing mrpt::slam::CHierarchicalMHMap).
double RAD2DEG(const double x)
Radians to degrees.
#define COMMON_TOPOLOG_HYP
mrpt::graphs::TNodeID TNodeID
The type of the IDs of nodes.
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
double DEG2RAD(const double x)
Degrees to radians.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
uint64_t TPoseID
An integer number uniquely identifying each robot pose stored in HMT-SLAM.
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
double m_log_w
Log-weight of this hypothesis.
GLsizei GLsizei GLuint * obj
An implementation of Hybrid Metric Topological SLAM (HMT-SLAM).
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
This class allows loading and storing values and vectors of different types from a configuration text...
A set of hypothesis IDs, used for arcs and nodes in multi-hypothesis hybrid maps. ...
This namespace contains representation of robot actions and observations.
The virtual base class for Topological Loop-closure Detectors; used in HMT-SLAM.
This class is used in HMT-SLAM to represent each of the Local Metric Hypotheses (LMHs).
#define NODE_ANNOTATION_METRIC_MAPS
GLsizei const GLchar ** string
#define LOADABLEOPTS_DUMP_VAR(variableName, variableType)
Macro for dumping a variable to a stream, within the method "dumpToTextStream(out)" (Variable types a...
#define MRPT_LOAD_CONFIG_VAR( variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
int64_t THypothesisID
An integer number uniquely identifying each of the concurrent hypotheses for the robot topological pa...
Virtual base class for "archives": classes abstracting I/O streams.
mrpt::safe_ptr< CHMTSLAM > m_parent
For quick access to our parent object.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define LOADABLEOPTS_DUMP_VAR_DEG(variableName)
Macro for dumping a variable to a stream, transforming the argument from radians to degrees...
The namespace for 3D scene representation and rendering.
void clearRobotPoses()
Rebuild the auxiliary metric maps in "m_robotPosesGraph" from the observations "m_SFs" and their esti...
GLuint const GLchar * name
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
GLsizei GLsizei GLchar * source
The virtual base class which provides a unified interface for all persistent objects in MRPT...
#define NODE_ANNOTATION_REF_POSEID
bool deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell=false)
Delete all the files in a given directory (nothing done if directory does not exists, or path is a file).
#define MRPT_LOG_WARN(_STRING)
#define MRPT_LOAD_CONFIG_VAR_DEGREES( variableName, configFileObject, sectionNameStr)
Loads a double variable, stored as radians but entered in the INI-file as degrees.
This class stores any customizable set of metric maps.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
const Scalar * const_iterator
TNodeIDSet m_neighbors
The list of all areas sourronding the current one (this includes the current area itself)...
#define MRPT_LOAD_CONFIG_VAR_CAST_NO_DEFAULT( variableName, variableType, variableTypeCast, configFileObject, sectionNameStr)
TPoseID m_currentRobotPose
The current robot pose (its global unique ID) for this hypothesis.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.