mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-11 12:09:51 +08:00
Fixed loadDatabase and backup services fatal error when database is read-only
This commit is contained in:
@@ -908,8 +908,7 @@ CoreWrapper::~CoreWrapper()
|
|||||||
saveDatabase = false;
|
saveDatabase = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rtabmap_.close(saveDatabase);
|
||||||
rtabmap_.close();
|
|
||||||
printf("rtabmap: Saving database/long-term memory...done! (located at %s, %ld MB)\n", databasePath_.c_str(), UFile::length(databasePath_)/(1024*1024));
|
printf("rtabmap: Saving database/long-term memory...done! (located at %s, %ld MB)\n", databasePath_.c_str(), UFile::length(databasePath_)/(1024*1024));
|
||||||
|
|
||||||
delete interOdomSync_;
|
delete interOdomSync_;
|
||||||
@@ -2970,18 +2969,27 @@ bool CoreWrapper::loadDatabaseCallback(rtabmap_msgs::LoadDatabase::Request& req,
|
|||||||
|
|
||||||
// Close old database
|
// Close old database
|
||||||
NODELET_INFO("LoadDatabase: Saving current map (%s)...", databasePath_.c_str());
|
NODELET_INFO("LoadDatabase: Saving current map (%s)...", databasePath_.c_str());
|
||||||
|
bool saveDatabase = true;
|
||||||
if(rtabmap_.getMemory())
|
if(rtabmap_.getMemory())
|
||||||
{
|
{
|
||||||
// save the grid map
|
if(!rtabmap_.getMemory()->isReadOnly())
|
||||||
float xMin=0.0f, yMin=0.0f, gridCellSize = 0.05f;
|
|
||||||
cv::Mat pixels = mapsManager_.getGridMap(xMin, yMin, gridCellSize);
|
|
||||||
if(!pixels.empty())
|
|
||||||
{
|
{
|
||||||
printf("rtabmap: 2D occupancy grid map saved.\n");
|
// save the grid map
|
||||||
rtabmap_.getMemory()->save2DMap(pixels, xMin, yMin, gridCellSize);
|
float xMin=0.0f, yMin=0.0f, gridCellSize = 0.05f;
|
||||||
|
cv::Mat pixels = mapsManager_.getGridMap(xMin, yMin, gridCellSize);
|
||||||
|
if(!pixels.empty())
|
||||||
|
{
|
||||||
|
printf("rtabmap: 2D occupancy grid map saved.\n");
|
||||||
|
rtabmap_.getMemory()->save2DMap(pixels, xMin, yMin, gridCellSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rtabmap: Database is read-only, the current state of the memory is not saved.\n");
|
||||||
|
saveDatabase = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rtabmap_.close();
|
rtabmap_.close(saveDatabase);
|
||||||
NODELET_INFO("LoadDatabase: Saving current map (%s, %ld MB)... done!", databasePath_.c_str(), UFile::length(databasePath_)/(1024*1024));
|
NODELET_INFO("LoadDatabase: Saving current map (%s, %ld MB)... done!", databasePath_.c_str(), UFile::length(databasePath_)/(1024*1024));
|
||||||
|
|
||||||
covariance_ = cv::Mat();
|
covariance_ = cv::Mat();
|
||||||
@@ -3113,18 +3121,27 @@ bool CoreWrapper::triggerNewMapCallback(std_srvs::Empty::Request&, std_srvs::Emp
|
|||||||
bool CoreWrapper::backupDatabaseCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
|
bool CoreWrapper::backupDatabaseCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
|
||||||
{
|
{
|
||||||
NODELET_INFO("Backup: Saving memory...");
|
NODELET_INFO("Backup: Saving memory...");
|
||||||
|
bool saveDatabase = true;
|
||||||
if(rtabmap_.getMemory())
|
if(rtabmap_.getMemory())
|
||||||
{
|
{
|
||||||
// save the grid map
|
if(!rtabmap_.getMemory()->isReadOnly())
|
||||||
float xMin=0.0f, yMin=0.0f, gridCellSize = 0.05f;
|
|
||||||
cv::Mat pixels = mapsManager_.getGridMap(xMin, yMin, gridCellSize);
|
|
||||||
if(!pixels.empty())
|
|
||||||
{
|
{
|
||||||
printf("rtabmap: 2D occupancy grid map saved.\n");
|
// save the grid map
|
||||||
rtabmap_.getMemory()->save2DMap(pixels, xMin, yMin, gridCellSize);
|
float xMin=0.0f, yMin=0.0f, gridCellSize = 0.05f;
|
||||||
|
cv::Mat pixels = mapsManager_.getGridMap(xMin, yMin, gridCellSize);
|
||||||
|
if(!pixels.empty())
|
||||||
|
{
|
||||||
|
printf("rtabmap: 2D occupancy grid map saved.\n");
|
||||||
|
rtabmap_.getMemory()->save2DMap(pixels, xMin, yMin, gridCellSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("rtabmap: Database is read-only, the current state of the memory is not saved.\n");
|
||||||
|
saveDatabase = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rtabmap_.close();
|
rtabmap_.close(saveDatabase);
|
||||||
NODELET_INFO("Backup: Saving memory... done!");
|
NODELET_INFO("Backup: Saving memory... done!");
|
||||||
|
|
||||||
covariance_ = cv::Mat();
|
covariance_ = cv::Mat();
|
||||||
|
|||||||
Reference in New Issue
Block a user