From 4776de7931bf7613aae2d00a23258137057c1313 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sat, 12 Feb 2022 16:46:10 -0500 Subject: [PATCH] rtabmap: updated proximity paths check order when likehood is not available (use closest node). MainWindow: don't pause when error happens in monitoring mode / ROS. DbViewer: show local transform of scan. --- corelib/src/Rtabmap.cpp | 30 ++++++++++++++++++++++++------ guilib/src/DatabaseViewer.cpp | 5 +++-- guilib/src/MainWindow.cpp | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/corelib/src/Rtabmap.cpp b/corelib/src/Rtabmap.cpp index 58baf32460..573237fed8 100644 --- a/corelib/src/Rtabmap.cpp +++ b/corelib/src/Rtabmap.cpp @@ -1038,23 +1038,32 @@ void Rtabmap::resetMemory() class NearestPathKey { public: - NearestPathKey(float l, int i) : + NearestPathKey(float l, int i, float d) : likelihood(l), - id(i){} + id(i), + distance(d){} bool operator<(const NearestPathKey & k) const { if(likelihood < k.likelihood) { return true; } - else if(likelihood == k.likelihood && id < k.id) + else if(likelihood == k.likelihood) { - return true; + if(distance > k.distance) + { + return true; + } + else if(distance == k.distance && id < k.id) + { + return true; + } } return false; } float likelihood; int id; + float distance; }; //============================================================ @@ -1952,6 +1961,11 @@ bool Rtabmap::process( else if(!signature->isBadSignature() && (smallDisplacement || tooFastMovement)) { _highestHypothesis = lastHighestHypothesis; + UDEBUG("smallDisplacement=%d tooFastMovement=%d", smallDisplacement?1:0, tooFastMovement?1:0); + } + else + { + UDEBUG("Ignoring likelihood and loop closure hypotheses as current signature doesn't have enough visual features."); } //============================================================ @@ -2429,21 +2443,25 @@ bool Rtabmap::process( UDEBUG("got %d paths", (int)nearestPathsNotSorted.size()); // sort nearest paths by highest likelihood (if two have same likelihood, sort by id) std::map > nearestPaths; + Transform currentPoseInv = _optimizedPoses.at(signature->id()); for(std::map >::const_iterator iter=nearestPathsNotSorted.begin();iter!=nearestPathsNotSorted.end(); ++iter) { const std::map & path = iter->second; float highestLikelihood = 0.0f; int highestLikelihoodId = iter->first; + float smallestDistanceSqr = -1; for(std::map::const_iterator jter=path.begin(); jter!=path.end(); ++jter) { float v = uValue(likelihood, jter->first, 0.0f); - if(v > highestLikelihood) + float distance = (currentPoseInv * jter->second).getNormSquared(); + if(v > highestLikelihood || (v == highestLikelihood && (smallestDistanceSqr < 0 || distance < smallestDistanceSqr))) { highestLikelihood = v; highestLikelihoodId = jter->first; + smallestDistanceSqr = distance; } } - nearestPaths.insert(std::make_pair(NearestPathKey(highestLikelihood, highestLikelihoodId), path)); + nearestPaths.insert(std::make_pair(NearestPathKey(highestLikelihood, highestLikelihoodId, smallestDistanceSqr), path)); } UDEBUG("nearestPaths=%d proximityMaxPaths=%d", (int)nearestPaths.size(), _proximityMaxPaths); diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp index 7a613f6bdc..5fd44a243d 100644 --- a/guilib/src/DatabaseViewer.cpp +++ b/guilib/src/DatabaseViewer.cpp @@ -4677,7 +4677,7 @@ void DatabaseViewer::update(int value, if(data.laserScanRaw().size()) { - labelScan->setText(tr("Format=%1 Points=%2 [max=%3] Range=[%4->%5 m] Angle=[%6->%7 rad inc=%8] Has [Color=%9 2D=%10 Normals=%11 Intensity=%12]") + labelScan->setText(tr("Format=%1 Points=%2 [max=%3] Range=[%4->%5 m] Angle=[%6->%7 rad inc=%8] Has [Color=%9 2D=%10 Normals=%11 Intensity=%12] %13") .arg(data.laserScanRaw().formatName().c_str()) .arg(data.laserScanRaw().size()) .arg(data.laserScanRaw().maxPoints()) @@ -4689,7 +4689,8 @@ void DatabaseViewer::update(int value, .arg(data.laserScanRaw().hasRGB()?1:0) .arg(data.laserScanRaw().is2d()?1:0) .arg(data.laserScanRaw().hasNormals()?1:0) - .arg(data.laserScanRaw().hasIntensity()?1:0)); + .arg(data.laserScanRaw().hasIntensity()?1:0) + .arg(data.laserScanRaw().localTransform().prettyPrint().c_str())); } //stereo diff --git a/guilib/src/MainWindow.cpp b/guilib/src/MainWindow.cpp index 93dda47688..210a14eb6e 100644 --- a/guilib/src/MainWindow.cpp +++ b/guilib/src/MainWindow.cpp @@ -962,7 +962,7 @@ bool MainWindow::handleEvent(UEvent* anEvent) { QMetaObject::invokeMethod(_ui->dockWidget_console, "show"); // The timer prevents multiple calls to pauseDetection() before the state can be changed - if(_state != kPaused && _state != kMonitoringPaused && _logEventTime->elapsed() > 1000) + if(_state != kPaused && _state != kMonitoringPaused && _state != kMonitoring && _logEventTime->elapsed() > 1000) { _logEventTime->start(); if(_preferencesDialog->beepOnPause())