31#include "rtabmap/core/rtabmap_core_export.h"
33#include "rtabmap/core/Parameters.h"
34#include "rtabmap/core/SensorData.h"
35#include "rtabmap/core/Statistics.h"
36#include "rtabmap/core/Link.h"
37#include "rtabmap/core/ProgressState.h"
38#include "rtabmap/core/Graph.h"
40#include <opencv2/core/core.hpp>
48class EpipolarGeometry;
226 const cv::Mat & odomCovariance = cv::Mat::eye(6,6,CV_64FC1),
227 const std::vector<float> & odomVelocity = std::vector<float>(),
228 const std::map<std::string, float> & externalStats = std::map<std::string, float>());
239 float odomLinearVariance,
240 float odomAngularVariance,
241 const std::vector<float> & odomVelocity = std::vector<float>(),
242 const std::map<std::string, float> & externalStats = std::map<std::string, float>());
254 const cv::Mat & image,
255 int id=0,
const std::map<std::string, float> & externalStats = std::map<std::string, float>());
271 void init(
const ParametersMap & parameters,
const std::string & databasePath =
"",
bool loadDatabaseParameters =
false);
282 void init(
const std::string & configFile =
"",
const std::string & databasePath =
"",
bool loadDatabaseParameters =
false);
294 void close(
bool databaseSaved =
true,
const std::string & ouputDatabasePath =
"");
504 const std::string & path,
568 void setOptimizedPoses(
const std::map<int, Transform> & poses,
const std::multimap<int, Link> & constraints);
576 Signature getSignatureCopy(
int id,
bool images,
bool scan,
bool userData,
bool occupancyGrid,
bool withWords,
bool withGlobalDescriptors)
const;
582 void get3DMap(std::map<int, Signature> & signatures,
583 std::map<int, Transform> & poses,
584 std::multimap<int, Link> & constraints,
604 std::multimap<int, Link> & constraints,
607 std::map<int, Signature> * signatures = 0,
608 bool withImages =
false,
609 bool withScan =
false,
610 bool withUserData =
false,
611 bool withGrid =
false,
612 bool withWords =
true,
613 bool withGlobalDescriptors =
true)
const;
635 std::map<int, Transform>
getNodesInRadius(
int nodeId,
float radius,
int k=0, std::map<int, float> * distsSqr=0);
664 float clusterRadiusMax = 0.5f,
665 float clusterAngle = M_PI/6.0f,
667 bool intraSession =
true,
668 bool interSession =
true,
670 float clusterRadiusMin = 0.0f,
671 int toFromMapId = -1);
685 int optimizerType = 1 ,
686 bool rematchFeatures =
true,
688 float pixelVariance = 0.0f);
698 const std::map<int, Transform> & mapPoses,
704 bool filterScans =
false);
805 const std::vector<std::pair<int, Transform> > &
getPath()
const {
return _path;}
843 std::map<int, Transform>
getForwardWMPoses(
int fromId,
int maxNearestNeighbors,
float radius,
int maxDiffID)
const;
879 std::map<int, std::map<int, Transform> >
getPaths(
const std::map<int, Transform> & poses,
const Transform & target,
int maxGraphDepth = 0)
const;
913 void setInitialGuessFromPreviousMaps(
915 const std::map<int, Transform> & guessPoses,
916 const std::multimap<int, Link> & links,
917 std::map<int, Transform> & poses)
const;
918 void updatePreviousMapsOptimizedPoses(
const std::multimap<int, Link> * newLinks = 0);
919 void optimizeCurrentMap(
int id,
921 std::map<int, Transform> & optimizedPoses,
922 cv::Mat & covariance,
923 std::multimap<int, Link> * constraints = 0,
925 int * iterationsDone = 0)
const;
926 std::map<int, Transform> optimizeGraph(
928 const std::set<int> & ids,
929 const std::map<int, Transform> & guessPoses,
931 cv::Mat & covariance,
932 std::multimap<int, Link> * constraints = 0,
934 int * iterationsDone = 0)
const;
935 Link findLoopClosureToRepair(
937 const std::map<int, Transform> & poses,
938 const std::multimap<int, Link> & constraints,
939 const std::set<std::pair<int, int> > & newLinks)
const;
940 std::list<std::pair<int, int> > repairGraph(
941 const Link & linkToRemove,
943 std::map<int, Transform> & poses,
944 std::multimap<int, Link> & constraints,
945 double & optimizationError,
946 int & optimizationIterations,
947 cv::Mat & optimizationCovariance,
948 const std::set<std::pair<int, int> > & newLinks);
949 bool hasLocalizationLinksInOdomCache()
const;
950 bool isLandmarkNormalValid(
const Signature * signature,
int landmarkId,
const Link & landmarkLink,
bool localized,
float * error = 0)
const;
951 void updateGoalIndex();
952 bool computePath(
int targetNode, std::map<int, Transform> nodes,
const std::multimap<int, rtabmap::Link> & constraints);
954 void createGlobalScanMap();
956 void setupLogFiles(
bool overwrite =
false);
957 void flushStatisticLogs();
962 bool _publishLastSignatureData;
964 bool _publishLikelihood;
965 bool _publishRAMUsage;
968 float _maxTimeAllowed;
969 unsigned int _maxMemoryAllowed;
972 float _aggressiveLoopThr;
973 int _virtualPlaceLikelihoodRatio;
974 float _maxLoopClosureDistance;
975 bool _verifyLoopClosureHypothesis;
976 unsigned int _maxRetrieved;
977 unsigned int _maxLocalRetrieved;
978 unsigned int _maxRepublished;
980 bool _statisticLogsBufferedInRAM;
981 bool _statisticLogged;
982 bool _statisticLoggedHeaders;
984 float _rgbdLinearUpdate;
985 float _rgbdAngularUpdate;
986 float _rgbdLinearSpeedUpdate;
987 float _rgbdAngularSpeedUpdate;
988 float _newMapOdomChangeDistance;
989 bool _neighborLinkRefining;
990 bool _proximityByTime;
991 bool _proximityBySpace;
992 bool _scanMatchingIdsSavedInLinks;
993 bool _loopClosureIdentityGuess;
995 float _localImmunizationRatio;
996 int _proximityMaxGraphDepth;
997 int _proximityMaxPaths;
998 int _proximityMaxNeighbors;
999 float _proximityFilteringRadius;
1000 bool _proximityRawPosesUsed;
1001 float _proximityAngle;
1002 bool _proximityOdomGuess;
1003 double _proximityMergedScanCovFactor;
1004 std::string _databasePath;
1005 bool _optimizeFromGraphEnd;
1006 float _optimizationMaxError;
1007 float _optimizationMaxErrorRepairRadius;
1008 bool _startNewMapOnLoopClosure;
1009 bool _startNewMapOnGoodSignature;
1010 float _goalReachedRadius;
1011 bool _goalsSavedInUserData;
1012 int _pathStuckIterations;
1013 float _pathLinearVelocity;
1014 float _pathAngularVelocity;
1015 bool _forceOdom3doF;
1016 bool _restartAtOrigin;
1017 bool _loopCovLimited;
1019 int _maxOdomCacheSize;
1020 float _landmarkMaxNormalError;
1021 bool _localizationSmoothing;
1022 double _localizationPriorInf;
1023 bool _localizationSecondTryWithoutProximityLinks;
1024 bool _createGlobalScanMap;
1025 float _markerPriorsLinearVariance;
1026 float _markerPriorsAngularVariance;
1028 std::pair<int, float> _loopClosureHypothesis;
1029 std::pair<int, float> _highestHypothesis;
1030 double _lastProcessTime;
1031 bool _someNodesHaveBeenTransferred;
1032 float _distanceTravelled;
1033 float _distanceTravelledSinceLastLocalization;
1034 bool _optimizeFromGraphEndChanged;
1047 std::list<std::string> _bufferedLogsF;
1048 std::list<std::string> _bufferedLogsI;
1054 std::map<int, Transform> _optimizedPoses;
1055 std::multimap<int, Link> _constraints;
1056 std::list<std::map<int, Transform> > _previousMapsOptimizedPoses;
1060 int _lastLocalizationNodeId;
1061 bool _localizationApplied;
1062 cv::Mat _localizationCovariance;
1063 std::map<int, std::pair<cv::Point3d, Transform> > _gpsGeocentricCache;
1064 bool _currentSessionHasGPS;
1066 std::map<int, Transform> _globalScanMapPoses;
1067 std::map<int, Transform> _odomCachePoses;
1068 std::multimap<int, Link> _odomCacheConstraints;
1069 std::map<int, Transform> _markerPriors;
1070 std::pair<int, int> _lastRejectedLoopClosureIds;
1072 std::set<int> _nodesToRepublish;
1076 std::vector<std::pair<int,Transform> > _path;
1077 std::set<unsigned int> _pathUnreachableNodes;
1078 unsigned int _pathCurrentIndex;
1079 unsigned int _pathGoalIndex;
1081 int _pathStuckCount;
1082 float _pathStuckDistance;
1084 bool _dummyDictionary;
Recursive Bayesian filter for loop-closure hypothesis estimation in RTAB-Map.
Represents 2D or 3D laser scan data with support for multiple point data formats.
Directed constraint between two nodes in RTAB-Map's pose graph.
Three-tiered memory management (STM, WM, LTM) for RTAB-Map.
Abstract base for pose-graph and bundle-adjustment optimizers.
Top-level RTAB-Map SLAM pipeline (mapping, localization and loop closure).
bool setUserData(int id, const cv::Mat &data)
Attaches user data to signature id, compressing it on the fly if needed.
const Memory * getMemory() const
void addNodesToRepublish(const std::vector< int > &ids)
Marks node ids whose data should be re-emitted on the next process().
bool computePath(const Transform &targetPose, float tolerance=-1.0f)
Plans a path in the current optimized map toward a metric goal pose.
std::map< int, Transform > getNodesInRadius(const Transform &pose, float radius, int k=0, std::map< int, float > *distsSqr=0)
Returns optimized poses within a metric radius of pose.
void setWorkingDirectory(std::string path)
Sets the working directory used for dumps, logs and temporary files.
void init(const std::string &configFile="", const std::string &databasePath="", bool loadDatabaseParameters=false)
Initializes Rtabmap from a configuration file and a database.
int getLoopClosureId() const
const Transform & getLastLocalizationPose() const
std::map< int, int > getWeights() const
bool process(const cv::Mat &image, int id=0, const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Appearance-only convenience overload (loop-closure detection without odometry).
void dumpData() const
Dumps the Memory state (signatures, words, dictionary) to the working directory.
void generateDOTGraph(const std::string &path, int id=0, int margin=5)
Writes a Graphviz DOT file of the pose graph.
void getGraph(std::map< int, Transform > &poses, std::multimap< int, Link > &constraints, bool optimized, bool global, std::map< int, Signature > *signatures=0, bool withImages=false, bool withScan=false, bool withUserData=false, bool withGrid=false, bool withWords=true, bool withGlobalDescriptors=true) const
Extracts a full snapshot of the current pose graph.
std::vector< int > getPathNextNodes() const
int triggerNewMap()
Starts a new map session (next process() will create a fresh map id).
const std::multimap< int, Link > & getLocalConstraints() const
void setDummyDictionary(bool enabled=true)
Loads the visual word dictionary as ids only, without descriptors.
float getHighestHypothesisValue() const
void clearPath(int status)
Clears the current path and sets its terminal status.
bool isInSTM(int locationId) const
void parseParameters(const ParametersMap ¶meters)
Re-parses parameters and propagates them to owned sub-objects (Memory, BayesFilter,...
const Statistics & getStatistics() const
void close(bool databaseSaved=true, const std::string &ouputDatabasePath="")
Closes Rtabmap and releases the underlying Memory.
bool isIDsGenerated() const
int getPathCurrentGoalId() const
const std::vector< std::pair< int, Transform > > & getPath() const
int detectMoreLoopClosures(float clusterRadiusMax=0.5f, float clusterAngle=M_PI/6.0f, int iterations=1, bool intraSession=true, bool interSession=true, const ProgressState *state=0, float clusterRadiusMin=0.0f, int toFromMapId=-1)
Post-processing: searches for additional loop closures over the existing graph.
float getGoalReachedRadius() const
const std::string & getWorkingDir() const
int refineLinks()
Re-runs registration on every link of the current graph and updates the ones that converge.
void setMemoryThreshold(int maxMemoryAllowed)
Sets the maximum number of signatures kept in WM (0 = unbounded).
float getLocalRadius() const
void init(const ParametersMap ¶meters, const std::string &databasePath="", bool loadDatabaseParameters=false)
Initializes Rtabmap with parameters and a database.
Signature getSignatureCopy(int id, bool images, bool scan, bool userData, bool occupancyGrid, bool withWords, bool withGlobalDescriptors) const
Returns a copy of signature id with optional payloads attached.
unsigned int getPathCurrentGoalIndex() const
void setOptimizedPoses(const std::map< int, Transform > &poses, const std::multimap< int, Link > &constraints)
Replaces the current optimized poses and constraints with externally provided ones.
Transform getMapCorrection() const
std::set< int > getSTM() const
void setTimeThreshold(float maxTimeAllowed)
Sets the per-iteration time budget (ms).
std::map< int, Transform > getForwardWMPoses(int fromId, int maxNearestNeighbors, float radius, int maxDiffID) const
Returns optimized poses of WM nodes located in front of fromId.
int getMemoryThreshold() const
double getLastProcessTime() const
bool process(const SensorData &data, Transform odomPose, float odomLinearVariance, float odomAngularVariance, const std::vector< float > &odomVelocity=std::vector< float >(), const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Convenience overload: builds a diagonal covariance from scalar variances.
int getLastLocationId() const
unsigned int getPathCurrentIndex() const
void setInitialPose(const Transform &initialPose)
Sets the localization prior pose used to seed the next process() call (localization mode only).
const ParametersMap & getParameters() const
std::map< int, Transform > getNodesInRadius(int nodeId, float radius, int k=0, std::map< int, float > *distsSqr=0)
Returns optimized poses within a metric radius of node nodeId.
void adjustLikelihood(std::map< int, float > &likelihood) const
Applies the standard RTAB-Map likelihood adjustment.
void rejectLastLoopClosure()
Removes the loop-closure link added at the last process() iteration.
bool globalBundleAdjustment(int optimizerType=1, bool rematchFeatures=true, int iterations=0, float pixelVariance=0.0f)
Runs a global bundle adjustment over the optimized graph.
int getHighestHypothesisId() const
int getTotalMemSize() const
bool computePath(int targetNode, bool global)
Plans a path from the current location to node targetNode.
Transform getPose(int locationId) const
int cleanupLocalGrids(const std::map< int, Transform > &mapPoses, const cv::Mat &map, float xMin, float yMin, float cellSize, int cropRadius=1, bool filterScans=false)
Filters spurious obstacles from every node's local grid using a reference 2D map.
void dumpPrediction() const
Dumps the Bayes-filter prediction matrix to a file in the working directory.
std::map< int, std::map< int, Transform > > getPaths(const std::map< int, Transform > &poses, const Transform &target, int maxGraphDepth=0) const
Segments a set of optimized poses into paths connected by neighbor links.
bool process(const SensorData &data, Transform odomPose, const cv::Mat &odomCovariance=cv::Mat::eye(6, 6, CV_64FC1), const std::vector< float > &odomVelocity=std::vector< float >(), const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Main RTAB-Map iteration: ingests one sensor frame and updates the map.
float getLoopClosureValue() const
std::list< int > getWM() const
RTABMAP_DEPRECATED void get3DMap(std::map< int, Signature > &signatures, std::map< int, Transform > &poses, std::multimap< int, Link > &constraints, bool optimized, bool global) const
Deprecated: use getGraph() instead with withImages=true, withScan=true, withUserData=true and withGri...
const std::map< int, Transform > & getLocalOptimizedPoses() const
const Transform & getPathTransformToGoal() const
void deleteLastLocation()
Deletes the most recent (non-intermediate) location from the map.
cv::Mat getInformation(const cv::Mat &covariance) const
Converts an odometry covariance into an information matrix, clipping by Memory::getOdomMaxInf() when ...
bool addLink(const Link &link)
Adds an external link to the map.
void exportPoses(const std::string &path, bool optimized, bool global, int format)
Exports the current pose graph to a text file.
void resetMemory()
Clears all in-memory state and resets the database.
bool labelLocation(int id, const std::string &label)
Assigns or clears a label on signature id.
float getTimeThreshold() const
std::vector< std::pair< int, Transform > > getPathNextPoses() const
VhStrategy
Loop-closure verification strategy.
@ kVhEpipolar
Epipolar geometry verification (mostly historical, RGB-only mode).
@ kVhNone
No verification: the highest hypothesis above threshold is accepted.
int getPathStatus() const
Container class for all sensor data captured at a specific time.
Represents a node in RTAB-Map's pose graph.
Collects and manages runtime statistics for RTAB-Map.
std::map< std::string, std::string > ParametersMap
Parameter keys mapped to their values, as used by every configurable class (see Parameters).
Largest pose-graph constraint violations after optimization.