Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding LoopClosure checker to serialize a posegraph correctly #182

Open
wants to merge 2 commits into
base: melodic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion slam_toolbox/lib/karto_sdk/include/karto_sdk/Mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,12 @@ namespace karto
*/
kt_bool TryCloseLoop(LocalizedRangeScan* pScan, const Name& rSensorName);

/**
* Returns the state of a loop closure (True or False)
*/

kt_bool IsLoopClosed();

/**
* Optimizes scan poses
*/
Expand Down Expand Up @@ -910,6 +916,11 @@ namespace karto
*/
GraphTraversal<LocalizedRangeScan>* m_pTraversal;

/**
* Member bool variable to keep track of the state of a loop closure.
*/
kt_bool m_pOptimizerCached;

/**
* Serialization: class MapperGraph
*/
Expand All @@ -923,8 +934,10 @@ namespace karto
ar & BOOST_SERIALIZATION_NVP(m_pMapper);
std::cout << "MapperGraph <- m_pLoopScanMatcher; ";
ar & BOOST_SERIALIZATION_NVP(m_pLoopScanMatcher);
std::cout << "MapperGraph <- m_pTraversal\n";
std::cout << "MapperGraph <- m_pTraversal; ";
ar & BOOST_SERIALIZATION_NVP(m_pTraversal);
std::cout << "MapperGraph <- m_pOptimizerCached\n";
ar & BOOST_SERIALIZATION_NVP(m_pOptimizerCached);
}

}; // MapperGraph
Expand Down Expand Up @@ -2018,6 +2031,14 @@ namespace karto
return m_pGraph->TryCloseLoop(pScan, rSensorName);
}

/**
* Returns the state of a loop closure (True or False)
*/
inline kt_bool IsLoopClosed()
{
return m_pGraph->IsLoopClosed();
}

inline void CorrectPoses()
{
m_pGraph->CorrectPoses();
Expand Down
7 changes: 6 additions & 1 deletion slam_toolbox/lib/karto_sdk/src/Mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ namespace karto
CorrectPoses();

m_pMapper->FireEndLoopClosure("Loop closed!");

m_pOptimizerCached = true;
loopClosed = true;
}
}
Expand All @@ -1538,6 +1538,11 @@ namespace karto
return loopClosed;
}

kt_bool MapperGraph::IsLoopClosed()
{
return m_pOptimizerCached;
}

LocalizedRangeScan* MapperGraph::GetClosestScanToPose(const LocalizedRangeScanVector& rScans,
const Pose2& rPose) const
{
Expand Down
6 changes: 6 additions & 0 deletions slam_toolbox/src/slam_toolbox_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ bool SlamToolbox::serializePoseGraphCallback(
slam_toolbox_msgs::SerializePoseGraph::Response &resp)
/*****************************************************************************/
{
if (!smapper_->getMapper()->IsLoopClosed())
{
ROS_WARN("Could not serialize the map because no loop closure has been detected yet!");
return false;
SteveMacenski marked this conversation as resolved.
Show resolved Hide resolved
}

std::string filename = req.filename;

// if we're inside the snap, we need to write to commonly accessible space
Expand Down